From 47d761347c67b7b33a75b3d9e47eb42533eac205 Mon Sep 17 00:00:00 2001 From: Giuliano Taffoni <giuliano.taffoni@inaf.it> Date: Tue, 5 Oct 2021 17:22:18 +0200 Subject: [PATCH] New Makefile structure and python plots of the results --- .gitignore | 2 ++ Build/Makefile.Magellanus | 32 ++++++++++++++++++++++ Build/Makefile.Marconi | 20 ++++++++++++++ Build/Makefile.systype | 24 +++++++++++++++++ Makefile | 57 ++++++++++++++++++++++----------------- scripts/gridfftbin.m | 4 +-- scripts/plotgrid.py | 27 +++++++++++++++++++ 7 files changed, 140 insertions(+), 26 deletions(-) create mode 100644 Build/Makefile.Magellanus create mode 100644 Build/Makefile.Marconi create mode 100644 Build/Makefile.systype create mode 100644 scripts/plotgrid.py diff --git a/.gitignore b/.gitignore index 797747a..77346fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.o +.DS_Store +sync.sh phase_correction.c w-stacking.c w-stackingCfftw diff --git a/Build/Makefile.Magellanus b/Build/Makefile.Magellanus new file mode 100644 index 0000000..c440365 --- /dev/null +++ b/Build/Makefile.Magellanus @@ -0,0 +1,32 @@ +CC = gcc-10 +CXX = g++-10 + +MPICC = mpicc +MPIC++ = mpiCC + +OPTIMIZE = -O3 +#-ffast-math -fopt-info-all-omp -fcf-protection=none -fno-stack-protector -foffload=nvptx-none + + +GSL_INCL = -I/home/taffoni/sw/include #-I/opt/cluster/openmpi/3.1.3/gnu/8.2.0/include +GSL_LIBS = -L/home/taffoni/sw/lib #-L/opt/cluster/openmpi/3.1.3/gnu/8.2.0/lib -lmpi + +FFTW_INCL= -I/home/taffoni/sw/include +FFTW_LIB= -L/home/taffoni/sw/lib -lfftw3_mpi -lfftw3 + +MPI_LIB = +MPI_INCL= +HDF5_INCL = +HDF5_LIB = + +OMP = -fopenmp + +NVCC = nvcc +NVFLAGS = -arch=sm_70 -Xcompiler -std=c++11 +NVLIB = -L/home/taffoni/sw/Linux_x86_64/21.5/cuda/11.3/lib64/ -lcudart -lcuda + +CFLAGS += $(OPTIMIZE) +CFLAGS += -I. +CFLAGS += -I/home/taffoni/sw/Linux_x86_64/21.5/comm_libs/mpi/include +CFLAGS += $(FFTW_INCL) $(GSL_INCL) +CFLAGS += $(FFTW_LIB) -lm diff --git a/Build/Makefile.Marconi b/Build/Makefile.Marconi new file mode 100644 index 0000000..4fb0d03 --- /dev/null +++ b/Build/Makefile.Marconi @@ -0,0 +1,20 @@ +CC = gcc +CXX = g++ + +MPICC = mpicc +MPIC++ = mpiCC + + +CFLAGS += -O3 -mcpu=native +CFLAGS += -I. +FFTW_INCL= -I/home/taffoni/sw/include +FFTW_LIB= -L/home/taffoni/sw/lib + +LIBS = $(FFTW_LIB) -lfftw3_mpi -lfftw3 -lm + +NVCC = nvcc +NVFLAGS = -arch=sm_70 -Xcompiler -mno-float128 -std=c++11 +NVLIB = -L/cineca/prod/opt/compilers/cuda/10.1/none/lib64/ -lcudart -lcuda + + +CFLAGS += -O3 -mtune=native diff --git a/Build/Makefile.systype b/Build/Makefile.systype new file mode 100644 index 0000000..0492232 --- /dev/null +++ b/Build/Makefile.systype @@ -0,0 +1,24 @@ +CC = gcc-10 +CXX = g++-10 + +MPICC = mpicc +MPIC++ = mpiCC + +OPTIMIZE = + + +GSL_INCL = +GSL_LIB = + +FFTW_INCL= +FFTW_LIB= + +NVCC = +NVFLAGS = +NVLIB = + +CFLAGS += + +MPICHLIB = +HDF5INCL = +HDF5LIB = diff --git a/Makefile b/Makefile index 80ba945..b066735 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,30 @@ # comment/uncomment the various options depending hoe you want to build the program +# Set default values for compiler options if no systype options are given or found +CC = mpiCC +CXX = mpiCC +OPTIMIZE = -std=c++11 -Wall -g -O2 +MPICHLIB = -lmpich +SWITCHES = + +ifdef SYSTYPE +SYSTYPE := $(SYSTYPE) +include Build/Makefile.$(SYSTYPE) +else +include Build/Makefile.systype +endif + + + + + # create MPI code OPT += -DUSE_MPI + # use FFTW (it can be switched on ONLY if MPI is active) -OPT += -DUSE_FFTW +ifeq (USE_MPI,$(findstring USE_MPI,$(OPT))) + OPT += -DUSE_FFTW +endif + # perform one-side communication (suggested) instead of reduce (only if MPI is active) OPT += -DONE_SIDE # write the full 3D cube of gridded visibilities and its FFT transform @@ -12,23 +34,6 @@ OPT += -DWRITE_IMAGE # perform w-stacking phase correction # OPT += PHASE_ON -CC = gcc -CXX = g++ -ifeq (USE_MPI,$(findstring USE_MPI,$(OPT))) - CC = mpicc - CXX = mpiCC -endif - -OMP = -fopenmp -#OMP = - -CFLAGS += -O3 -mcpu=native -CFLAGS += -I. -LIBS = -L$(FFTW_LIB) -lfftw3_mpi -lfftw3 -lm - -NVCC = nvcc -NVFLAGS = -arch=sm_70 -Xcompiler -mno-float128 -std=c++11 -NVLIB = -L/cineca/prod/opt/compilers/cuda/10.1/none/lib64/ -lcudart -lcuda DEPS = w-stacking.h w-stacking-fftw.c w-stacking.cu phase_correction.cu COBJ = w-stacking.o w-stacking-fftw.o phase_correction.o @@ -39,27 +44,31 @@ w-stacking.c: w-stacking.cu phase_correction.c: phase_correction.cu cp phase_correction.cu phase_correction.c +ifeq (USE_MPI,$(findstring USE_MPI,$(OPT))) +%.o: %.c $(DEPS) + $(MPICC) -c -o $@ $< $(CFLAGS) $(OPT) +else %.o: %.c $(DEPS) $(CC) $(OMP) -c -o $@ $< $(CFLAGS) $(OPT) +endif serial: $(COBJ) - $(CC) $(OMP) -o w-stackingCfftw_serial $(CFLAGS) $^ -lm + $(CC) -o w-stackingCfftw_serial $(CFLAGS) $^ -lm serial_cuda: $(NVCC) $(NVFLAGS) -c w-stacking.cu phase_correction.cu $(NVLIB) $(CC) $(CFLAGS) $(OPT) -c w-stacking-fftw.c $(CXX) $(CFLAGS) $(OPT) -o w-stackingfftw_serial w-stacking-fftw.o w-stacking.o phase_correction.o $(NVLIB) -lm -mpi: $(COBJ) - $(CC) $(OMP) -o w-stackingCfftw $(CFLAGS) $^ $(LIBS) +mpi: $(COBJ) + $(MPICC) -o w-stackingCfftw $^ $(CFLAGS) mpi_cuda: $(NVCC) $(NVFLAGS) -c w-stacking.cu phase_correction.cu $(NVLIB) - $(CC) $(CFLAGS) $(OPT) -c w-stacking-fftw.c - $(CXX) $(CFLAGS) $(OPT) -o w-stackingfftw w-stacking-fftw.o w-stacking.o phase_correction.o $(NVLIB) $(LIBS) -lm + $(MPICC) $(CFLAGS) $(OPT) -c w-stacking-fftw.c + $(MPIC++) $(OPT) -o w-stackingfftw w-stacking-fftw.o w-stacking.o phase_correction.o $(NVLIB) $(CFLAGS) clean: rm *.o rm w-stacking.c rm phase_correction.c - diff --git a/scripts/gridfftbin.m b/scripts/gridfftbin.m index d948638..b4bc237 100644 --- a/scripts/gridfftbin.m +++ b/scripts/gridfftbin.m @@ -10,7 +10,8 @@ nplanes = 1; % id = '4'; suffix = ''; id = ''; -datadir = "/Users/cgheller/Work/Gridding/data/"; +d +atadir = "/Users/cgheller/Work/Gridding/data/"; filename1 = strcat(datadir,"fft_real",suffix,id,'.bin'); filename2 = strcat(datadir,"fft_img",suffix,id,'.bin'); s = dir(filename1); @@ -52,4 +53,3 @@ xlabel('cell'); ylabel('cell'); pngimage = strcat(datadir,'fft-2freq',suffix,id,'.png'); saveas(gcf,pngimage); - diff --git a/scripts/plotgrid.py b/scripts/plotgrid.py new file mode 100644 index 0000000..2cf1bab --- /dev/null +++ b/scripts/plotgrid.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +import numpy as np +import matplotlib.pyplot as plt +filename1 = "fft_real.bin" +filename2 = "fft_img.bin" +nplanes = 1 + +with open(filename1, 'rb') as f1: + vreal = np.fromfile(f1, dtype=np.float64) +with open(filename2, 'rb') as f2: + vimg = np.fromfile(f2, dtype=np.float64) + +xaxis = int(np.sqrt(vreal.size)) +yaxes = xaxis +residual = np.vectorize(complex)(vreal, vimg) + +cumul2d = residual.reshape((xaxis,yaxes,nplanes), order='F') +for i in range(nplanes): + gridded = np.squeeze(cumul2d[:,:,i]) + ax = plt.subplot() + img = ax.imshow(np.abs(np.fft.fftshift(gridded)), aspect='auto', interpolation='none', origin='lower') + ax.set_xlabel('cell') + ax.set_ylabel('cell') + cbar = plt.colorbar(img) + cbar.set_label('norm(FFT)',size=18) + figname='grid_image_' + str(i) + '.png' + plt.savefig(figname) -- GitLab