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);
157 FILE_SPEC
f_open(
const char *fname,
const char *mode);
175 void f_read_par(
void *ptr,
size_t size,
size_t nmemb, FILE_SPEC stream, MPI_Comm comm = PETSC_COMM_WORLD);
187 void f_write_par(
void* ptr,
size_t size,
size_t nmemb,
int source_pid, FILE_SPEC stream,
188 MPI_Comm comm = PETSC_COMM_WORLD);
212 char*
f_gets_par(
char* s,
int size, FILE_SPEC stream, 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);
308 #define ECHO 1 // screen output 309 #define LOCAL 2 // output all cores 310 #define SYNCED 4 // synchronized 311 #define FLUSH 8 // flush screen output 312 #define NONL 16 // no new line 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;
383 enum shape_t {sphere = 1, block = 2, cylinder = 3};
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) long int get_global< long int >(long int in, MPI_Op OP, MPI_Comm comm)
int get_global< int >(int in, MPI_Op OP, MPI_Comm comm)
The vector class and related algorithms.
void sltlst_append(Salt_list *sl, void *p, int quantum)
class to store shape definitions
char * dupstr(const char *old_str)
void remove_preceding_char(char *buff, const int buffsize, const char c)
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.
bool has_char(char *buff, const int buffsize, const char c)
void f_read_par(void *ptr, size_t size, size_t nmemb, FILE_SPEC stream, MPI_Comm comm)
Parallel fread. Root reads, then broadcasts.
T * data()
Pointer to the vector's start.
void write_bin_string(FILE_SPEC out, const char *s)
void remove_char(char *buff, const int buffsize, const char c)
char * read_bin_string_par(FILE_SPEC in)
char * read_bin_string(FILE_SPEC in)
int chunk
allocate memory to hold this many items
bool file_can_be_opened(const char *file)
Check wheterh a file can be opened for reading.
void get_time(double &tm)
T get_global(T in, MPI_Op OP, MPI_Comm comm=PETSC_COMM_WORLD)
Do a global reduction on a variable.
V timing(V &t2, const V &t1)
bool f_exist(const char *fname)
int get_remote_size(MPI_Comm intercomm)
std::string get_basename(const std::string &path)
size_t size() const
The current size of the vector.
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
int nitems
number of items
A vector storing arbitrary data.
void f_close(FILE_SPEC &f)
Close a FILE_SPEC.
saltatory list – memory is allocated in chunks
void init_iterations_logger(FILE_SPEC *&logger, const char *filename)
init a logger for solver iterations
bool point_in_shape(const Point &p, const geom_shape &shape)
test if a point is inside a simple geometric shape
void resize(size_t n)
Resize a vector.
int get_size(MPI_Comm comm=PETSC_COMM_WORLD)
char * f_gets_par(char *s, int size, FILE_SPEC stream, MPI_Comm comm)
int size
size of list items
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
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 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.
char * stringify(double r)