milupHPC documentation
  • src
simulation_time_handler.cpp
Go to the documentation of this file.
1#include "../include/simulation_time_handler.h"
2
3SimulationTimeHandler::SimulationTimeHandler(real dt, real endTime, real dt_max) {
4
5 h_dt = new real;
6 h_startTime = new real;
7 h_subEndTime = new real;
8 h_endTime = new real;
9 h_currentTime = new real;
10 h_dt_max = new real;
11
12 *h_dt = dt;
13 *h_startTime = 0;
14 *h_subEndTime = 0;
15 *h_endTime = endTime;
16 *h_currentTime = 0;
17 *h_dt_max = dt_max;
18
19 h_simulationTime = new SimulationTime;
20 h_simulationTime->set(h_dt, h_startTime, h_subEndTime, h_endTime, h_currentTime, h_dt_max);
21
22 cuda::malloc(d_dt, 1);
23 cuda::malloc(d_startTime, 1);
24 cuda::malloc(d_subEndTime, 1);
25 cuda::malloc(d_endTime, 1);
26 cuda::malloc(d_currentTime, 1);
27 cuda::malloc(d_dt_max, 1);
28
29 cuda::malloc(d_simulationTime, 1);
30 SimulationTimeNS::Kernel::Launch::set(d_simulationTime, d_dt, d_startTime, d_subEndTime, d_endTime,
31 d_currentTime, d_dt_max);
32
33 copy(To::device);
34}
35
36SimulationTimeHandler::~SimulationTimeHandler() {
37 delete h_dt;
38 delete h_startTime;
39 delete h_subEndTime;
40 delete h_endTime;
41 delete h_currentTime;
42 delete h_dt_max;
43
44 delete h_simulationTime;
45
46 cuda::free(d_dt);
47 cuda::free(d_startTime);
48 cuda::free(d_subEndTime);
49 cuda::free(d_endTime);
50 cuda::free(d_currentTime);
51 cuda::free(d_dt_max);
52
53 cuda::free(d_simulationTime);
54}
55
56void SimulationTimeHandler::copy(To::Target target) {
57
58 cuda::copy(h_dt, d_dt, 1, target);
59 cuda::copy(h_startTime, d_startTime, 1, target);
60 cuda::copy(h_subEndTime, d_subEndTime, 1, target);
61 cuda::copy(h_endTime, d_endTime, 1, target);
62 cuda::copy(h_currentTime, d_currentTime, 1, target);
63 cuda::copy(h_dt_max, d_dt_max, 1, target);
64
65}
66
67void SimulationTimeHandler::globalizeTimeStep(Execution::Location exLoc) {
68
69 boost::mpi::communicator comm;
70 switch (exLoc) {
71
72 case Execution::host: {
73 all_reduce(comm, boost::mpi::inplace_t<real*>(h_dt), 1, boost::mpi::minimum<real>());
74 } break;
75 case Execution::device: {
76 all_reduce(comm, boost::mpi::inplace_t<real*>(d_dt), 1, boost::mpi::minimum<real>());
77 } break;
78
79 }
80
81}
SimulationTimeHandler::h_simulationTime
SimulationTime * h_simulationTime
Definition: simulation_time_handler.h:26
SimulationTimeHandler::d_subEndTime
real * d_subEndTime
Definition: simulation_time_handler.h:30
SimulationTimeHandler::h_dt_max
real * h_dt_max
Definition: simulation_time_handler.h:24
SimulationTimeHandler::globalizeTimeStep
void globalizeTimeStep(Execution::Location exLoc)
Definition: simulation_time_handler.cpp:67
SimulationTimeHandler::copy
void copy(To::Target target)
Definition: simulation_time_handler.cpp:56
SimulationTimeHandler::~SimulationTimeHandler
~SimulationTimeHandler()
Definition: simulation_time_handler.cpp:36
SimulationTimeHandler::d_endTime
real * d_endTime
Definition: simulation_time_handler.h:31
SimulationTimeHandler::d_dt_max
real * d_dt_max
Definition: simulation_time_handler.h:33
SimulationTimeHandler::SimulationTimeHandler
SimulationTimeHandler(real dt, real endTime, real dt_max)
Definition: simulation_time_handler.cpp:3
SimulationTimeHandler::d_startTime
real * d_startTime
Definition: simulation_time_handler.h:29
SimulationTimeHandler::d_currentTime
real * d_currentTime
Definition: simulation_time_handler.h:32
SimulationTimeHandler::d_dt
real * d_dt
Definition: simulation_time_handler.h:28
SimulationTimeHandler::h_subEndTime
real * h_subEndTime
Definition: simulation_time_handler.h:21
SimulationTimeHandler::h_dt
real * h_dt
Definition: simulation_time_handler.h:19
SimulationTimeHandler::h_endTime
real * h_endTime
Definition: simulation_time_handler.h:22
SimulationTimeHandler::h_currentTime
real * h_currentTime
Definition: simulation_time_handler.h:23
SimulationTimeHandler::d_simulationTime
SimulationTime * d_simulationTime
Definition: simulation_time_handler.h:35
SimulationTimeHandler::h_startTime
real * h_startTime
Definition: simulation_time_handler.h:20
SimulationTime
Definition: simulation_time.cuh:14
SimulationTime::set
CUDA_CALLABLE_MEMBER void set(real *dt, real *startTime, real *subEndTime, real *endTime, real *currentTime, real *dt_max)
Definition: simulation_time.cu:17
SimulationTimeNS::Kernel::Launch::set
void set(SimulationTime *simulationTime, real *dt, real *startTime, real *subEndTime, real *endTime, real *currentTime, real *dt_max)
Definition: simulation_time.cu:35
cuda::copy
void copy(T *h_var, T *d_var, std::size_t count=1, To::Target copyTo=To::device)
Copy between host and device and vice-versa.
Definition: cuda_runtime.h:30
cuda::free
void free(T *d_var)
Free device memory.
Definition: cuda_runtime.h:81
cuda::malloc
void malloc(T *&d_var, std::size_t count)
Allocate device memory.
Definition: cuda_runtime.h:70
real
double real
Definition: parameter.h:15
Execution::Location
Location
Definition: parameter.h:192
Execution::device
@ device
Definition: parameter.h:193
Execution::host
@ host
Definition: parameter.h:193
To::Target
Target
Definition: parameter.h:164
To::device
@ device
Definition: parameter.h:165

milupHPC - src/simulation_time_handler.cpp Source File
Generated on Wed Aug 31 2022 12:16:53 by Doxygen 1.9.3