Code_Saturne
CFD tool
cs_base.h
Go to the documentation of this file.
1 #ifndef __CS_BASE_H__
2 #define __CS_BASE_H__
3 
4 /*============================================================================
5  * Definitions, global variables, and base functions
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2012 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 /*----------------------------------------------------------------------------
31  * Standard C library headers
32  *----------------------------------------------------------------------------*/
33 
34 /*=============================================================================
35  * Macro definitions
36  *============================================================================*/
37 
38 /* Application type name */
39 
40 #define CS_APP_NAME "Code_Saturne"
41 #define CS_APP_VERSION PACKAGE_VERSION /* PACKAGE_VERSION from autoconf */
42 
43 /* System type name */
44 
45 #if defined(__blrts__) || defined(__bg__)
46 #define _CS_ARCH_Blue_Gene
47 
48 #elif defined(__linux__) || defined(__linux) || defined(linux)
49 #define _CS_ARCH_Linux
50 
51 #elif defined(__sun__) || defined(__sun) || defined(sun)
52 #define _CS_ARCH_SunOS
53 
54 #endif
55 
56 /* On certain architectures such as IBM Blue Gene, some operations may
57  * be better optimized on memory-aligned data (if 0 here, no alignment
58  * is leveraged). This alignment is not exploited yet in Code_Saturne. */
59 
60 #if defined(__blrts__) || defined(__bgp__)
61 #define CS_MEM_ALIGN 16
62 #elif defined(__bgq__)
63 #define CS_MEM_ALIGN 32
64 #else
65 #define CS_MEM_ALIGN 0
66 #endif
67 
68 /*----------------------------------------------------------------------------*/
69 
71 
72 /*============================================================================
73  * Type definitions
74  *============================================================================*/
75 
76 /* Datatype enumeration to transmit a data's type to a function */
77 
78 typedef enum {
85 } cs_type_t;
86 
87 /*=============================================================================
88  * Global variable definitions
89  *============================================================================*/
90 
91 /*============================================================================
92  * Public function prototypes for Fortran API
93  *============================================================================*/
94 
95 /*----------------------------------------------------------------------------
96  * Call exit routine from Fortran code
97  *
98  * Fortran interface:
99  *
100  * SUBROUTINE CSEXIT (STATUS)
101  * *****************
102  *
103  * INTEGER STATUS : --> : 0 for success, 1+ for error
104  *----------------------------------------------------------------------------*/
105 
106 void CS_PROCF (csexit, CSEXIT)
107 (
108  const cs_int_t *status
109 );
110 
111 /*----------------------------------------------------------------------------
112  * CPU time used since execution start
113  *
114  * Fortran interface:
115  *
116  * SUBROUTINE DMTMPS (TCPU)
117  * *****************
118  *
119  * DOUBLE PRECISION TCPU : --> : CPU time (user + system)
120  *----------------------------------------------------------------------------*/
121 
122 void CS_PROCF (dmtmps, DMTMPS)
123 (
124  cs_real_t *tcpu
125 );
126 
127 /*=============================================================================
128  * Public function prototypes
129  *============================================================================*/
130 
131 /*----------------------------------------------------------------------------
132  * First analysis of the command line to determine an application name.
133  *
134  * If no name is defined by the command line, a name is determined based
135  * on the working directory.
136  *
137  * The caller is responsible for freeing the returned string.
138  *
139  * parameters:
140  * argc <-- number of command line arguments
141  * argv <-- array of command line arguments
142  *
143  * returns:
144  * pointer to character string with application name
145  *----------------------------------------------------------------------------*/
146 
147 char *
148 cs_base_get_app_name(int argc,
149  const char *argv[]);
150 
151 /*----------------------------------------------------------------------------
152  * Print logfile header
153  *
154  * parameters:
155  * argc <-- number of command line arguments
156  * argv <-- array of command line arguments
157  *----------------------------------------------------------------------------*/
158 
159 void
160 cs_base_logfile_head(int argc,
161  char *argv[]);
162 
163 #if defined(HAVE_MPI)
164 
165 /*----------------------------------------------------------------------------
166  * First analysis of the command line and environment variables to determine
167  * if we require MPI, and initialization if necessary.
168  *
169  * parameters:
170  * argc <-> number of command line arguments
171  * argv <-> array of command line arguments
172  *
173  * Global variables `cs_glob_n_ranks' (number of Code_Saturne processes)
174  * and `cs_glob_rank_id' (rank of local process) are set by this function.
175  *----------------------------------------------------------------------------*/
176 
177 void
178 cs_base_mpi_init(int *argc,
179  char **argv[]);
180 
181 #endif /* defined(HAVE_MPI) */
182 
183 /*----------------------------------------------------------------------------
184  * Exit, with handling for both normal and error cases.
185  *
186  * Finalize MPI if necessary.
187  *
188  * parameters:
189  * status <-- value to be returned to the parent:
190  * EXIT_SUCCESS / 0 for the normal case,
191  * EXIT_FAILURE or other nonzero code for error cases.
192  *----------------------------------------------------------------------------*/
193 
194 void
195 cs_exit(int status);
196 
197 /*----------------------------------------------------------------------------
198  * Initialize error and signal handlers.
199  *----------------------------------------------------------------------------*/
200 
201 void
202 cs_base_error_init(void);
203 
204 /*----------------------------------------------------------------------------
205  * Initialize management of memory allocated through BFT.
206  *----------------------------------------------------------------------------*/
207 
208 void
209 cs_base_mem_init(void);
210 
211 /*----------------------------------------------------------------------------
212  * Finalize management of memory allocated through BFT.
213  *
214  * A summary of the consumed memory is given.
215  *----------------------------------------------------------------------------*/
216 
217 void
219 
220 /*----------------------------------------------------------------------------
221  * Print summary of running time, including CPU and elapsed times.
222  *----------------------------------------------------------------------------*/
223 
224 void
226 
227 /*----------------------------------------------------------------------------
228  * Replace default bft_printf() mechanism with internal mechanism.
229  *
230  * This allows redirecting or suppressing logging for different ranks.
231  *
232  * parameters:
233  * log_name <-- base file name for log
234  * r0_log_flag <-- redirection for rank 0 log;
235  * 0: not redirected; 1: redirected to "listing" file
236  * rn_log_flag <-- redirection for ranks > 0 log:
237  * 0: not redirected; 1: redirected to "listing_n*" file;
238  * 2: redirected to "/dev/null" (suppressed)
239  *----------------------------------------------------------------------------*/
240 
241 void
242 cs_base_bft_printf_set(const char *log_name,
243  int r0_log_flag,
244  int rn_log_flag);
245 
246 /*----------------------------------------------------------------------------
247  * Print a warning message header.
248  *
249  * parameters:
250  * file_name <-- name of source file
251  * line_nume <-- line number in source file
252  *----------------------------------------------------------------------------*/
253 
254 void
255 cs_base_warn(const char *file_name,
256  int line_num);
257 
258 /*----------------------------------------------------------------------------
259  * Convert a character string from the Fortran API to the C API.
260  *
261  * Eventual leading and trailing blanks are removed.
262  *
263  * parameters:
264  * f_str <-- Fortran string
265  * f_len <-- Fortran string length
266  *
267  * returns:
268  * pointer to C string
269  *----------------------------------------------------------------------------*/
270 
271 char *
272 cs_base_string_f_to_c_create(const char *f_str,
273  int f_len);
274 
275 /*----------------------------------------------------------------------------
276  * Free a string converted from the Fortran API to the C API.
277  *
278  * parameters:
279  * str <-> pointer to C string
280  *----------------------------------------------------------------------------*/
281 
282 void
283 cs_base_string_f_to_c_free(char **c_str);
284 
285 /*----------------------------------------------------------------------------
286  * Clean a string representing options.
287  *
288  * Characters are converted to lowercase, leading and trailing whitespace
289  * is removed, and multi ple whitespaces or tabs are replaced by single
290  * spaces.
291  *
292  * parameters:
293  * s <-> string to be cleaned
294  *----------------------------------------------------------------------------*/
295 
296 void
298 
299 /*----------------------------------------------------------------------------*/
300 
302 
303 #endif /* __CS_BASE_H__ */
void cs_base_string_f_to_c_free(char **c_str)
Definition: cs_base.c:1567
void cs_base_mem_finalize(void)
Definition: cs_base.c:1230
Definition: cs_base.h:83
void cs_base_error_init(void)
Definition: cs_base.c:1131
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
char * cs_base_string_f_to_c_create(const char *f_str, int f_len)
Definition: cs_base.c:1510
Definition: cs_base.h:81
void cs_base_warn(const char *file_name, int line_num)
Definition: cs_base.c:1489
int cs_int_t
Definition: cs_defs.h:263
void dmtmps(cs_real_t *tcpu)
Definition: cs_base.c:753
void cs_base_option_string_clean(char *s)
Definition: cs_base.c:1595
Definition: cs_base.h:84
void cs_base_mem_init(void)
Definition: cs_base.c:1171
void csexit(const cs_int_t *status)
Definition: cs_base.c:734
Definition: cs_base.h:80
void cs_exit(int status)
Definition: cs_base.c:1097
void cs_base_logfile_head(int argc, char *argv[])
Definition: cs_base.c:840
char * cs_base_get_app_name(int argc, const char *argv[])
Definition: cs_base.c:781
#define END_C_DECLS
Definition: cs_defs.h:366
double cs_real_t
Definition: cs_defs.h:264
void cs_base_bft_printf_set(const char *log_name, int r0_log_flag, int rn_log_flag)
Definition: cs_base.c:1419
#define CS_PROCF(x, y)
Definition: cs_defs.h:379
Definition: cs_base.h:79
Definition: cs_base.h:82
void cs_base_time_summary(void)
Definition: cs_base.c:1345
cs_type_t
Definition: cs_base.h:78