-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.h
More file actions
119 lines (89 loc) · 2.58 KB
/
simulation.h
File metadata and controls
119 lines (89 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef SIMULATION_H
#define SIMULATION_H
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <cuda_runtime_api.h>
#include <vector_types.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <memory>
#include "planet.hpp"
#include "common.hpp"
double getElapsed(struct timeval t0, struct timeval t1);
bool operator!=(const float3 &a, const float3 &b);
__host__ __device__ float3 operator+(const float3 &a, const float3 &b);
__host__ __device__ float3 operator*(const float &a, const float3 &b);
__host__ __device__ void update_particle(int , Particle *particles, float dt, int num_particles);
__global__ void simulation_GPU(Particle *particles, int n, float dt);
class Simulation
{
public:
virtual void init() = 0;
virtual void update(cudaGraphicsResource_t&) = 0;
virtual void display() = 0;
virtual void release() = 0;
};
class GPUSimulation : public Simulation
{
private:
float dt;
int NUM_PARTICLES = (NUM_SILICATE_PARTICLES+NUM_IRON_PARTICLES) * 2 ;
thrust::device_vector<Particle> allDevice;
Particle *d_p;
//Particle *d_p;
// Particle *d_pB;
double gpu_calculating_time;
struct timeval t0, t1, t2, t3, t5, t6;
int count;
cudaEvent_t start, stop;
public:
thrust::host_vector<Particle> all;
std::vector<std::shared_ptr<Planet>> planets;
GPUSimulation();
// virtual void init(int argc, char const *argv[])
void init();
void update(cudaGraphicsResource_t&);
void display();
void release();
// void preset_values(int n, int it, int size);
// void initial_particles();
/*Sergio Rivas Gómez*/
void checkCUDAError();
// void update_random(int it);
};
// class CPUSimulation : public Simulation
// {
// private:
// float dt;
// int NUM_PARTICLES;
// int NUM_ITERATIONS;
// int BLOCK_SIZE;
// Particle *particles;
// float3 *fake_random;
//
// struct timeval t0, t1;
// int count;
//
// public:
// CPUSimulation(int n, int it, int size);
//
// virtual void init();
//
// virtual void update();
//
// virtual void display();
//
// virtual void release();
//
// void simulation_CPU();
//
// // void update_random(int it);
// };
//
// void initial_particles(Particle *particles, int n);
//
// void update_random(int it, float3 *fake_random, int n);
//
// void print_particle(Particle *particles, int c);
#endif