Skip to content

Commit

Permalink
Add configure and amrexpr.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Sep 21, 2024
1 parent bb83d8b commit b5b168d
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 150 deletions.
25 changes: 25 additions & 0 deletions GNUmakefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

AMREXPR_HOME := $(shell pwd)

Pdirs := .
include $(AMREXPR_HOME)/Tools/GNUMake/Make.defs

ifeq ($(USE_CUDA),TRUE)
ALLOW_DIFFERENT_COMP = TRUE
endif

include $(AMREXPR_HOME)/Src/Make.package

all: $(amrexprlib)
@echo SUCCESS

.PHONY: distclean install uninstall

distclean: realclean
$(SILENT) $(RM) GNUmakefile

install: install_lib install_headers install_pkg_config

uninstall: uninstall_lib uninstall_headers uninstall_pkg_config distclean

include $(AMREXPR_HOME)/Tools/GNUMake/Make.rules
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ follows the convention of the C and C++ programming languages. Here is an
example of using the parser.

```c++
#include "amrexpr_Parser.H"
#include "amrexpr.hpp"

Parser parser("if(x>a and x<b, sin(x)*cos(y)*if(z<0, 1.0, exp(-z)), .3*c**2)");
parser.setConstant(a, ...);
Expand Down
1 change: 1 addition & 0 deletions Src/Make.package
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CEXE_headers += amrexpr.hpp

CEXE_headers += amrexpr_Arena.H \
amrexpr_BLassert.H \
Expand Down
3 changes: 3 additions & 0 deletions Src/amrexpr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "amrexpr_Parser.H"
2 changes: 1 addition & 1 deletion Tests/GPU/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "amrexpr_Parser.H"
#include "amrexpr.hpp"
#include <cmath>
#include <iostream>

Expand Down
2 changes: 1 addition & 1 deletion Tests/Parser/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "amrexpr_Parser.H"
#include "amrexpr.hpp"
#include <array>
#include <cstdlib>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Parser2/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "amrexpr_Parser.H"
#include "amrexpr.hpp"
#include <cstdlib>
#include <fstream>
#include <iostream>
Expand Down
5 changes: 5 additions & 0 deletions Tools/GNUMake/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ ALLOW_DIFFERENT_COMP ?= TRUE
SKIP_LINKING ?= FALSE
USE_COMPILE_PIC ?= FALSE

AMREXPR_GIT_VERSION := $(shell cd $(AMREXPR_HOME); git describe --abbrev=12 --dirty --always --tags)
ifndef AMREXPR_GIT_VERSION
AMREXPR_GIT_VERSION := Unknown
endif

MKCONFIG = $(AMREXPR_HOME)/Tools/libamrexpr/mkconfig.py
MKPKGCONFIG = $(AMREXPR_HOME)/Tools/libamrexpr/mkpkgconfig.py

Expand Down
2 changes: 1 addition & 1 deletion Tools/GNUMake/Make.rules
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ TAGS: $(allSources)

FORCE:

.PHONY: all cleanconfig clean realclean file_locations tags TAGS install_lib install_headers install_fortran_modules install_pkg_config
.PHONY: all cleanconfig clean realclean file_locations tags TAGS install_lib install_headers install_pkg_config

#
# Rules for objects.
Expand Down
122 changes: 15 additions & 107 deletions Tools/libamrexpr/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,8 @@ def configure(argv):
argv[0] = "configure" # So the help message print it
parser = argparse.ArgumentParser()
parser.add_argument("--prefix",
help="Install libamrexpr, headers and Fortran modules in PREFIX directory [default=tmp_install_dir]",
help="Install libamrexpr and headers in PREFIX directory [default=tmp_install_dir]",
default="tmp_install_dir")
parser.add_argument("--dim",
help="Dimension [default=3]",
choices=['1','2','3'],
default="3")
parser.add_argument("--with-fortran",
help="Use Fortran [default=yes]",
choices=["yes","no"],
default="yes")
parser.add_argument("--with-mpi",
help="Use MPI [default=yes]",
choices=["yes","no"],
default="yes")
parser.add_argument("--with-omp",
help="Use OpenMP [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--with-cuda",
help="Use CUDA [default=no]",
choices=["yes","no"],
Expand All @@ -37,128 +21,52 @@ def configure(argv):
help="Use SYCL [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--with-acc",
help="Use OpenACC [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--comp",
help="Compiler [default=gnu]",
choices=["gnu","intel","intel-llvm","intel-classic","cray","pgi","llvm","nag","nec","ibm","armclang"],
choices=["gnu","intel","llvm"],
default="gnu")
parser.add_argument("--debug",
help="Debug build [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--enable-particle",
help="Enable amrexpr particle classes [default=yes]",
choices=["yes","no"],
default="yes")
parser.add_argument("--enable-fortran-api",
help="Enable amrexpr Fortran API [default=yes]",
choices=["yes","no"],
default="yes")
parser.add_argument("--enable-linear-solver",
help="Enable amrexpr linear solvers [default=yes]",
choices=["yes","no"],
default="yes")
parser.add_argument("--enable-hypre",
help="Enable Hypre as an option for bottom solver of amrexpr linear solvers [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--enable-petsc",
help="Enable PETSc as an option for bottom solver of amrexpr linear solvers [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--enable-eb",
help="Enable amrexpr embedded boundary capability [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--single-precision",
help="Define amrexpr::Real as float [default=no (i.e., double)]",
choices=["yes","no"],
default="no")
parser.add_argument("--single-precision-particles",
help="Define amrexpr::ParticleReal as float [default=no (i.e., double)]",
choices=["yes","no"],
default="no")
parser.add_argument("--enable-xsdk-defaults",
help="Enable XSDK mode [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--allow-different-compiler",
help="Allow an application to use a different compiler than the one used to build libamrexpr [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--with-sensei-insitu",
help="Enables the SENSEI in situ integration. [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--sensei-amr-inst",
help="Enables the SENSEI instrumentation in amrexpr::Amr. [default=yes]",
choices=["yes","no"],
default="yes")
parser.add_argument("--with-omp-offload",
help="Use OpenMP-offload [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--enable-tiny-profile",
help="Enable tiny profile [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--enable-pic",
help="Enable position independent code [default=no]",
choices=["yes","no"],
default="no")
parser.add_argument("--cuda-arch",
help="Specify CUDA architecture [default=70]",
default="70")
parser.add_argument("--enable-probinit",
help="Only relevant to Amr/AmrLevel based codes that need to read probin file or call amrexpr_probinit",
choices=["yes","no"],
default="yes")
parser.add_argument("--enable-bittree",
help="Enable Bittree mode [default=no]",
choices=["yes","no"],
default="no")
help="Specify CUDA architecture. Required when CUDA is enabled.")
parser.add_argument("--amd-arch",
help="Specify AMD GPU architecture. Requried when HIP is enabled.")
parser.add_argument("--intel-arch",
help="Specify Intel GPU architecture. Optional.")
args = parser.parse_args()

if args.with_fortran == "no":
args.enable_fortran_api = "no";
if args.enable_hypre == "yes":
sys.exit("ERROR: must have --with-fortran=yes to use hypre")
if args.enable_petsc == "yes":
sys.exit("ERROR: must have --with-fortran=yes to use petsc")

f = open("GNUmakefile","w")
f.write("AMREXPR_INSTALL_DIR = " + args.prefix.strip() + "\n")
f.write("DIM = " + args.dim.strip() + "\n")
f.write("BL_NO_FORT = {}\n".format("TRUE" if args.with_fortran == "no" else "FALSE"))
f.write("USE_MPI = {}\n".format("FALSE" if args.with_mpi == "no" else "TRUE"))
f.write("USE_OMP = {}\n".format("FALSE" if args.with_omp == "no" else "TRUE"))
f.write("USE_CUDA = {}\n".format("FALSE" if args.with_cuda == "no" else "TRUE"))
f.write("USE_HIP = {}\n".format("FALSE" if args.with_hip == "no" else "TRUE"))
f.write("USE_SYCL = {}\n".format("FALSE" if args.with_sycl == "no" else "TRUE"))
f.write("USE_ACC = {}\n".format("FALSE" if args.with_acc == "no" else "TRUE"))
f.write("COMP = " + args.comp.strip() + "\n")
f.write("DEBUG = {}\n".format("TRUE" if args.debug == "yes" else "FALSE"))
f.write("USE_PARTICLES = {}\n".format("FALSE" if args.enable_particle == "no" else "TRUE"))
f.write("USE_FORTRAN_INTERFACE = {}\n".format("FALSE" if args.enable_fortran_api == "no" else "TRUE"))
f.write("USE_LINEAR_SOLVERS = {}\n".format("FALSE" if args.enable_linear_solver == "no" else "TRUE"))
f.write("USE_HYPRE = {}\n".format("TRUE" if args.enable_hypre == "yes" else "FALSE"))
f.write("USE_PETSC = {}\n".format("TRUE" if args.enable_petsc == "yes" else "FALSE"))
f.write("USE_EB = {}\n".format("TRUE" if args.enable_eb == "yes" else "FALSE"))
f.write("PRECISION = {}\n".format("FLOAT" if args.single_precision == "yes" else "DOUBLE"))
f.write("USE_SINGLE_PRECISION_PARTICLES = {}\n".format("TRUE" if args.single_precision_particles == "yes" else "FALSE"))
f.write("AMREXPR_XSDK = {}\n".format("TRUE" if args.enable_xsdk_defaults == "yes" else "FALSE"))
f.write("ALLOW_DIFFERENT_COMP = {}\n".format("FALSE" if args.allow_different_compiler == "no" else "TRUE"))
f.write("USE_SENSEI_INSITU = {}\n".format("FALSE" if args.with_sensei_insitu == "no" else "TRUE"))
f.write("NO_SENSEI_AMR_INST = {}\n".format("FALSE" if args.sensei_amr_inst == "yes" else "TRUE"))
f.write("USE_OMP_OFFLOAD = {}\n".format("FALSE" if args.with_omp_offload == "no" else "TRUE"))
f.write("TINY_PROFILE = {}\n".format("FALSE" if args.enable_tiny_profile == "no" else "TRUE"))
f.write("USE_COMPILE_PIC = {}\n".format("FALSE" if args.enable_pic == "no" else "TRUE"))
f.write("CUDA_ARCH = " + args.cuda_arch.strip() + "\n")
f.write("AMREXPR_NO_PROBINIT = {}\n".format("TRUE" if args.enable_probinit == "no" else "FALSE"))
f.write("USE_BITTREE = {}\n".format("TRUE" if args.enable_bittree == "yes" else "FALSE"))
if args.with_cuda == "yes":
f.write("CUDA_ARCH = " + args.cuda_arch.strip() + "\n")
if args.with_hip == "yes":
f.write("AMD_ARCH = " + args.amd_arch.strip() + "\n")
if args.with_sycl == "yes":
if args.intel_arch:
f.write("INTEL_ARCH = " + args.intel_arch.strip() + "\n")

f.write("\n")

fin = open("GNUmakefile.in","r")
Expand Down
34 changes: 3 additions & 31 deletions Tools/libamrexpr/mkconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,15 @@ def doit(defines, undefines, comp, allow_diff_comp):
print("#ifdef __cplusplus");

if allow_diff_comp == "FALSE":
if comp == "gnu" or comp == "nag":
if comp == "gnu":
comp_macro = "__GNUC__"
comp_id = "GNU"
elif comp == "intel" or comp == "intel-classic":
elif comp == "intel":
comp_macro = "__INTEL_COMPILER"
comp_id = "Intel"
elif comp == "intel-llvm":
comp_macro = "__INTEL_LLVM_COMPILER"
comp_id = "Intel"
elif comp == "cray":
comp_macro = "_CRAYC"
comp_id = "Cray"
elif comp == "pgi":
comp_macro = "__PGI"
comp_id = "PGI"
elif comp == "nvhpc":
comp_macro = "__NVCOMPILER"
comp_id = "NVHPC"
elif comp == "llvm":
comp_macro = "__llvm__"
comp_id = "Clang/LLVM"
elif comp == "nec":
comp_macro = "__NEC__"
comp_id = "NEC"
elif comp == "ibm":
comp_macro = "__ibmxl__"
comp_id = "IBM"
elif comp == "armclang":
comp_macro = "__armclang_version__"
comp_id = "ArmClang"
elif comp == "hip":
comp_macro = "__HIP__"
comp_id = "HIP"
Expand All @@ -75,12 +54,6 @@ def doit(defines, undefines, comp, allow_diff_comp):

print("#endif") # ifdef __cplusplus

# hipcc does not necessarily set the _OPENMP macro
# https://rocmdocs.amd.com/en/latest/Programming_Guides/HIP-FAQ.html?highlight=_openmp#openmp-is-undefined-when-compiling-with-fopenmp
print("#if defined(AMREXPR_USE_OMP) && !defined(_OPENMP) && !defined(AMREXPR_USE_HIP)")
print('#error libamrexpr was built with OpenMP')
print("#endif")

print("#endif")

if __name__ == "__main__":
Expand All @@ -94,8 +67,7 @@ def doit(defines, undefines, comp, allow_diff_comp):
default="")
parser.add_argument("--comp",
help="compiler",
choices=["gnu","intel","intel-llvm","intel-classic","cray","pgi","nvhpc","llvm","nag","nec","ibm",
"armclang","hip","sycl"])
choices=["gnu","intel","llvm","hip","sycl"])
parser.add_argument("--allow-different-compiler",
help="allow an application to use a different compiler than the one used to build libamrexpr",
choices=["TRUE","FALSE"])
Expand Down
9 changes: 2 additions & 7 deletions Tools/libamrexpr/mkpkgconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import argparse

def doit(prefix, version, cflags, libs, libpriv, fflags):
def doit(prefix, version, cflags, libs, libpriv):
print("# amrexpr Version: "+version)
print("")
print("prefix="+prefix)
print("exec_prefix=${prefix}")
print("libdir=${prefix}/lib")
print("includedir=${prefix}/include")
print("")
print("fflags="+fflags);
print("")
print("Name: amrexpr")
print("Description: AMReX's Math Expression Parser")
print("Version:")
Expand Down Expand Up @@ -39,14 +37,11 @@ def doit(prefix, version, cflags, libs, libpriv, fflags):
parser.add_argument("--libpriv",
help="libpriv",
default="")
parser.add_argument("--fflags",
help="fflags",
default="")
args = parser.parse_args()

try:
doit(prefix=args.prefix, version=args.version, cflags=args.cflags,
libs=args.libs, libpriv=args.libpriv, fflags=args.fflags)
libs=args.libs, libpriv=args.libpriv)
except:
# something went wrong
print("$(error something went wrong in mkpkgconfig.py)")
4 changes: 4 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

Tools/libamrexpr/configure.py "$@"

0 comments on commit b5b168d

Please sign in to comment.