YAC 3.20.0
Yet Another Coupler
Loading...
Searching...
No Matches
utils_core.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include "utils_core.h"
#include "yac_mpi_internal.h"
Include dependency graph for utils_core.c:

Go to the source code of this file.

Functions

char const * yac_name_type_pair_get_name (struct yac_name_type_pair const *pairs, size_t count, int type)
 
int yac_name_type_pair_get_type (struct yac_name_type_pair const *pairs, size_t count, char const *name)
 
char * yac_string_dup (char const *string)
 
 DEF_NAME_TYPE_PAIRS (bool_table, DEF_NAME_TYPE_PAIR(false, 0), DEF_NAME_TYPE_PAIR(true, 1), DEF_NAME_TYPE_PAIR(FALSE, 0), DEF_NAME_TYPE_PAIR(TRUE, 1), DEF_NAME_TYPE_PAIR(no, 0), DEF_NAME_TYPE_PAIR(yes, 1), DEF_NAME_TYPE_PAIR(NO, 0), DEF_NAME_TYPE_PAIR(YES, 1), DEF_NAME_TYPE_PAIR(off, 0), DEF_NAME_TYPE_PAIR(on, 1), DEF_NAME_TYPE_PAIR(OFF, 0), DEF_NAME_TYPE_PAIR(ON, 1), DEF_NAME_TYPE_PAIR(0, 0), DEF_NAME_TYPE_PAIR(1, 1))
 
int yac_getenv_int (const char *name, int default_value, int threshold, MPI_Comm comm)
 
char * yac_getenv_str (const char *name, const char *default_value, MPI_Comm comm)
 

Function Documentation

◆ DEF_NAME_TYPE_PAIRS()

DEF_NAME_TYPE_PAIRS ( bool_table ,
DEF_NAME_TYPE_PAIR(false, 0) ,
DEF_NAME_TYPE_PAIR(true, 1) ,
DEF_NAME_TYPE_PAIR(FALSE, 0) ,
DEF_NAME_TYPE_PAIR(TRUE, 1) ,
DEF_NAME_TYPE_PAIR(no, 0) ,
DEF_NAME_TYPE_PAIR(yes, 1) ,
DEF_NAME_TYPE_PAIR(NO, 0) ,
DEF_NAME_TYPE_PAIR(YES, 1) ,
DEF_NAME_TYPE_PAIR(off, 0) ,
DEF_NAME_TYPE_PAIR(on, 1) ,
DEF_NAME_TYPE_PAIR(OFF, 0) ,
DEF_NAME_TYPE_PAIR(ON, 1) ,
DEF_NAME_TYPE_PAIR(0, 0) ,
DEF_NAME_TYPE_PAIR(1, 1)  )

Definition at line 37 of file utils_core.c.

Here is the call graph for this function:

◆ yac_getenv_int()

int yac_getenv_int ( const char * name,
int default_value,
int threshold,
MPI_Comm comm )

Get the value of an environment variable as an integer. If the environment variable is not set, or if its value is below the provided threshold, the provided default value will be returned. The environment variable is only queried on rank 0 of the provided communicator, and the result is broadcast to all ranks.

Parameters
[in]nameName of the environment variable
[in]default_valueDefault value to return if the environment variable is not set or below threshold
[in]thresholdMinimum accepted value for the environment variable
[in]commCommunicator used for rank-0 evaluation and broadcasting
Returns
default_value if the environment variable is not set, empty or below threshold, otherwise the parsed integer value
Remarks
If the environment variable is set to a value that cannot be interpreted as an integer, an error will be raised.

Definition at line 89 of file utils_core.c.

Here is the caller graph for this function:

◆ yac_getenv_str()

char * yac_getenv_str ( const char * name,
const char * default_value,
MPI_Comm comm )

Get the value of an environment variable as a string. If the environment variable is not set or is an empty string, the provided default value will be returned. The environment variable is only queried on rank 0 of the provided communicator, and the result is broadcast to all ranks.

Parameters
[in]nameName of the environment variable
[in]default_valueDefault value to return if the environment variable is not set or empty (may be NULL)
[in]commCommunicator used for rank-0 evaluation and broadcasting
Returns
Newly allocated string with the value of the environment variable, or a duplicate of default_value if the variable is not set or empty. The caller is responsible for freeing the returned string.

Definition at line 125 of file utils_core.c.

Here is the call graph for this function:

◆ yac_string_dup()

char * yac_string_dup ( char const * string)

duplicate a string by allocating new memory and copying the content of the original string into it. If a NULL value is provided, NULL will be returned.

Note
The returned string must be freed by the caller.
Parameters
[in]stringstring to duplicate
Returns
pointer to the duplicated string

Definition at line 33 of file utils_core.c.

Here is the caller graph for this function: