openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
main.cc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
12 #include <cstdio>
13 #include <csignal>
14 
15 //#include <omp.h>
16 #include "simulator.h"
17 #include "async_io.h"
18 #include "numerics.h"
19 #include "fem.h"
20 
21 
22 #ifdef WITH_CALIPER
23 #include "caliper/cali.h"
24 #else
25 #include "caliper_hooks.h"
26 #endif
27 
28 // globals
29 namespace opencarp {
30 namespace user_globals {
34  std::map<mesh_t, sf_mesh> mesh_reg;
36  std::map<SF::quadruple<int>, SF::index_mapping<mesh_int_t> > map_reg;
38  std::map<physic_t, Basic_physic*> physics_reg;
42  std::map<datavec_t, sf_vec*> datavec_reg;
44  FILE* petsc_error_fd = NULL;
46  bool using_legacy_stimuli = false;
48  MPI_Comm IO_Intercomm;
49 #ifdef WITH_POWERCAPPING
51  powercapping_manager *pc_manager;
52 #endif
53 } // namespace user_globals
54 } // namespace opencarp
55 
56 using namespace opencarp;
57 
58 #undef __FUNCT__
59 #define __FUNCT__ "main"
60 int main(int argc, char** argv)
61 {
63 // #ifdef __osf__
64 // signal( SIGFPE, SIG_IGN );
65 // #endif
66 // signal( SIGHUP, savequit );
67 // signal( SIGINT, savequit );
68 // signal( SIGQUIT, savequit );
69 // signal( SIGIO, savequit );
70 
71  //omp_set_num_threads(20);
72 
73  parse_params_cpy(argc, argv);
74 
75  // This is called intentionally before MPI_Init(), which might be helpful
76  // in an HPC context, where a script might call this without mpirun on the master.
77  // Still, in a parallel run we dont want every rank to print the build info,
78  // as this is quite spammy. Therefore, // we call show_build_info() a second time
79  // after MPI_Init, but only on rank 0.
80  if(param_globals::buildinfo) {
82  exit(EXIT_SUCCESS);
83  }
84 
85  char *DBfile = NULL; // could be used to pass in ~/.petscrc
86  char *help_msg = NULL;
87  initialize_PETSc(&argc, argv, DBfile, help_msg);
88 
89  if(get_rank() == 0)
91 
92  bool io_rank = setup_IO(argc, argv);
93 
94  if(!io_rank) {
96 
97  // accumulate check and conversions of param globals in here, so that
98  // the rest of the codebase can remain stateless
100 
101  // set up meshes
103  bool require_fibers = phys_defined(PHYSREG_INTRA_ELEC) || phys_defined(PHYSREG_LAPLACE);
104  setup_meshes(require_fibers);
105  output_meshes();
106 
107  // for experiment EXP_SETUP_MESH we quit after the mesh output step
108  if(param_globals::experiment == EXP_SETUP_MESH)
110 
111  // convert input to internal unit
113 
114  // register and initialize physics
117 
118  // for experiment EXP_OUTPUT_FEM we quit after the electrics initialization
119  if(param_globals::experiment == EXP_OUTPUT_FEM)
121 
122  // simulate
123  if(param_globals::experiment == EXP_NORMAL){
124 simulate();
125  }
126 
127  post_process();
128 
129  if(param_globals::num_io_nodes > 0)
131 
133  } else {
134  async::async_IO_queue queue;
136 
137  PetscFinalize();
138  exit(EXIT_SUCCESS);
139  }
140 }
Async IO functions.
#define CALI_CXX_MARK_FUNCTION
Definition: caliper_hooks.h:8
The scatterer registry class.
centralize time managment and output triggering
Definition: timer_utils.h:58
Top-level header of FEM module.
int main(int argc, char **argv)
Definition: main.cc:60
void COMPUTE_send_exit_flag()
this function sends the exit flag from a compute node to an io node.
Definition: async_io.cc:79
void IO_poll_for_output(async_IO_queue &io_queue)
Definition: async_io.cc:21
MPI_Comm IO_Intercomm
Communicator between IO and compute worlds.
Definition: main.cc:48
FILE * petsc_error_fd
file descriptor for petsc error output
Definition: main.cc:44
timer_manager * tm_manager
a manager for the various physics timers
Definition: main.cc:40
std::map< datavec_t, sf_vec * > datavec_reg
important solution vectors from different physics
Definition: main.cc:42
std::map< SF::quadruple< int >, SF::index_mapping< mesh_int_t > > map_reg
Registriy for the inter domain mappings.
Definition: main.cc:36
bool using_legacy_stimuli
flag storing whether legacy stimuli are used
Definition: main.cc:46
SF::scatter_registry scatter_reg
Registry for the different scatter objects.
Definition: main.cc:32
std::map< mesh_t, sf_mesh > mesh_reg
Registry for the different meshes used in a multi-physics simulation.
Definition: main.cc:34
std::map< physic_t, Basic_physic * > physics_reg
the physics
Definition: main.cc:38
void initialize_physics()
Initialize all physics in the registry.
Definition: sim_utils.cc:1219
bool setup_IO(int argc, char **argv)
Definition: sim_utils.cc:1555
void parse_params_cpy(int argc, char **argv)
Initialize input parameters on a copy of the real command line parameters.
Definition: sim_utils.cc:1150
void cleanup_and_exit()
Definition: sim_utils.cc:2650
void register_physics()
Register physics to the physics registry.
Definition: sim_utils.cc:1197
void post_process()
do postprocessing
Definition: sim_utils.cc:2025
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:1346
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
Definition: basics.h:269
bool phys_defined(int physreg)
function to check if certain physics are defined
void show_build_info()
show the build info, exit if -buildinfo was provided. This code runs before MPI_Init().
Definition: sim_utils.cc:1334
void basic_timer_setup()
Here we set up the timers that we always want to have, independent of physics.
Definition: sim_utils.cc:1627
void setup_meshes(bool require_fibers=true)
Read in the reference mesh and use its data to populate all meshes registered in the mesh registry.
Definition: sim_utils.cc:2235
void output_meshes()
Definition: sim_utils.cc:2553
void setup_petsc_err_log()
set up error logs for PETSc, so that it doesnt print errors to stderr.
Definition: sim_utils.cc:2677
void simulate()
Main simulate loop.
Definition: sim_utils.cc:1937
void parse_mesh_types()
Parse the phys_type CLI parameters and set up (empty) SF::meshdata meshes.
Definition: sim_utils.cc:2100
Top-level header file of numerics module.
#define PHYSREG_INTRA_ELEC
Definition: sf_interface.h:69
#define PHYSREG_LAPLACE
Definition: sf_interface.h:74
#define EXP_OUTPUT_FEM
Definition: sim_utils.h:189
#define EXP_SETUP_MESH
Definition: sim_utils.h:191
#define EXP_NORMAL
Definition: sim_utils.h:188
queue with the data required for performing async IO writes to IGB
Definition: async_io.h:40