openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
main.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is licensed under the openCARP Academic Public License (APL)
7 // v1.0: You can use and redistribute it and/or modify it in non-commercial
8 // academic environments under the terms of APL as published by the openCARP
9 // project v1.0, or (at your option) any later version. Commercial use requires
10 // a commercial license (info@opencarp.org).
11 //
12 // This program is distributed without any warranty; see the openCARP APL for
13 // more details.
14 //
15 // You should have received a copy of the openCARP APL along with this program
16 // and can find it online: http://www.opencarp.org/license
17 // ----------------------------------------------------------------------------
18 
27 #include <cstdio>
28 #include <csignal>
29 
30 //#include <omp.h>
31 // we set PrMGLOBAL ONLY ONCE. this will initialize the global variables
32 // in only one compilation unit
33 #define PrMGLOBAL
34 #include "simulator.h"
35 #include "async_io.h"
36 #include "numerics.h"
37 #include "fem.h"
38 
39 
40 #ifdef WITH_CALIPER
41 #include "caliper/cali.h"
42 #else
43 #include "caliper_hooks.h"
44 #endif
45 
46 // globals
47 namespace opencarp {
48 namespace user_globals {
52  std::map<mesh_t, sf_mesh> mesh_reg;
54  std::map<SF::quadruple<int>, SF::index_mapping<int> > map_reg;
56  std::map<physic_t, Basic_physic*> physics_reg;
60  std::map<datavec_t, sf_vec*> datavec_reg;
62  FILE* petsc_error_fd = NULL;
64  bool using_legacy_stimuli = false;
66  MPI_Comm IO_Intercomm;
67 } // namespace user_globals
68 } // namespace opencarp
69 
70 using namespace opencarp;
71 
72 #undef __FUNCT__
73 #define __FUNCT__ "main"
74 int main(int argc, char** argv)
75 {
76 // #ifdef __osf__
77 // signal( SIGFPE, SIG_IGN );
78 // #endif
79 // signal( SIGHUP, savequit );
80 // signal( SIGINT, savequit );
81 // signal( SIGQUIT, savequit );
82 // signal( SIGIO, savequit );
83 
84  //omp_set_num_threads(20);
85 
86  parse_params_cpy(argc, argv);
87 
88  // This is called intentionally before MPI_Init(), which might be helpful
89  // in an HPC context, where a script might call this without mpirun on the master.
90  // Still, in a parallel run we dont want every rank to print the build info,
91  // as this is quite spammy. Therefore, // we call show_build_info() a second time
92  // after MPI_Init, but only on rank 0.
93  if(param_globals::buildinfo) {
95  exit(EXIT_SUCCESS);
96  }
97 
98  char *DBfile = NULL; // could be used to pass in ~/.petscrc
99  char *help_msg = NULL;
100  initialize_PETSc(&argc, argv, DBfile, help_msg);
101 
102  if(get_rank() == 0)
103  show_build_info();
104 
105  bool io_rank = setup_IO(argc, argv);
106 
107  if(!io_rank) {
109 
110  // accumulate check and conversions of param globals in here, so that
111  // the rest of the codebase can remain stateless
113 
114  // set up meshes
115 CALI_MARK_BEGIN("parse_meshes");
117 CALI_MARK_END("parse_meshes");
118 CALI_MARK_BEGIN("setup_meshes");
119  setup_meshes();
120 CALI_MARK_END("setup_meshes");
121 CALI_MARK_BEGIN("output_meshes");
122  output_meshes();
123 CALI_MARK_END("output_meshes");
124 
125  // for experiment EXP_SETUP_MESH we quit after the mesh output step
126  if(param_globals::experiment == EXP_SETUP_MESH)
128 
129  // convert input to internal units
131 
132  // register and initialize physics
133 CALI_MARK_BEGIN("init_physics");
136 CALI_MARK_END("init_physics");
137 
138  // for experiment EXP_OUTPUT_FEM we quit after the electrics initialization
139  if(param_globals::experiment == EXP_OUTPUT_FEM)
141 
142  // simulate
143  if(param_globals::experiment == EXP_NORMAL){
144 CALI_MARK_BEGIN("simulate");
145 simulate();
146 CALI_MARK_END("simulate");
147  }
148 
149 CALI_MARK_BEGIN("postprocess");
150  post_process();
151 CALI_MARK_END("postprocess");
152 
153  if(param_globals::num_io_nodes > 0)
155 
157  } else {
158  async::async_IO_queue queue;
160 
161  PetscFinalize();
162  exit(EXIT_SUCCESS);
163  }
164 }
165 
Async IO functions.
#define CALI_MARK_BEGIN(_str)
Definition: caliper_hooks.h:4
#define CALI_MARK_END(_str)
Definition: caliper_hooks.h:5
Index mapping class. This is a bijective mapping.
Definition: SF_container.h:220
The scatterer registry class.
centralize time managment and output triggering
Definition: timer_utils.h:73
Top-level header of FEM module.
int main(int argc, char **argv)
Definition: main.cc:74
void COMPUTE_send_exit_flag()
this function sends the exit flag from a compute node to an io node.
Definition: async_io.cc:94
void IO_poll_for_output(async_IO_queue &io_queue)
Definition: async_io.cc:36
MPI_Comm IO_Intercomm
Communicator between IO and compute worlds.
Definition: main.cc:66
FILE * petsc_error_fd
file descriptor for petsc error output
Definition: main.cc:62
timer_manager * tm_manager
a manager for the various physics timers
Definition: main.cc:58
std::map< datavec_t, sf_vec * > datavec_reg
important solution vectors from different physics
Definition: main.cc:60
std::map< SF::quadruple< int >, SF::index_mapping< int > > map_reg
Registriy for the inter domain mappings.
Definition: main.cc:54
bool using_legacy_stimuli
flag storing whether legacy stimuli are used
Definition: main.cc:64
SF::scatter_registry scatter_reg
Registry for the different scatter objects.
Definition: main.cc:50
std::map< mesh_t, sf_mesh > mesh_reg
Registry for the different meshes used in a multi-physics simulation.
Definition: main.cc:52
std::map< physic_t, Basic_physic * > physics_reg
the physics
Definition: main.cc:56
void initialize_physics()
Initialize all physics in the registry.
Definition: sim_utils.cc:103
bool setup_IO(int argc, char **argv)
Definition: sim_utils.cc:425
void parse_params_cpy(int argc, char **argv)
Initialize input parameters on a copy of the real command line parameters.
Definition: sim_utils.cc:46
void setup_meshes()
Read in the reference mesh and use its data to populate all meshes registered in the mesh registry.
Definition: sim_utils.cc:1030
void cleanup_and_exit()
Definition: sim_utils.cc:1260
void register_physics()
Register physics to the physics registry.
Definition: sim_utils.cc:89
void post_process()
do postprocessing
Definition: sim_utils.cc:848
void check_and_convert_params()
Here we want to put all parameter checks, conversions and modifications that have been littered throu...
Definition: sim_utils.cc:230
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
Definition: basics.h:276
void show_build_info()
show the build info, exit if -buildinfo was provided. This code runs before MPI_Init().
Definition: sim_utils.cc:222
void basic_timer_setup()
Here we set up the timers that we always want to have, independent of physics.
Definition: sim_utils.cc:495
void output_meshes()
Definition: sim_utils.cc:1208
void setup_petsc_err_log()
set up error logs for PETSc, so that it doesnt print errors to stderr.
Definition: sim_utils.cc:1284
void simulate()
Main simulate loop.
Definition: sim_utils.cc:791
void parse_mesh_types()
Parse the phys_type CLI parameters and set up (empty) SF::meshdata meshes.
Definition: sim_utils.cc:900
Top-level header file of numerics module.
#define EXP_OUTPUT_FEM
Definition: sim_utils.h:158
#define EXP_SETUP_MESH
Definition: sim_utils.h:160
#define EXP_NORMAL
Definition: sim_utils.h:157
queue with the data required for performing async IO writes to IGB
Definition: async_io.h:55