AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
MPISync.h
Go to the documentation of this file.
1/*
2 * This file is part of AQUAgpusph, a free CFD program based on SPH.
3 * Copyright (C) 2012 Jose Luis Cercos Pita <jl.cercos@upm.es>
4 *
5 * AQUAgpusph is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * AQUAgpusph is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with AQUAgpusph. If not, see <http://www.gnu.org/licenses/>.
17 */
18
27#ifndef MPISYNC_H_INCLUDED
28#define MPISYNC_H_INCLUDED
29
30#ifndef HAVE_MPI
31#error MPI not available
32#endif
33
34#include <mpi.h>
35
36#include <CalcServer.h>
37#include <CalcServer/Kernel.h>
40#include <CalcServer/UnSort.h>
42#include <CalcServer/Set.h>
43
44namespace Aqua {
45namespace CalcServer {
46
74{
75 public:
90 MPISync(const std::string name,
91 const std::string mask,
92 const std::vector<std::string> fields,
93 const std::vector<unsigned int> procs,
94 bool once = false);
95
99
102 void setup();
103
104 protected:
109 cl_event _execute(const std::vector<cl_event> events);
110
111 private:
114 void variables();
115
124 void setupSort();
125
131 void setupFieldSort(InputOutput::ArrayVariable* field);
132
135 void setupSenders();
136
139 void setupReceivers();
140
142 std::string _mask_name;
145
147 std::vector<std::string> _field_names;
149 std::vector<InputOutput::ArrayVariable*> _fields;
151 std::vector<InputOutput::ArrayVariable*> _fields_sorted;
152
154 std::vector<unsigned int> _procs;
155
159 InputOutput::ArrayVariable* _unsorted_id;
160
164 InputOutput::ArrayVariable* _sorted_id;
165
167 RadixSort* _sort;
168
170 std::vector<UnSort*> _field_sorters;
171
173 unsigned int _n;
174
175 public:
183 {
184 public:
195 Exchanger(const std::string name,
197 const std::vector<InputOutput::ArrayVariable*> fields,
198 const std::vector<void*> field_hosts,
199 const unsigned int proc);
200
204
208 const std::string name() { return _name; }
209
217 typedef struct
218 {
220 unsigned int n;
222 MPI_Datatype t;
223 } MPIType;
224
230 static const MPIType typeToMPI(std::string t);
231
232 protected:
235
237 std::vector<InputOutput::ArrayVariable*> _fields;
238
240 unsigned int _proc;
241
243 unsigned int _n;
244
246 std::vector<void*> _fields_host;
247
248 private:
250 std::string _name;
251 };
252
258 class Sender : public Exchanger
259 {
260 public:
275 Sender(const std::string name,
277 const std::vector<InputOutput::ArrayVariable*> fields,
278 const std::vector<void*> field_hosts,
279 const unsigned int proc);
280
284
287 void execute(void);
288
289 private:
292 void setupSubMaskMems();
293
298 void setupOpenCL(const std::string kernel_name);
299
303 void setupReduction(const std::string var_name);
304
306 InputOutput::UIntVariable* _n_offset;
307
309 InputOutput::ArrayVariable* _n_offset_mask;
310
312 cl_kernel _n_offset_kernel;
313
315 Reduction* _n_offset_reduction;
316
319
321 InputOutput::ArrayVariable* _n_send_mask;
322
324 cl_kernel _n_send_kernel;
325
327 Reduction* _n_send_reduction;
328
330 size_t _global_work_size;
332 size_t _local_work_size;
333 };
334
340 class Receiver : public Exchanger
341 {
342 public:
355 Receiver(const std::string name,
357 const std::vector<InputOutput::ArrayVariable*> fields,
358 const std::vector<void*> field_hosts,
359 const unsigned int proc,
360 InputOutput::UIntVariable* n_offset);
361
365
368 void execute(void);
369
370 private:
373 void setupOpenCL();
374
376 cl_kernel _kernel;
377
379 InputOutput::UIntVariable* _n_offset;
380
382 size_t _local_work_size;
383 };
384
385 private:
387 std::vector<void*> _fields_send;
388
390 std::vector<Sender*> _senders;
391
393 Set* _mask_reinit;
394
396 InputOutput::UIntVariable* _n_offset_recv;
397
399 SetScalar* _n_offset_recv_reinit;
400
402 std::vector<void*> _fields_recv;
403
405 std::vector<Receiver*> _receivers;
406};
407
408}
409} // namespace
410
411#endif // MPISYNC_H_INCLUDED
The calculation main entry point. (See Aqua::CalcServer::CalcServer for details)
Methods to perform a radix sort using the GPU (or any device supported by OpenCL)....
Reductions, like scans, prefix sums, maximum or minimum, etc... (See Aqua::CalcServer::Reduction for ...
Set a scalar variable. (See Aqua::CalcServer::SetScalar for details)
Set all the components of an array with the desired value. (See Aqua::CalcServer::Set for details)
UnSort Recover the original id of each particle. (See Aqua::CalcServer::UnSort for details)
Interprocess array synchronization base class.
Definition: MPISync.h:183
static const MPIType typeToMPI(std::string t)
MPI type descriptor.
const std::string name()
Parent tool name.
Definition: MPISync.h:208
std::vector< InputOutput::ArrayVariable * > _fields
Field.
Definition: MPISync.h:237
unsigned int _proc
Processor.
Definition: MPISync.h:240
InputOutput::ArrayVariable * _mask
Mask.
Definition: MPISync.h:234
Exchanger(const std::string name, InputOutput::ArrayVariable *mask, const std::vector< InputOutput::ArrayVariable * > fields, const std::vector< void * > field_hosts, const unsigned int proc)
std::vector< void * > _fields_host
Host memory arrays to download, send, receive and upload the data.
Definition: MPISync.h:246
unsigned int _n
Total number of elements.
Definition: MPISync.h:243
Synchronize arrays between processes.
Definition: MPISync.h:341
Receiver(const std::string name, InputOutput::ArrayVariable *mask, const std::vector< InputOutput::ArrayVariable * > fields, const std::vector< void * > field_hosts, const unsigned int proc, InputOutput::UIntVariable *n_offset)
void execute(void)
Receive the information.
Synchronize arrays between processes.
Definition: MPISync.h:259
void execute(void)
Send the information.
Sender(const std::string name, InputOutput::ArrayVariable *mask, const std::vector< InputOutput::ArrayVariable * > fields, const std::vector< void * > field_hosts, const unsigned int proc)
Synchronize arrays between processes.
Definition: MPISync.h:74
MPISync(const std::string name, const std::string mask, const std::vector< std::string > fields, const std::vector< unsigned int > procs, bool once=false)
cl_event _execute(const std::vector< cl_event > events)
Methods to perform a radix sort using the GPU (or any device supported by OpenCL)....
Definition: RadixSort.h:97
Reductions, like scans, prefix sums, maximum or minimum, etc...
Definition: Reduction.h:43
Set a scalar variable.
Definition: SetScalar.h:37
Set all the components of an array with the desired value.
Definition: Set.h:39
Tools base class. The way that AQUAgpusph compute each problem is set through a set of tools that are...
Definition: Tool.h:46
const std::string name()
Definition: Tool.h:66
Definition: Variable.h:700
An integer variable.
Definition: Variable.h:317
__kernel void fields(__global const unsigned int *iset, __global const uint *isplit, __global const uint *mybuffer, __global const unsigned int *ilevel, __global const float *split_weight, __global float *m0, __global float *m, __global vec *r, __global vec *u, __global vec *dudt, __global float *rho, __global float *drhodt, __global const uint *icell, __global const uint *ihoc, __constant float *dr_level0, unsigned int N, uivec4 n_cells)
Collect the children, and the seed itself, in order to compute the field values of the buffer partner...
Definition: Coalesce.cl:435
OpenCL kernel kernel based tool. (see Aqua::CalcServer::Kernel for details)
Main AQUAgpusph namespace.
Definition: ArgumentsManager.cpp:45
Data structure to store the type information required by MPI.
Definition: MPISync.h:218
MPI_Datatype t
Underlying type, in MPI format.
Definition: MPISync.h:222
unsigned int n
Number of components.
Definition: MPISync.h:220