47 #include "openCARP_p.h"
48 #include "openCARP_d.h"
51 #define STRUCT_ZERO(S) memset(&(S), 0, sizeof(S))
52 #define SLIST_APPEND( S, P ) sltlst_append( S, &(P), sizeof(P) )
81 char*
dupstr(
const char* old_str);
102 template<
class STRVEC>
103 void split_string(
const std::string & input,
const char s, STRVEC & list)
105 size_t fnd = 0, ofnd = 0;
106 int num_parts = 1, idx = 0;
109 while (fnd != std::string::npos)
113 fnd = input.find(s, ofnd);
116 list.resize(num_parts);
118 fnd = input.find(s); ofnd = 0;
119 while (fnd != std::string::npos)
121 list[idx++].assign(input.begin() + ofnd, input.begin() + fnd);
123 fnd = input.find(s, ofnd);
126 if(ofnd < input.size())
127 list[idx].assign(input.begin() + ofnd, input.end());
147 bool f_exist(
const char *fname);
175 void f_read_par(
void *ptr,
size_t size,
size_t nmemb,
FILE_SPEC stream, MPI_Comm comm = PETSC_COMM_WORLD);
188 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_DOUBLE, OP, comm);
244 MPI_Allreduce(MPI_IN_PLACE, &dat, 1, MPI_INT, OP, comm);
252 MPI_Allreduce(MPI_IN_PLACE, &dat, 1, MPI_LONG, OP, comm);
263 template<
typename T>
inline
266 size_t sz = vec.
size();
267 MPI_Bcast(&sz,
sizeof(
size_t), MPI_BYTE, sender, comm);
269 MPI_Bcast(vec.
data(), sz*
sizeof(T), MPI_BYTE, sender, comm);
276 inline int get_rank(MPI_Comm comm = PETSC_COMM_WORLD)
279 MPI_Comm_rank(comm, &rank);
290 inline int get_size(MPI_Comm comm = PETSC_COMM_WORLD)
294 MPI_Comm_size(comm, &size);
303 MPI_Comm_remote_size(intercomm, &size);
314 #define MAX_MESG_LEN 2048
315 #define MAX_LOG_LEVEL 5
340 void log_msg(
FILE_SPEC out,
int level,
unsigned char flag,
const char *fmt, ...);
347 int ridx = 0, widx=0;
348 while(ridx < buffsize && buff[ridx] == c) ridx++;
350 while(ridx < (buffsize - 1))
351 buff[widx++] = buff[ridx++];
356 inline void remove_char(
char* buff,
const int buffsize,
const char c)
358 int ridx = 0, widx=0;
359 while(ridx < buffsize) {
361 buff[widx++] = buff[ridx];
368 inline bool has_char(
char* buff,
const int buffsize,
const char c)
371 while(ridx < buffsize) {
372 if(buff[ridx] ==
'\0')
return false;
373 if(buff[ridx] == c)
return true;
415 #define USE_FMEM_WRAPPER 1
419 #define USE_FMEM_WRAPPER 1
422 #ifdef USE_FMEM_WRAPPER
428 typedef struct fmem fmem_t;
430 FILE *
fmemopen_(
void *,
size_t,
const char *);
433 #define fmemopen_ fmemopen
443 double tm = MPI_Wtime();
447 template<
typename V>
inline
458 #define OPENCARP_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
459 template _macro(std::int32_t, double)
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)
long int get_global< long int >(long int in, MPI_Op OP, MPI_Comm comm)
char * read_bin_string(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.
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.
int get_global< int >(int in, MPI_Op OP, MPI_Comm comm)
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