7 #ifndef cf3_common_PE_broadcast_hpp
8 #define cf3_common_PE_broadcast_hpp
70 T *inout_buf=(
T*)out_values;
71 if (((in_map!=0)&&(irank==root))||(out_map!=0)){
74 if (stride==1) {
for(
int i=0; i<in_n; i++) inout_buf[i]=in_values[in_map[i]]; }
75 else {
for(
int i=0; i<in_n; i++) memcpy(&inout_buf[stride*i],&in_values[stride*in_map[i]],stride*
sizeof(
T)); }
77 }
else if ((irank==root)&&(in_values!=out_values)) {
78 memcpy(inout_buf,in_values,stride*in_n*
sizeof(
T));
86 if (stride==1) {
for(
int i=0; i<in_n; i++) out_values[out_map[i]]=inout_buf[i]; }
87 else {
for(
int i=0; i<in_n; i++) memcpy(&out_values[stride*out_map[i]],&inout_buf[stride*i],stride*
sizeof(
T)); }
91 if (((in_map!=0)&&(irank==root))||(out_map!=0))
delete[] inout_buf;
118 T* out_buf=out_values;
153 int size=out_values.size();
154 if (out_values.size()==0)
156 if (irank==root) size=(int)in_values.size();
163 if (irank==root) size=(int)in_values.size();
165 cf3_assert_desc(
"out_values.size() must be set to zero, or be compatible",size == out_values.size());
169 out_values.resize(size);
170 out_values.reserve(size);
198 broadcast(
const Communicator& comm,
const T* in_values,
const int in_n,
const int *in_map,
T* out_values,
const int *out_map,
const int root,
const int stride=1)
205 T* out_buf=out_values;
210 for (
int i=0; i<out_sum; i++) out_sum_tmp=out_map[i]>out_sum_tmp?out_map[i]:out_sum_tmp;
211 if (out_sum==0) out_sum=1;
214 if (out_sum==0) out_sum=1;
247 broadcast(
const Communicator& comm,
const std::vector<T>& in_values,
const std::vector<int>& in_map, std::vector<T>& out_values,
const std::vector<int>& out_map,
const int root,
const int stride=1)
257 if (out_values.size() == 0 ){
258 int out_sum=in_map.size();
259 if (out_map.size()!=0) {
263 if (out_sum==0) out_sum=1;
265 out_values.resize(stride*out_sum);
266 out_values.reserve(stride*out_sum);
271 detail::broadcast_impl(comm, (
T*)(&in_values[0]), in_map.size(), (in_map.empty() ?
nullptr : &in_map[0]), (
T*)(&out_values[0]), (out_map.empty() ?
nullptr : &out_map[0]), root, stride);
273 detail::broadcast_impl(comm, (
T*)0, in_map.size(), (
int*)0, (
T*)(&out_values[0]), (out_map.empty() ?
nullptr : &out_map[0]), root, stride);
285 #endif // cf3_common_PE_broadcast_hpp
MPI_Datatype Datatype
datatype
Datatype get_mpi_datatype(const T &ref_of_type)
ACCESS AND REGISTRATION MECHANISM.
#define boost_foreach
lowercase version of BOOST_FOREACH
#define cf3_assert_desc(m, a)
Top-level namespace for coolfluid.
T * broadcast(const Communicator &comm, const T *in_values, const int in_n, T *out_values, const int root, const int stride=1)
MPI_Comm Communicator
communicator
#define MPI_CHECK_RESULT(MPIFunc, Args)
Macro for checking return values of any mpi calls and throws exception on error.
void broadcast_impl(const Communicator &comm, const T *in_values, const int in_n, const int *in_map, T *out_values, const int *out_map, const int root, const int stride)