43 #include "opencarp_types.h"
49 #include <openCARP_p.h>
50 #include <openCARP_d.h>
53 #define STRUCT_ZERO(S) memset(&(S), 0, sizeof(S))
54 #define SLIST_APPEND( S, P ) sltlst_append( S, &(P), sizeof(P) )
83 char*
dupstr(
const char* old_str);
104 template<
class STRVEC>
105 void split_string(
const std::string & input,
const char s, STRVEC & list)
107 size_t fnd = 0, ofnd = 0;
108 int num_parts = 1, idx = 0;
111 while (fnd != std::string::npos)
115 fnd = input.find(s, ofnd);
118 list.resize(num_parts);
120 fnd = input.find(s); ofnd = 0;
121 while (fnd != std::string::npos)
123 list[idx++].assign(input.begin() + ofnd, input.begin() + fnd);
125 fnd = input.find(s, ofnd);
128 if(ofnd < input.size())
129 list[idx].assign(input.begin() + ofnd, input.end());
149 bool f_exist(
const char *fname);
177 void f_read_par(
void *ptr,
size_t size,
size_t nmemb,
FILE_SPEC stream, MPI_Comm comm = PETSC_COMM_WORLD);
190 MPI_Comm comm = PETSC_COMM_WORLD);
232 template<
typename T>
inline
233 T
get_global(T in, MPI_Op OP, MPI_Comm comm = PETSC_COMM_WORLD)
236 MPI_Allreduce(MPI_IN_PLACE, &dat, 1, mpi_datatype<T>(), OP, comm);
244 MPI_Allreduce(MPI_IN_PLACE, &dat, 1, mpi_datatype<size_t>(), OP, comm);
255 template<
typename T>
inline
258 size_t sz = vec.
size();
259 MPI_Bcast(&sz,
sizeof(
size_t), MPI_BYTE, sender, comm);
261 MPI_Bcast(vec.
data(), sz*
sizeof(T), MPI_BYTE, sender, comm);
271 MPI_Initialized(&initialized);
276 MPI_Finalized(&finalized);
284 inline int get_rank(MPI_Comm comm = PETSC_COMM_WORLD)
287 MPI_Comm_rank(comm, &rank);
298 inline int get_size(MPI_Comm comm = PETSC_COMM_WORLD)
302 MPI_Comm_size(comm, &size);
311 MPI_Comm_remote_size(intercomm, &size);
322 #define MAX_MESG_LEN 2048
323 #define MAX_LOG_LEVEL 5
348 void log_msg(
FILE_SPEC out,
int level,
unsigned char flag,
const char *fmt, ...);
355 int ridx = 0, widx=0;
356 while(ridx < buffsize && buff[ridx] == c) ridx++;
358 while(ridx < (buffsize - 1))
359 buff[widx++] = buff[ridx++];
364 inline void remove_char(
char* buff,
const int buffsize,
const char c)
366 int ridx = 0, widx=0;
367 while(ridx < buffsize) {
369 buff[widx++] = buff[ridx];
376 inline bool has_char(
char* buff,
const int buffsize,
const char c)
379 while(ridx < buffsize) {
380 if(buff[ridx] ==
'\0')
return false;
381 if(buff[ridx] == c)
return true;
423 #define USE_FMEM_WRAPPER 1
427 #define USE_FMEM_WRAPPER 1
430 #ifdef USE_FMEM_WRAPPER
436 typedef struct fmem fmem_t;
438 FILE *
fmemopen_(
void *,
size_t,
const char *);
441 #define fmemopen_ fmemopen
451 double tm = MPI_Wtime();
455 template<
typename V>
inline
464 #if OPENCARP_GLOBAL_INDEX_BITS == 64
465 #define OPENCARP_INSTANTIATE_INDEX_TYPE std::int64_t
467 #define OPENCARP_INSTANTIATE_INDEX_TYPE std::int32_t
470 #if OPENCARP_REAL_BITS == 32
471 #define OPENCARP_INSTANTIATE_VALUE_TYPE float
473 #define OPENCARP_INSTANTIATE_VALUE_TYPE double
476 #define OPENCARP_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
477 template _macro(OPENCARP_INSTANTIATE_INDEX_TYPE, OPENCARP_INSTANTIATE_VALUE_TYPE)
The vector class and related algorithms.
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_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)
void f_read_par(void *ptr, size_t size, size_t nmemb, FILE_SPEC stream, MPI_Comm comm)
Parallel fread. Root reads, then broadcasts.
bool file_can_be_opened(const char *file)
Check wheterh a file can be opened for reading.
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
T get_global(T in, MPI_Op OP, MPI_Comm comm=PETSC_COMM_WORLD)
Do a global reduction on a variable.
void write_bin_string(FILE_SPEC out, const char *s)
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.
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)
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_size(MPI_Comm comm=PETSC_COMM_WORLD)
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