diff --git a/Makefile b/Makefile index b11637e..e619edb 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ BINDIR=bin MYBIN=/home/maan/pulsar_softwares/bin/ CC=gcc -CFLAGS=-I$(IDIR) -Wno-unused-result -O3 -march=native -LIBS=-lm -lfftw3 -lcpgplot +CFLAGS=-I$(IDIR) -Wno-unused-result -O3 -march=native -fopenmp +LIBS=-lm -lfftw3_threads -lfftw3 -lcpgplot _DEPS = header.h rficlean.h version.h DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) diff --git a/include/rficlean.h b/include/rficlean.h index 2aec681..d55ae05 100644 --- a/include/rficlean.h +++ b/include/rficlean.h @@ -9,17 +9,17 @@ long byte_offset; int headerless,obits,iflip,nred, iwhite,nints,nsub,maxhist,numhist,nsubchans,tnorm,fnorm,igetstat,nharm,pcl,nsect,zerodm,bl_start,nblocks; char inpfile[128], outfile[128], gminfofile[128],gmhdrfile[128],psfile[100]; FILE *input, *output, *gminfo, *gmhdr; -double tempra,tempdec, psrf, psrfdf, *last_mspec, *wrms, *wmean, *ai; +double tempra,tempdec, psrf, psrfdf, *last_mspec, **wrms, **wmean, **ai; float forcefthresh,fthresh,rthresh,sthresh,last_tvar,last_fvar,chanfrac,sampfrac,clipthresh; float *fftstat, *chanstat, *predist, *xpredist, *postdist, *xpostdist, *finaldist, *xfinaldist ; double *tfvar, *tfmean,meanvar,rmsvar ; -double *chandata, *mspec, *rspec, *vspec, *wspec, *wt; +double **chandata, *mspec, *rspec, *vspec, *wspec, *wt; long int *coff; bool RFIx,rfiFDx,rfiTx,rfiSx,rfiMSx,rfiVSx,rfiSclip; -fftw_complex *in; -fftw_complex *out; -fftw_plan fplan, bplan; +fftw_complex **in; +fftw_complex **out; +fftw_plan *fplan, *bplan; int strings_equal (char *string1, char *string2); diff --git a/src/cleanit.c b/src/cleanit.c index 2425acb..2318121 100644 --- a/src/cleanit.c +++ b/src/cleanit.c @@ -1,16 +1,19 @@ /* * cleanit --- the actual cleaning/processing of data. - * - * + * + * * Yogesh Maan 2018. - * - * + * + * */ #include #include #include #include "rficlean.h" #include +#ifdef _OPENMP +#include +#endif //-------------------------------------------------------------- int all_samef(double *arr, long int np) @@ -133,7 +136,15 @@ void fftclean(fftw_complex *in, fftw_complex *out, long int npts, int ioff) nfft = npts ; nfft2 = nfft/2; - fftw_execute ( fplan ); + + #ifdef _OPENMP + int thread_num = omp_get_thread_num(); + #else + int thread_num=0; + #endif + + fftw_execute ( fplan[thread_num] ); + anfft = (double)nfft; for (i=0;iath || fabs(out[i][1])>bth) && psrifs[i]>0 ){ - fftstat[ioff+i] = fftstat[ioff+i] + 1.0; + fftstat[ioff+i] += 1.0; for (j=i,ih=1; ih<=nharm && jath) ai[i] = (ai[i]/fabs(ai[i]))*ath; + if( fabs(ai[thread_num][i])>ath) ai[thread_num][i] = (ai[thread_num][i]/fabs(ai[thread_num][i]))*ath; } - for (i=0;iath) ai[i] = m1; + if( fabs((ai[thread_num][i]-m1))>ath) ai[thread_num][i] = m1; } - for (i=0;iath){ + if( fabs(ai[thread_num][i]-m1)>ath){ wt[i] = -1.0; wt[i+1] = -1.0; } @@ -297,18 +326,23 @@ void tsfind(double *ttdata, long int npts, float thresh, double *wt) double anpt,ath; double m1,r1,m2; - - for (i=0;iath){ + if( fabs((ai[thread_num][i]-m1))>ath){ wt[i] = -1.0; } } @@ -354,43 +388,51 @@ void cleanit(float *data, int nchans, long int nadd) float thresh; double lg,lgr, an, atemp; + int thread_num=0; // get some pre-cleaning statistics for (channum=0; channum 0.0) { lg = mspec[i]; lgr = rspec[i]; break; } } - for (i=0;ichanfrac){ + for (ii=0; iichanfrac) { + #pragma omp parallel for private(channum,ii,jj) collapse(2) for (channum=0; channum 0.0) last_mspec[ii] = mspec[ii];} + for (ii=0; ii 0.0) last_mspec[ii] = mspec[ii]; } - + // Try clipping some channels in individual samples if(rfiSclip){ + #pragma omp parallel for private(t,c,nxc,thread_num) schedule(dynamic) for (t=0; t0) isame = isame + 1; + for (c=0; c0) isame = isame + 1; } if(isame >= (int)(0.8*nvar)){ for (c=0; c 2018 * */ @@ -12,9 +12,12 @@ #include #include "rficlean.h" #include +#ifdef _OPENMP +#include +#endif -void rficlean_data(FILE *input, FILE *output) -{ +void rficlean_data(FILE *input, FILE *output) +{ char string[80],plotdevice[100]; float *fblock,min,max,hpower,realtime,fsaved[2], *ts0dm, atemp; unsigned short *sblock; @@ -41,7 +44,7 @@ void rficlean_data(FILE *input, FILE *output) printf ("\n Preparing all buffers...\n"); /***/ - chandata = (double *) malloc(nsize*sizeof(double)); + // chandata = (double *) malloc(nsize*sizeof(double)); vspec = (double *) malloc(nsize*sizeof(double)); rspec = (double *) malloc(nsize*sizeof(double)); coff = (long int *) malloc((nchans)*sizeof(long int)); @@ -50,17 +53,37 @@ void rficlean_data(FILE *input, FILE *output) wspec = (double *) malloc(nsize*sizeof(double)); /***/ - in = fftw_malloc (sizeof(fftw_complex)*(naddt+5)); - out = fftw_malloc (sizeof(fftw_complex)*(naddt+5)); - fplan = fftw_plan_dft_1d( naddt, in, out,FFTW_FORWARD, FFTW_ESTIMATE ); - bplan = fftw_plan_dft_1d( naddt, in, out,FFTW_BACKWARD, FFTW_ESTIMATE ); - ai = (double *) malloc(sizeof(double)*(nsize)); + // in = fftw_malloc (sizeof(fftw_complex)*(naddt+5)); + // out = fftw_malloc (sizeof(fftw_complex)*(naddt+5)); + // fplan = fftw_plan_dft_1d( naddt, in, out, FFTW_FORWARD, FFTW_ESTIMATE ); + // bplan = fftw_plan_dft_1d( naddt, in, out, FFTW_BACKWARD, FFTW_ESTIMATE ); + // ai = (double *) malloc(sizeof(double)*(nsize)); psrifs = (long int *) malloc(sizeof(long int)*(naddt)); + #ifdef _OPENMP + int max_threads = omp_get_max_threads(); + if (fftw_init_threads()) fftw_plan_with_nthreads(omp_get_max_threads()); + #else + int max_threads = 1; + #endif + chandata = (double **) malloc(max_threads * sizeof(double *)); + in = (fftw_complex**) malloc (max_threads * sizeof(fftw_complex*)); + out = (fftw_complex**) malloc (max_threads * sizeof(fftw_complex*)); + fplan = (fftw_plan*) malloc (max_threads * sizeof(fftw_plan)); + bplan = (fftw_plan*) malloc (max_threads * sizeof(fftw_plan)); + ai = (double **) malloc(max_threads * sizeof(double *)); + for (i=0; i