21#include <Perf_counters.h>
30static const char directory_separator =
'\\';
32static const char directory_separator =
'/';
34#include <DeviceMemory.h>
35#include <TRUSTTravPool.h>
36#include <Schema_Comm_Vecteurs.h>
37#include <MD_Vector_tools.h>
39extern void desalloue_pwd();
43 Cerr <<
"TRUST_EXECUTABLE [CASE[.data]] [options]\n";
44 Cerr <<
" CASE is the basename of the trust data file (must have .data extension)\n";
45 Cerr <<
" If no CASE given, the current directory name is used\n";
46 Cerr <<
" -help_trust => print options\n";
47 Cerr <<
" -mpi => run in parallel with MPI (must run with mpirun)\n";
48 Cerr <<
" -check_enabled=0|1 => enables or disables runtime checking of parallel messages\n";
49 Cerr <<
" -debugscript=SCRIPT => execute \"SCRIPT n\" after parallel initialisation, n=processor rank\n";
50 Cerr <<
" -petsc=0 => disable call to PetscInitialize\n";
51 Cerr <<
" -journal=0..9 => select journal level (0=disable, 9=maximum verbosity)\n";
52 Cerr <<
" -journal_master => only master processor writes a journal \n";
53 Cerr <<
" -log_directory=DIR => Writes the .log files into directory DIR\n";
54 Cerr <<
" -disable_ieee => Disable the detection of NaNs. The detection can also be de-activated with env variable TRUST_DISABLE_FP_EXCEPT set to non zero.\n";
55 Cerr <<
" -no_verify => Disable the call to verifie function (from Type_Verifie) to catch outdated keywords while reading data file.\n";
56 Cerr <<
" -disable_stop => Disable the writing of the .stop file.\n";
57 Cerr <<
" -unit => Only perform TRUST initialisation without trying to execute any data file. Used for unit testing.\n";
63#define DEFAULT_CHECK_ENABLED 0
65#define DEFAULT_CHECK_ENABLED 1
68int main_TRUST(
int argc,
char** argv,
mon_main*& main_process,
bool with_mpi,
bool ieee)
81 int check_enabled = DEFAULT_CHECK_ENABLED;
82 bool with_petsc =
true;
84 int verbose_level = -1;
85 bool journal_master =
false;
87 Nom log_directory =
"";
88 bool helptrust =
false;
91#if defined(_COMPILE_AVEC_CLANG) || defined (_COMPILE_AVEC_FCC) || defined(__NVCOMPILER) || defined(__NVCC__)
94 bool apply_verification =
true;
95 bool disable_stop =
false;
96 bool unit_test =
false;
102 arguments_info =
"Executable: ";
103 arguments_info += argv[0];
104 arguments_info +=
"\n";
105 for (
int i = 1; i < argc; i++)
109 if (strcmp(argv[i],
"-help_trust") == 0)
113 else if (strcmp(argv[i],
"-disable_ieee") == 0)
116 arguments_info +=
"-disable_ieee => disable of feenableexcept\n";
118 else if (strcmp(argv[i],
"-mpi") == 0)
121 arguments_info +=
"-mpi => parallel computation with mpi\n";
123 else if (strcmp(argv[i],
"-no_verify") == 0)
125 apply_verification =
false;
126 arguments_info +=
"-no_verify => Disable the call to verifie function (from Type_Verifie) to catch outdated keywords while reading data file.\n";
128 else if (strcmp(argv[i],
"-check_enabled=1") == 0)
130 check_enabled =
true;
131 arguments_info +=
"-check_enabled=1 => force enable parallel message checking\n";
133 else if (strcmp(argv[i],
"-check_enabled=0") == 0)
135 check_enabled =
false;
136 arguments_info +=
"-check_enabled=0 => force disable parallel message checking\n";
138 else if (strncmp(argv[i],
"-debugscript=", 13) == 0)
140 exec_script = argv[i]+13;
141 arguments_info +=
"-debugscript => execute script ";
142 arguments_info += exec_script;
143 arguments_info +=
"\n";
145 else if (strcmp(argv[i],
"-petsc=0") == 0)
148 arguments_info +=
"-petsc=0 => disable call to PetscInitialize\n";
150 else if (strncmp(argv[i],
"-journal=", 9) == 0)
152 int level = atoi(argv[i]+9);
153 if (level < 0 || level > 9)
155 Cerr <<
"Bad journal level : " << argv[i] << finl;
160 verbose_level = level;
161 arguments_info +=
"-journal=";
162 arguments_info +=
Nom(level);
163 arguments_info +=
"\n";
166 else if (strcmp(argv[i],
"-journal_master") == 0)
168 journal_master =
true;
169 arguments_info +=
"-journal_master => Only the master processor will write a journal";
170 arguments_info +=
"\n";
172 else if (strncmp(argv[i],
"-log_directory=", 15) == 0)
174 log_directory = argv[i]+15;
175 log_directory += directory_separator;
176 arguments_info +=
"-log_directory => Writes the .log files into directory ";
177 arguments_info += log_directory;
178 arguments_info +=
"\n";
180 else if (strcmp(argv[i],
"-disable_stop") == 0)
183 arguments_info +=
"-disable_stop => Disable the writing of the .stop file.\n";
185 else if (strcmp(argv[i],
"-unit") == 0)
193 arguments_info +=
"Data file name = ";
194 arguments_info += data_file;
195 arguments_info +=
"\n";
200 int nprocs = (int) strtol(argv[2], (
char **)
nullptr, 10);
201 if (!errno && nprocs)
207 arguments_info +=
"Running in parallel with ";
208 arguments_info +=
Nom(nproc);
209 arguments_info +=
" processors\n";
213 arguments_info +=
"Sequential calculation\n";
217 Cerr <<
"Bad number of processors in old syntax TRUST case N" << finl;
264 statistics().begin_count(STD_COUNTERS::total_execution_time);
265 main_process=
new mon_main(verbose_level, journal_master, log_directory, apply_verification, disable_stop);
266 main_process->
init_parallel(argc, argv, with_mpi, check_enabled, with_petsc);
270 fedisableexcept(FE_ALL_EXCEPT);
274 char* theValue = getenv(
"TRUST_DISABLE_FP_EXCEPT");
275 if (theValue ==
nullptr || atoi(theValue) == 0)
277 arguments_info +=
"feenableexcept enabled.\n";
281 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
296 if(exec_script !=
"")
300 Cerr <<
"[" <<
Process::me() <<
"] Debug mode => execute command : " << exec_script << finl;
301 std::cerr << system(exec_script) << std::endl;
306 if (helptrust) usage();
310 Cerr << arguments_info;
314 Cerr <<
"Error: nproc on command line does not match mpirun parameter.\n"
315 <<
" Use same number or -mpi parameter instead." << finl;
320 cerr.setf(ios::scientific);
322 cout.setf(ios::scientific);
334 Cerr <<
"No command line argument. Data file name from directory name:\n "
336 const int l = pwd.longueur() - 1;
338 while(i > 0 && pwd[i] != directory_separator)
346 Cerr <<
"Error : pwd() ends with directory separator " << (int)directory_separator << finl;
354 Cerr <<
"Data file : " << data_file << finl;
361 Cerr <<
" (removing .data extension)" << finl;
363 data_file.
prefix(
".data");
368 Cerr<<
"Study location: " << ::pwd() << finl;
369 Cerr<<
"Case name: " << data_file << finl;
370 Cerr<<
" code : "<< argv[0] << finl;
371 Cerr<<
" version : " << TRUST_VERSION <<
" " << finl;
374 main_process->
dowork(data_file);
380 Cerr <<
"Stopping processes." << finl;
383 Cerr <<
"DEBUG: Statistics for Trav arrays (int): " << finl;
386 Cerr <<
"DEBUG: Statistics for Trav arrays (double): " << finl;
389 Cerr <<
"DEBUG: Statistics for Trav arrays (float): " << finl;
407 if(statistics().is_running(STD_COUNTERS::total_execution_time))
408 statistics().end_count(STD_COUNTERS::total_execution_time);
class Nom: a character string for naming TRUST objects.
virtual int finit_par(const char *const n) const
Nom substr_old(const int, const int) const
Returns a name using the usual substr command. NOTE: deb = 1 means the first character of the string.
Nom & prefix(const char *const)
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
static void CleanMyStaticViews()
static void ClearPool()
Empty the TRUSTTrav pool explicitely.
static void PrintStats()
Debug method printing useful stats.
Class created and run by main() and during a TRUST execution through Python.
void dowork(const Nom &nom_du_cas)
void init_parallel(const int argc, char **argv, bool with_mpi, bool check_enabled=false, bool with_petsc=true)