StatMech
Loading...
Searching...
No Matches
constructGlobal_h_gpu.cu File Reference

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
12 {
13 if(argc != 6) {
14 std::cerr << "Usage: constructGlobal_h 1.N 2.Momentum 3.Type 4.Param 5.InputFile for matLoc"
15 << std::endl;
16 std::exit(EX_USAGE);
17 }
18 Integer_t N = (Integer_t)std::atoi(argv[1]);
19 Integer_t momentum = (Integer_t)std::atoi(argv[2]);
20
21 char* initStr[9];
22 initStr[1] = argv[1];
23 initStr[2] = argv[1];
24 initStr[7] = argv[3];
25 initStr[8] = argv[4];
26 Initialize(9, (char**)initStr);
27
28 std::string InFName(argv[5]);
29 std::ifstream Infs(InFName);
30 Infs.exceptions(std::ios::badbit);
31 if(!Infs.is_open()) {
32 std::cerr << "Can't open a file \"" << InFName << "\"" << std::endl;
33 std::exit(EX_NOINPUT);
34 }
35 try {
36 skip_header(Infs);
37 }
38 catch(std::exception& e) {
39 std::cerr << "Error(skip_header): " << e.what() << std::endl;
40 std::cerr << "File: \"" << InFName << "\" is empty." << std::endl;
41 std::exit(EX_NOINPUT);
42 }
43 Infs.exceptions(std::ifstream::badbit);
44
45 std::cout << "########## Input ##########" << std::endl;
46 bool dimLocFlag = false, numLocFlag = false;
47 Integer_t dimLoc = 0, numLoc = 0, dimLocMat = 0;
48 matrix<Complex_t> matLoc;
49 std::string str;
50 std::stringstream ss;
51 auto oldPos = Infs.tellg();
52 while(std::getline(Infs, str)) {
53 ss.str(str);
54 ss.clear(std::stringstream::goodbit);
55 ss >> str;
56 if(str.find("dimLoc") != std::string::npos) {
57 ss >> str;
58 dimLoc = std::atoi(str.c_str());
59 dimLocFlag = true;
60 }
61 else if(str.find("numLoc") != std::string::npos) {
62 ss >> str;
63 numLoc = std::atoi(str.c_str());
64 numLocFlag = true;
65 }
66 else if(str.find("mat") != std::string::npos) {
67 if(dimLocFlag && numLocFlag != true) {
68 std::cerr << "Error: Invalid data format." << std::endl;
69 std::exit(EX_DATAERR);
70 }
71 dimLocMat = pow(dimLoc, numLoc);
72 Infs.seekg(oldPos);
73 std::cout << "dimLocMat=" << dimLocMat << std::endl;
74 matLoc.resize(dimLocMat, dimLocMat);
75 readMatrix(Infs, dimLocMat, matLoc);
76 std::cout << "matLoc:" << std::endl;
77 matLoc.print(dimLocMat, dimLocMat);
78 }
79 oldPos = Infs.tellg();
80 }
81
82 magma_init();
83 magma_queue_t queue = NULL;
84 magma_int_t dev = 0;
85 magma_getdevice(&dev);
86 magma_queue_create(dev, &queue);
87
89 Sector.initialize(N, momentum, dimLoc);
90 Sector.copyToGPU(queue);
91
92 std::cout << "########## Output ##########" << std::endl;
93 GlobFuncPtr = MatrixElementsInSector;
94 struct cudaFuncAttributes attr;
95 cudaFuncGetAttributes(&attr, GlobFuncPtr);
96 Integer_t nThread = (Integer_t)sqrt(attr.maxThreadsPerBlock);
98 if(Sector.dim() > nBlock * nThread) nBlock += 1;
99 GPUconfig conf(dim3(nBlock, nBlock, 1), dim3(nThread, nThread, 1), 0, queue);
100
101 std::cout << "# constSizeBytes = " << attr.constSizeBytes << "\n"
102 << "# maxThreadsPerBlock = " << attr.maxThreadsPerBlock << "\n"
103 << "# (dim=" << Sector.dim() << ") nBlock=" << nBlock << ", nThread= " << nThread
104 << "*" << nThread << " =" << nThread * nThread << std::endl;
105 magma_queue_sync(queue);
106
107 constexpr Integer_t GPU_UNIT = 32;
108 Integer_t const LDT = magma_roundup(Sector.dim(), GPU_UNIT);
109 matrix_gpu<Complex_t> dmatLoc(LDT, dimLocMat);
110 matrix_gpu<Complex_t> dmatTot(LDT, Sector.dim());
111
112 magma_setmatrix(dimLocMat, dimLocMat, sizeof(Complex_t), &*matLoc.begin(), dimLocMat,
113 dmatLoc.ptr(), dmatLoc.LD(), queue);
114 constructGlobal_h(dmatTot, dmatLoc, numLoc, Sector, conf);
115
116 std::cout << "# After constructGlobal_h" << std::endl;
117 std::cout << "matTot:" << std::endl;
118 dmatTot.print(Sector.dim(), Sector.dim(), queue);
119
120 return 0;
121}
__global__ void MatrixElementsInSector(void)
Definition generateRM.cuh:61
std::vector< TransSector > Sector(n_max+1)
Definition mytypes.hpp:147
Definition mytypes.hpp:272
Translation invariant sector of a many-body Hilbert space.
Definition TransSector.hpp:19
struct cudaFuncAttributes attr
Definition getAttributesOfMatrixElementsInSector.cpp:2
Integer_t const nBlock
Definition getAttributesOfMatrixElementsInSector.cpp:5
Integer_t const nThread
Definition getAttributesOfMatrixElementsInSector.cpp:4
MKL_INT Integer_t
Definition mytypes.hpp:359