HARM
harm and utilities
 All Data Structures Files Functions Variables Typedefs Macros Pages
main.c
Go to the documentation of this file.
1 
187 
188 //
190 //
192 
220 
221 
222 
223 
224 
225 // #include "decs.h"
226 #include "defs.h"
227 
232 int main(int argc, char *argv[])
233 {
234  // extern void testffdeinversion(void);
235  //OPENMPMARK: static ok here
236  static SFTYPE comptstart;
237  static SFTYPE diagtstart;
238 
239 
240  // uncomment if get SIGFPE 8 error at run with floats and no result problem
241  // signal(8,SIG_IGN);
242 
243 
244  crapdebug=0; // CHANGINGMARK: to debug stuff
245 
246 
247  // start timing for init -> computation start
248  timecheck(INITSTARTTIME,0);
249 
250 
251 
253  //
254  // perform initializations
255  //
257  if (init(&argc,&argv) >= 1) {
258  dualfprintf(fail_file, "main:init: failure\n");
259  myexit(1);
260  }
261 
262 
264  //
265  // write version header info for perf and step logs
266  //
268  if((myid<=0)&&(appendold==0)){
269  if(DOLOGSTEP){
270  myfprintf(logstep_file,"#%10s\n%10d %10d\n#","STEPVER",STEPVER,STEPTYPE);
271  }
272  if(DOLOGPERF){
273  myfprintf(logperf_file,"#%10s\n%10d %10d\n#","PERFVER",PERFVER,PERFTYPE);
274  }
275  }
276 
277 
278 
279 
280 
281  // end timing for init -> computation start
282  timecheck(INITSTOPTIME,0);
283 
285  //
286  // set initial computational time [start before diags since report how diags affect computational time]
287  //
289 
290  // GODMARK: Should store timestart and initial "t" time so running-average can properly be computed when restart simulation.
291  // comptstart=t; // not right
292  comptstart=0; // assumes normal simulation started t=0 at nstep=0
293  // start timing
294  timecheck(STARTTIME,comptstart);
295 
296 
297 
299  //
300  // Do initial diagnostics
301  //
303  if (DODIAGS) {
304  diagtstart=0; timecheck(DIAGSTARTTIME,diagtstart);
305 
306  trifprintf("proc: %04d : Start initial diagnostics\n", myid);
307  // no error_check since if init passed, diag(0) should pass
309  trifprintf("proc: %04d : End initial diagnostics\n", myid);
310 
311  timecheck(DIAGSTOPTIME,diagtstart);
312  }
313 
314  // testffdeinversion();
315  // myexit(0);
316 
317 
318 
320  //
321  // START MAJOR WHILE LOOP OVER ITERATIONS
322  //
324 
325  trifprintf("proc: %04d : Start computation\n", myid);
326 
327  int fakenstep=0;
328  onemorestep=reallaststep=0; // global variable set also in step_ch.c
329  while (reallaststep==0) {
330 
331  /* step variables forward in time */
332  nstroke = 0;
333 
334  // take full step with all non-physics evolutionary code as well
335  // SUPERGODMARK: Should insert *all* global variables here, including non-array one's, so that call is modular
336  // Then can vary ACTIVEREGION or ACTIVESUBREGION or something on this scale to do AMR and ATR
337  // currently ok to have emf as Atemp since both are used as temp variables to get flux or vpot independently
338  // ulastglobal used for evolving vpot, which occurs after all steps, so ok to use ulastglobal
339 
340  int truestep=1; // indicates true time step and not fake pass-through (as used by, e.g., metric gravity update)
341 
342  step_ch_full(truestep,GLOBALPOINT(pglobal),GLOBALPOINT(pstagglobal),GLOBALPOINT(unewglobal),GLOBALPOINT(vpotarrayglobal),GLOBALPOINT(Bhatglobal),GLOBALPOINT(gp_l),GLOBALPOINT(gp_r),GLOBALPOINT(F1),GLOBALPOINT(F2),GLOBALPOINT(F3),GLOBALPOINT(emf),GLOBALPOINT(ulastglobal));
343 
344  if(nstep%10 && PRODUCTION==0){
345  dualfprintf(fail_file,"nstroke: %ld\n",nstroke);
346  }
347 
348  // get total number of inversion steps
349  mpiisum0(&nstroke,0);
350 
351 
352  /* restart dump */
353  // if(nstep == 130) restart_write(1) ;
354  //if(fakenstep==50) break;
355 
356 
357  nstep++;
358  fakenstep++;
359  // restartsteps[whichrestart]=realnstep;
360 
361 
362  /* perform diagnostics */
363  // no error check since assume if step_ch passed, diag(1) will pass
364 
365 
366  // start diagnostic timing
367  if (DODIAGS && !DODIAGEVERYSUBSTEP){
368  // start diagnostic timing
369  diagtstart=0; timecheck(DIAGSTARTTIME,diagtstart);
370 
371  GLOBALPOINT(pdump) = GLOBALPOINT(pglobal);
373 #if(PRODUCTION==0)
374  trifprintf( "D");
375 #endif
376  // stop diagnostic timing
377  timecheck(DIAGSTOPTIME,diagtstart);
378  }
379 
380 
381  // time check (should come after first nstep++ to setup things first)
382  timecheck(CHECKTIME,comptstart);
383 
384  // speed check
385  timecheck(SPEEDTIME,comptstart);
386 
387 
388  // output timestep info
389  output_steptimedt_info(comptstart);
390 
391  }
392  trifprintf("proc: %04d : End computation\n", myid);
393 
395  //
396  // END MAJOR WHILE LOOP OVER ITERATIONS
397  //
399 
400 
401  // stop timing
402  timecheck(STOPTIME,comptstart);
403 
404 
406  //
407  // do final diagnostics
408  //
410  if (DODIAGS){
411  diagtstart=0; timecheck(DIAGSTARTTIME,diagtstart);
412 
413  GLOBALPOINT(pdump) = GLOBALPOINT(pglobal);
415 
416  timecheck(DIAGSTOPTIME,diagtstart);
417  }
418 
420  //
421  // report if go initiated stopping of simulation
422  //
424  gocheck(STOPTIME);
425 
426  // report final timing and other simulation performance characteristics
427  timecheck(REPORTTIME,comptstart);
428 
429 
430  myexit(0);
431  return (0);
432 }
433 
434 
435 
436 
437 
444 int gocheck(int whichlocation)
445 {
446  static int goend=0; // init to 0
447  // non-static
448  char stemp[MAXFILENAME];
449  char goch;
450  FILE *gogo_file,*gocont_file;
451 
452 
453 
454  if(whichlocation==STARTTIME){
455 
456  if(myid<=0){
457  if(CHECKCONT){
458 
459  sprintf(stemp,"%sgo.cont",DATADIR);
460 
461  if((gocont_file=fopen(stemp,"rt"))==NULL){
462  dualfprintf(fail_file,"WARNING: Could not open go.cont file: %s , assume user doesn't want to use it\n",stemp);
463  // myexit(1); // can't exit yet if want clean MPI exit
464  goch='z';
465  }
466  else goch='a';
467  }
468  }
469 
470 #if(USEMPI)
471  MPI_Bcast(&goch,1,MPI_INT,MPIid[0], MPI_COMM_GRMHD);
472 #endif
473 
474  if(goch=='z'){
475  // myexit(1);
476  // for now just assume if file doesn't exist that user didn't want to restart
477  }
478  else{
479  if(CHECKCONT){
480  if(myid<=0){
481  goch=fgetc(gocont_file);
482  if( (goch=='y')||(goch=='Y')){
483  gocont=1;
484  trifprintf("#go.cont called\n");
485 
486  fscanf(gocont_file,"%d",&runtype); // can be used to specify which restart file to use among other things
487  }
488  fclose(gocont_file);
489  }
490 
491 
492  if(numprocs>1){
493 #if(USEMPI)
494  MPI_Bcast(&gocont,1,MPI_INT,MPIid[0], MPI_COMM_GRMHD);
495  MPI_Bcast(&runtype,1,MPI_INT,MPIid[0], MPI_COMM_GRMHD);
496 #endif
497  }
498  }// end if checking cont file
499 
500  }// end if cont file exits
501  }
502  else if(whichlocation==CHECKTIME){
503  // check if user wants to stop or not(go.go)
504  if(myid==0){
505 
506  if(!(nstep%NGOCHECK)){
507  sprintf(stemp,"%sgo.go",DATADIR);
508 
509  if((gogo_file=fopen(stemp,"rt"))==NULL){
510  // dualfprintf(fail_file,"Could not open go file: %s\n",stemp);
511  // myexit(1);
512  // just assume user didn't want to use this file
513  }
514  else{
515  goch=fgetc(gogo_file);
516  if( (goch=='n')||(goch=='N')){
517  goend=1;
518  trifprintf("#go.go called\n");
519  }
520  fclose(gogo_file);
521  // if myid!=0 and numprocs>1 then could deal with this, but messy due to timers
522 
523  }// end if go file exists
524  }// end if time to check go file
525 
526  }// end myid==0
527 
528 #if(USEMPI)
529  MPI_Bcast(&goend,1,MPI_INT,MPIid[0], MPI_COMM_GRMHD);
530 #endif
531  trifprintf("#proc: %s go.go called\n",myidtxt);
532  if(goend==1) reallaststep=1;
533 
534  }
535  else if(whichlocation==STOPTIME){
536  if(goend==1) trifprintf("proc: %s Go end called(go.go)\n",myidtxt) ;
537  }
538 
539 
540 
541 
542  return(0);
543 
544 }
545 
546 
547 
548 
549 
550 
551 
552 
553 
554 
555 
556