Main driver.
The main driver function that calls the initialization, solving, and cleaning up functions.
184 struct timeval main_start, solve_start;
185 struct timeval main_end , solve_end ;
187 PetscBool use_petscts;
195 printf(
"HyPar - Serial Version\n");
199 MPI_Init(&argc,&argv);
200 MPI_Comm_dup(MPI_COMM_WORLD, &world);
201 MPI_Comm_rank(MPI_COMM_WORLD,&rank );
202 MPI_Comm_size(MPI_COMM_WORLD,&nproc);
203 if (!rank) printf(
"HyPar - Parallel (MPI) version with %d processes\n",nproc);
207 PetscInitialize(&argc,&argv,(
char*)0,
help);
208 if (!rank) printf(
"Compiled with PETSc time integration.\n");
216 gettimeofday(&main_start,NULL);
226 FILE *f_ensemble_sim = fopen(ensemble_sim_fname.c_str(),
"r");
227 FILE *f_sparsegrids_sim = fopen(sparsegrids_sim_fname.c_str(),
"r");
229 if (f_ensemble_sim && f_sparsegrids_sim) {
231 fprintf(stderr,
"Error: Cannot have both %s and %s input files.\n",
233 fprintf(stderr,
"Remove one or both of them depending on the kind of simulation you want to run.\n");
234 fclose(f_ensemble_sim);
235 fclose(f_sparsegrids_sim);
237 }
else if (f_ensemble_sim) {
240 fclose(f_ensemble_sim);
242 }
else if (f_sparsegrids_sim) {
245 fclose(f_sparsegrids_sim);
256 MPI_Bcast(&sim_type, 1, MPI_INT, 0, MPI_COMM_WORLD);
262 if (!rank) printf(
"-- Ensemble Simulation --\n");
265 if (!rank) printf(
"-- Sparse Grids Simulation --\n");
268 fprintf(stderr,
"ERROR: invalid sim_type (%d) on rank %d.\n",
273 fprintf(stderr,
"ERROR: unable to create sim on rank %d.\n",
279 ierr = sim->
define(rank, nproc);
281 printf(
"Error: Simulation::define() failed on rank %d\n",
286 printf(
"Error: Simulation::define() returned with status %d on process %d.\n",
296 use_petscts = PETSC_FALSE;
297 ierr = PetscOptionsGetBool(
nullptr,
nullptr,
300 nullptr); CHKERRQ(ierr);
301 if (use_petscts == PETSC_TRUE) use_petsc = 1;
308 printf(
"Error: Simulation::ReadInputs() returned with status %d on process %d.\n",ierr,rank);
315 printf(
"Error: Simulation::Initialize() returned with status %d on process %d.\n",ierr,rank);
322 printf(
"Error: Simulation::InitialSolution() returned with status %d on process %d.\n",ierr,rank);
329 printf(
"Error: Simulation::InitializeBoundaries() returned with status %d on process %d.\n",ierr,rank);
336 printf(
"Error: Simulation::InitializeImmersedBoundaries() returned with status %d on process %d.\n",ierr,rank);
343 printf(
"Error: Simulation::InitializeSolvers() returned with status %d on process %d.\n",ierr,rank);
350 printf(
"Error: Simulation::InitializePhysics() returned with status %d on process %d.\n",ierr,rank);
357 printf(
"Error: Simulation::InitializePhysicsData() returned with status %d on process %d.\n",ierr,rank);
364 printf(
"Error: Simulation::InitializationWrapup() returned with status %d on process %d.\n",ierr,rank);
372 MPI_Barrier(MPI_COMM_WORLD);
374 gettimeofday(&solve_start,NULL);
376 if (use_petsc == 1) {
380 printf(
"Error: Simulation::SolvePETSc() returned with status %d on process %d.\n",ierr,rank);
387 printf(
"Error: Simulation::Solve() returned with status %d on process %d.\n",ierr,rank);
395 printf(
"Error: Simulation::Solve() returned with status %d on process %d.\n",ierr,rank);
399 gettimeofday(&solve_end,NULL);
401 MPI_Barrier(MPI_COMM_WORLD);
403 gettimeofday(&main_end,NULL);
407 walltime = ( (main_end.tv_sec * 1000000 + main_end.tv_usec )
408 - (main_start.tv_sec * 1000000 + main_start.tv_usec));
409 double main_runtime = (double) walltime / 1000000.0;
410 ierr =
MPIMax_double(&main_runtime,&main_runtime,1,&world);
if(ierr)
return(ierr);
411 walltime = ( (solve_end.tv_sec * 1000000 + solve_end.tv_usec )
412 - (solve_start.tv_sec * 1000000 + solve_start.tv_usec));
413 double solver_runtime = (double) walltime / 1000000.0;
414 ierr =
MPIMax_double(&solver_runtime,&solver_runtime,1,&world);
if(ierr)
return(ierr);
421 if (!rank) printf(
"Finished.\n");
432 MPI_Comm_free(&world);
virtual int SolvePETSc()=0
Class describing ensemble simulations.
virtual int InitialSolution()=0
virtual int define(int, int)=0
virtual int InitializationWrapup()
virtual int mpiCommDup()=0
Class describing sparse grids simulations.
virtual int Initialize()=0
virtual int InitializeSolvers()=0
virtual int InitializeImmersedBoundaries()=0
#define _SIM_TYPE_SINGLE_
virtual int ReadInputs()=0
static void initializePythonPlotting(int)
virtual void WriteErrors(double, double)=0
virtual bool isDefined() const =0
virtual int InitializeBoundaries()=0
int MPIMax_double(double *, double *, int, void *)
#define _SIM_TYPE_SPARSE_GRIDS_
virtual int InitializePhysicsData()=0
#define _SPARSEGRIDS_SIM_INP_FNAME_
static void initializePython(int)
#define _SIM_TYPE_ENSEMBLE_
Base class for a simulation.
Class describing a single simulation.
#define _ENSEMBLE_SIM_INP_FNAME_
virtual void usePetscTS(PetscBool)=0
virtual int InitializePhysics()=0