| 1 | #define PRINT_STACKTRACE |
| 2 | |
| 3 | #include "VCluster.hpp" |
| 4 | #ifndef __CYGWIN__ |
| 5 | #include <execinfo.h> |
| 6 | #endif |
| 7 | |
| 8 | #include "util/print_stack.hpp" |
| 9 | #include "util/math_util_complex.hpp" |
| 10 | |
| 11 | Vcluster<> * global_v_cluster_private_heap = NULL; |
| 12 | Vcluster<CudaMemory> * global_v_cluster_private_cuda = NULL; |
| 13 | |
| 14 | // |
| 15 | std::vector<int> sieve_spf; |
| 16 | |
| 17 | // number of vcluster instances |
| 18 | size_t n_vcluster = 0; |
| 19 | bool ofp_initialized = false; |
| 20 | |
| 21 | size_t tot_sent = 0; |
| 22 | size_t tot_recv = 0; |
| 23 | |
| 24 | //! NBX has a potential pitfall that must be addressed, |
| 25 | //! NBX Send all the messages and probe for incoming messages, |
| 26 | //! if there is an incoming message it receive it producing |
| 27 | //! an acknowledge notification on the sending processor. |
| 28 | //! When all the sends has been acknowledged, the processor call the MPI_Ibarrier |
| 29 | //! when all the processors call MPI_Ibarrier all send has been received. |
| 30 | //! While the processors are waiting for the MPI_Ibarrier to complete, all processors |
| 31 | //! are still probing for incoming message, Unfortunately some processor |
| 32 | //! can quit the MPI_Ibarrier before others and this mean that some |
| 33 | //! processor can exit the probing status before others, these processors can in theory |
| 34 | //! start new communications while the other processor are still in probing status producing |
| 35 | //! a wrong send/recv association to |
| 36 | //! resolve this problem an incremental NBX_cnt is used as message TAG to distinguish that the |
| 37 | //! messages come from other send or subsequent NBX procedures |
| 38 | size_t NBX_cnt = 0; |
| 39 | |
| 40 | std::string program_name; |
| 41 | |
| 42 | #ifdef CUDA_GPU |
| 43 | |
| 44 | #include "memory/CudaMemory.cuh" |
| 45 | |
| 46 | CudaMemory mem_tmp; |
| 47 | |
| 48 | CudaMemory rem_tmp; |
| 49 | CudaMemory rem_tmp2[MAX_NUMER_OF_PROPERTIES]; |
| 50 | |
| 51 | CudaMemory exp_tmp; |
| 52 | CudaMemory exp_tmp2[MAX_NUMER_OF_PROPERTIES]; |
| 53 | |
| 54 | #endif |
| 55 | |
| 56 | // Segmentation fault signal handler |
| 57 | void bt_sighandler(int sig, siginfo_t * info, void * ctx_p) |
| 58 | { |
| 59 | if (sig == SIGSEGV) |
| 60 | std::cout << "Got signal " << sig << " faulty address is %p, " << info->si_addr << " from " << info->si_pid << std::endl; |
| 61 | else |
| 62 | std:: cout << "Got signal " << sig << std::endl; |
| 63 | |
| 64 | print_stack(); |
| 65 | |
| 66 | exit(0); |
| 67 | } |
| 68 | |
| 69 | double time_spent = 0.0; |
| 70 | |
| 71 | |
| 72 | /*! \brief Initialize the library |
| 73 | * |
| 74 | * This function MUST be called before any other function |
| 75 | * |
| 76 | */ |
| 77 | void openfpm_init_vcl(int *argc, char ***argv) |
| 78 | { |
| 79 | #ifdef HAVE_PETSC |
| 80 | |
| 81 | PetscInitialize(argc,argv,NULL,NULL); |
| 82 | |
| 83 | #endif |
| 84 | |
| 85 | init_global_v_cluster_private(argc,argv); |
| 86 | |
| 87 | #ifdef SE_CLASS1 |
| 88 | std::cout << "OpenFPM is compiled with debug mode LEVEL:1. Remember to remove SE_CLASS1 when you go in production" << std::endl; |
| 89 | #endif |
| 90 | |
| 91 | #ifdef SE_CLASS2 |
| 92 | std::cout << "OpenFPM is compiled with debug mode LEVEL:2. Remember to remove SE_CLASS2 when you go in production" << std::endl; |
| 93 | #endif |
| 94 | |
| 95 | #ifdef SE_CLASS3 |
| 96 | std::cout << "OpenFPM is compiled with debug mode LEVEL:3. Remember to remove SE_CLASS3 when you go in production" << std::endl; |
| 97 | #endif |
| 98 | |
| 99 | #ifdef CUDA_ON_CPU |
| 100 | init_wrappers(); |
| 101 | #endif |
| 102 | |
| 103 | // install segmentation fault signal handler |
| 104 | |
| 105 | struct sigaction sa; |
| 106 | |
| 107 | sa.sa_sigaction = bt_sighandler; |
| 108 | sigemptyset(&sa.sa_mask); |
| 109 | sa.sa_flags = SA_RESTART; |
| 110 | |
| 111 | sigaction(SIGSEGV, &sa, NULL); |
| 112 | |
| 113 | if (argc != NULL && *argc != 0) |
| 114 | {program_name = std::string(*argv[0]);} |
| 115 | |
| 116 | // Initialize math pre-computation tables |
| 117 | openfpm::math::init_getFactorization(); |
| 118 | |
| 119 | ofp_initialized = true; |
| 120 | |
| 121 | #ifdef CUDA_GPU |
| 122 | |
| 123 | // Initialize temporal memory |
| 124 | mem_tmp.incRef(); |
| 125 | |
| 126 | exp_tmp.incRef(); |
| 127 | |
| 128 | for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++) |
| 129 | { |
| 130 | exp_tmp2[i].incRef(); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | #endif |
| 135 | } |
| 136 | |
| 137 | size_t openfpm_vcluster_compilation_mask() |
| 138 | { |
| 139 | size_t compiler_mask = 0; |
| 140 | |
| 141 | #ifdef CUDA_ON_CPU |
| 142 | compiler_mask |= 0x1; |
| 143 | #endif |
| 144 | |
| 145 | |
| 146 | #ifdef CUDA_GPU |
| 147 | compiler_mask |= 0x04; |
| 148 | #endif |
| 149 | |
| 150 | return compiler_mask; |
| 151 | } |
| 152 | |
| 153 | /*! \brief Finalize the library |
| 154 | * |
| 155 | * This function MUST be called at the end of the program |
| 156 | * |
| 157 | */ |
| 158 | void openfpm_finalize() |
| 159 | { |
| 160 | #ifdef HAVE_PETSC |
| 161 | |
| 162 | PetscFinalize(); |
| 163 | |
| 164 | #endif |
| 165 | |
| 166 | delete_global_v_cluster_private(); |
| 167 | ofp_initialized = false; |
| 168 | |
| 169 | #ifdef CUDA_GPU |
| 170 | |
| 171 | // Release memory |
| 172 | mem_tmp.destroy(); |
| 173 | mem_tmp.decRef(); |
| 174 | |
| 175 | exp_tmp.destroy(); |
| 176 | exp_tmp.decRef(); |
| 177 | |
| 178 | for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++) |
| 179 | { |
| 180 | exp_tmp2[i].destroy(); |
| 181 | exp_tmp2[i].decRef(); |
| 182 | } |
| 183 | |
| 184 | #endif |
| 185 | } |
| 186 | |