Skip to content

Commit

Permalink
Two major changes to makefiles:
Browse files Browse the repository at this point in the history
- Debug level can be now one of three levels:
  1) default one (formerly release) - no debug symbols, no warnings, maximum optimization.
  2) DEBUG - turns on producing debug symbols (-g) and warnings and brings optimization down to O2 (to produce all possible warnings by the compiler).
  3) DEBUGFULL turns off optimization completely (for more accurate debugging symbols) and turns on additional diagnostic messages in the source code (formerly DEBUG).
Debugging seems to be working in a bundle Eclipse-MinGW-gdb. Fixes issue 65.

- Compilation options are now saved to .lastopts. If new options are different from the last ones (as unordered sets of words), then complete recompilation is performed. This allows safe and efficient passing compilation options to makefiles through the command line.

Other changes in the source files: 
- DEBUG changed to DEBUGFULL
- several minor edits to remove 'uninitialized' and 'unused' warnings
  • Loading branch information
myurkin committed Sep 6, 2010
1 parent ae0d36f commit e92e8eb
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/CalculateE.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
92 changes: 70 additions & 22 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 ----------------------------)

#===================================================================================================
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/Romberg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/debug.c
Original file line number Diff line number Diff line change
@@ -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"
*
Expand Down Expand Up @@ -30,7 +30,7 @@
#include "io.h"
#include "vars.h"

#ifdef DEBUG
#ifdef DEBUGFULL
//============================================================

void DebugPrintf(ERR_LOC_DECL,const char * restrict fmt, ... )
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/fft.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/make_particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions src/mpi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 9 additions & 5 deletions src/param.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -350,8 +352,8 @@ static struct opt_struct options[]={
{PAR(asym),"","Calculate the asymmetry vector. Implies '-Csca' and '-vec'",0,NULL},
{PAR(beam),"<type> [<args>]","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),"<dirname>","Sets directory for the checkpoint (both for saving and loading).\n"
"Default: "FD_CHP_DIR,1,NULL},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/seq/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e92e8eb

Please sign in to comment.