28
28
#include <omp.h>
29
29
#endif
30
30
31
+ int interrupt_status_DDrppi_mocks_DOUBLE=EXIT_SUCCESS;
32
+
33
+ void interrupt_handler_countpairs_rp_pi_mocks_DOUBLE(int signo)
34
+ {
35
+ fprintf(stderr,"Received signal = `%s' (signo = %d). Aborting \n",strsignal(signo), signo);
36
+ interrupt_status_DDrppi_mocks_DOUBLE = EXIT_FAILURE;
37
+ }
38
+
31
39
32
40
int check_ra_dec_cz_DOUBLE(const int64_t N, DOUBLE *phi, DOUBLE *theta, DOUBLE *cz)
33
41
{
@@ -207,6 +215,16 @@ int countpairs_mocks_DOUBLE(const int64_t ND1, DOUBLE *ra1, DOUBLE *dec1, DOUBLE
207
215
int zbin_refine_factor=2;
208
216
const int npibin = (int) pimax;
209
217
218
+ /* setup interrupt handler -> mostly useful during the python execution.
219
+ Let's Ctrl-C abort the extension */
220
+ int interrupt_signals[] = {SIGTERM, SIGINT, SIGHUP};
221
+ for(size_t i=0;i<sizeof(interrupt_signals)/sizeof(interrupt_signals[0]);i++) {
222
+ int signo = interrupt_signals[i];
223
+ if (signal(signo, interrupt_handler_countpairs_rp_pi_mocks_DOUBLE) == SIG_ERR) {
224
+ fprintf(stderr,"Can not handle signal = %d\n", signo);
225
+ }
226
+ }
227
+
210
228
//Try to initialize cosmology - code will exit if comoslogy is not implemented.
211
229
//Putting in a different scope so I can call the variable status
212
230
{
@@ -424,7 +442,7 @@ int countpairs_mocks_DOUBLE(const int64_t ND1, DOUBLE *ra1, DOUBLE *dec1, DOUBLE
424
442
425
443
426
444
#if defined(_OPENMP)
427
- #pragma omp parallel shared(numdone, abort_status)
445
+ #pragma omp parallel shared(numdone, abort_status, interrupt_status_DDrppi_mocks_DOUBLE )
428
446
{
429
447
const int tid = omp_get_thread_num();
430
448
uint64_t npairs[totnbins];
@@ -441,10 +459,10 @@ int countpairs_mocks_DOUBLE(const int64_t ND1, DOUBLE *ra1, DOUBLE *dec1, DOUBLE
441
459
for(int64_t index1=0;index1<totncells;index1++) {
442
460
443
461
#if defined(_OPENMP)
444
- #pragma omp flush (abort_status)
462
+ #pragma omp flush (abort_status, interrupt_status_DDrppi_mocks_DOUBLE )
445
463
#endif
446
- if(abort_status == EXIT_SUCCESS) { //omp cancel was introduced in omp 4.0 - so this is my way of checking if loop needs to be cancelled
447
-
464
+ if(abort_status == EXIT_SUCCESS && interrupt_status_DDrppi_mocks_DOUBLE == EXIT_SUCCESS) {
465
+ //omp cancel was introduced in omp 4.0 - so this is my way of checking if loop needs to be cancelled
448
466
/* If the verbose option is not enabled, avoid outputting anything unnecessary*/
449
467
if(options.verbose) {
450
468
#if defined(_OPENMP)
@@ -524,13 +542,8 @@ int countpairs_mocks_DOUBLE(const int64_t ND1, DOUBLE *ra1, DOUBLE *dec1, DOUBLE
524
542
if(autocorr == 0) {
525
543
free_cellarray_mocks_index_particles_DOUBLE(lattice2,totncells);
526
544
}
527
-
528
- if(options.verbose) {
529
- finish_myprogressbar(&interrupted);
530
- }
531
-
532
545
533
- if(abort_status != EXIT_SUCCESS) {
546
+ if(abort_status != EXIT_SUCCESS || interrupt_status_DDrppi_mocks_DOUBLE != EXIT_SUCCESS ) {
534
547
/* Cleanup memory here if aborting */
535
548
free(rupp);
536
549
#if defined(_OPENMP)
0 commit comments