Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cdeps build concurancy #291

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 42 additions & 24 deletions cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def buildlib(bldroot, libroot, case):
strthread = "nothreads"
mpilib = case.get_value("MPILIB")
compiler = case.get_value("COMPILER")
sharedpath = os.path.join(compiler, mpilib, strdebug, strthread, "nuopc")

sharedpath = os.path.join(compiler, mpilib, strdebug, strthread)
sharedroot = case.get_value("SHAREDLIBROOT")
cdepsblddir = os.path.join(sharedroot, sharedpath, "CDEPS")

logger.info("Running cmake for CDEPS")
srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
cmake_flags = get_standard_cmake_args(case, os.path.join(sharedpath, "cdeps"))
Expand Down Expand Up @@ -147,31 +149,47 @@ def buildlib(bldroot, libroot, case):
else:
bld_time = src_time - 1

# if any file in src is newer than CmakeFiles in the build directory, rerun cmake
# Make sure that no other process is currently trying to build this library, done with a simple lockfile
if os.path.exists(cdepsblddir):
logger.info("{} already exists, checking for lockfile".format(cdepsblddir))
while os.path.exists(os.path.join(cdepsblddir,"lockfile")):
logger.info("Waiting for lockfile in {}".format(cdepsblddir))
time.sleep(10)
else:
logger.info("{} does not exist, creating lockfile".format(cdepsblddir))
os.makedirs(cdepsblddir)
with open(os.path.join(cdepsblddir,"lockfile"),"w") as fd:
fd.write(str(os.getpid()))

try:
# if any file in src is newer than CmakeFiles in the build directory, rerun cmake
if src_time > bld_time:
logger.info("cmake_flags {}".format(cmake_flags))
s, o, e = run_cmd(
"cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True
)
expect(not s, "ERROR from cmake output={}, error={}".format(o, e))
else:
# The dwav_lib is the last file built in cdeps, wait for it to be built
dwav_lib = os.path.join(bldroot, "dwav", "libdwav.a")
time_to_wait = 600
time_counter = 0
while not os.path.exists(dwav_lib):
time.sleep(1)
time_counter += 1
if time_counter > time_to_wait:
break
expect(time_counter <= time_to_wait, " Timeout waiting for {}".format(dwav_lib))

if src_time > bld_time:
logger.info("cmake_flags {}".format(cmake_flags))
s, o, e = run_cmd(
"cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True
"make install VERBOSE=1 DESTDIR={}".format(libroot),
from_dir=bldroot,
verbose=True,
)
expect(not s, "ERROR from cmake output={}, error={}".format(o, e))
else:
# The dwav_lib is the last file built in cdeps, wait for it to be built
dwav_lib = os.path.join(bldroot, "dwav", "libdwav.a")
time_to_wait = 300
time_counter = 0
while not os.path.exists(dwav_lib):
time.sleep(1)
time_counter += 1
if time_counter > time_to_wait:
break
expect(time_counter <= time_to_wait, " Timeout waiting for {}".format(dwav_lib))

s, o, e = run_cmd(
"make install VERBOSE=1 DESTDIR={}".format(libroot),
from_dir=bldroot,
verbose=True,
)
finally:
if os.path.exists(os.path.join(cdepsblddir,"lockfile")):
os.remove(os.path.join(cdepsblddir,"lockfile"))

expect(not s, "ERROR from make output={}, error={}".format(o, e))
logger.info("make output={}\nerror={}".format(o, e))
if compiler == "gnu" and case.get_value("DEBUG"):
Expand Down
Loading