-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jgfouca/mct_no_makefile' into next (PR #6009)
MCT/Mpi-serial: Remove dependence on CIME/Tools/Makefile This is a continuation of the effort to remove all use of the CIME/Tools/Makefile from the E3SM build system so we can be free to change how we express our build settings in our cmake macros. Changes: 1) Move the python build wrapper scripts for MCT and mpi-serial from CIME to E3SM. 2) Refactor and clean up these scripts to use a similar approach as was used for the scorpio build wrapper: remove the reliance on CIME/Tools/Makefile and instead pull the needed items from the Macros directly and call the native build system (autoconf in this case) directly. 3) Clean up the macro extraction a bit 4) Fix pnetcdf setting for spio Testing: * Mappy_gnu A case (Mpilib=serial, openmpi) * anlgce_gnu A case (Mpilib=serial, mpich) * pm-cpu_gnu A case ((Mpilib=mpich, mpi-serial does not work on pm-cpu on master) * summit_ibm A case (Mpilib=spectrum-mpi, mpi-serial does not work on summit_ibm on master) * summit_gnu A case (Mpilib=spectrum-mpi, mpi-serial) [BFB]
- Loading branch information
Showing
5 changed files
with
332 additions
and
36 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
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 |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#!/usr/bin/env python3 | ||
import sys, os, logging, argparse | ||
|
||
_CIMEROOT = os.getenv("CIMEROOT") | ||
sys.path.append(os.path.join(_CIMEROOT, "CIME", "Tools")) | ||
|
||
from standard_script_setup import * | ||
from CIME.config import Config | ||
from CIME import utils | ||
from CIME.utils import copyifnewer, run_bld_cmd_ensure_logging, expect | ||
from CIME.case import Case | ||
import glob | ||
|
||
sys.path.append(os.path.dirname(__file__)) | ||
from buildlib_util import extract_from_macros | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
############################################################################### | ||
def parse_command_line(args, description): | ||
############################################################################### | ||
parser = argparse.ArgumentParser( | ||
usage="""\n{0} [--debug] | ||
OR | ||
{0} --verbose | ||
OR | ||
{0} --help | ||
\033[1mEXAMPLES:\033[0m | ||
\033[1;32m# Run \033[0m | ||
> {0} | ||
""".format( | ||
os.path.basename(args[0]) | ||
), | ||
description=description, | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
) | ||
|
||
utils.setup_standard_logging_options(parser) | ||
|
||
parser.add_argument("buildroot", help="build path root") | ||
|
||
parser.add_argument("installpath", help="install path ") | ||
|
||
parser.add_argument( | ||
"caseroot", nargs="?", default=os.getcwd(), help="Case directory to build" | ||
) | ||
|
||
args = utils.parse_args_and_handle_standard_logging_options(args, parser) | ||
|
||
return args.buildroot, args.installpath, args.caseroot | ||
|
||
############################################################################### | ||
def buildlib(bldroot, installpath, case): | ||
############################################################################### | ||
caseroot = case.get_value("CASEROOT") | ||
cimeroot = case.get_value("CIMEROOT") | ||
srcroot = case.get_value("SRCROOT") | ||
gmake_cmd = case.get_value("GMAKE") | ||
gmake_j = case.get_value("GMAKE_J") | ||
mpilib = case.get_value("MPILIB") | ||
|
||
expect( | ||
os.path.abspath(os.path.realpath(cimeroot)) == os.path.abspath(os.path.realpath(_CIMEROOT)), | ||
"CIMEROOT mismatch {} vs {}".format(_CIMEROOT, cimeroot), | ||
) | ||
|
||
customize_path = os.path.join(srcroot, "cime_config", "customize") | ||
|
||
config = Config.load(customize_path) | ||
|
||
mct_path = config.mct_path.format(srcroot=srcroot) | ||
|
||
for _dir in ("mct", "mpeu"): | ||
if not os.path.isdir(os.path.join(bldroot, _dir)): | ||
os.makedirs(os.path.join(bldroot, _dir)) | ||
|
||
copyifnewer( | ||
os.path.join(mct_path, _dir, "Makefile"), | ||
os.path.join(bldroot, _dir, "Makefile"), | ||
) | ||
|
||
# | ||
# Get autoconf arguments | ||
# | ||
|
||
fc, cc, _, mfc, mcc, _, fflags, cflags, _, cppdefs, ldflags, ffree, config_args = \ | ||
extract_from_macros(case, "mct", extra_vars=("FREEFLAGS", "CONFIG_ARGS")) | ||
|
||
fflags += f" {ffree} -I{installpath}/include" | ||
cflags += f" -I{installpath}/include" | ||
if mpilib == "mpi-serial": | ||
mfc = fc | ||
mcc = cc | ||
else: | ||
fc = mfc | ||
cc = mcc | ||
|
||
# Only need the netcdf_c library | ||
if "NETCDF_PATH" in os.environ: | ||
netcdf_args = f"NETCDF_PATH={os.environ['NETCDF_PATH']} " | ||
elif "NETCDF_C_PATH" in os.environ: | ||
netcdf_args = f"NETCDF_PATH={os.environ['NETCDF_C_PATH']} " | ||
|
||
config_cmd = f"{mct_path}/configure CC={cc} FC={fc} MPICC={mcc} MPIFC={mfc} FCFLAGS='{fflags}' CPPDEFS='{cppdefs}' CFLAGS='{cflags}' LDFLAGS='{ldflags}' {config_args} {netcdf_args} --srcdir {mct_path}" | ||
|
||
# run configure | ||
run_bld_cmd_ensure_logging(config_cmd, logger, from_dir=bldroot) | ||
|
||
# Now we run the mct make command | ||
gmake_opts = "-f {} ".format(os.path.join(mct_path, "Makefile")) | ||
gmake_opts += " -C {} ".format(bldroot) | ||
gmake_opts += " -j {} ".format(gmake_j) | ||
gmake_opts += " SRCDIR={} ".format(os.path.join(mct_path)) | ||
|
||
cmd = "{} {}".format(gmake_cmd, gmake_opts) | ||
run_bld_cmd_ensure_logging(cmd, logger, from_dir=bldroot) | ||
|
||
for _dir in ("mct", "mpeu"): | ||
for _file in glob.iglob(os.path.join(bldroot, _dir, "*.a")): | ||
logger.info("Installing {} to {}".format(_file, installpath)) | ||
copyifnewer( | ||
_file, os.path.join(installpath, "lib", os.path.basename(_file)) | ||
) | ||
for _file in glob.iglob(os.path.join(bldroot, _dir, "*.mod")): | ||
logger.info("Installing {} to {}".format(_file, installpath)) | ||
copyifnewer( | ||
_file, os.path.join(installpath, "include", os.path.basename(_file)) | ||
) | ||
|
||
############################################################################### | ||
def _main(argv, documentation): | ||
############################################################################### | ||
bldroot, installpath, caseroot = parse_command_line(argv, documentation) | ||
with Case(caseroot) as case: | ||
buildlib(bldroot, installpath, case) | ||
|
||
############################################################################### | ||
if __name__ == "__main__": | ||
_main(sys.argv, __doc__) |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/bin/env python3 | ||
import os, sys, logging, argparse | ||
|
||
from standard_script_setup import * | ||
from CIME import utils | ||
from CIME.config import Config | ||
from CIME.utils import copyifnewer, run_bld_cmd_ensure_logging | ||
from CIME.case import Case | ||
from CIME.build import get_standard_makefile_args | ||
import glob | ||
|
||
sys.path.append(os.path.dirname(__file__)) | ||
from buildlib_util import extract_from_macros | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
############################################################################### | ||
def parse_command_line(args, description): | ||
############################################################################### | ||
parser = argparse.ArgumentParser( | ||
usage="""\n{0} [--debug] | ||
OR | ||
{0} --verbose | ||
OR | ||
{0} --help | ||
\033[1mEXAMPLES:\033[0m | ||
\033[1;32m# Run \033[0m | ||
> {0} | ||
""".format( | ||
os.path.basename(args[0]) | ||
), | ||
description=description, | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
) | ||
|
||
utils.setup_standard_logging_options(parser) | ||
|
||
parser.add_argument("buildroot", help="build path root") | ||
|
||
parser.add_argument("installpath", help="install path ") | ||
|
||
parser.add_argument( | ||
"caseroot", nargs="?", default=os.getcwd(), help="Case directory to build" | ||
) | ||
|
||
args = utils.parse_args_and_handle_standard_logging_options(args, parser) | ||
|
||
return args.buildroot, args.installpath, args.caseroot | ||
|
||
############################################################################### | ||
def buildlib(bldroot, installpath, case): | ||
############################################################################### | ||
caseroot = case.get_value("CASEROOT") | ||
srcroot = case.get_value("SRCROOT") | ||
gmake_cmd = case.get_value("GMAKE") | ||
gmake_j = case.get_value("GMAKE_J") | ||
mpilib = case.get_value("MPILIB") | ||
|
||
customize_path = os.path.join(srcroot, "cime_config", "customize") | ||
|
||
config = Config.load(customize_path) | ||
|
||
mct_path = config.mct_path.format(srcroot=srcroot) | ||
mpi_serial_path = os.path.join(mct_path, "mpi-serial") | ||
|
||
for _file in glob.iglob(os.path.join(mpi_serial_path, "*.h")): | ||
copyifnewer(_file, os.path.join(bldroot, os.path.basename(_file))) | ||
|
||
# Hacky way of getting stuff from Macros. | ||
fc, cc, _, _, _, _, fflags, cflags, _, cppdefs, ldflags, ffree, config_args = \ | ||
extract_from_macros(case, "mpi-serial", extra_vars=("FREEFLAGS", "CONFIG_ARGS")) | ||
|
||
fflags += f" {ffree}" | ||
|
||
# Only need the netcdf_c library | ||
if "NETCDF_PATH" in os.environ: | ||
netcdf_args = f"NETCDF_PATH={os.environ['NETCDF_PATH']} " | ||
elif "NETCDF_C_PATH" in os.environ: | ||
netcdf_args = f"NETCDF_PATH={os.environ['NETCDF_C_PATH']} " | ||
|
||
config_cmd = f"{mpi_serial_path}/configure CC={cc} FC={fc} FCFLAGS='{fflags}' CPPDEFS='{cppdefs}' CFLAGS='{cflags}' LDFLAGS='{ldflags}' {config_args} {netcdf_args} --srcdir {mpi_serial_path}" | ||
|
||
# run configure | ||
run_bld_cmd_ensure_logging(config_cmd, logger, from_dir=bldroot) | ||
|
||
# Now we run the mpi-serial make command | ||
gmake_opts = "-f {} ".format(os.path.join(mpi_serial_path, "Makefile")) | ||
gmake_opts += " -C {} ".format(bldroot) | ||
gmake_opts += " -j {} ".format(case.get_value("GMAKE_J")) | ||
gmake_opts += " SRCDIR={} ".format(os.path.join(mct_path)) | ||
|
||
cmd = "{} {}".format(gmake_cmd, gmake_opts) | ||
run_bld_cmd_ensure_logging(cmd, logger) | ||
|
||
copyifnewer( | ||
os.path.join(bldroot, "libmpi-serial.a"), | ||
os.path.join(installpath, "lib", "libmpi-serial.a"), | ||
) | ||
for _file in ("mpi.h", "mpif.h", "mpi.mod", "MPI.mod"): | ||
if os.path.isfile(os.path.join(bldroot, _file)): | ||
copyifnewer( | ||
os.path.join(bldroot, _file), | ||
os.path.join(installpath, "include", _file), | ||
) | ||
|
||
############################################################################### | ||
def _main(argv, documentation): | ||
############################################################################### | ||
bldroot, installpath, caseroot = parse_command_line(argv, documentation) | ||
with Case(caseroot) as case: | ||
buildlib(bldroot, installpath, case) | ||
|
||
############################################################################### | ||
if __name__ == "__main__": | ||
_main(sys.argv, __doc__) |
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
Oops, something went wrong.