OpenFPM  5.2.0
Project that contain the implementation of distributed structures
VCluster.cpp
1 #define PRINT_STACKTRACE
2 
3 #include "config.h"
4 #include "VCluster.hpp"
5 
6 #include "util/print_stack.hpp"
7 #include "util/math_util_complex.hpp"
8 
9 //init_options global_option;
10 Vcluster<> * global_v_cluster_private_heap = NULL;
11 Vcluster<CudaMemory> * global_v_cluster_private_cuda = NULL;
12 
13 //
14 std::vector<int> sieve_spf;
15 
16 // number of vcluster instances
17 size_t n_vcluster = 0;
18 bool ofp_initialized = false;
19 
20 size_t tot_sent = 0;
21 size_t tot_recv = 0;
22 
23 std::string program_name;
24 
25 #ifdef CUDA_GPU
26 
27 #include "memory/CudaMemory.cuh"
28 
29 CudaMemory mem_tmp;
30 
31 CudaMemory rem_tmp;
32 CudaMemory rem_tmp2[MAX_NUMER_OF_PROPERTIES];
33 
34 CudaMemory exp_tmp;
35 CudaMemory exp_tmp2[MAX_NUMER_OF_PROPERTIES];
36 
37 #endif
38 
39 // Segmentation fault signal handler
40 void bt_sighandler(int sig, siginfo_t * info, void * ctx_p)
41 {
42  if (sig == SIGSEGV)
43  std::cout << "Got signal " << sig << " faulty address is %p, " << info->si_addr << " from " << info->si_pid << std::endl;
44  else
45  std:: cout << "Got signal " << sig << std::endl;
46 
47  print_stack();
48 
49  exit(1);
50 }
51 
52 double time_spent = 0.0;
53 
54 
60 void openfpm_init_vcl(int *argc, char ***argv, MPI_Comm ext_comm)
61 {
62 
63 #if defined (ENABLE_NUMERICS) && defined (HAVE_PETSC)
64  #ifndef PETSC_SAFE_CALL
65  #define PETSC_SAFE_CALL(call) {\
66  PetscErrorCode err = call;\
67  if (err != 0) {\
68  std::string msg("Petsc error: ");\
69  msg += std::string(__FILE__) + std::string(" ") + std::to_string(__LINE__);\
70  PetscInt ln = __LINE__;\
71  PetscError(PETSC_COMM_WORLD,ln,__FUNCTION__,__FILE__,err,PETSC_ERROR_INITIAL,"Error petsc");\
72  }\
73  }
74  #endif
75 
76  if (ext_comm!=MPI_COMM_WORLD)
77  {
78  PETSC_COMM_WORLD = ext_comm;
79  }
80  PetscBool initialized;
81  PETSC_SAFE_CALL(PetscInitialized(&initialized));
82  if(initialized==PETSC_FALSE)
83  {
84  PETSC_SAFE_CALL(PetscInitialize(argc,argv,NULL,NULL));
85  }
86 #endif
87 
88  init_global_v_cluster_private(argc,argv,ext_comm);
89 
90 #ifdef SE_CLASS1
91  std::cout << "OpenFPM is compiled with debug mode LEVEL:1. Remember to remove SE_CLASS1 when you go in production" << std::endl;
92 #endif
93 
94 #ifdef SE_CLASS2
95  std::cout << "OpenFPM is compiled with debug mode LEVEL:2. Remember to remove SE_CLASS2 when you go in production" << std::endl;
96 #endif
97 
98 #ifdef SE_CLASS3
99  std::cout << "OpenFPM is compiled with debug mode LEVEL:3. Remember to remove SE_CLASS3 when you go in production" << std::endl;
100 #endif
101 
102  init_wrappers();
103 
104  // install segmentation fault signal handler
105 
106  struct sigaction sa;
107 
108  sa.sa_sigaction = bt_sighandler;
109  sigemptyset(&sa.sa_mask);
110  sa.sa_flags = SA_RESTART;
111 
112  sigaction(SIGSEGV, &sa, NULL);
113 
114  if (argc != NULL && *argc != 0)
115  {program_name = std::string(*argv[0]);}
116 
117  // Initialize math pre-computation tables
118  openfpm::math::init_getFactorization();
119 
120  ofp_initialized = true;
121 
122 #ifdef CUDA_GPU
123 
124  // Initialize temporal memory
125  mem_tmp.incRef();
126 
127  exp_tmp.incRef();
128 
129  for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++)
130  {
131  exp_tmp2[i].incRef();
132  }
133 
134 
135 #endif
136 }
137 
138 size_t openfpm_vcluster_compilation_mask()
139 {
140  size_t compiler_mask = CUDA_ON_BACKEND;
141 
142  return compiler_mask;
143 }
144 
150 void openfpm_finalize()
151 {
152 #if defined (ENABLE_NUMERICS) && defined (HAVE_PETSC)
153 
154  PetscFinalize();
155 
156 #endif
157 
158  delete_global_v_cluster_private();
159  ofp_initialized = false;
160 
161 #ifdef CUDA_GPU
162 
163  // Release memory
164  mem_tmp.destroy();
165  mem_tmp.decRef();
166 
167  exp_tmp.destroy();
168  exp_tmp.decRef();
169 
170  for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++)
171  {
172  exp_tmp2[i].destroy();
173  exp_tmp2[i].decRef();
174  }
175 
176 #endif
177 }
virtual void incRef()
Increment the reference counter.
Definition: CudaMemory.cuh:136
virtual void decRef()
Decrement the reference counter.
Definition: CudaMemory.cuh:142
virtual void destroy()
destroy memory
Definition: CudaMemory.cu:80
Implementation of VCluster class.
Definition: VCluster.hpp:59