forked from rgmelko/Spin-Models-on-GPU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.cu
107 lines (92 loc) · 3.09 KB
/
launcher.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*!
\file launcher.cu
\brief Controller code that launches Hamiltonian generation and Lanczos diagonalization
*/
#include "lattice.h"
#include <cstdlib>
#include "cuda.h"
#include <fstream>
#include <iostream>
#include "lanczos.h"
//#include"hamiltonian.h"
int main()
{
for(int i = 0; i < 1; i++)
{
int** Bond;
//cout<<i<<" "<<endl;
int how_many;
/*if (i == 1)
{
how_many = 5;
}*/
ifstream fin;
fin.open("data.dat");
fin >> how_many ;
Bond = (int**)malloc(how_many*sizeof(int*));
d_hamiltonian* hamil_lancz = (d_hamiltonian*)malloc(how_many*sizeof(d_hamiltonian));
parameters* data = (parameters*)malloc(how_many*sizeof(parameters));
double** groundstates = (double**)malloc(how_many*sizeof(double*));
double** eigenvalues = (double**)malloc(how_many*sizeof(double*));
if (data == NULL)
{
cerr<<"Malloc of parameter container failed!"<<endl;
return 1;
}
int* num_Elem = (int*)malloc(how_many*sizeof(int));
//cudaSetDevice(1);
int device = 1; //i%2;
for(int i = 0; i < how_many; i++)
{
fin >> data[i].nsite >> data[i].Sz >> data[i].J1 >> data[i].J2 >> data[i].modelType >> data[i].dimension;
switch (data[i].dimension)
{
case 1:
Bond[i] = (int*)malloc(2*data[i].nsite*sizeof(int));
for( int j = 0; j < data[i].nsite; j++ ){
Bond[i][j] = j;
Bond[i][j+ data[i].nsite] = (j+1)%data[i].nsite;
}
break;
case 2:
Bond[i] = (int*)malloc(3*data[i].nsite*sizeof(int));
Fill_Bonds_16B(Bond[i]);
break;
}
eigenvalues[i] = (double*)malloc(3*sizeof(double));
}
/*cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);*/
//float time;
//cudaEventRecord(start,0);
ConstructSparseMatrix(how_many, Bond, hamil_lancz, data, num_Elem, device);
/*cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
cout<<"Time to construct Hamiltonians: "<<time<<endl;
cudaEventRecord(start,0);
*/
lanczos(how_many, num_Elem, hamil_lancz, groundstates, eigenvalues, 200, 3, 1e-12);
/*
cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
cout<<"Time to perform Lanczos: "<<time<<endl;*/
for(int j = 0; j<how_many; j++)
{
cudaFree(hamil_lancz[j].rows);
cudaFree(hamil_lancz[j].cols);
cudaFree(hamil_lancz[j].vals);
cudaFree(groundstates[j]);
}
//cudaEventDestroy(start);
//cudaEventDestroy(stop);
free(data);
free(Bond);
free(hamil_lancz);
free(num_Elem);
free(groundstates);
}
return 0;
}