1
1
/*============================================================================
3
* This file is part of the Code_Saturne Kernel, element of the
4
* Code_Saturne CFD tool.
6
* Copyright (C) 1998-2009 EDF S.A., France
8
* contact: saturne-support@edf.fr
10
* The Code_Saturne Kernel is free software; you can redistribute it
11
* and/or modify it under the terms of the GNU General Public License
12
* as published by the Free Software Foundation; either version 2 of
13
* the License, or (at your option) any later version.
15
* The Code_Saturne Kernel is distributed in the hope that it will be
16
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with the Code_Saturne Kernel; if not, write to the
22
* Free Software Foundation, Inc.,
23
* 51 Franklin St, Fifth Floor,
24
* Boston, MA 02110-1301 USA
26
*============================================================================*/
28
/*============================================================================
29
2
* Parsing of program arguments and associated initializations
30
3
*============================================================================*/
6
This file is part of Code_Saturne, a general-purpose CFD tool.
8
Copyright (C) 1998-2011 EDF S.A.
10
This program is free software; you can redistribute it and/or modify it under
11
the terms of the GNU General Public License as published by the Free Software
12
Foundation; either version 2 of the License, or (at your option) any later
15
This program is distributed in the hope that it will be useful, but WITHOUT
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22
Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
/*----------------------------------------------------------------------------*/
32
27
#if defined(HAVE_CONFIG_H)
33
28
#include "cs_config.h"
258
215
*============================================================================*/
260
217
/*----------------------------------------------------------------------------
261
* Print logfile header
264
* argc <-- number of command line arguments
265
* argv <-- array of command line arguments
266
*----------------------------------------------------------------------------*/
269
cs_opts_logfile_head(int argc,
274
char date_str[] = __DATE__;
275
char time_str[] = __TIME__;
276
const char mon_name[12][4]
277
= {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
278
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
281
/* Define MPI Information */
283
#if defined(MPI_VERSION) && defined(MPI_SUBVERSION)
284
#if defined(OPEN_MPI)
285
const char mpi_lib[] = "Open MPI";
286
#elif defined(MPICH2)
287
const char mpi_lib[] = "MPICH2";
288
#elif defined(LAM_MPI)
289
const char mpi_lib[] = "LAM/MPI";
290
#elif defined(MPICH_NAME)
291
const char mpi_lib[] = "MPICH";
292
#elif defined(HP_MPI)
293
const char mpi_lib[] = "HP-MPI";
294
#elif defined(MPI_VERSION) && defined(MPI_SUBVERSION)
295
const char *mpi_lib = NULL;
297
#endif /* defined(MPI_VERSION) && defined(MPI_SUBVERSION) */
299
/* Determine compilation date */
301
for (ii = 0; ii < 12; ii++) {
302
if (strncmp(date_str, mon_name[ii], 3) == 0) {
303
time_cnv.tm_mon = ii ;
308
sscanf(date_str + 3, "%d", &(time_cnv.tm_mday)) ;
309
sscanf(date_str + 6, "%d", &(time_cnv.tm_year)) ;
311
time_cnv.tm_year -= 1900 ;
313
sscanf(time_str , "%d", &(time_cnv.tm_hour)) ;
314
sscanf(time_str + 3, "%d", &(time_cnv.tm_min)) ;
315
sscanf(time_str + 6, "%d", &(time_cnv.tm_sec)) ;
317
time_cnv.tm_isdst = -1 ;
319
/* Re-compute and internationalize build date */
322
strftime(str, 80, "%c", &time_cnv) ;
326
bft_printf(_("command: \n"));
328
for (ii = 0 ; ii < argc ; ii++)
329
bft_printf(" %s", argv[ii]);
332
bft_printf("\n************************************"
333
"***************************\n\n");
339
bft_printf("\n Copyright (C) 1998-2011 EDF S.A., France\n\n");
341
bft_printf(_(" build %s\n"), str);
343
#if defined(MPI_VERSION) && defined(MPI_SUBVERSION)
345
bft_printf(_(" MPI version %d.%d (%s)\n\n"),
346
MPI_VERSION, MPI_SUBVERSION, mpi_lib);
348
bft_printf(_(" MPI version %d.%d\n\n"),
349
MPI_VERSION, MPI_SUBVERSION);
353
bft_printf(" The Code_Saturne CFD tool is free software;\n"
354
" you can redistribute it and/or modify it under the terms\n"
355
" of the GNU General Public License as published by the\n"
356
" Free Software Foundation; either version 2 of the License,\n"
357
" or (at your option) any later version.\n\n");
359
bft_printf(" The Code_Saturne CFD tool is distributed in the hope that\n"
360
" it will be useful, but WITHOUT ANY WARRANTY; without even\n"
361
" the implied warranty of MERCHANTABILITY or FITNESS FOR A\n"
362
" PARTICULAR PURPOSE. See the GNU General Public License\n"
363
" for more details.\n");
365
bft_printf("\n************************************"
366
"***************************\n\n");
369
/*----------------------------------------------------------------------------
370
* First analysis of the command line to determine if we require MPI,
371
* and initialization if necessary
374
* argc <-> number of command line arguments
375
* argv <-> array of command line arguments
378
* -1 if MPI is not needed, or application number in MPI_COMM_WORLD of
379
* processes associated with this instance of Code_Saturne
380
*----------------------------------------------------------------------------*/
383
cs_opts_mpi_init(int *argc,
386
#if defined(HAVE_MPI)
390
int arg_id = 0, flag = 0;
394
#if defined(__bg__) || defined(__CRAYXT_COMPUTE_LINUX_TARGET)
396
/* Notes: Blue Gene/L also defines the BGLMPI_SIZE environment variable.
397
* Blue Gene/P defines BG_SIZE (plus BG_MAPPING, and BG_RELEASE). */
401
#elif defined(MPICH2)
402
if (getenv("PMI_RANK") != NULL)
405
#elif defined(MPICH_NAME)
408
Using standard MPICH1 1.2.x with the p4 (default) mechanism,
409
the information required by MPI_Init() are transferred through
410
the command line, which is then modified by MPI_Init();
411
in this case, only rank 0 knows the "user" command line arguments
412
at program startup, the other processes obtaining them only upon
413
calling MPI_Init(). In this case, it is thus necessary to initialize
414
MPI before parsing the command line.
417
for (arg_id = 0 ; arg_id < *argc ; arg_id++) {
418
if ( !strcmp((*argv)[arg_id], "-p4pg") /* For process 0 */
419
|| !strcmp((*argv)[arg_id], "-p4rmrank")) { /* For other processes */
425
if (getenv("GMPI_ID") != NULL) /* In case we are using MPICH-GM */
428
#elif defined(LAM_MPI)
429
if (getenv("LAMRANK") != NULL)
432
#elif defined(OPEN_MPI)
433
if (getenv("OMPI_MCA_ns_nds_vpid") != NULL) /* OpenMPI 1.2 */
435
else if (getenv("OMPI_COMM_WORLD_RANK") != NULL) /* OpenMPI 1.3 */
438
#endif /* Tests for known MPI variants */
440
/* If we have determined from known MPI environment variables
441
of command line arguments that we are running under MPI,
444
if (use_mpi == true) {
445
MPI_Initialized(&flag);
447
#if defined(MPI_VERSION) && (MPI_VERSION >= 2) && defined(HAVE_OPENMP)
449
MPI_Init_thread(argc, argv, MPI_THREAD_FUNNELED, &mpi_threads);
451
MPI_Init(argc, argv);
456
/* Loop on command line arguments */
460
while (++arg_id < *argc) {
466
if (strcmp(s, "--mpi") == 0) {
470
_appnum = _arg_to_int(arg_id + 1, *argc, *argv, &tmperr);
477
} /* End of loop on command line arguments */
479
if (use_mpi == true) {
481
MPI_Initialized(&flag);
483
#if defined(MPI_VERSION) && (MPI_VERSION >= 2) && defined(HAVE_OPENMP)
485
MPI_Init_thread(argc, argv, MPI_THREAD_FUNNELED, &mpi_threads);
487
MPI_Init(argc, argv);
492
If appnum was not given through the command line but we
493
are running under MPI-2, appnum may be available through
494
the MPI_APPNUM attribute.
497
#if defined(MPI_VERSION) && (MPI_VERSION >= 2)
500
MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_APPNUM, &attp, &flag);
502
appnum = *(int *)attp;
512
#else /* if defined(HAVE_MPI) */
519
/*----------------------------------------------------------------------------
520
218
* Define options and call some associated initializations
521
219
* based on command line arguments