AQUAgpusph 5.0.4
Loading...
Searching...
No Matches
MPISync.hpp
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
26
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.hpp"
37#include "Kernel.hpp"
38#include "RadixSort.hpp"
39#include "Reduction.hpp"
40#include "UnSort.hpp"
41#include "SetScalar.hpp"
42#include "Set.hpp"
43
44namespace Aqua {
45namespace CalcServer {
46
75{
76 public:
91 MPISync(const std::string name,
92 const std::string mask,
93 const std::vector<std::string> fields,
94 const std::vector<unsigned int> procs,
95 bool once = false);
96
100
103 void setup();
104
105 protected:
110 cl_event _execute(const std::vector<cl_event> events);
111
112 private:
115 void variables();
116
125 void setupSort();
126
132 void setupFieldSort(InputOutput::ArrayVariable* field);
133
136 void setupSenders();
137
140 void setupReceivers();
141
143 std::string _mask_name;
146
148 std::vector<std::string> _field_names;
150 std::vector<InputOutput::ArrayVariable*> _fields;
152 std::vector<InputOutput::ArrayVariable*> _fields_sorted;
153
155 std::vector<uicl> _procs;
156
160 InputOutput::ArrayVariable* _unsorted_id;
161
165 InputOutput::ArrayVariable* _sorted_id;
166
168 RadixSort* _sort;
169
171 std::vector<UnSort*> _field_sorters;
172
174 size_t _n;
175
176 public:
185 {
186 public:
199 Exchanger(const std::string name,
200 const std::string vars_prefix,
202 const std::vector<InputOutput::ArrayVariable*> fields,
203 const std::vector<void*> field_hosts,
204 const uicl proc);
205
209
213 inline const std::string name() const { return _name; }
214
218 inline uicl proc() const { return _proc; }
219
227 typedef struct
228 {
230 size_t n;
232 MPI_Datatype t;
233 } MPIType;
234
240 static const MPIType typeToMPI(std::string t);
241
242 protected:
244 std::string _var_prefix;
245
248
250 std::vector<InputOutput::ArrayVariable*> _fields;
251
254
256 size_t _n;
257
259 std::vector<void*> _fields_host;
260
261 private:
263 std::string _name;
264 };
265
271 class Sender : public Exchanger
272 {
273 public:
290 Sender(const std::string name,
291 const std::string vars_prefix,
293 const std::vector<InputOutput::ArrayVariable*> fields,
294 const std::vector<void*> field_hosts,
295 const uicl proc);
296
300
304 void execute(EventProfile* profiler);
305
306 private:
309 void setupSubMaskMems();
310
315 void setupOpenCL(const std::string kernel_name);
316
320 void setupReduction(const std::string var_name);
321
323 InputOutput::Variable* _n_offset;
324
326 InputOutput::ArrayVariable* _n_offset_mask;
327
329 cl_kernel _n_offset_kernel;
330
332 Reduction* _n_offset_reduction;
333
335 InputOutput::Variable* _n_send;
336
338 InputOutput::ArrayVariable* _n_send_mask;
339
341 cl_kernel _n_send_kernel;
342
344 Reduction* _n_send_reduction;
345
347 size_t _global_work_size;
349 size_t _local_work_size;
350 };
351
357 class Receiver : public Exchanger
358 {
359 public:
374 Receiver(const std::string name,
375 const std::string vars_prefix,
377 const std::vector<InputOutput::ArrayVariable*> fields,
378 const std::vector<void*> field_hosts,
379 const uicl proc,
380 InputOutput::Variable* n_offset);
381
385
389 void execute(EventProfile* profiler);
390
391 private:
394 void setupOpenCL();
395
397 cl_kernel _kernel;
398
400 InputOutput::Variable* _n_offset;
401
403 size_t _local_work_size;
404 };
405
406 private:
408 std::vector<void*> _fields_send;
409
411 std::vector<Sender*> _senders;
412
414 Set* _mask_reinit;
415
417 InputOutput::Variable* _n_offset_recv;
418
420 SetScalar* _n_offset_recv_reinit;
421
423 std::vector<void*> _fields_recv;
424
426 std::vector<Receiver*> _receivers;
427};
428
429}
430} // namespace
431
432#endif // MPISYNC_H_INCLUDED
The calculation main entry point. (See Aqua::CalcServer::CalcServer for details)
OpenCL kernel kernel based tool. (see Aqua::CalcServer::Kernel 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)
Profiler for tools based on OpenCL enqueued commands.
Definition Kernel.hpp:54
Exchanger(const std::string name, const std::string vars_prefix, InputOutput::ArrayVariable *mask, const std::vector< InputOutput::ArrayVariable * > fields, const std::vector< void * > field_hosts, const uicl proc)
size_t _n
Total number of elements.
Definition MPISync.hpp:256
static const MPIType typeToMPI(std::string t)
MPI type descriptor.
uicl proc() const
Processor.
Definition MPISync.hpp:218
~Exchanger()
Definition MPISync.hpp:208
std::string _var_prefix
Variables prefix.
Definition MPISync.hpp:244
std::vector< InputOutput::ArrayVariable * > _fields
Field.
Definition MPISync.hpp:250
InputOutput::ArrayVariable * _mask
Mask.
Definition MPISync.hpp:247
std::vector< void * > _fields_host
Host memory arrays to download, send, receive and upload the data.
Definition MPISync.hpp:259
const std::string name() const
Parent tool name.
Definition MPISync.hpp:213
uicl _proc
Processor.
Definition MPISync.hpp:253
void execute(EventProfile *profiler)
Receive the information.
Receiver(const std::string name, const std::string vars_prefix, InputOutput::ArrayVariable *mask, const std::vector< InputOutput::ArrayVariable * > fields, const std::vector< void * > field_hosts, const uicl proc, InputOutput::Variable *n_offset)
Sender(const std::string name, const std::string vars_prefix, InputOutput::ArrayVariable *mask, const std::vector< InputOutput::ArrayVariable * > fields, const std::vector< void * > field_hosts, const uicl proc)
void execute(EventProfile *profiler)
Send the information.
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)
void name(const std::string tool_name)
Definition Tool.hpp:66
Methods to perform a radix sort using the GPU (or any device supported by OpenCL)....
Definition RadixSort.hpp:94
Reductions, like scans, prefix sums, maximum or minimum, etc...
Definition Reduction.hpp:45
Set a scalar variable.
Definition SetScalar.hpp:176
Set all the components of an array with the desired value.
Definition Set.hpp:40
Tools base class.
Definition Tool.hpp:176
An array variable.
Definition Variable.hpp:894
A generic variable. Almost useless, use the overloaded classes instead of this one.
Definition Variable.hpp:68
__kernel void fields(__global const unsigned int *iset, __global const uint *isplit, __global const usize *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, __constant float *dr_level0, usize N, LINKLIST_LOCAL_PARAMS)
Collect the children, and the seed itself, in order to compute the field values of the buffer partner...
Definition Coalesce.cl:426
Calculation server name space.
Definition Assert.cpp:32
Main AQUAgpusph namespace.
Definition ArgumentsManager.cpp:50
#define uicl
Unsigned integer number.
Definition sphPrerequisites.hpp:85
Data structure to store the type information required by MPI.
Definition MPISync.hpp:228
size_t n
Number of components.
Definition MPISync.hpp:230
MPI_Datatype t
Underlying type, in MPI format.
Definition MPISync.hpp:232