AcouSTO  version 2.0

◆ main()

int main ( int  argc,
char **  argv 
)

AcouSTO Entry point.

int main(int argv, char **argv) AcouSTO Entry point.

  • MPI initialization
  • configuration parsing
  • modules calling geometry, BEM coefficients, solution
  • finalization many things could be improved among which:
    • avoid (where possible) global variables to improve readability
    • introduce a dynamic linking architecture to load modules at runtime
43  {
44  int c ;
45  int option_index = 0; // for getopt
46 
47  /* used for time recording */
48  double rawtime0;
49  double rawtime1;
50  double rawtime2;
51  double rawtime3;
52  double rawtime4;
53  double timebco, timemco, timesol;
54 
55  // log level as read by command line */
56  int log_level = LOG_INFO;
57 
58  /* convenience array chars to store dates */
59  char starttime[80];
60  char endtime[80];
61 
62  int mpierr; // mpi error code
63  int iam, nprocs;
64 
65 
66  int onlymemoryout;
67  DOUBLE mem2 = 0.0;
68  int check_dir = 0; // Defaults to overwrite directory
69 
70  /* Start of code */
71  setLogLevel(log_level); // setting level to info for starters
72 
73  // MPI Initialization. We didn't declare a different error handler, thus the
74  // default behaviour on error is aborting the code. We are fine with it for now.
75  mpierr = MPI_Init(&argc, &argv);
76 
77  MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* getting my rank */
78  MPI_Comm_size(MPI_COMM_WORLD, &size); /* getting group size */
79 
80  MPI_AcouSTO_structs(); // Initialization of AcouSTO custom structures
81 
82 // allocating GLOBAL structures for data (defined in common.h)
83  runinfo = calloc(1,sizeof(struct run_info));
84  rundetails = calloc(1,sizeof(struct run_details));
85  modgeominfo = calloc(1,sizeof(struct modgeom_info));
86  modcoefacinfo = calloc(1,sizeof(struct modcoefac_info));
87  modcoemicinfo = calloc(1,sizeof(struct modcoemic_info));
88  modsolinfo = calloc(1,sizeof(struct modsol_info));
89 #ifdef _MYSQL_
90  mysqlinfo = calloc(1,sizeof(struct mysql_info));
91 #endif
92 
93  // recording start time
94  time(&rundetails->starttime);
95 
96  // Allocating solution struct
97  solution = calloc(1,sizeof(struct solution_struct));
98 
99  /*
100  * Read main options with getopt only on master process.
101  */
102  if (0 == rank) { /* MASTER PROCESS */
103  fileinfo = malloc(sizeof(struct file_info));
104 
105  /* Defining long options struct */
106  static struct option long_options[] = {
107  { "dat-file", required_argument, 0, 'f' },
108  { "version", no_argument, 0, 'V' },
109  { "help", no_argument, 0, 'h' },
110  { "log-level", required_argument, 0, 'l' },
111  { "estimate-memory", required_argument, 0, 'm' } ,
112  { "check-dir", no_argument, 0, 'c' }
113  };
114 
115  opterr = 0; // reset error
116 
117  //back up main parameters
118  main_argc = argc;
119  main_argv = argv;
120  onlymemoryout= 0;
121 
122  /* Options Parsing loop */
123  while ((c = getopt_long(argc, argv, "f:l:Vhmc", long_options, &option_index)) != -1)
124  switch (c)
125  {
126  case 'f': // file name
127  datfile = malloc(strlen(optarg)+1);
128  strcpy(datfile,optarg);
129  break;
130  case 'V': // version
131  printf("%s %s\n", ac_name,ac_version);
132  break;
133  case 'c': // Checkdir flag
134  check_dir = 1;
135  break;
136  case 'h': // help
137  printhelp();
138  exit(1);
139  break;
140  case 'l': // log level
141  log_level = atoi(optarg);
142  setLogLevel(log_level);
143  break;
144  case '?': // what ?!
145  if (optopt == 'f')
146  fprintf(stderr, "Option -%c requires an argument.\n", optopt);
147  case 'm': // Only memory out
148  onlymemoryout = 1;
149 
150  default: // default prints nothing
151  printf(" ");
152  }
153  logger(LOG_INFO, "**************** Job started ***************\n");
154  logger(LOG_INFO, "Program started\n");
155 
156  /* READING CONFIG FILE */
157  if(-1 == readconfig(datfile,check_dir)){
158  cleanup();
159  return -1;
160  }
161 
162 
163  } // END OF MASTER PROCESS SECTION
164 
165  // Sending &configuration to all nodes
166  MPI_Bcast(&log_level, 1, MPI_INT, 0, MPI_COMM_WORLD);
167  setLogLevel(log_level);
168 
169  logger(LOG_DEBUG, "Broadcasting &config...\n");
170  MPI_Bcast(runinfo , 1, mpi_runinfo_type , 0, MPI_COMM_WORLD);
171  MPI_Bcast(modgeominfo , 1, mpi_geominfo_type, 0, MPI_COMM_WORLD);
172  MPI_Bcast(modsolinfo , 1, mpi_solinfo_type , 0, MPI_COMM_WORLD);
173  MPI_Bcast(&modcoemicinfo->active, 1, MPI_INT , 0, MPI_COMM_WORLD);
174  MPI_Bcast(&modcoefacinfo->active, 1, MPI_INT , 0, MPI_COMM_WORLD);
175 
176 #ifdef _MYSQL_
177  // broadcasting only info on mysql active
178  MPI_Bcast(&mysqlinfo->active,1,MPI_INT,0,MPI_COMM_WORLD);
179 #endif
180  logger(LOG_DEBUG, "Broadcasting &config done\n");
181 
182  // consistency checks
184  logger(LOG_ERROR, "Number of radiant panels (%d) cannot be higher then number of unsymmetrized elements(%d): \n", modsolinfo->nradian, modgeominfo->ncntr);
185  cleanup();
186  return 1;
187  }
188 
189  // consistency checks
191  logger(LOG_ERROR, "Number of impedent panels (%d) cannot be higher then number of unsymmetrized elements(%d): \n", modsolinfo->nimped, modgeominfo->ncntr);
192  cleanup();
193  return 1;
194  }
195 
196  // initializing BLACS grid
197  if (size < runinfo->nprows * runinfo->npcols) { // check on grid size
198  logger(LOG_ERROR, "Number of processes (%d) not enough for grid size (%d x %d )\n", size, runinfo->nprows, runinfo->npcols);
199  cleanup();
200  return 1;
201  }
202 
203  logger(LOG_INFO, " Initializing process grid [%d x %d]\n", runinfo->nprows, runinfo->npcols);
204  Cblacs_pinfo(&iam, &nprocs);
205  Cblacs_get(0, 0, &runinfo->ctxt);
206  Cblacs_gridinit(&runinfo->ctxt, "R", runinfo->nprows, runinfo->npcols); // grid init
208  logger(LOG_INFO, " Successfully initialized process grid [%d x %d]\n", runinfo->nprows, runinfo->npcols);
209 
210  rawtime0 = MPI_Wtime(); // checkpoint
211 
212  MPI_Bcast(&onlymemoryout,1,MPI_INT,0,MPI_COMM_WORLD);
213  if (rank == 0) {
214  logger(LOG_INFO, "**************** Memory Estimate ***************\n");
215  logger(LOG_INFO,"Consider this as a rough estimate. \n");
216  logger(LOG_INFO,"Memory actually allocated heavily depends on \n");
217  logger(LOG_INFO," the particular combination of parameters used \n");
218  mem2 = estimate_memory2();
219  PRINT_MEM("Estimated Memory for Each Process:", mem2);
220  logger(LOG_INFO, "**************** Memory Estimate-end ***********\n");
221  }
222  if (onlymemoryout) {
223  goto cleanup;
224  }
225  /*******************************************
226  * STARTING ELABORATION
227  *******************************************/
228  /* GEOMETRY */
229  if (1 == modgeominfo->active) {
231  if (1 != georeader()) {
233  cleanup();
234  return 1;
235  }
236  }
237  rawtime1 = MPI_Wtime(); // checkpoint
238 
239  /* Prints VRML and VTK files */
240  if(modsolinfo->printwrl){
241  vrmlout();
242  }
243  if(modsolinfo->printvtk){
244  vtkout_unc();
245  }
246 
248  /* BODY COEFFICIENTS */
249  logger(LOG_DEBUG, "Body Coefficient active: %d\n", modcoefacinfo->active);
251  if (1 != acoustic_body_coefs()) {
253  cleanup();
254  return 1;
255  }
256 
257  //MPI_Barrier(MPI_COMM_WORLD);
258  rawtime2 = MPI_Wtime(); // checkpoint
259 
260  /* MICS COEFFICIENTS */
261  logger(LOG_DEBUG, "Mics Coefficient active: %d\n", modcoemicinfo->active);
262  if (1 != acoustic_mics_coefs()) {
264  cleanup();
265  return 1;
266  }
267  rawtime3 = MPI_Wtime(); // checkpoint
268  }
269 
270  /* SOLUTION */
271  logger(LOG_DEBUG, "Solution active: %d\n", modsolinfo->active);
272  if (1 == modsolinfo->active) {
275  /* Prints VRML files for solution*/
276  if(modsolinfo->printwrl){
277  vrmlout_sol();
278  }
279  }
280 
281  rawtime4 = MPI_Wtime(); // recording end time
282 
283  time(&rundetails->endtime); // recording end time
284  rundetails->elapsed = rawtime4 - rawtime0; // setting elapsed
285  timebco = 0.0; // setting elapsed
286  timemco = 0.0; // setting elapsed
287  timesol = rawtime4 - rawtime1; // setting elapsed
289  timebco = rawtime2 - rawtime1; // setting elapsed
290  timemco = rawtime3 - rawtime2; // setting elapsed
291  timesol = rawtime4 - rawtime3; // setting elapsed
292  }
293  logger(LOG_INFO, "total run time=%f seconds\n", rundetails->elapsed);
294  // dumping rundetails
295  if (rank == 0) {
296  strftime(starttime, sizeof(starttime), "%a %Y-%m-%d %H:%M:%S %Z", localtime(&rundetails->starttime));
297  strftime(endtime, sizeof(endtime), "%a %Y-%m-%d %H:%M:%S %Z", localtime(&rundetails->endtime));
298  logger(LOG_INFO, "---------------------------------\n");
299  logger(LOG_INFO, " Run details\n");
300  logger(LOG_INFO, "---------------------------------\n");
301 #ifdef _MYSQL_
302  logger(LOG_INFO," mysql id = %d\n",mysqlinfo->runid);
303 #endif
304  logger(LOG_INFO, " title = %s\n", rundetails->title);
305  logger(LOG_INFO, " owner = %s\n", rundetails->owner);
306  logger(LOG_INFO, " cfg path = %s\n", rundetails->cfg_filepath);
307  logger(LOG_INFO, " cfg = %s\n", rundetails->cfg_filename);
308  logger(LOG_INFO, " start = %s\n", starttime);
309  logger(LOG_INFO, " end = %s\n", endtime);
310  logger(LOG_INFO, " elapsed = %f s\n", rundetails->elapsed);
311  logger(LOG_INFO, " for body coefs = %f s\n", timebco);
312  logger(LOG_INFO, " for mics coefs = %f s\n", timemco);
313  logger(LOG_INFO, " for solution = %f s\n", timesol);
314  logger(LOG_INFO, " no. of procs. = %d\n", rundetails->nnodes);
315 #ifdef _MYSQL_
316  // Storing run on MySQL if enabled.
317  if(mysqlinfo->active) {
318  mysql_update();
319  }
320 #endif
322  "**************** Job finished ***************\n");
323  }
324 
325  cleanup:
326  if (onlymemoryout) {
327  if (0 == rank) {
328  PRINT_MEM("Total Allocated Memory:", TOTAL_MEMORY);
329  }
330  } else {
331  PRINT_MEM("Total Allocated Memory:", TOTAL_MEMORY);
332  }
334  logger(LOG_INFO, "cleanup...\n");
335  cleanup(); // cleaning up
337  MPI_Finalize();
338  return 0;
339 }
#define MSG_SOLUTION_START
Definition: messages.h:50
int acoustic_mics_coefs()
Definition: ac_coef_mics.c:48
struct run_info * runinfo
Definition: globals.h:34
#define MSG_PROGRAM_END
Definition: messages.h:52
int npcols
Definition: structs.h:113
Definition: structs.h:392
int mysql_update()
Definition: mysqlsave.c:60
MPI_Datatype mpi_solinfo_type
Definition: globals.h:118
Definition: structs.h:355
const char * title
Definition: structs.h:135
int ncntr
Definition: structs.h:299
void Cblacs_pinfo(int *mypnum, int *nprocs)
int nimped
Definition: structs.h:450
int main_argc
Definition: globals.h:74
Holds Solution values.
Definition: structs.h:553
time_t endtime
Definition: structs.h:147
Parameters and variables for the solution Module.
Definition: structs.h:436
const char * owner
Definition: structs.h:133
char * cfg_filename
Definition: structs.h:137
void MPI_AcouSTO_structs()
Definition: mpiutils.c:54
int nnodes
Definition: structs.h:151
MPI_Datatype mpi_geominfo_type
Definition: globals.h:114
int myrow
Definition: structs.h:115
int nprows
Definition: structs.h:111
MEMORY TOTAL_MEMORY
Definition: globals.h:152
#define MSG_GEOMETRY_START
Definition: messages.h:44
BOOL active
Definition: structs.h:282
BOOL active
Definition: structs.h:393
void vrmlout_sol()
Definition: vrmlout_sol.c:30
void acoustic_solution()
Definition: solution.c:32
int size
Definition: globals.h:81
#define LOG_INFO
Definition: logger.h:26
void printhelp()
Definition: ac_mysqlread.c:56
char * cfg_filepath
Definition: structs.h:139
int georeader()
Definition: geom.c:64
int ctxt
Definition: structs.h:109
struct file_info * fileinfo
Definition: globals.h:32
double elapsed
Definition: structs.h:149
struct modcoefac_info * modcoefacinfo
Definition: globals.h:40
Details about the run.
Definition: structs.h:131
int Cblacs_gridinit(int *context, char *order, int np_row, int np_col)
BOOL active
Definition: structs.h:356
BOOL printwrl
Definition: structs.h:485
#define LOG_ERROR
Definition: logger.h:24
void cleanup()
Definition: cleanup.c:26
struct solution_struct * solution
Definition: globals.h:52
MPI_Datatype mpi_runinfo_type
Definition: globals.h:110
const char * ac_version
Definition: main.c:28
#define MSG_COEF_START
Definition: messages.h:45
int acoustic_body_coefs()
Definition: ac_coef_body.c:50
void Cblacs_get(int context, int request, int *value)
MEMORY estimate_memory2()
Definition: memory.c:145
void Cblacs_gridinfo(int context, int *np_row, int *np_col, int *my_row, int *my_col)
int custombc
Definition: structs.h:523
BOOL pre_calculate_coefs
Definition: structs.h:519
#define PRINT_MEM(s, memory)
Definition: allocation.h:24
struct modsol_info * modsolinfo
Definition: globals.h:44
void vtkout_unc()
Definition: vtkout_unc.c:34
void setLogLevel(int level)
Definition: logger.c:44
#define LOG_DEBUG
Definition: logger.h:27
int readconfig(char *datfile, int check_dir)
Definition: config.c:22
int nradian
Definition: structs.h:452
#define malloc(size)
Definition: allocation.h:38
int mycol
Definition: structs.h:117
BOOL printvtk
Definition: structs.h:482
#define MSG_BODYCOEF_ERROR
Definition: messages.h:40
double DOUBLE
Definition: types.h:44
char * datfile
Definition: globals.h:29
char ** main_argv
Definition: globals.h:75
int rank
Definition: globals.h:79
#define MSG_GEOM_ERROR
Definition: messages.h:36
Structure containing names of additional files.
Definition: structs.h:402
Structure containing information about the run.
Definition: structs.h:86
const char * ac_name
Definition: main.c:27
struct run_details * rundetails
Definition: globals.h:36
void Cblacs_gridexit(int context)
struct modcoemic_info * modcoemicinfo
Definition: globals.h:42
#define MSG_MICSCOEF_ERROR
Definition: messages.h:41
time_t starttime
Definition: structs.h:145
void logger(int level, char *msg,...)
Definition: logger.c:56
#define calloc(n, size)
Definition: allocation.h:37
struct modgeom_info * modgeominfo
Definition: globals.h:38
BOOL active
Definition: structs.h:438
General information on geometry evaluation module.
Definition: structs.h:279
void vrmlout()
Definition: vrmlout.c:29