diff --git a/src/CalculateE.c b/src/CalculateE.c index f4b90baf..d72bde04 100644 --- a/src/CalculateE.c +++ b/src/CalculateE.c @@ -222,6 +222,7 @@ void MuellerMatrix(void) // redundant initialization to remove warnings mueller=ampl=NULL; + co=si=0; // Everything is done on ROOT only if (!IFROOT) return; diff --git a/src/Makefile b/src/Makefile index 4c7dd08f..31f6415b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -41,6 +41,11 @@ PROGSEQ = adda PROGMPI = adda_mpi # Targets implying compilation (empty one is always included) NONTRIVIAL = all seq mpi +# targets implying sequential or mpi compilation. This duplicates the functionality of the target +# designation, but is required for timely update of .lastopts +SEQGOALS = seq all +MPIGOALS = mpi all +LASTOPTSFILE = .lastopts #=================================================================================================== # !!! Start of control section. Flags and options here can be modified by user. However, the default @@ -67,11 +72,16 @@ ifneq ($(if $(MAKECMDGOALS),$(if $(filter $(NONTRIVIAL),$(MAKECMDGOALS)),1,),1), # separated by spaces, e.g. 'make OPTIONS="DEBUG FFT_TEMPERTON" ...'. OPTIONS that are uncommented # below are appended to the list specified elsewhere. # Full list of possible options is the following: -VALID_OPTS=DEBUG FFT_TEMPERTON PRECISE_TIMING NOT_USE_LOCK ONLY_LOCKFILE NO_FORTRAN \ +VALID_OPTS=DEBUG DEBUGFULL FFT_TEMPERTON PRECISE_TIMING NOT_USE_LOCK ONLY_LOCKFILE NO_FORTRAN \ OVERRIDE_STDC_TEST -# Debug mode (debug.h). +# Debug mode. By default, release configuration is used (no debug, no warnings, maximum +# optimization). DEBUG turns on producing debugging symbols (-g) and warnings and brings +# optimization down to O2 (this is required to produce all possible warnings by the compiler). +# DEBUGFULL turns off optimization completely (for more accurate debugging symbols) and turns on +# additional diagnostic messages in the source code (debug.c/h). #override OPTIONS += DEBUG +#override OPTIONS += DEBUGFULL # Temperton FFT (fft.h). #override OPTIONS += FFT_TEMPERTON @@ -111,9 +121,6 @@ COMPILER = gnu # command line of make (see explanation above for OPTIONS). override EXTRA_CFLAGS += -# --Warnings-- If uncommented, all warning are suppressed -RELEASE = on - # --FFTW3 paths-- # Specify path to headers and libraries of FFTW3. Some systems do not need them at all, some specify # special global variables (first or second 2 lines), on some - FFTW3 is installed under user @@ -177,9 +184,20 @@ $(foreach var,$(filter-out $(VALID_OPTS),$(OPTIONS)),\ $(warning The option '$(var)' is not recognized. Please check the spelling.)) $(info --- Compilation options: ---) -ifneq ($(filter DEBUG,$(OPTIONS)),) +ifneq ($(filter DEBUGFULL,$(OPTIONS)),) + $(info Full debug mode) + DBGLVL = 2 + CDEFS += -DDEBUGFULL + ifneq ($(filter DEBUG,$(OPTIONS)),) + $(warning DEBUG has no effect when DEBUGFULL is enabled) + endif +else ifneq ($(filter DEBUG,$(OPTIONS)),) $(info Debug mode) + DBGLVL = 1 CDEFS += -DDEBUG +else + $(info Release mode) + DBGLVL = 0 endif ifneq ($(filter FFT_TEMPERTON,$(OPTIONS)),) $(info Temperton FFT) @@ -241,22 +259,26 @@ ifeq ($(COMPILER),gnu) # You can add '-march=...' or 'mcpu=...' to COPT and FOPT in this section CC = gcc CF = g77 - COPT = -std=c99 -O3 -ffast-math -funroll-loops + CSTD = -std=c99 + CDBG = -g + COPT1 = -O2 + COPT2 = -O3 -ffast-math -funroll-loops + CWARN = -Wall -Wextra -pedantic -Wcast-qual -Wpointer-arith -Wwrite-strings -Wstrict-prototypes \ + -Wstrict-aliasing=1 -Wshadow -Wcast-align -Wnested-externs -Wcomment -Wno-unknown-pragmas FOPT = -O FLIBS += -lg2c - CWARN = -Wall -Wextra -pedantic -Wcast-qual -Wpointer-arith \ - -Wwrite-strings -Wstrict-prototypes -Wstrict-aliasing=1 -Wshadow \ - -Wcast-align -Wnested-externs -Wcomment \ - -Wno-unknown-pragmas else ifeq ($(COMPILER),intel) CC = icc CF = ifort - COPT = -std=c99 -O3 + CSTD = -std=c99 + CDBG = -g + COPT1 = -O2 + COPT2 = -O3 + CWARN = -Wall -Wcheck -diag-disable 981,1418,1419,1572,2259 -vec-report0 FOPT = -O3 FWARN += -vec-report0 FLIBS += -lifcore - CWARN = -Wall -Wcheck -diag-disable 981,1418,1419,1572,2259 -vec-report0 # if IPO is used, corresponding flags should be added to linker options: LDFLAGS += ... else ifeq ($(COMPILER),compaq) # This compiler was not tested since 2007. In particular, warning options may not fit exactly the @@ -266,7 +288,10 @@ else ifeq ($(COMPILER),compaq) # You can add option '-arch host' to COPT and FOPT in this section CC = cc CF = f77 - COPT = -fast + #CSTD = -std=c99 + CDBG = -g + COPT1 = -O2 + COPT2 = -fast CWARN = -w0 -msg_disable nestedcomment,unknownpragma,unreachcode else ifeq ($(COMPILER),ibm) # This compiler was not tested since 2008. In particular, it is not clear, whether and what FLIBS @@ -277,15 +302,20 @@ else ifeq ($(COMPILER),ibm) # Then use '-O3 -qarch=... -qtune=...' instead CC = xlc CF = xlf - COPT = -O3 -qcache=auto -qlanglvl=extc99 + CSTD = -qlanglvl=extc99 + CDBG = -g + COPT1 = -O2 + COPT2 = -O3 -qcache=auto # DFREDIRECT = 2>nul -qipa=level=2 -qhot DEPFLAG = -qmakedep=gcc -qsyntaxonly CWARN = -qsuppress=1506-224:1506-342:1500-036 else ifeq ($(COMPILER),hpux) CC = cc CF = f90 - FOPT = +O3 +DD64 - COPT = -AC99 +O3 +DD64 + CSTD = -AC99 + CDBG = -g + COPT1 = +O2 +DD64 + COPT2 = +O3 +DD64 CWARN = CFLAGS += -DNOT_USE_LOCK else ifeq ($(COMPILER),other) @@ -300,17 +330,35 @@ ifneq ($(strip $(FSOURCE)),) LDLIBS += $(FLIBS) endif # if 'release' turn off warningns -ifdef RELEASE - $(info All warnings are suppressed) +ifeq ($(DBGLVL),0) CWARN = -w LDFLAGS += -w + COPT = $(COPT2) + CDBG = +else ifeq ($(DBGLVL),1) + COPT = $(COPT1) +else ifeq ($(DBGLVL),2) + COPT = endif # Finalize option flags (almost) -CFLAGS += $(COPT) $(CWARN) +CFLAGS += $(CSTD) $(CDBG) $(COPT) $(CWARN) FFLAGS += $(FOPT) $(FWARN) FOBJECTS = $(FSOURCE:.f=.o) +ifneq ($(if $(MAKECMDGOALS),$(if $(filter $(SEQGOALS),$(MAKECMDGOALS)),1,),1),) + -include $(SEQ)/$(LASTOPTSFILE) + ifneq ($(strip $(filter-out $(LASTOPTS),$(OPTIONS)) $(filter-out $(OPTIONS),$(LASTOPTS))),) + $(shell rm -f $(SEQ)/$(LASTOPTSFILE)) + endif +endif +ifneq ($(if $(MAKECMDGOALS),$(if $(filter $(MPIGOALS),$(MAKECMDGOALS)),1,),1),) + -include $(MPI)/$(LASTOPTSFILE) + ifneq ($(strip $(filter-out $(LASTOPTS),$(OPTIONS)) $(filter-out $(OPTIONS),$(LASTOPTS))),) + $(shell rm -f $(MPI)/$(LASTOPTSFILE)) + endif +endif + $(info ----------------------------) #=================================================================================================== @@ -337,8 +385,8 @@ clean: cleanseq cleanmpi # Moving 'clean' commands to child makefiles is problematic due to included dependency files cleanseq: @echo "Removing sequential compiled files" - cd $(SEQ) && rm -f *.o *.d $(PROGSEQ) $(PROGSEQ).exe + cd $(SEQ) && rm -f *.o *.d $(LASTOPTSFILE) $(PROGSEQ) $(PROGSEQ).exe cleanmpi: @echo "Removing MPI compiled files" - cd $(MPI) && rm -f *.o *.d $(PROGMPI) $(PROGMPI).exe + cd $(MPI) && rm -f *.o *.d $(LASTOPTSFILE) $(PROGMPI) $(PROGMPI).exe diff --git a/src/Romberg.c b/src/Romberg.c index 89993578..8b2f1878 100644 --- a/src/Romberg.c +++ b/src/Romberg.c @@ -308,7 +308,7 @@ static double InnerRomberg(const int fixed,double * restrict res,const bool onep double err; // redundant initialization to remove warnings - abs_err=err=0; + abs_err=err=int_err=0; if (input[PHI].Grid_size==1 || onepoint) { // if only one point (really or assumed) int_err=(*func)(fixed,0,res); @@ -416,7 +416,7 @@ static double OuterRomberg(double * restrict res) double err; // redundant initialization to remove warnings - err=0; + err=int_err=0; if (input[THETA].Grid_size==1) { // if only one point N_eval=0; diff --git a/src/debug.c b/src/debug.c index 852bec88..e0d55b00 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,7 +1,7 @@ /* File: debug.c * $Author$ * $Date:: $ - * Descr: functions for printing debugging information when compiling with option -DDEBUG + * Descr: functions for printing debugging information when compiling with option -DDEBUGFULL * * Previous versions by "vesseur" * @@ -30,7 +30,7 @@ #include "io.h" #include "vars.h" -#ifdef DEBUG +#ifdef DEBUGFULL //============================================================ void DebugPrintf(ERR_LOC_DECL,const char * restrict fmt, ... ) @@ -66,4 +66,4 @@ void FieldPrint (doublecomplex * restrict x) fprintf(logfile,"E = "CFORM3V,x[i][RE],x[i][IM],x[i+1][RE],x[i+1][IM],x[i+2][RE],x[i+2][IM]); } -#endif // DEBUG +#endif // DEBUGFULL diff --git a/src/debug.h b/src/debug.h index 49c1ebb7..f3442c4d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -27,9 +27,9 @@ * and convenient tool to generate such messages is used. */ -//#define DEBUG // uncomment to degug +//#define DEBUGFULL // uncomment to degug -#ifdef DEBUG +#ifdef DEBUGFULL # include "function.h" // for function attributes # include "const.h" // for POS diff --git a/src/fft.c b/src/fft.c index e1fe817d..6ca927cf 100644 --- a/src/fft.c +++ b/src/fft.c @@ -43,14 +43,17 @@ */ # define PLAN_FFTW FFTW_MEASURE # define PLAN_FFTW_DM FFTW_ESTIMATE +# define ONLY_FOR_FFTW3 +#else +# define ONLY_FOR_FFTW3 ATT_UNUSED #endif // for transpose YZ #define TR_BLOCK 64 #ifdef FFT_TEMPERTON -#define ONLY_FOR_TEMPERTON +# define ONLY_FOR_TEMPERTON #else -#define ONLY_FOR_TEMPERTON ATT_UNUSED +# define ONLY_FOR_TEMPERTON ATT_UNUSED #endif // SEMI-GLOBAL VARIABLES @@ -422,7 +425,7 @@ int fftFit(int x,int divis) //============================================================= -static void fftInitBeforeD(const int lengthZ) +static void fftInitBeforeD(const int lengthZ ONLY_FOR_FFTW3) // initialize fft before initialization of Dmatrix { #ifdef FFTW3 diff --git a/src/make_particle.c b/src/make_particle.c index 26e0a08d..cc79925f 100644 --- a/src/make_particle.c +++ b/src/make_particle.c @@ -746,7 +746,7 @@ static double PlaceGranules(void) * small and large granules is largely independent (although there are some common parts, which * motivates against complete separation of them into two functions). */ - zerofit=gX2=gY2=gZ2=locgZ2=id0=id1=jd0=jd1=kd0=kd1=indZ=locgZ=gr_locgN=0; + zerofit=gX2=gY2=gZ2=locgZ2=id0=id1=jd0=jd1=kd0=kd1=indZ=locgZ=gr_locgN=sx=sy=sz=0; gdXh=gdYh=gdZh=0; ginX=ginY=ginZ=NULL; dom=NULL; diff --git a/src/mpi/Makefile b/src/mpi/Makefile index 80714a4b..0c289e20 100644 --- a/src/mpi/Makefile +++ b/src/mpi/Makefile @@ -77,19 +77,22 @@ $(PROGMPI): $(COBJECTS) $(FOBJECTS) @echo "Building $@" $(MPICC) -o $@ $(LDFLAGS) $(COBJECTS) $(FOBJECTS) $(LDLIBS) -# Everything is recompiled when any of makefiles is changed) -$(COBJECTS): %.o: %.c %.d $(MFILES) +$(COBJECTS): %.o: %.c %.d $(MPICC) -c $(CFLAGS) $(CDEFS) $< $(FOBJECTS): %.o: %.f $(MFILES) $(CF) -c $(FFLAGS) $< -# Dependencies are only generated for C sources; we assume that each Fortran file is completely -# independent or all of them are compiled at once +# Dependencies are only generated for C sources; we assume that each Fortran file is completely +# independent or all of them are compiled at once. +# Everything is recompiled when any of makefiles or .lastopts is changed -$(CDEPEND): %.d: %.c $(MFILES) - $(MPICC) $(DEPFLAG) $(CFLAGS) $(CDEFS) $< $(DFFLAG) $@.$$$$; \ +$(CDEPEND): %.d: %.c $(MFILES) $(LASTOPTSFILE) + $(CC) $(DEPFLAG) $(CFLAGS) $(CDEFS) $< $(DFFLAG) $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ +$(LASTOPTSFILE): + echo LASTOPTS = $(OPTIONS) > $@ + -include $(CDEPEND) diff --git a/src/param.c b/src/param.c index 928991fe..1f06bd4a 100644 --- a/src/param.c +++ b/src/param.c @@ -54,8 +54,10 @@ # endif # define LOCK_WAIT 1 // in seconds # define MAX_LOCK_WAIT_CYCLES 60 +# define ONLY_FOR_LOCK #else # define FILEHANDLE int +# define ONLY_FOR_LOCK ATT_UNUSED #endif // GLOBAL VARIABLES @@ -350,8 +352,8 @@ static struct opt_struct options[]={ {PAR(asym),"","Calculate the asymmetry vector. Implies '-Csca' and '-vec'",0,NULL}, {PAR(beam)," []","Sets a type of the incident beam. Four other float arguments are " "relevant for all beam types except 'plane'. These are the width and x, y, z coordinates of " - "the center of the beam respectively (all in um). The latter three can be omitted (then " - "beam center is located in the origin).\n" + "the center of the beam respectively in the laboratory reference fram (all in um). The " + "latter three can be omitted (then beam center is located in the origin).\n" "Default: plane",UNDEF,beam_opt}, {PAR(chp_dir),"","Sets directory for the checkpoint (both for saving and loading).\n" "Default: "FD_CHP_DIR,1,NULL}, @@ -1348,7 +1350,9 @@ PARSE_FUNC(V) printf(" (%d-bit)\n",bits); // extra build flags strncpy(build_opts, -#ifdef DEBUG +#ifdef DEBUGFULL + "DEBUGFULL, " +#elif defined(DEBUG) "DEBUG, " #endif #ifdef FFT_TEMPERTON @@ -1417,7 +1421,7 @@ PARSE_FUNC(yz) // end of parsing functions //============================================================= -static FILEHANDLE CreateLockFile(const char * restrict fname) +static FILEHANDLE CreateLockFile(const char * restrict fname ONLY_FOR_LOCK) // create lock file; works only if USE_LOCK is enabled { #ifdef USE_LOCK @@ -1475,7 +1479,7 @@ static FILEHANDLE CreateLockFile(const char * restrict fname) //============================================================ -static void RemoveLockFile(FILEHANDLE fd,const char * restrict fname) +static void RemoveLockFile(FILEHANDLE fd ONLY_FOR_LOCK,const char * restrict fname ONLY_FOR_LOCK) // closes and remove lock file; works only if USE_LOCK is enabled { #ifdef USE_LOCK diff --git a/src/seq/Makefile b/src/seq/Makefile index 3717de5f..648c8daf 100644 --- a/src/seq/Makefile +++ b/src/seq/Makefile @@ -34,19 +34,22 @@ $(PROGSEQ): $(COBJECTS) $(FOBJECTS) @echo "Building $@" $(CC) -o $@ $(LDFLAGS) $(COBJECTS) $(FOBJECTS) $(LDLIBS) -# Everything is recompiled when any of makefiles is changed -$(COBJECTS): %.o: %.c %.d $(MFILES) +$(COBJECTS): %.o: %.c %.d $(CC) -c $(CFLAGS) $(CDEFS) $< $(FOBJECTS): %.o: %.f $(MFILES) $(CF) -c $(FFLAGS) $< # Dependencies are only generated for C sources; we assume that each Fortran file is completely -# independent or all of them are compiled at once +# independent or all of them are compiled at once. +# Everything is recompiled when any of makefiles or .lastopts is changed -$(CDEPEND): %.d: %.c $(MFILES) +$(CDEPEND): %.d: %.c $(MFILES) $(LASTOPTSFILE) $(CC) $(DEPFLAG) $(CFLAGS) $(CDEFS) $< $(DFFLAG) $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ +$(LASTOPTSFILE): + echo LASTOPTS = $(OPTIONS) > $@ + -include $(CDEPEND)