-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oasis3-mct: support building with the Intel compiler
- Loading branch information
Showing
1 changed file
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,19 @@ class Oasis3Mct(MakefilePackage): | |
version("spack-build", branch="spack-build") | ||
|
||
depends_on("[email protected]:") | ||
# TODO: Should we depend on virtual package "mpi" instead? | ||
depends_on("[email protected]:") | ||
# Depend on virtual package "mpi". | ||
depends_on("mpi") | ||
|
||
phases = ["build", "install"] | ||
phases = ["edit", "build", "install"] | ||
|
||
# TODO: Implement a determine_version(cls, exe) | ||
|
||
__builddir = "compile_oa3-mct" | ||
__incdir = join_path(__builddir, "build", "lib") | ||
__libdir = join_path(__builddir, "lib") | ||
__pkgdir = join_path(__libdir, "pkgconfig") | ||
__makefiledir = join_path("util", "make_dir") | ||
__makeinc = join_path(__makefiledir, "make.inc") | ||
__libs = {"mct": {}, "mpeu": {}, "psmile.MPI1": {}, "scrip": {}} | ||
|
||
# doc/oasis3mct_UserGuide.pdf: | ||
|
@@ -203,22 +205,117 @@ def libs(self): | |
libraries, root=self.prefix, shared=False, recursive=True | ||
) | ||
|
||
# Following pattern: | ||
# https://spack-tutorial.readthedocs.io/en/latest/tutorial_buildsystems.html | ||
def edit(self, spec, prefix): | ||
SRCDIR = self.stage.source_path | ||
makeinc_path = join_path(SRCDIR, self.__makeinc) | ||
config = {} | ||
|
||
CFLAGS = "" | ||
|
||
config["pre"] = f""" | ||
# CHAN : communication technique used in OASIS3 (MPI1/MPI2/NONE) | ||
CHAN = MPI1 | ||
# | ||
# Paths for libraries, object files and binaries | ||
# | ||
# COUPLE : path for oasis3-mct main directory | ||
COUPLE={SRCDIR} | ||
# ARCHDIR : directory created when compiling | ||
ARCHDIR= $(COUPLE)/compile_oa3-mct | ||
AR = ar | ||
ARFLAGS = -rvD | ||
CFLAGS = {CFLAGS} | ||
F = $(F90) | ||
f90 = $(F90) | ||
f = $(F90) | ||
""" | ||
|
||
config["gcc"] = f""" | ||
# Compiling and other commands | ||
MAKE = make | ||
F90 = mpif90 -Wall -fallow-argument-mismatch | ||
CC = gcc | ||
LD = mpif90 | ||
MCT_FCFLAGS = | ||
# | ||
# CPP keys and compiler options | ||
# | ||
CPPDEF = -Duse_netCDF -Duse_comm_$(CHAN) -D__VERBOSE -DTREAT_OVERLAY | ||
F90FLAGS_1 = | ||
""" | ||
|
||
# module load intel-compiler/2019.5.281 | ||
config["intel"] = f""" | ||
# Compiling and other commands | ||
MAKE = /usr/bin/make | ||
F90 = mpifort | ||
CC = mpicc | ||
LD = $(F90) | ||
# -g is necessary in F90FLAGS and LDFLAGS for pgf90 versions lower than 6.1 | ||
# For compiling in double precision, put -r8 | ||
# For compiling in single precision, remove -r8 and add -Duse_realtype_single | ||
# Causes non-deterministic builds: -traceback -debug all | ||
NCI_INTEL_FLAGS = -r8 -i4 -traceback -fpe0 -convert big_endian -fno-alias -ip -check noarg_temp_created | ||
NCI_REPRO_FLAGS = -fp-model precise -fp-model source -align all | ||
ifeq ($(DEBUG), yes) | ||
NCI_DEBUG_FLAGS = -g3 -O0 -fpe0 -no-vec -debug all -check all -no-vec | ||
F90FLAGS_1 = $(NCI_INTEL_FLAGS) $(NCI_REPRO_FLAGS) $(NCI_DEBUG_FLAGS) | ||
CPPDEF = -Duse_netCDF -Duse_comm_$(CHAN) -DTREAT_OVERLAY -DDEBUG -D__VERBOSE | ||
MCT_FCFLAGS = $(NCI_REPRO_FLAGS) $(NCI_DEBUG_FLAGS) -ip | ||
else | ||
NCI_OPTIM_FLAGS = -g3 -O2 -axCORE-AVX2 -debug all -check none -qopt-report=5 -qopt-report-annotate | ||
F90FLAGS_1 = $(NCI_INTEL_FLAGS) $(NCI_REPRO_FLAGS) $(NCI_OPTIM_FLAGS) | ||
CPPDEF = -Duse_netCDF -Duse_comm_$(CHAN) -DTREAT_OVERLAY | ||
MCT_FCFLAGS = $(NCI_REPRO_FLAGS) $(NCI_OPTIM_FLAGS) -ip | ||
endif | ||
""" | ||
|
||
config["post"] = f""" | ||
f90FLAGS_1 = $(F90FLAGS_1) | ||
FFLAGS_1 = $(F90FLAGS_1) | ||
fFLAGS_1 = $(F90FLAGS_1) | ||
CCFLAGS_1 = | ||
LDFLAGS = | ||
# | ||
################### | ||
# | ||
# Additional definitions that should not be changed | ||
# | ||
FLIBS = "" | ||
# BINDIR : directory for executables | ||
BINDIR = $(ARCHDIR)/bin | ||
# LIBBUILD : contains a directory for each library | ||
LIBBUILD = $(ARCHDIR)/build/lib | ||
# INCPSMILE : includes all *o and *mod for each library | ||
INCPSMILE = -I$(LIBBUILD)/psmile.$(CHAN) -I$(LIBBUILD)/mct | ||
F90FLAGS = $(F90FLAGS_1) $(INCPSMILE) $(CPPDEF) | ||
f90FLAGS = $(f90FLAGS_1) $(INCPSMILE) $(CPPDEF) | ||
FFLAGS = $(FFLAGS_1) $(INCPSMILE) $(CPPDEF) | ||
fFLAGS = $(fFLAGS_1) $(INCPSMILE) $(CPPDEF) | ||
CCFLAGS = $(CCFLAGS_1) $(INCPSMILE) $(CPPDEF) | ||
# | ||
############################################################################# | ||
""" | ||
|
||
with open(makeinc_path, "w") as makeinc: | ||
makeinc.write( | ||
config["pre"] | ||
+ config[self.compiler.name] | ||
+ config["post"] | ||
) | ||
|
||
def build(self, spec, prefix): | ||
# See doc/oasis3mct_UserGuide.pdf: | ||
# | ||
# compiles all OASIS3-MCT libraries mct, scrip and psmile: | ||
# make -f TopMakefileOasis3 | ||
srcdir = os.getcwd() | ||
print(f"cwd: {srcdir}") | ||
makefile_dir = join_path(srcdir, "util", "make_dir") | ||
with working_dir(makefile_dir): | ||
with open("make.inc", "w") as makeinc: | ||
makespack = join_path(makefile_dir, "make.spack") | ||
makeinc.write(f"include {makespack}") | ||
|
||
with working_dir(join_path(self.stage.source_path, self.__makefiledir)): | ||
build = Executable("make") | ||
build.add_default_env("OASIS_HOME", srcdir) | ||
build("-f", "TopMakefileOasis3", "F90=mpif90", "CC=gcc") | ||
build("-f", "TopMakefileOasis3") | ||
|
||
# Upstream is missing a pkgconfig files, so we'll create them. | ||
self.__create_pkgconfig(spec, prefix) | ||
|