18 int init_MPI_general(
int *argc,
char **argv[])
26 int provided,required=MPI_THREAD_MULTIPLE;
28 ierr=MPI_Init_thread(argc, argv,required,&provided);
29 stderrfprintf(
"Using MPI_Init_thread with required=%d and provided=%d\n",required,provided);
31 stderrfprintf(
"Begin: MPI_Init\n"); fflush(stderr);
32 ierr=MPI_Init(argc, argv);
33 stderrfprintf(
"End: MPI_Init\n"); fflush(stderr);
39 stderrfprintf(
"MPI Error during MPI_Init\n");
44 MPI_Comm_rank(MPI_COMM_WORLD, &myid_world);
45 MPI_Get_processor_name(processor_name, &
procnamelen);
47 stderrfprintf(
"WORLD proc: %d of %d on %s\n", myid_world,
truenumprocs,processor_name);
49 stderrfprintf(
"end: init_MPI\n");
61 stderrfprintf(
"Problem allocating memory for MPIid with truenumprocs=%d\n",
truenumprocs); fflush(stderr);
102 void init_MPI_setupfilesandgrid(
int argc,
char *argv[])
148 init_placeongrid_gridlocation();
160 if(
sizeof(CTYPE)==
sizeof(
long long int)){
161 MPI_Type_size(MPI_LONG_LONG_INT,&size);
163 dualfprintf(
fail_file,
"size of the long long int in MPI=%d, should be 8\n",size);
168 if((
sizeof(
REALTYPE)==
sizeof(
long double))||(
sizeof(
SENSITIVE)==
sizeof(
long double))){
169 MPI_Type_size(MPI_LONG_DOUBLE,&size);
171 dualfprintf(
fail_file,
"size of the long double in MPI=%d, should be 16\n",size);
178 trifprintf(
"done with init_MPI_setupfilesandgrid()\n");
189 void myargs(
int argc,
char *argv[])
191 int argi,numargs,numextraargs;
210 if(! (argc==numargs || argc==numargs+numextraargs) ){
212 stderrfprintf(
"proc: %04d : Incorrect command line: argc: %d needed at least=%d, please specify:\n",myid,argc,numargs);
213 stderrfprintf(
"proc: %04d : mpirun <mpirunoptions> <progname> numopenmpithreads ncpux1 ncpux2 ncpux3\n",myid);
214 stderrfprintf(
"proc: %04d : OR\n",myid);
215 stderrfprintf(
"proc: %04d : mpirun <mpirunoptions> <progname> numopenmpithreads ncpux1 ncpux2 ncpux3 RESTARTMODE WHICHFILE\n",myid);
221 ncpux1=atoi(argv[argi++]);
222 ncpux2=atoi(argv[argi++]);
223 ncpux3=atoi(argv[argi++]);
228 if(! (argc==numargs || argc==numargs+numextraargs) ){
230 stderrfprintf(
"proc: %04d : Incorrect command line: argc: %d needed at least=%d, please specify:\n",myid,argc,numargs);
231 stderrfprintf(
"proc: %04d : mpirun <mpirunoptions> <progname> ncpux1 ncpux2 ncpux3\n",myid);
232 stderrfprintf(
"proc: %04d : OR\n",myid);
233 stderrfprintf(
"proc: %04d : mpirun <mpirunoptions> <progname> ncpux1 ncpux2 ncpux3 RESTARTMODE WHICHFILE\n",myid);
238 ncpux1=atoi(argv[argi++]);
239 ncpux2=atoi(argv[argi++]);
240 ncpux3=atoi(argv[argi++]);
245 if(! (argc==numargs || argc==numargs+numextraargs) ){
247 stderrfprintf(
"proc: %04d : Incorrect command line: argc: %d needed at least=%d, please specify:\n",myid,argc,numargs);
248 stderrfprintf(
"proc: %04d : mpirun <mpirunoptions> <progname> numopenmpthreads\n",myid);
249 stderrfprintf(
"proc: %04d : OR\n",myid);
250 stderrfprintf(
"proc: %04d : mpirun <mpirunoptions> <progname> numopenmpthreads RESTARTMODE WHICHFILE\n",myid);
260 if(! (argc==numargs || argc==numargs+numextraargs) ){
262 stderrfprintf(
"<progname>\n");
263 stderrfprintf(
"OR\n");
264 stderrfprintf(
"<progname> RESTARTMODE WHICHFILE\n");
275 if(argc==numargs+numextraargs){
292 stderrfprintf(
"Cannot have ncpux1=%d>N1=%d\n",
ncpux1,
N1);
296 stderrfprintf(
"Cannot have ncpux2=%d>N2=%d\n",
ncpux2,
N2);
300 stderrfprintf(
"Cannot have ncpux3=%d>N3=%d\n",
ncpux3,
N3);
319 stderrfprintf(
"Got (sizeproclist_grmhd=%d) != (numprocs=ncpux1*ncpux2*ncpux3=%d). ncpux1=%d ncpux2=%d ncpux3=%d. Did you run without mpirun?\n",sizeproclist_grmhd,
numprocs,
ncpux1,
ncpux2,ncpux3);
325 "numprocs=%d ncpux1=%d ncpux2=%d ncpux3=%d numopenmpthreads=%d :: percpusize: N1=%d N2=%d N3=%d\n",
342 stderrfprintf(
"begin: init_genfiles ... ");
346 strcpy(extension,
PPEXT);
347 }
else if (gopp == 0) {
348 strcpy(extension,
OUTEXT);
353 sprintf(temps,
"%s0_fail%s%s",
DATADIR, extension, myidtxt);
354 if ((
fail_file = fopen(temps,
"at")) == NULL) {
355 stderrfprintf(
"fail: Cannot open: %s\n", temps);
358 stderrfprintf(
"opened: %s\n", temps);
363 sprintf(temps,
"%s0_log%s%s",
DATADIR, extension, myidtxt);
364 if ((
log_file = fopen(temps,
"at")) == NULL) {
365 stderrfprintf(
"log: Cannot open: %s\n", temps);
368 stderrfprintf(
"opened: %s\n", temps);
376 sprintf(temps,
"%s0_logdt%s%s",
DATADIR, extension, myidtxt);
377 if ((
logdt_file = fopen(temps,
"at")) == NULL) {
378 stderrfprintf(
"logdt: Cannot open: %s\n", temps);
381 stderrfprintf(
"opened: %s\n", temps);
394 sprintf(temps,
"%s0_logfull%s%s",
DATADIR, binarytype, extension);
396 stderrfprintf(
"logfull: Cannot open: %s\n", temps);
399 stderrfprintf(
"opened: %s\n", temps);
401 fflush(logfull_file);
404 sprintf(temps,
"%s0_logdtfull%s%s",
DATADIR, binarytype, extension);
406 stderrfprintf(
"logdtfull: Cannot open: %s\n", temps);
409 stderrfprintf(
"opened: %s\n", temps);
411 fflush(logdtfull_file);
413 sprintf(temps,
"%s0_logstep%s%s",
DATADIR, binarytype, extension);
415 stderrfprintf(
"logstep: Cannot open: %s\n", temps);
418 stderrfprintf(
"opened: %s\n", temps);
420 sprintf(temps,
"%s0_logperf%s%s",
DATADIR, binarytype, extension);
422 stderrfprintf(
"logperf: Cannot open: %s\n", temps);
425 stderrfprintf(
"opened: %s\n", temps);
433 trifprintf(
"end: init_genfiles\n");
441 sprintf(binarytype,
".grmhd");
444 sprintf(binarytype,
".grray");
447 sprintf(binarytype,
".liaison");
455 void set_primgridpos(
void)
506 void init_placeongrid_gridlocation(
void)
513 trifprintf(
"begin: init_placeongrid_gridlocation ... ");
536 for (m = 1; m <=
COMPDIM; m++) {
551 dualfprintf(
fail_file,
"can't allocate mycpupos0[%d]\n",m);
555 dualfprintf(
fail_file,
"can't allocate startpos0[%d]\n",m);
558 if((
endpos0[m]=(
int*)malloc(
sizeof(
int)*numprocs))==NULL){
559 dualfprintf(
fail_file,
"can't allocate endpos0[%d]\n",m);
570 for (m = 1; m <=
COMPDIM; m++) {
593 logfprintf(
"myid=%d node_name=%s procnamelen=%d\n",myid,processor_name,
procnamelen);
595 trifprintf(
"\nnumprocs(MPI)=%d ncpux1=%d ncpux2=%d ncpux3=%d numopenmpthreads=%d\n",numprocs,
ncpux1,ncpux2,ncpux3,
numopenmpthreads);
596 trifprintf(
"\n Per MPI Task: N1=%d N2=%d N3=%d\n",
N1,
N2,N3);
599 for (m = 1; m <=
COMPDIM; m++) {
600 logfprintf(
"mycpupos[%d]: %d\n", m,
mycpupos[m]);
601 logfprintf(
"startpos[%d]: %d\n", m,
startpos[m]);
602 logfprintf(
"endpos[%d]: %d\n", m,
endpos[m]);
603 logfprintf(
"totalsize[%d]: %lld\n", m, totalsize[m]);
614 trifprintf(
"end: init_placeongrid_gridlocation\n");
623 void init_placeongrid_griddecomposition(
void)
626 int stage,stagei,stagef;
638 trifprintf(
"begin: init_placeongrid_griddecomposition ... ");
770 for(dir=0;dir<COMPDIM*2;dir++){
815 dualfprintf(
fail_file,
"ncpux3=%d must be even for polar transmissive BCs\n",ncpux3);
823 int othermyid = othercpupos1 + othercpupos2*ncpux1 + othercpupos3*ncpux1*
ncpux2;
891 set_numbnd(bti, numbnd, &numnpr);
895 for(dir=0;dir<COMPDIM*2;dir++){
920 dualfprintf(
fail_file,
"No such bti=%d setup in set number of variable types in mpi_init.c\n",bti);
931 surfa[1]=(
N2+numbnd[2]*2)*(N3+numbnd[3]*2)*
N1NOT1;
932 surfa[2]=(
N1+numbnd[1]*2)*(N3+numbnd[3]*2)*
N2NOT1;
933 surfa[3]=(
N1+numbnd[1]*2)*(
N2+numbnd[2]*2)*
N3NOT1;
960 dualfprintf(
fail_file,
"No such bti=%d setup in set transfer size in mpi_init.c\n",bti);
1028 dualfprintf(
fail_file,
"No such bti=%d defined for dirloopset[]\n",bti);
1037 set_numbnd(bti, numbnd, &numnpr);
1041 for(dir=0;dir<COMPDIM*2;dir++){
1272 dirloopset[bti][dir][gridpos][
DIRUDIR1]=+1;
1277 dirloopset[bti][dir][gridpos][
DIRUDIR1]=+1;
1318 else dirloopset[bti][dir][gridpos][
DIRUSTART2]=-0;
1321 dirloopset[bti][dir][gridpos][
DIRUDIR2]=-1;
1359 dirloopset[bti][dir][gridpos][
DIRUDIR2]=+1;
1364 dirloopset[bti][dir][gridpos][
DIRUDIR2]=+1;
1370 dirloopset[bti][dir][gridpos][
DIRUDIR2]=+1;
1375 dirloopset[bti][dir][gridpos][
DIRUDIR2]=+1;
1381 dirloopset[bti][dir][gridpos][
DIRUSTART1]=-numbnd[1];
1382 dirloopset[bti][dir][gridpos][
DIRUSTOP1]=
N1-1+numbnd[1];
1383 dirloopset[bti][dir][gridpos][
DIRUDIR1]=+1;
1384 dirloopset[bti][dir][gridpos][
DIRUSTART3]=-numbnd[3];
1385 dirloopset[bti][dir][gridpos][
DIRUSTOP3]=N3-1+numbnd[3];
1386 dirloopset[bti][dir][gridpos][
DIRUDIR3]=+1;
1396 dirloopset[bti][dir][gridpos][
DIRUDIR3]=+1;
1401 dirloopset[bti][dir][gridpos][
DIRUDIR3]=+1;
1407 dirloopset[bti][dir][gridpos][
DIRUDIR3]=+1;
1412 dirloopset[bti][dir][gridpos][
DIRUDIR3]=+1;
1417 dirloopset[bti][dir][gridpos][
DIRUSTART1]=-numbnd[1];
1418 dirloopset[bti][dir][gridpos][
DIRUSTOP1]=
N1-1+numbnd[1];
1419 dirloopset[bti][dir][gridpos][
DIRUDIR1]=+1;
1420 dirloopset[bti][dir][gridpos][
DIRUSTART2]=-numbnd[2];
1421 dirloopset[bti][dir][gridpos][
DIRUSTOP2]=
N2-1+numbnd[2];
1422 dirloopset[bti][dir][gridpos][
DIRUDIR2]=+1;
1455 for (m = 0; m < COMPDIM*2; m++) {
1457 logfprintf(
"dirgenset[%d][%d][%d]: %d\n", bti, m, l,
dirgenset[bti][m][l]);
1463 for (m = 0; m < COMPDIM*2; m++) {
1466 logfprintf(
"dirloopset[%d][%d][%d][%d]: %d\n", bti, m, gridpos, l, dirloopset[bti][m][gridpos][l]);
1483 #if(SIMULBCCALC!=-1)
1492 for(stage=stagei;stage<=stagef;stage++){
1494 logfprintf(
"CZLOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1496 logfprintf(
"F1LOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1498 logfprintf(
"F2LOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1500 logfprintf(
"EMFLOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1502 logfprintf(
"F1CTLOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1504 logfprintf(
"F2CTLOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1506 logfprintf(
"DQLOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1508 logfprintf(
"PREDQLOOP: stage=%d : %d %d %d %d\n",stage,
isc,
iec,
jsc,
jec);
1519 trifprintf(
"end: init_placeongrid_griddecomposition\n");
1525 int myexit(
int call_code)
1537 trifprintf(
"proc: %s : Exiting cc: %d nstep: %ld\n", myidtxt, call_code,
nstep);
1541 if(omp_in_parallel()){
1543 tid=omp_get_thread_num();
1558 #if(MAILWHENDONE && !MPIAVOIDFORK)
1564 sprintf(mysys,
"echo \"%s : done with `pwd`, inparallel=%d\" > done%s.txt",
EMAILMESSAGE,inparallel,binarytype);
1571 sprintf(mysys,
"mail %s < done%s.txt",
EMAILADDRESS,binarytype);
1578 if (call_code > 0) {
1580 "proc: %s : Failure. Please check failure file: cc: %d\n",
1581 myidtxt, call_code);
1586 if(cleanfinish) dofaildump=1;
1590 MPI_Abort(MPI_COMM_GRMHD, 1);
1602 stderrfprintf(
"proc: %s : dumping failure dump with callcode=2\n",
1618 if(cleanfinish &&
USEROMIO==1 && MPIVERSION==2 ){
1630 if (call_code >= 0) {
1639 stderrfprintf(
"Ending Computation on proc: %s, holding for other cpus\n", myidtxt);
1643 myfprintf(stderr,
"Ended Computation on all processors\n");
1645 stderrfprintf(
"END\n");
1664 int error_check(
int wherefrom)
1672 "Detected failure on proc: %d failed: %d nstep: %ld realnstep: %ld steppart=%d :: t: %21.15g wherefrom = %d\n",
1681 MPI_Allreduce(&errorsend, &
failed, 1, MPI_INT, MPI_MAX,
1689 "Result: Detected failure on proc: %d failed: %d nstep: %ld realnstep: %ld steppart=%d :: t: %21.15g\n",
1710 void init_MPIgroup(
void)
1719 stderrfprintf(
"Problem allocating memory for ranks with truenumprocs=%d\n",
truenumprocs); fflush(stderr);
1724 MPI_Comm_group(MPI_COMM_WORLD, &MPI_GROUP_WORLD);
1726 stderrfprintf(
"begin: proc: %s init_MPIgroup\n",myidtxt); fflush(stderr);
1737 if(numranks!=ncpux2*ncpux3){
1738 stderrfprintf(
"problem with inner x1-group: numranks: %d ncpux2: %d ncpux3: %d ncpux2*ncpux3: %d\n",numranks,ncpux2,ncpux3,ncpux2*ncpux3);
1744 MPI_Group_incl(MPI_GROUP_WORLD, numranks, ranks, &grprem[2]);
1745 MPI_Comm_create(MPI_COMM_WORLD, grprem[2], &combound[2]);
1750 if(i%ncpux1==ncpux1-1){
1756 if(numranks!=ncpux2*ncpux3){
1757 stderrfprintf(
"problem with outer x1-group: numranks: %d ncpux2*ncpux3: %d\n",numranks,ncpux2*ncpux3);
1761 MPI_Group_incl(MPI_GROUP_WORLD, numranks, ranks, &grprem[0]);
1762 MPI_Comm_create(MPI_COMM_WORLD, grprem[0], &combound[0]);
1767 if((i%(ncpux1*ncpux2))/ncpux1==0){
1773 if(numranks!=ncpux1*ncpux3){
1774 stderrfprintf(
"problem with inner x2-group: numranks: %d ncpux1*ncpux3: %d\n",numranks,ncpux1*ncpux3);
1778 MPI_Group_incl(MPI_GROUP_WORLD, numranks, ranks, &grprem[1]);
1779 MPI_Comm_create(MPI_COMM_WORLD, grprem[1], &combound[1]);
1784 if((i%(ncpux1*ncpux2))/ncpux1==ncpux2-1){
1790 if(numranks!=ncpux1*ncpux3){
1791 stderrfprintf(
"problem with outer x2-group: numranks: %d ncpux1*ncpux3: %d\n",numranks,ncpux1*ncpux3);
1796 MPI_Group_incl(MPI_GROUP_WORLD, numranks, ranks, &grprem[3]);
1797 MPI_Comm_create(MPI_COMM_WORLD, grprem[3], &combound[3]);
1804 if(i/(ncpux1*ncpux2)==0){
1810 if(numranks!=ncpux1*ncpux2){
1811 stderrfprintf(
"problem with inner x3-group: numranks: %d ncpux1*ncpux2: %d\n",numranks,ncpux1*ncpux2);
1815 MPI_Group_incl(MPI_GROUP_WORLD, numranks, ranks, &grprem[5]);
1816 MPI_Comm_create(MPI_COMM_WORLD, grprem[5], &combound[5]);
1821 if(i/(ncpux1*ncpux2)==ncpux3-1){
1827 if(numranks!=ncpux1*ncpux2){
1828 stderrfprintf(
"problem with outer x3-group: numranks: %d ncpux1*ncpux2: %d\n",numranks,ncpux1*ncpux2);
1833 MPI_Group_incl(MPI_GROUP_WORLD, numranks, ranks, &grprem[4]);
1834 MPI_Comm_create(MPI_COMM_WORLD, grprem[4], &combound[4]);
1843 stderrfprintf(
"end: proc: %s init_MPIgroup\n",myidtxt); fflush(stderr);
1905 #if(USEOPENMP) // need inside cpp conditional since using OpenMP functions, not just directives.
1907 #pragma omp parallel private(tid)
1910 fprintf(out,
"proc: %d : Thread = %d activated\n", myid,omp_get_thread_num());
1912 tid = omp_get_thread_num();
1917 #if(OPENMPVERSION==3)
1918 fprintf(out,
"OpenMP 3.0 activated: Maximum number of threads available=%d\n",omp_get_thread_limit());
1921 fprintf(out,
"Master MPI proc=%d reports: Number of threads originaly=%d out of maximum=%d out of procs=%d\n", myid,
numopenmpthreadsorig,omp_get_max_threads(),omp_get_num_procs());
1922 if(omp_get_dynamic()){
1923 fprintf(out,
"Dynamic thread adjustment is enabled\n");
1926 fprintf(out,
"Dynamic thread adjustment is disabled\n");
1931 if(omp_get_nested()){
1932 fprintf(out,
"Nested parallelism is enabled, so allowed\n");
1935 fprintf(out,
"Nested parallelism is disabled, so is NOT allowed\n");