82 #ifndef AU_LOCAL_MIRROR_H
83 #define AU_LOCAL_MIRROR_H
85 #define LOCAL_MIRROR_READ_FLAG 0
86 #define LOCAL_MIRROR_WRITE_FLAG 1
102 T *local_mirror_buffer_typed = (T *)malloc(local_mirror_size *
sizeof(T));
103 if (local_mirror_buffer_typed == NULL)
105 AU_EXIT(
"Not enough memory to crate local mirror.");
110 std::memset(local_mirror_buffer_typed, 0, local_mirror_size *
sizeof(T));
112 if (init_value_str !=
"")
114 std::istringstream reader(init_value_str);
117 for (
int i = 0; i < local_mirror_size; i++)
119 local_mirror_buffer_typed[i] = init_val;
122 return (
void *)local_mirror_buffer_typed;
125 template <
typename T>
127 std::vector<unsigned long long> &start, std::vector<unsigned long long> &end,
128 void *data,
int read_write_code)
130 T *local_mirror_buffer_typed = (T *)local_mirror_buffer;
131 T *data_typed = (T *)data;
133 std::vector<unsigned long long> read_count;
134 unsigned long long element_count = 1;
135 read_count.resize(mirror_size.size());
136 for (
int i = 0; i < mirror_size.size(); i++)
138 read_count[i] = end[i] - start[i] + 1;
139 element_count = element_count * read_count[i];
142 if (read_count == mirror_size)
147 std::memcpy(data, local_mirror_buffer, element_count *
sizeof(T));
151 std::memcpy(local_mirror_buffer, data, element_count *
sizeof(T));
162 switch (mirror_size.size())
166 unsigned long long data_typed_offset = 0;
167 for (
unsigned long long i = start[0]; i <= end[0]; i++)
171 data_typed[data_typed_offset] = local_mirror_buffer_typed[i];
175 local_mirror_buffer_typed[i] = data_typed[data_typed_offset];
183 unsigned long long offset;
184 unsigned long long data_typed_offset = 0;
185 std::vector<unsigned long long> coodinate_temp(2);
186 for (
unsigned long long i = start[0]; i <= end[0]; i++)
188 for (
unsigned long long j = start[1]; j <= end[1]; j++)
190 coodinate_temp[0] = i;
191 coodinate_temp[1] = j;
196 data_typed[data_typed_offset] = local_mirror_buffer_typed[offset];
200 local_mirror_buffer_typed[offset] = data_typed[data_typed_offset];
210 unsigned long long offset;
211 unsigned long long data_typed_offset = 0;
212 std::vector<unsigned long long> coodinate_temp(3);
213 for (
unsigned long long i = start[0]; i <= end[0]; i++)
215 for (
unsigned long long j = start[1]; j <= end[1]; j++)
217 for (
unsigned long long k = start[2]; k <= end[2]; k++)
219 coodinate_temp[0] = i;
220 coodinate_temp[1] = j;
221 coodinate_temp[2] = k;
225 data_typed[data_typed_offset] = local_mirror_buffer_typed[offset];
229 local_mirror_buffer_typed[offset] = data_typed[data_typed_offset];
244 template <
typename T>
245 T *
MergeMirrorsHelp(
void *local_mirror_buffer,
unsigned long long &local_mirror_size, std::string &opt_str)
247 T *reduced_mirror_buffer = NULL;
250 reduced_mirror_buffer = (T *)malloc(local_mirror_size *
sizeof(T));
259 std::memcpy(local_mirror_buffer, reduced_mirror_buffer, local_mirror_size *
sizeof(T));
262 return reduced_mirror_buffer;
265 template <
typename T>
266 void BcastHelp(
void *local_mirror_buffer,
unsigned long long &local_mirror_size)
void * CreateLocalMirrorHelp(std::string init_value_str, size_t local_mirror_size)
Definition: ft_local_mirror.h:100
int ft_rank
Definition: ft.cpp:86
void BcastHelp(void *local_mirror_buffer, unsigned long long &local_mirror_size)
Definition: ft_local_mirror.h:266
T * MergeMirrorsHelp(void *local_mirror_buffer, unsigned long long &local_mirror_size, std::string &opt_str)
Definition: ft_local_mirror.h:245
int AccessLocalMirrorHelp(void *local_mirror_buffer, std::vector< unsigned long long > &mirror_size, std::vector< unsigned long long > &start, std::vector< unsigned long long > &end, void *data, int read_write_code)
Definition: ft_local_mirror.h:126
int ft_size
Definition: ft.cpp:85
#define LOCAL_MIRROR_READ_FLAG
Definition: ft_local_mirror.h:85
#define AU_MPI_Datatype
Definition: ft_mpi.h:96
MPI_Op InferMPIMergeOp(std::string &opt_str)
Definition: ft_mpi.h:175
#define AU_MPI_Op
Definition: ft_mpi.h:97
#define MPI_COMM_WORLD_DEFAULT
Definition: ft_mpi.h:94
#define AU_Bcast(data_bffer_p, count_p, datatype_p, root_p, comm_p)
Definition: ft_mpi.h:234
#define AU_Reduce(local_buffer_p, reduced_buffer_p, size, type, op, root, comm)
Definition: ft_mpi.h:230
#define ROW_MAJOR_ORDER_MACRO(dsize, dsize_len, coordinate, offset)
macro version of above two functions for speed
Definition: ft_utility_macro.h:124
#define AU_EXIT(info)
Definition: ft_utility_macro.h:147