Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
common.h
Go to the documentation of this file.
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
3 #include <string.h>
4 #include <string>
5 #include <stdio.h>
6 #include <assert.h>
7 #include <stdint.h>
8 #include <math.h>
9 #include <algorithm>
10 #include <list>
11 #include <vector>
12 #include <complex>
13 #include <unistd.h>
14 #include <iostream>
15 #include <limits.h>
16 #include <random>
17 
18 #include <mpi.h>
19 #include "../shared/model.h"
20 
28 //enum SYM : int { NS, SY, AS, SH };
37 enum STRUCTURE : int { NS, SY, AS, SH, SP };
38 typedef STRUCTURE SYM;
39 
40 namespace CTF {
45  extern int DGTOG_SWITCH;
46 
52 
56 }
57 
58 
59 namespace CTF_int {
64  void init_rng(int rank);
65 
69  double get_rand48();
70 
71 
72 
73  void handler();
74  #define IASSERT(...) \
75  do { if (!(__VA_ARGS__)){ int rank; MPI_Comm_rank(MPI_COMM_WORLD,&rank); if (rank == 0){ printf("CTF ERROR: %s:%d, ASSERT(%s) failed\n",__FILE__,__LINE__,#__VA_ARGS__); } CTF_int::handler(); assert(__VA_ARGS__); } } while (0)
76 
84  int64_t sy_packed_size(int order, const int* len, const int* sym);
85 
86 
94  int64_t packed_size(int order, const int* len, const int* sym);
95 
96 
97  enum { SUCCESS, ERROR, NEGATIVE };
98 
99  template <typename type=char>
100  int conv_idx(int order,
101  type const * cidx,
102  int ** iidx);
103 
104  template <typename type=char>
105  int conv_idx(int order_A,
106  type const * cidx_A,
107  int ** iidx_A,
108  int order_B,
109  type const * cidx_B,
110  int ** iidx_B);
111 
112  template <typename type=char>
113  int conv_idx(int order_A,
114  type const * cidx_A,
115  int ** iidx_A,
116  int order_B,
117  type const * cidx_B,
118  int ** iidx_B,
119  int order_C,
120  type const * cidx_C,
121  int ** iidx_C);
122 
123  void flops_add(int64_t n);
124 
125  int64_t get_flops();
126 
127  class CommData {
128  public:
129  MPI_Comm cm;
130  int np;
131  int rank;
132  int color;
133  int alive;
134  int created;
135 
136  CommData();
137  ~CommData();
138 
140  CommData(CommData const & other);
141  CommData& operator=(CommData const & other);
142 
147  CommData(MPI_Comm cm);
148 
155  CommData(int rank, int color, int np);
156 
163  CommData(int rank, int color, CommData parent);
164 
169  void activate(MPI_Comm parent);
170 
171  /* \brief deactivate (MPI_Free) this comm */
172  void deactivate();
173 
174  /* \brief provide estimate of broadcast execution time */
175  double estimate_bcast_time(int64_t msg_sz);
176 
177  /* \brief provide estimate of allreduction execution time */
178  double estimate_allred_time(int64_t msg_sz, MPI_Op op);
179 
180  /* \brief provide estimate of reduction execution time */
181  double estimate_red_time(int64_t msg_sz, MPI_Op op);
182 
183  /* \brief provide estimate of sparse reduction execution time */
184 // double estimate_csrred_time(int64_t msg_sz, MPI_Op op);
185 
186  /* \brief provide estimate of all_to_all execution time */
187  double estimate_alltoall_time(int64_t chunk_sz);
188 
189  /* \brief provide estimate of all_to_all_v execution time */
190  double estimate_alltoallv_time(int64_t tot_sz);
191 
195  void bcast(void * buf, int64_t count, MPI_Datatype mdtype, int root);
196 
200  void allred(void * inbuf, void * outbuf, int64_t count, MPI_Datatype mdtype, MPI_Op op);
201 
205  void red(void * inbuf, void * outbuf, int64_t count, MPI_Datatype mdtype, MPI_Op op, int root);
206 
218  void all_to_allv(void * send_buffer,
219  int64_t const * send_counts,
220  int64_t const * send_displs,
221  int64_t datum_size,
222  void * recv_buffer,
223  int64_t const * recv_counts,
224  int64_t const * recv_displs);
225 
226  };
227 
228  int alloc_ptr(int64_t len, void ** const ptr);
229  int mst_alloc_ptr(int64_t len, void ** const ptr);
230  void * alloc(int64_t len);
231  void * mst_alloc(int64_t len);
232  int cdealloc(void * ptr);
233 
234 
235  void cvrt_idx(int order,
236  int const * lens,
237  int64_t idx,
238  int ** idx_arr);
239 
240  void cvrt_idx(int order,
241  int const * lens,
242  int64_t idx,
243  int * idx_arr);
244 
245  void cvrt_idx(int order,
246  int const * lens,
247  int const * idx_arr,
248  int64_t * idx);
249 
258  bool get_mpi_dt(int64_t count, int64_t datum_size, MPI_Datatype & dt);
259 
260 
261 }
262 #endif
OP
reduction types for tensor data deprecated types: OP_NORM1=OP_SUMABS, OP_NORM2=call norm2()...
Definition: common.h:51
bool get_mpi_dt(int64_t count, int64_t datum_size, MPI_Datatype &dt)
gives a datatype for arbitrary datum_size, errors if exceeding 32-bits
Definition: common.cxx:587
def rank(self)
Definition: core.pyx:312
void * mst_alloc(int64_t len)
mst_alloc allocates buffer on the specialized memory stack
Definition: memcontrol.cxx:307
Definition: common.h:37
double get_rand48()
returns new random number in [0,1)
Definition: common.cxx:27
void * alloc(int64_t len)
alloc abstraction
Definition: memcontrol.cxx:365
Definition: common.h:37
int64_t get_flops()
Definition: common.cxx:177
STRUCTURE SYM
Definition: common.h:38
void init_rng(int rank)
initialized random number generator
Definition: common.cxx:23
void flops_add(int64_t n)
Definition: common.cxx:173
int mst_alloc_ptr(int64_t len, void **const ptr)
mst_alloc abstraction
Definition: memcontrol.cxx:269
STRUCTURE
Definition: common.h:37
int alloc_ptr(int64_t len, void **const ptr)
alloc abstraction
Definition: memcontrol.cxx:320
MPI_Comm cm
Definition: common.h:129
void handler()
Definition: common.cxx:181
int cdealloc(void *ptr)
free abstraction
Definition: memcontrol.cxx:480
Definition: apsp.cxx:17
int DGTOG_SWITCH
Definition: common.cxx:12
int64_t packed_size(int order, const int *len, const int *sym)
computes the size of a tensor in packed symmetric (SY, SH, or AS) layout
Definition: util.cxx:38
Definition: common.h:37
Definition: common.h:37
Definition: common.h:37
int64_t sy_packed_size(int order, const int *len, const int *sym)
computes the size of a tensor in SY (NOT HOLLOW) packed symmetric layout
Definition: util.cxx:10
int conv_idx(int order, type const *cidx, int **iidx)
Definition: common.cxx:50
void cvrt_idx(int order, int const *lens, int64_t idx, int *idx_arr)
Definition: common.cxx:533