27 #include "wrapperMPI.hpp" 35 #include "common/setmemory.hpp" 47 ierr = MPI_Init(&argc, &argv);
48 ierr = MPI_Comm_size(MPI_COMM_WORLD, &
nproc);
49 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &
myrank);
59 #pragma omp parallel default(none) shared(nthreads) 66 fprintf(
stdoutMPI,
"\n\n##### Parallelization Info. #####\n\n");
77 ierr = MPI_Finalize();
78 if (ierr != 0) fprintf(stderr,
"\n MPI_Finalize() = %d\n\n", ierr);
92 fprintf(stdout,
"\n\n ####### [HPhi] You DO NOT have to WORRY about the following MPI-ERROR MESSAGE. #######\n\n");
94 ierr = MPI_Abort(MPI_COMM_WORLD, errorcode);
95 ierr = MPI_Finalize();
96 if (ierr != 0) fprintf(stderr,
"\n MPI_Finalize() = %d\n\n", ierr);
106 const char* FileName,
111 if (
myrank == 0) fp = fopen(FileName, mode);
112 else fp = fopen(
"/dev/null",
"w");
133 ctmp = fgets(InputString, maxcount, fp);
138 while(*InputString ==
'\n' || strncmp(InputString,
"#", 1)==0){
139 ctmp = fgets(InputString, maxcount, fp);
147 MPI_Bcast(InputString, maxcount, MPI_CHAR, 0, MPI_COMM_WORLD);
148 MPI_Bcast(&inull, 1, MPI_INT, 0, MPI_COMM_WORLD);
150 if (
myrank != 0 && inull == 1) {
162 MPI_Barrier(MPI_COMM_WORLD);
176 ierr = MPI_Allreduce(MPI_IN_PLACE, &idim, 1,
177 MPI_LONG, MPI_MAX, MPI_COMM_WORLD);
193 ierr = MPI_Allreduce(MPI_IN_PLACE, &dvalue, 1,
194 MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
206 std::complex<double> norm
210 ierr = MPI_Allreduce(MPI_IN_PLACE, &norm, 1,
211 MPI_DOUBLE_COMPLEX, MPI_SUM, MPI_COMM_WORLD);
227 ierr = MPI_Allreduce(MPI_IN_PLACE, &norm, 1,
228 MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD);
244 ierr = MPI_Allreduce(MPI_IN_PLACE, norm, nnorm,
245 MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD);
256 std::complex<double> *norm
260 ierr = MPI_Allreduce(MPI_IN_PLACE, norm, nnorm,
261 MPI_DOUBLE_COMPLEX, MPI_SUM, MPI_COMM_WORLD);
276 ierr = MPI_Allreduce(MPI_IN_PLACE, &idim, 1,
277 MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
293 ierr = MPI_Allreduce(MPI_IN_PLACE, &idim, 1,
294 MPI_INT, MPI_SUM, MPI_COMM_WORLD);
312 MPI_Bcast(&idim0, 1, MPI_LONG, root, MPI_COMM_WORLD);
323 std::complex<double> *_v1
329 #pragma omp parallel for default(none) private(i) \ 330 shared(_v1, idim) reduction(+:dnorm) 331 for (i = 1; i <= idim; i++)
332 dnorm += real(conj(_v1[i])*_v1[i]);
347 std::complex<double> **_v1,
353 for (istate = 0; istate < nstate; istate++) dnorm[istate] = 0.0;
354 for (idim = 1; idim <= ndim; idim++) {
355 for (istate = 0; istate < nstate; istate++) {
356 dnorm[istate] += real(conj(_v1[idim][istate])*_v1[idim][istate]);
360 for (istate = 0; istate < nstate; istate++) dnorm[istate] = sqrt(dnorm[istate]);
369 std::complex<double> *
v1,
370 std::complex<double> *v2
373 std::complex<double> prod, *prod_thr;
376 prod_thr = cd_1d_allocate(
nthreads);
377 #pragma omp parallel default(none) shared(v1,v2,ndim,prod,prod_thr) private(idim,mythread) 380 mythread = omp_get_thread_num();
385 for (idim = 1; idim <= ndim; idim++)
386 prod_thr[mythread] += conj(v1[idim]) * v2[idim];
389 for (mythread = 0; mythread <
nthreads; mythread++)
390 prod += prod_thr[mythread];
391 free_cd_1d_allocate(prod_thr);
404 std::complex<double> **
v1,
405 std::complex<double> **v2,
406 std::complex<double> *prod
411 for (istate = 0; istate < nstate; istate++) prod[istate] = 0.0;
412 for (idim = 1; idim <= ndim; idim++) {
413 for (istate = 0; istate < nstate; istate++) {
414 prod[istate] += conj(v1[idim][istate])*v2[idim][istate];
428 std::complex<double> *vecs,
429 std::complex<double> *vecr
432 int ierr, two31m1 = 2147483647, modMsg, nMsgS2, nMsgR2;
433 long int nMsg, nnMsg, iMsg, sMsgR, sMsgS;
434 MPI_Status statusMPI;
436 if (nMsgS > nMsgR) nMsg = nMsgS;
438 nnMsg = nMsg / two31m1;
439 modMsg = nMsg % two31m1;
440 if (modMsg != 0) nnMsg += 1;
444 for (iMsg = 0; iMsg < nnMsg; iMsg++) {
445 nMsgS2 = nMsgS / nnMsg;
446 nMsgR2 = nMsgR / nnMsg;
447 if (iMsg < nMsgS % nnMsg) nMsgS2 += 1;
448 if (iMsg < nMsgR % nnMsg) nMsgR2 += 1;
450 ierr = MPI_Sendrecv(&vecs[sMsgS], nMsgS2, MPI_DOUBLE_COMPLEX, origin, 0,
451 &vecr[sMsgR], nMsgR2, MPI_DOUBLE_COMPLEX, origin, 0,
452 MPI_COMM_WORLD, &statusMPI);
473 int ierr, two31m1 = 2147483647, modMsg, nMsgS2, nMsgR2;
474 long int nMsg, nnMsg, iMsg, sMsgR, sMsgS;
475 MPI_Status statusMPI;
477 if (nMsgS > nMsgR) nMsg = nMsgS;
479 nnMsg = nMsg / two31m1;
480 modMsg = nMsg % two31m1;
481 if (modMsg != 0) nnMsg += 1;
485 for (iMsg = 0; iMsg < nnMsg; iMsg++) {
486 nMsgS2 = nMsgS / nnMsg;
487 nMsgR2 = nMsgR / nnMsg;
488 if (iMsg < nMsgS % nnMsg) nMsgS2 += 1;
489 if (iMsg < nMsgR % nnMsg) nMsgR2 += 1;
491 ierr = MPI_Sendrecv(&vecs[sMsgS], nMsgS2, MPI_LONG, origin, 0,
492 &vecr[sMsgR], nMsgR2, MPI_LONG, origin, 0,
493 MPI_COMM_WORLD, &statusMPI);
510 MPI_Status statusMPI;
512 ierr = MPI_Sendrecv(&isend, 1, MPI_LONG, origin, 0,
513 &ircv, 1, MPI_LONG, origin, 0,
514 MPI_COMM_WORLD, &statusMPI);
void exitMPI(int errorcode)
MPI Abortation wrapper.
int nproc
Number of processors, defined in InitializeMPI()
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
double NormMPI_dc(long int idim, std::complex< double > *_v1)
Compute norm of process-distributed vector .
void FinalizeMPI()
MPI Finitialization wrapper.
void splash()
Print logo mark and version number.
long int SumMPI_li(long int idim)
MPI wrapper function to obtain sum of unsigned long integer across processes.
FILE * fopenMPI(const char *FileName, const char *mode)
MPI file I/O (open) wrapper. Only the root node (myrank = 0) should be open/read/write (small) parame...
double MaxMPI_d(double dvalue)
MPI wrapper function to obtain maximum Double across processes.
long int MaxMPI_li(long int idim)
MPI wrapper function to obtain maximum unsigned long integer across processes.
void NormMPI_dv(long int ndim, int nstate, std::complex< double > **_v1, double *dnorm)
Compute norm of process-distributed vector .
std::complex< double > ** v1
void SumMPI_cv(int nnorm, std::complex< double > *norm)
MPI wrapper function to obtain sum of Double array across processes.
long int SendRecv_i(int origin, long int isend)
Wrapper of MPI_Sendrecv for long integer number.
void BarrierMPI()
MPI barrier wrapper.
std::complex< double > VecProdMPI(long int ndim, std::complex< double > *v1, std::complex< double > *v2)
Compute conjugate scaler product of process-distributed vector .
int nthreads
Number of Threads, defined in InitializeMPI()
void InitializeMPI(int argc, char *argv[])
MPI initialization wrapper Process ID (myrank), Number of processes (nproc), Number of threads (nthre...
int SumMPI_i(int idim)
MPI wrapper function to obtain sum of integer across processes.
char * fgetsMPI(char *InputString, int maxcount, FILE *fp)
MPI file I/O (get a line, fgets) wrapper. Only the root node (myrank = 0) reads and broadcast string...
int myrank
Process ID, defined in InitializeMPI()
void SendRecv_cv(int origin, long int nMsgS, long int nMsgR, std::complex< double > *vecs, std::complex< double > *vecr)
Wrapper of MPI_Sendrecv for std::complex<double> number. When we pass a message longer than 2^31-1 (m...
void SumMPI_dv(int nnorm, double *norm)
MPI wrapper function to obtain sum of Double array across processes.
void MultiVecProdMPI(long int ndim, int nstate, std::complex< double > **v1, std::complex< double > **v2, std::complex< double > *prod)
Compute conjugate scaler product of process-distributed vector .
double SumMPI_d(double norm)
MPI wrapper function to obtain sum of Double across processes.
long int BcastMPI_li(int root, long int idim)
MPI wrapper function to broadcast long integer across processes.
void SendRecv_iv(int origin, long int nMsgS, long int nMsgR, long int *vecs, long int *vecr)
Wrapper of MPI_Sendrecv for long integer number. When we pass a message longer than 2^31-1 (max of in...
std::complex< double > SumMPI_dc(std::complex< double > norm)
MPI wrapper function to obtain sum of Double complex across processes.