FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
main.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
9 #include <stdio.h>
10 #include <time.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <FrontISTRConfig.h>
14 #include "hecmw_log.h"
15 #ifndef HECMW_SERIAL
16 #include "mpi.h"
17 #else
18 #include <unistd.h>
19 #endif
20 #ifdef _OPENMP
21 #include <omp.h>
22 #endif /* _OPENMP */
23 #ifdef WITH_MKL
24 #include <mkl.h>
25 #endif
26 
27 extern void fstr_main();
28 
32 struct option_rec {
33  char *option_name;
34  void (*func)(char *);
35 };
36 
38 #ifndef HECMW_SERIAL
39  int proc;
40  MPI_Comm_size(MPI_COMM_WORLD, &proc);
41  return proc;
42 #else
43  return 1;
44 #endif
45 }
46 
48 #ifdef _OPENMP
49  return omp_get_max_threads();
50 #else
51  return 1;
52 #endif /* _OPENMP */
53 }
54 
55 #ifdef _OPENMP
56 
59 void set_num_threads(char *arg) {
60  int exec_threads;
61 
62  if (arg == NULL) {
63  fprintf(stderr, "Error : specify number of OpenMP threads.\n");
64  fprintf(stderr, "Format: -t <n>\n");
65  exit(1);
66  }
67 
68  exec_threads = atoi(arg);
69 
70  if (exec_threads == 0) {
71  fprintf(stderr, "Error : specify 1 or more OpenMP threads.\n");
72  exit(1);
73  }
74  omp_set_num_threads(exec_threads);
75 #ifdef WITH_MKL
76  mkl_set_num_threads(exec_threads);
77 #endif
78 
79 }
80 #endif /* _OPENMP */
81 
85 void help(char *arg) {
86  printf("usage: [ mpirun -np <mpiprocs> ] fistr1 [options] \n");
87  printf(" -h: Show this help message.\n");
88  printf(" -v: Show version.\n");
89 #ifdef _OPENMP
90  printf(" -t <n>: Set number of OpenMP threads\n");
91 #endif
92  printf(" -c <Path of control file>: Use this control file. Default "
93  "./hecmw_ctrl.dat\n");
94  printf("--debug: Show debug messages.\n");
95  exit(0);
96 }
97 
101 void print_buildinfo(int log_level) {
102  int rank;
103 #ifndef HECMW_SERIAL
104  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
105  if (rank!=0) return;
106 #endif
107  printf("##################################################################\n");
108  printf("# FrontISTR #\n");
109  printf("##################################################################\n");
110  printf("---\n");
111  if (VERSION_PATCH == 0){
112  printf("version: %d.%d\n", VERSION_MAJOR, VERSION_MINOR);
113  }else{
114  printf("version: %d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
115  }
116  printf("git_hash: %s\n", GIT_HASH );
117  printf("build:\n");
118  printf(" date: %s\n", BUILD_DATE );
119  printf("");
120 #ifdef WITH_MPI
121  printf(" MPI: \"%d.%d", MPI_VERSION, MPI_SUBVERSION);
122 #if defined(MVAPITCH2_VERSION)
123  printf(", MVAPITCH %s", MVAPITCH2_VERSION);
124 #elif defined(I_MPI_VERSION)
125  printf(", Intel MPI %s", I_MPI_VERSION);
126 #elif defined(MSMPI_VER)
127  printf(", Microsoft MPI");
128 #elif defined(MPI_NEC_MODE_GETPUTALIGNED)
129  printf(", NEC MPI");
130 #elif defined(MPICH_VERSION)
131  printf(", MPICH %s", MPICH_VERSION);
132 #elif defined(OMPI_MAJOR_VERSION)
133  printf(", Open MPI %d.%d.%d", OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION);
134 #endif
135  printf("\"\n");
136 #else
137  printf(" MPI: disabled\n");
138 #endif
139 #ifdef _OPENMP
140  printf(" OpenMP: %d\n", _OPENMP);
141 #else
142  printf(" OpenMP: disabled\n");
143 #endif
144  printf(" option: ");
145  printf("\"");
146 #ifdef WITH_MPI
147  printf("-p ");
148 #endif
149 #ifdef WITH_TOOLS
150  printf("--with-tools ");
151 #endif
152 #ifdef WITH_REFINER
153  printf("--with-refiner ");
154 #endif
155 #ifdef WITH_METIS
156  printf("--with-metis ");
157 #endif
158 #ifdef WITH_MUMPS
159  printf("--with-mumps ");
160 #endif
161 #ifdef WITH_LAPACK
162  printf("--with-lapack ");
163 #endif
164 #ifdef WITH_ML
165  printf("--with-ml ");
166 #endif
167 #ifdef WITH_PARMETIS
168  printf("--with-parmetis ");
169 #endif
170 #ifdef WITH_MKL
171  printf("--with-mkl ");
172 #endif
173  printf("\"");
174  printf("\n");
175 #ifdef HECMW_METIS_VER
176  printf(" HECMW_METIS_VER: %d\n", HECMW_METIS_VER);
177 #endif
178 }
179 
183 void print_executeinfo(int log_level) {
184  int rank=0;
185  int proc, i, len, mpi_ver, mpi_subver;
186  char *p;
187  char date[32];
188  time_t t;
189  int d;
190 #ifndef HECMW_SERIAL
191  char hostname[MPI_MAX_PROCESSOR_NAME];
192  char mpilibver[MPI_MAX_LIBRARY_VERSION_STRING];
193  MPI_Status status;
194  MPI_Comm_size(MPI_COMM_WORLD, &proc);
195  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
196  MPI_Get_version(&mpi_ver, &mpi_subver);
197  MPI_Get_library_version(mpilibver,&len);
198  /* mpich returns too long string, clip 1st line. */
199  while ((p = strchr(mpilibver, '\n')) != NULL) *p = '\0';
200  MPI_Get_processor_name(hostname, &len);
201 #else
202  char hostname[128];
203 #endif
204 
205  if (rank==0){
206  printf("execute: \n");
207  t=time(NULL);
208  /* for windows compatibility */
209  d=(int)difftime(t,mktime(gmtime(&t)));
210  strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%S", localtime(&t));
211  printf(" date: %s", date);
212  if (abs(d)<86400) printf("%+05d", (int)(d/3600)*100+(int)(d/60)%60);
213  printf("\n");
214  printf(" processes: %d\n", get_procs_num());
215  printf(" threads: %d\n", get_threads_num());
216  printf(" cores: %d\n", get_threads_num()*get_procs_num());
217 #ifndef HECMW_SERIAL
218  printf(" MPI: \"%d.%d, %.128s\"\n", mpi_ver, mpi_subver, mpilibver);
219 #endif
220  printf(" host:\n");
221  }
222 #ifndef HECMW_SERIAL
223 
224  if (rank == 0){
225  printf(" %d: %s\n",0,hostname);
226  for (i=1;i<proc;i++){
227  MPI_Recv(&hostname, sizeof(hostname), MPI_CHAR, i, 0, MPI_COMM_WORLD, &status);
228  printf(" %d: %s\n",i,hostname);
229  }
230  }else{
231  MPI_Send(&hostname, len, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
232  }
233 #else
234  gethostname(hostname, sizeof(hostname));
235  printf(" %d: %s\n",0,hostname);
236 #endif
237  if (rank==0) printf("---\n");
238 }
239 
243 void version(char *arg) {
244  int rank=0;
245 #ifndef HECMW_SERIAL
246  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
247 #endif
248  print_buildinfo(9);
249  if (rank==0) printf("---\n");
250  exit(0);
251 }
252 
256 void load_hecmw_ctrl(char *arg) {
257  fprintf(stderr, "Sorry this option cannot work yet. (-c)\n");
258  fprintf(stderr, "%s\n", arg);
259  exit(0);
260 }
261 
265 void set_loglevel_debug(char *arg) {
267 }
268 
273 struct option_rec options[] = {
274  {"-h", help},
275  {"-H", help},
276  {"-v", version},
277  {"-V", version},
278 #ifdef _OPENMP
279  {"-t", set_num_threads},
280  {"-T", set_num_threads},
281 #endif /* _OPENMP */
282  {"-c", load_hecmw_ctrl},
283  {"-C", load_hecmw_ctrl},
284  {"--debug", set_loglevel_debug},
285  {NULL, NULL}
286 };
287 
291 int main(int argc, char *argv[])
292 {
293  struct option_rec *p;
294  unsigned int i;
295 
296 #ifndef HECMW_SERIAL
297  MPI_Init(&argc, &argv);
298 #endif
299  for (i = 0; i < argc; i++) {
300  for (p = options; p->option_name != NULL; p++) {
301  if (strncmp(p->option_name, argv[i], strlen(p->option_name)) == 0) {
302  p->func(argv[i + 1]);
303  }
304  }
305  }
306  print_buildinfo(1);
308 #ifndef HECMW_SERIAL
309  MPI_Barrier( MPI_COMM_WORLD );
310 #endif
311  fstr_main();
312  return 0;
313 }
get_threads_num
int get_threads_num()
Definition: main.c:47
fstr_main
void fstr_main()
Startup routine for FrontISTR.
Definition: fistr_main.f90:38
version
void version(char *arg)
show version and revision of FrontISTR
Definition: main.c:243
HECMW_LOG_DEBUG
#define HECMW_LOG_DEBUG
Definition: hecmw_log.h:21
print_executeinfo
void print_executeinfo(int log_level)
show execute environment information
Definition: main.c:183
set_loglevel_debug
void set_loglevel_debug(char *arg)
set log level to HECMW_LOG_DEBUG
Definition: main.c:265
hecmw_log.h
print_buildinfo
void print_buildinfo(int log_level)
show build information
Definition: main.c:101
get_procs_num
int get_procs_num()
Definition: main.c:37
main
int main(int argc, char *argv[])
main function
Definition: main.c:291
option_rec::func
void(* func)(char *)
Definition: main.c:34
option_rec
struct of command-line option
Definition: main.c:32
load_hecmw_ctrl
void load_hecmw_ctrl(char *arg)
load hecmw_ctrl.dat from specified place
Definition: main.c:256
option_rec::option_name
char * option_name
Definition: main.c:33
HECMW_setloglv
void HECMW_setloglv(int loglv)
Definition: hecmw_log.c:57
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
options
struct option_rec options[]
specify command line option name and executing function name.
Definition: main.c:273
help
void help(char *arg)
show available command line option
Definition: main.c:85