28 #include "opencarp_types.h"
35 #include <openCARP_p.h>
36 #include <openCARP_d.h>
39 #define STRUCT_ZERO(S) memset(&(S), 0, sizeof(S))
40 #define SLIST_APPEND( S, P ) sltlst_append( S, &(P), sizeof(P) )
69 char*
dupstr(
const char* old_str);
90 template<
class STRVEC>
91 void split_string(
const std::string & input,
const char s, STRVEC & list)
93 size_t fnd = 0, ofnd = 0;
94 int num_parts = 1, idx = 0;
97 while (fnd != std::string::npos)
101 fnd = input.find(s, ofnd);
104 list.resize(num_parts);
106 fnd = input.find(s); ofnd = 0;
107 while (fnd != std::string::npos)
109 list[idx++].assign(input.begin() + ofnd, input.begin() + fnd);
111 fnd = input.find(s, ofnd);
114 if(ofnd < input.size())
115 list[idx].assign(input.begin() + ofnd, input.end());
135 bool f_exist(
const char *fname);
218 template<
typename T>
inline
222 MPI_Allreduce(MPI_IN_PLACE, &dat, 1, mpi_datatype<T>(), OP, comm);
230 MPI_Allreduce(MPI_IN_PLACE, &dat, 1, mpi_datatype<size_t>(), OP, comm);
241 template<
typename T>
inline
244 size_t sz = vec.
size();
245 MPI_Bcast(&sz,
sizeof(
size_t), MPI_BYTE, sender, comm);
247 MPI_Bcast(vec.
data(), sz*
sizeof(T), MPI_BYTE, sender, comm);
257 MPI_Initialized(&initialized);
262 MPI_Finalized(&finalized);
273 MPI_Comm_rank(comm, &rank);
288 MPI_Comm_size(comm, &size);
297 MPI_Comm_remote_size(intercomm, &size);
308 #define MAX_MESG_LEN 2048
309 #define MAX_LOG_LEVEL 5
334 void log_msg(
FILE_SPEC out,
int level,
unsigned char flag,
const char *fmt, ...);
341 int ridx = 0, widx=0;
342 while(ridx < buffsize && buff[ridx] == c) ridx++;
344 while(ridx < (buffsize - 1))
345 buff[widx++] = buff[ridx++];
350 inline void remove_char(
char* buff,
const int buffsize,
const char c)
352 int ridx = 0, widx=0;
353 while(ridx < buffsize) {
355 buff[widx++] = buff[ridx];
362 inline bool has_char(
char* buff,
const int buffsize,
const char c)
365 while(ridx < buffsize) {
366 if(buff[ridx] ==
'\0')
return false;
367 if(buff[ridx] == c)
return true;
409 #define USE_FMEM_WRAPPER 1
413 #define USE_FMEM_WRAPPER 1
416 #ifdef USE_FMEM_WRAPPER
422 typedef struct fmem fmem_t;
424 FILE *
fmemopen_(
void *,
size_t,
const char *);
427 #define fmemopen_ fmemopen
437 double tm = MPI_Wtime();
441 template<
typename V>
inline
450 #if OPENCARP_GLOBAL_INDEX_BITS == 64
451 #define OPENCARP_INSTANTIATE_INDEX_TYPE std::int64_t
453 #define OPENCARP_INSTANTIATE_INDEX_TYPE std::int32_t
456 #if OPENCARP_REAL_BITS == 32
457 #define OPENCARP_INSTANTIATE_VALUE_TYPE float
459 #define OPENCARP_INSTANTIATE_VALUE_TYPE double
462 #define OPENCARP_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
463 template _macro(OPENCARP_INSTANTIATE_INDEX_TYPE, OPENCARP_INSTANTIATE_VALUE_TYPE)
#define SF_COMM
the default SlimFem MPI communicator
The vector class and related algorithms.
Starts and stops the linear algebra backend the flavor parameter selects.
A vector storing arbitrary data.
size_t size() const
The current size of the vector.
void resize(size_t n)
Resize a vector.
T * data()
Pointer to the vector's start.
class to store shape definitions
void sltlst_append(Salt_list *sl, void *p, int quantum)
bool has_char(char *buff, const int buffsize, const char c)
char * f_gets_par(char *s, int size, FILE_SPEC stream, MPI_Comm comm)
bool point_in_shape(const Point &p, const geom_shape &shape)
test if a point is inside a simple geometric shape
char * stringify(double r)
int get_size(MPI_Comm comm=SF_COMM)
int get_remote_size(MPI_Comm intercomm)
char * read_bin_string(FILE_SPEC in)
size_t get_global< size_t >(size_t in, MPI_Op OP, MPI_Comm comm)
bool file_can_be_opened(const char *file)
Check wheterh a file can be opened for reading.
T get_global(T in, MPI_Op OP, MPI_Comm comm=SF_COMM)
Do a global reduction on a variable.
void f_write_par(void *ptr, size_t size, size_t nmemb, int source_pid, FILE_SPEC stream, MPI_Comm comm)
Write in parallel. Data comes from one rank, rank 0 writes.
void write_bin_string(FILE_SPEC out, const char *s)
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
bool path_is_absolute(const char *path)
check whether path is absolute
void split_string(const std::string &input, const char s, STRVEC &list)
Split a string holding a character-seperated list into a vector of strings.
char * read_bin_string_par(FILE_SPEC in)
void f_read_par(void *ptr, size_t size, size_t nmemb, FILE_SPEC stream, MPI_Comm comm)
Parallel fread. Root reads, then broadcasts.
char * dupstr(const char *old_str)
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
void get_time(double &tm)
int get_rank(MPI_Comm comm=SF_COMM)
void remove_char(char *buff, const int buffsize, const char c)
V timing(V &t2, const V &t1)
bool f_exist(const char *fname)
std::string get_basename(const std::string &path)
void init_iterations_logger(FILE_SPEC *&logger, const char *filename)
init a logger for solver iterations
void f_close(FILE_SPEC &f)
Close a FILE_SPEC.
void remove_preceding_char(char *buff, const int buffsize, const char c)
saltatory list – memory is allocated in chunks
int chunk
allocate memory to hold this many items
int size
size of list items
int nitems
number of items