Skip to content

Commit

Permalink
Merge remote-tracking branch 'class_public/master' into gravity_dream
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliobellini committed Apr 23, 2024
2 parents fa55c07 + ae99bce commit a283b74
Show file tree
Hide file tree
Showing 20 changed files with 1,237 additions and 1,229 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ python/*.pyc
python/build/i
ini_files
.vscode/
python/classy.cpp
*.pyc
python/build/
*.dSYM
Expand Down
42 changes: 20 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ WRKDIR = $(MDIR)/build

vpath %.c source:tools:main:test
vpath %.o build
vpath %.opp build
vpath .base build

########################################################
Expand All @@ -21,6 +22,7 @@ vpath .base build
CC = gcc
#CC = icc
#CC = pgcc
CPP = g++ --std=c++11 -fpermissive -Wno-write-strings

# your tool for creating static libraries:
AR = ar rv
Expand All @@ -38,7 +40,7 @@ OPTFLAG = -O3
#OPTFLAG = -fast

# your openmp flag (comment for compiling without openmp)
OMPFLAG = -fopenmp
OMPFLAG = -pthread #-fopenmp
#OMPFLAG = -mp -mp=nonuma -mp=allcores -g
#OMPFLAG = -openmp

Expand All @@ -61,7 +63,8 @@ HI_CLASS_PATH = gravity_smg
########################################################

# pass current working directory to the code
CCFLAG += -D__CLASSDIR__='"$(MDIR)"'
CLASSDIR ?= $(MDIR)
CCFLAG += -D__CLASSDIR__='"$(CLASSDIR)"'

# where to find include files *.h
INCLUDES = -I../include
Expand Down Expand Up @@ -104,9 +107,12 @@ endif
%.o: %.c .base $(HEADERFILES)
cd $(WRKDIR);$(CC) $(OPTFLAG) $(OMPFLAG) $(CCFLAG) $(INCLUDES) -c ../$< -o $*.o

TOOLS = growTable.o dei_rkck.o sparse.o evolver_rkck.o evolver_ndf15.o arrays.o parser.o quadrature.o hyperspherical.o common.o rootfinder.o trigonometric_integrals.o
%.opp: %.c .base $(HEADERFILES)
cd $(WRKDIR);$(CPP) $(OPTFLAG) $(OMPFLAG) $(CCFLAG) $(INCLUDES) -c ../$< -o $*.opp

SOURCE = input.o background.o thermodynamics.o perturbations.o primordial.o fourier.o transfer.o harmonic.o lensing.o distortions.o
TOOLS = growTable.o dei_rkck.o sparse.o evolver_rkck.o evolver_ndf15.o arrays.opp parser.o quadrature.o hyperspherical.opp common.o rootfinder.o trigonometric_integrals.o

SOURCE = input.o background.o thermodynamics.o perturbations.opp primordial.opp fourier.o transfer.opp harmonic.opp lensing.opp distortions.o

INPUT = input.o

Expand Down Expand Up @@ -169,51 +175,43 @@ libclass.a: $(TOOLS) $(SOURCE) $(EXTERNAL)
$(AR) $@ $(addprefix build/, $(TOOLS) $(SOURCE) $(EXTERNAL))

class: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(CLASS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o class $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o class $(addprefix build/,$(notdir $^)) -lm

test_loops: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_loops_omp: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS_OMP)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_harmonic: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_HARMONIC)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_transfer: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_TRANSFER)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_fourier: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_FOURIER)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_perturbations: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_PERTURBATIONS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_thermodynamics: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_THERMODYNAMICS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_background: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_BACKGROUND)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm

test_hyperspherical: $(TOOLS) $(TEST_HYPERSPHERICAL)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o test_hyperspherical $(addprefix build/,$(notdir $^)) -lm


tar: $(C_ALL) $(C_TEST) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)
tar czvf class.tar.gz $(C_ALL) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)

classy: libclass.a python/classy.pyx python/cclassy.pxd
ifdef OMPFLAG
cp python/setup.py python/autosetup.py
else
grep -v "lgomp" python/setup.py > python/autosetup.py
endif
cd python; export CC=$(CC); $(PYTHON) autosetup.py install || $(PYTHON) autosetup.py install --user
rm python/autosetup.py
cd python; export CC=$(CC); $(PYTHON) setup.py install || $(PYTHON) setup.py install --user

clean: .base
rm -rf $(WRKDIR);
rm -f libclass.a
rm -f $(MDIR)/python/classy.c
rm -rf $(MDIR)/python/build
rm -f python/autosetup.py
89 changes: 59 additions & 30 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef __COMMON__
#define __COMMON__

#define _VERSION_ "v3.2.2"
#define _VERSION_ "v3.2.3"

/* @cond INCLUDE_WITH_DOXYGEN */

Expand Down Expand Up @@ -79,22 +79,37 @@ typedef char FileName[_FILENAMESIZE_];

/* @endcond */

/* needed because of weird openmp bug on macosx lion... */

void class_protect_sprintf(char* dest, char* tpl,...);
void class_protect_fprintf(FILE* dest, char* tpl,...);
void* class_protect_memcpy(void* dest, void* from, size_t sz);

/* some general functions */

int get_number_of_titles(char * titlestring);
int file_exists(const char *fname);
int compare_doubles(const void * a,
const void * b);
int string_begins_with(char* thestring, char beginchar);
#ifdef __cplusplus
extern "C" {
#endif
/* needed because of weird openmp bug on macosx lion... */
void class_protect_sprintf(char* dest, char* tpl, ...);
void class_protect_fprintf(FILE* dest, char* tpl, ...);
void* class_protect_memcpy(void* dest, void* from, size_t sz);

/* some general functions */
int get_number_of_titles(char * titlestring);
int file_exists(const char *fname);
int compare_doubles(const void * a,
const void * b);
int string_begins_with(char* thestring, char beginchar);
#ifdef __cplusplus
}
#endif

/* general CLASS macros */

//This macro receives additional 'do {' and '} while(0)' to safeguard
//in single-line if else clauses without '{' and '}'
//Also, careful: Since sprintf(NULL,0,x) returns the size of characters
//that are inside of the string x, then the buffer needs to be
//actually one character longer to hold also the null character '\0'
#define class_sprintf(string, format...) do { \
int _buffer_size_sprintf = snprintf(NULL, 0, format); \
snprintf(string, _buffer_size_sprintf+1, format); \
} while (0)

#define class_build_error_string(dest,tmpl,...) { \
ErrorMsg FMsg; \
class_protect_sprintf(FMsg,tmpl,__VA_ARGS__); \
Expand Down Expand Up @@ -128,15 +143,15 @@ int string_begins_with(char* thestring, char beginchar);
#define class_call(function, error_message_from_function, error_message_output) \
class_call_except(function, error_message_from_function,error_message_output,)

/* same in parallel region */
#define class_call_parallel(function, error_message_from_function, error_message_output) { \
if (abort == _FALSE_) { \
/* same in parallel region -- UNUSED NOW */
/*#define class_call_parallel(function, error_message_from_function, error_message_output) { \
if (abort_now == _FALSE_) { \
if (function == _FAILURE_) { \
class_call_message(error_message_output,#function,error_message_from_function); \
abort=_TRUE_; \
abort_now=_TRUE_; \
} \
} \
}
}*/



Expand All @@ -147,7 +162,7 @@ int string_begins_with(char* thestring, char beginchar);

/* macro for allocating memory and returning error if it failed */
#define class_alloc(pointer, size, error_message_output) { \
pointer=malloc(size); \
pointer=(__typeof__(pointer))malloc(size); \
if (pointer == NULL) { \
int size_int; \
size_int = size; \
Expand All @@ -156,23 +171,24 @@ int string_begins_with(char* thestring, char beginchar);
} \
}

/* same inside parallel structure */

/* same inside parallel structure -- UNUSED NOW
#define class_alloc_parallel(pointer, size, error_message_output) { \
pointer=NULL; \
if (abort == _FALSE_) { \
pointer=malloc(size); \
if (abort_now == _FALSE_) { \
pointer=(__typeof__(pointer))malloc(size); \
if (pointer == NULL) { \
int size_int; \
size_int = size; \
class_alloc_message(error_message_output,#pointer, size_int); \
abort=_TRUE_; \
abort_now=_TRUE_; \
} \
} \
}
}*/

/* macro for allocating memory, initializing it with zeros/ and returning error if it failed */
#define class_calloc(pointer, init,size, error_message_output) { \
pointer=calloc(init,size); \
pointer=(__typeof__(pointer))calloc(init,size); \
if (pointer == NULL) { \
int size_int; \
size_int = size; \
Expand All @@ -182,8 +198,8 @@ int string_begins_with(char* thestring, char beginchar);
}

/* macro for re-allocating memory, returning error if it failed */
#define class_realloc(pointer, newname, size, error_message_output) { \
pointer=realloc(newname,size); \
#define class_realloc(pointer, size, error_message_output) { \
pointer=(__typeof__(pointer))realloc(pointer,size); \
if (pointer == NULL) { \
int size_int; \
size_int = size; \
Expand Down Expand Up @@ -218,14 +234,15 @@ int string_begins_with(char* thestring, char beginchar);
} \
}

/* UNUSED NOW
#define class_test_parallel(condition, error_message_output, args...) { \
if (abort == _FALSE_) { \
if (abort_now == _FALSE_) { \
if (condition) { \
class_test_message(error_message_output,#condition, args); \
abort=_TRUE_; \
abort_now=_TRUE_; \
} \
} \
}
}*/

/* macro for returning error message;
args is a variable list of optional arguments, e.g.: args="x=%d",x
Expand Down Expand Up @@ -328,6 +345,17 @@ int string_begins_with(char* thestring, char beginchar);
#define class_print_species(name,type) \
printf("-> %-30s Omega = %-15g , omega = %-15g\n",name,pba->Omega0_##type,pba->Omega0_##type*pba->h*pba->h);

//Generic evolver prototype
#define EVOLVER_PROTOTYPE \
int (*)(double, double *, double *, void *, ErrorMsg), \
double, double, double *, int *, \
int, void *, double, double, \
int (*)(double, void *, double *, ErrorMsg), \
double, double *, int, \
int (*)(double, double *, double *, int, void *, ErrorMsg), \
int (*)(double, double *, double *, void *, ErrorMsg), \
ErrorMsg

/* Forward-Declare the structs of CLASS */
struct background;
struct thermodynamics;
Expand Down Expand Up @@ -404,4 +432,5 @@ struct precision

};


#endif
4 changes: 2 additions & 2 deletions include/evolver_rkck.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __EVO__
#define __EVO__
#ifndef __EVO_RK__
#define __EVO_RK__

#include "dei_rkck.h"

Expand Down
Loading

0 comments on commit a283b74

Please sign in to comment.