OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
Odeintegrators_test_gpu.cu
1//
2// Created by abhinav on 2/28/23.
3//
4#include "config.h"
5#include <type_traits>
6#include <cstring>
7#include "util/common.hpp"
8
9#define BOOST_TEST_DYN_LINK
10
11#include "util/util_debug.hpp"
12#include <boost/test/unit_test.hpp>
13#include <iostream>
14#include "Operators/Vector/vector_dist_operators.hpp"
15#include "OdeIntegrators/OdeIntegrators.hpp"
16//#include "DCPSE/DCPSE_op/DCPSE_op.hpp"
17#ifdef __NVCC__
18
19typedef state_type_1d_ofp_gpu state_type;
20//const double a = 2.8e-4;
21//const double b = 5e-3;
22//const double tau = .1;
23//const double k = .005;
24
25void ExponentialGPU( const state_type &x , state_type &dxdt , const double t )
26{
27 //timer tt;
28 //tt.startGPU();
29 dxdt.data.get<0>() = x.data.get<0>();
30 //tt.stopGPU();
31 //std::cout<<"GPU Time:"<<tt.getwctGPU()<<std::endl;
32 //x.data.get<0>().getVector().deviceToHost<0>();
33 //dxdt.data.get<0>().getVector().deviceToHost<0>();
34}
35
36BOOST_AUTO_TEST_SUITE(odeInt_BASE_tests)
37
38BOOST_AUTO_TEST_CASE(odeint_base_test_gpu)
39 {
40 size_t edgeSemiSize = 512;
41 const size_t sz[2] = {edgeSemiSize,edgeSemiSize };
42 Box<2, double> box({ 0, 0 }, { 1.0, 1.0 });
43 size_t bc[2] = { NON_PERIODIC, NON_PERIODIC };
44 double spacing[2];
45 spacing[0] = 1.0 / (sz[0] - 1);
46 spacing[1] = 1.0 / (sz[1] - 1);
47 double rCut = 3.9 * spacing[0];
48 Ghost<2, double> ghost(rCut);
49 BOOST_TEST_MESSAGE("Init vector_dist...");
50
52
53 auto it = Particles.getGridIterator(sz);
54 while (it.isNext())
55 {
56 Particles.add();
57 auto key = it.get();
58 mem_id k0 = key.get(0);
59 double xp0 = k0 * spacing[0];
60 Particles.getLastPos()[0] = xp0;
61 mem_id k1 = key.get(1);
62 double yp0 = k1 * spacing[1];
63 Particles.getLastPos()[1] = yp0;
64 Particles.getLastProp<0>() = xp0*yp0*exp(-5);
65 Particles.getLastProp<1>() = xp0*yp0*exp(5);
66 ++it;
67 }
68
69 Particles.map();
70 Particles.ghost_get<0>();
71 Particles.hostToDeviceProp<0,1,2>();
72 auto Init = getV<0,comp_dev>(Particles);
73 auto Sol = getV<1,comp_dev>(Particles);
74 auto OdeSol = getV<2,comp_dev>(Particles);
75
76 state_type x0;
77 x0.data.get<0>()=Init;
78 x0.data.get<0>().getVector().deviceToHost<0>();
79 // The rhs of x' = f(x)
80
81 double t0=-5,tf=5;
82 const double dt=0.01;
83
84
85 //This doesnt work Why?
86 //size_t steps=boost::numeric::odeint::integrate(Exponential,x0,0.0,tf,dt);
87 timer tt;
88 tt.start();
89 size_t steps=boost::numeric::odeint::integrate_const( boost::numeric::odeint::runge_kutta4< state_type, double, state_type, double, boost::numeric::odeint::vector_space_algebra_ofp_gpu,boost::numeric::odeint::ofp_operations>(),ExponentialGPU,x0,t0,tf,dt);
90 tt.stop();
91 OdeSol=x0.data.get<0>();
92 Particles.deviceToHostProp<0,1,2>();
93 auto it2 = Particles.getDomainIterator();
94 double worst = 0.0;
95 while (it2.isNext()) {
96 auto p = it2.get();
97 if (fabs(Particles.getProp<1>(p) - Particles.getProp<2>(p)) > worst) {
98 worst = fabs(Particles.getProp<1>(p) - Particles.getProp<2>(p));
99 }
100 ++it2;
101 }
102 std::cout<<"WCT:"<<tt.getwct()<<std::endl;
103 std::cout<<"CPU:"<<tt.getcputime()<<std::endl;
104 std::cout<<worst<<std::endl;
105 BOOST_REQUIRE(worst < 1e-6);
106 }
107BOOST_AUTO_TEST_SUITE_END()
108#endif
This class represent an N-dimensional box.
Definition Box.hpp:61
Class for cpu time benchmarking.
Definition timer.hpp:28
void stop()
Stop the timer.
Definition timer.hpp:119
double getcputime()
Return the cpu time.
Definition timer.hpp:142
void start()
Start the timer.
Definition timer.hpp:90
double getwct()
Return the elapsed real time.
Definition timer.hpp:130
Main class that encapsulate a vector properties operand to be used for expressions construction.
Distributed vector.