From f368adcb4425cd002b9f44744044032bbb2a0636 Mon Sep 17 00:00:00 2001 From: nandhanas Date: Wed, 23 Feb 2022 09:16:53 +0100 Subject: [PATCH] Added paramfile --- Makefile | 18 ++++---- allvars.c | 7 +-- allvars.h | 6 ++- init.c | 91 +++++++++++++++++++++++++++++++++++++ w-stacking-fftw.c => main.c | 65 +++++++------------------- proto.h | 9 ++++ 6 files changed, 134 insertions(+), 62 deletions(-) create mode 100644 init.c rename w-stacking-fftw.c => main.c (94%) create mode 100644 proto.h diff --git a/Makefile b/Makefile index 4b31f3e..2a3f21c 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ endif FFTW_MPI_INC = -I/${HOME}/include FFTW_MPI_LIB = /${HOME}/lib -CFLAGS += $(FFTW_MPI_INC) +CFLAGS += $(FFTW_MPI_INC) -I/proto.h LIBS = -L$(FFTW_MPI_LIB) -lfftw3_mpi -lfftw3 -lm #-lcudart -lcuda # create MPI code @@ -39,8 +39,8 @@ OPT += -DWRITE_IMAGE OPT += -DPHASE_ON -DEPS = w-stacking.h w-stacking-fftw.c w-stacking.cu phase_correction.cu allvars.h -COBJ = w-stacking.o w-stacking-fftw.o phase_correction.o allvars.o +DEPS = w-stacking.h main.c w-stacking.cu phase_correction.cu allvars.h init.c +COBJ = w-stacking.o main.o phase_correction.o allvars.o init.o w-stacking.c: w-stacking.cu cp w-stacking.cu w-stacking.c @@ -60,25 +60,25 @@ serial: $(COBJ) $(CC) $(OPTIMIZE) $(OPT) -o w-stackingCfftw_serial $^ $(LIBS) serial_omp: phase_correction.c - $(CC) $(OPTIMIZE) $(OPT) -o w-stackingOMP_serial w-stacking-fftw.c w-stacking_omp.c $(CFLAGS) $(LIBS) + $(CC) $(OPTIMIZE) $(OPT) -o w-stackingOMP_serial main.c init.c w-stacking_omp.c $(CFLAGS) $(LIBS) simple_mpi: phase_correction.c - $(MPICC) $(OPTIMIZE) $(OPT) -o w-stackingMPI_simple w-stacking_omp.c w-stacking-fftw.c phase_correction.c $(CFLAGS) $(LIBS) + $(MPICC) $(OPTIMIZE) $(OPT) -o w-stackingMPI_simple w-stacking_omp.c main.c init.c phase_correction.c $(CFLAGS) $(LIBS) mpi_omp: phase_correction.c - $(MPICC) $(OPTIMIZE) $(OPT) -o w-stackingMPI_omp w-stacking_omp.c w-stacking-fftw.c phase_correction.c $(CFLAGS) $(LIBS) + $(MPICC) $(OPTIMIZE) $(OPT) -o w-stackingMPI_omp w-stacking_omp.c main.c init.c phase_correction.c $(CFLAGS) $(LIBS) serial_cuda: $(NVCC) $(NVFLAGS) -c w-stacking.cu phase_correction.cu $(NVLIB) - $(CC) $(OPTIMIZE) $(OPT) -c w-stacking-fftw.c $(CFLAGS) $(LIBS) + $(CC) $(OPTIMIZE) $(OPT) -c main.c init.c $(CFLAGS) $(LIBS) $(CXX) $(OPTIMIZE) $(OPT) -o w-stackingfftw_serial w-stacking-fftw.o w-stacking.o phase_correction.o $(CFLAGS) $(NVLIB) -lm mpi: $(COBJ) - $(MPICC) $(OPTIMIZE) -o w-stackingCfftw $^ $(CFLAGS) $(LIBS) + $(MPICC) $(OPTIMIZE) -o w-stackingCfftw $^ $(CFLAGS) $(LIBS) mpi_cuda: $(NVCC) $(NVFLAGS) -c w-stacking.cu phase_correction.cu $(NVLIB) - $(MPICC) $(OPTIMIZE) $(OPT) -c w-stacking-fftw.c $(CFLAGS) $(LIBS) + $(MPICC) $(OPTIMIZE) $(OPT) -c main.c init.c$(CFLAGS) $(LIBS) $(MPIC++) $(OPTIMIZE) $(OPT) -o w-stackingfftw w-stacking-fftw.o w-stacking.o phase_correction.o $(NVLIB) $(CFLAGS) $(LIBS) clean: diff --git a/allvars.c b/allvars.c index cf26d03..d391fe0 100644 --- a/allvars.c +++ b/allvars.c @@ -2,13 +2,14 @@ struct io file; -struct ip in = {"ucoord.bin", "vcoord.bin", "wcoord.bin", "weights.bin", "visibilities_real.bin", "visibilities_img.bin", "meta.txt" }; +struct ip in; struct op out = {"grid.txt", "coords.txt", "grid_real.bin", "grid_img.bin", "fft.txt", "fft_real.bin", "fft_img.bin", "run.log", ".txt", "timings.dat"}; struct meta metaData; - struct time timing; char filename[1000]; - +int num_threads; +char datapath_multi[NFILES][900]; +int ndatasets; diff --git a/allvars.h b/allvars.h index 70dc68d..03220e5 100644 --- a/allvars.h +++ b/allvars.h @@ -1,6 +1,7 @@ /* file to store global variables*/ #include +#define NFILES 100 extern struct io { @@ -19,7 +20,7 @@ extern struct ip char visrealfile[30]; char visimgfile[30]; char metafile[30]; - + char paramfile[30]; } in; extern struct op @@ -66,3 +67,6 @@ extern struct time } timing; extern char filename[1000]; +extern int num_threads; +extern char datapath_multi[NFILES][900]; +extern int ndatasets; diff --git a/init.c b/init.c new file mode 100644 index 0000000..057c081 --- /dev/null +++ b/init.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include "allvars.h" +#include "proto.h" + +void init() +{ + read_parameter_file(in.paramfile); +} + + +void read_parameter_file(char *fname) +{ + if(file.pFile = fopen (fname,"r")) + { + char buf1[30], buf2[100]; + while(fscanf(file.pFile, "%s" "%s", buf1, buf2) != EOF) + { + if(strcmp(buf1, "num_threads") == 0) + { + num_threads = atoi(buf2); + } + if(strcmp(buf1, "Datapath") == 0) + { + strcpy(datapath_multi[0], buf2); + } + if(strcmp(buf1, "ndatasets") == 0) + { + ndatasets = atoi(buf2); + } + if(strcmp(buf1, "ufile") == 0) + { + strcpy(in.ufile, buf2); + } + if(strcmp(buf1, "vfile") == 0) + { + strcpy(in.vfile, buf2); + } + if(strcmp(buf1, "wfile") == 0) + { + strcpy(in.wfile, buf2); + } + if(strcmp(buf1, "weightsfile") == 0) + { + strcpy(in.weightsfile, buf2); + } + if(strcmp(buf1, "visrealfile") == 0) + { + strcpy(in.visrealfile, buf2); + } + if(strcmp(buf1, "visimgfile") == 0) + { + strcpy(in.visimgfile, buf2); + } + if(strcmp(buf1, "metafile") == 0) + { + strcpy(in.metafile, buf2); + } + } + fclose(file.pFile); + + } + else + { + printf("error opening paramfile"); + exit(1); + } +} + +void fileName(char datapath[900], char file[30]) { + strcpy(filename,datapath); + strcat(filename,file); +} + +void readMetaData(char fileLocal[1000]) { + file.pFile = fopen (fileLocal,"r"); + fscanf(file.pFile,"%ld",&metaData.Nmeasures); + fscanf(file.pFile,"%ld",&metaData.Nvis); + fscanf(file.pFile,"%ld",&metaData.freq_per_chan); + fscanf(file.pFile,"%ld",&metaData.polarisations); + fscanf(file.pFile,"%ld",&metaData.Ntimes); + fscanf(file.pFile,"%lf",&metaData.dt); + fscanf(file.pFile,"%lf",&metaData.thours); + fscanf(file.pFile,"%ld",&metaData.baselines); + fscanf(file.pFile,"%lf",&metaData.uvmin); + fscanf(file.pFile,"%lf",&metaData.uvmax); + fscanf(file.pFile,"%lf",&metaData.wmin); + fscanf(file.pFile,"%lf",&metaData.wmax); + fclose(file.pFile); +} diff --git a/w-stacking-fftw.c b/main.c similarity index 94% rename from w-stacking-fftw.c rename to main.c index 5bddebc..18bf8a2 100644 --- a/w-stacking-fftw.c +++ b/main.c @@ -12,6 +12,7 @@ #include #include #include "allvars.h" +#include "proto.h" #ifdef ACCOMP #include "w-stacking_omp.h" #else @@ -22,7 +23,6 @@ #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) #define NOVERBOSE -#define NFILES 100 // Linked List set-up struct sectorlist { @@ -37,27 +37,6 @@ void Push(struct sectorlist** headRef, long data) { *headRef = newNode; } -void fileName(char datapath[900], char file[30]) { - strcpy(filename,datapath); - strcat(filename,file); -} - -void readMetaData(char fileLocal[1000]) { - file.pFile = fopen (fileLocal,"r"); - fscanf(file.pFile,"%ld",&metaData.Nmeasures); - fscanf(file.pFile,"%ld",&metaData.Nvis); - fscanf(file.pFile,"%ld",&metaData.freq_per_chan); - fscanf(file.pFile,"%ld",&metaData.polarisations); - fscanf(file.pFile,"%ld",&metaData.Ntimes); - fscanf(file.pFile,"%lf",&metaData.dt); - fscanf(file.pFile,"%lf",&metaData.thours); - fscanf(file.pFile,"%ld",&metaData.baselines); - fscanf(file.pFile,"%lf",&metaData.uvmin); - fscanf(file.pFile,"%lf",&metaData.uvmax); - fscanf(file.pFile,"%lf",&metaData.wmin); - fscanf(file.pFile,"%lf",&metaData.wmax); - fclose(file.pFile); -} // Main Code int main(int argc, char * argv[]) @@ -66,7 +45,6 @@ int main(int argc, char * argv[]) int size; char datapath[900]; - char datapath_multi[NFILES][900]; char srank[4]; @@ -98,14 +76,20 @@ int main(int argc, char * argv[]) struct timespec begin, finish, begin0, begink, finishk; double elapsed; long nsectors; - /* GT get nymber of threads exit if not given */ - if(argc == 1) { - fprintf(stderr, "Usage: %s number_of_OMP_Threads \n", argv[0]); - exit(1); + + if(argc > 1) + { + strcpy(in.paramfile,argv[1]); + printf("parameter file = %s\n", in.paramfile); + init(); } - // Set the number of OpenMP threads - num_threads = atoi(argv[1]); - + else + { + fprintf(stderr, "Parameter file is not given\n"); + exit(1); + } + + if ( num_threads == 0 ) { fprintf(stderr, "Wrong parameter: %s\n\n", argv[1]); @@ -125,6 +109,7 @@ int main(int argc, char * argv[]) #ifdef USE_FFTW fftw_mpi_init(); #endif + MPI_Barrier(MPI_COMM_WORLD); #else rank = 0; size = 1; @@ -160,28 +145,10 @@ if(rank == 0){ start = clock(); // INPUT FILES (only the first ndatasets entries are used) - int ndatasets = 1; - strcpy(datapath_multi[0], "/u/nsakthivel/LOFAR/data/newgauss2noconj_t201806301100_SBL180.binMS/"); - - strcpy(datapath,datapath_multi[0]); + strcpy(datapath,datapath_multi[0]); // Read metadata fileName(datapath, in.metafile); readMetaData(filename); -/* file.pFile = fopen (filename,"r"); - fscanf(file.pFile,"%ld",&metaData.Nmeasures); - fscanf(file.pFile,"%ld",&metaData.Nvis); - fscanf(file.pFile,"%ld",&metaData.freq_per_chan); - fscanf(file.pFile,"%ld",&metaData.polarisations); - fscanf(file.pFile,"%ld",&metaData.Ntimes); - fscanf(file.pFile,"%lf",&metaData.dt); - fscanf(file.pFile,"%lf",&metaData.thours); - fscanf(file.pFile,"%ld",&metaData.baselines); - fscanf(file.pFile,"%lf",&metaData.uvmin); - fscanf(file.pFile,"%lf",&metaData.uvmax); - fscanf(file.pFile,"%lf",&metaData.wmin); - fscanf(file.pFile,"%lf",&metaData.wmax); - fclose(file.pFile); - */ // WATCH THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! int nsub = 1000; diff --git a/proto.h b/proto.h new file mode 100644 index 0000000..644727f --- /dev/null +++ b/proto.h @@ -0,0 +1,9 @@ +/* function declaration */ + + +/* init.c */ + +void init(); +void read_parameter_file(char *); +void fileName(char datapath[900], char file[30]); +void readMetaData(char fileLocal[1000]); -- GitLab