Skip to content

Commit

Permalink
Fix --case-optimization (MFlowCode#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre committed Jan 6, 2024
1 parent cce8402 commit fa49968
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ endif()
# * For each .fpp file found with filepath <dirpath>/<filename>.fpp, using a
# custom command, instruct CMake how to generate a file with path
#
# src/<target>/autogen/<filename>.f90
# src/<target>/fypp/<filename>.f90
#
# by running Fypp on <dirpath>/<filename>.fpp. It is important to understand
# that this does not actually run the pre-processor. Rather, it instructs
# CMake what to do when it finds a src/<target>/autogen/<filename>.f90 path
# CMake what to do when it finds a src/<target>/fypp/<filename>.f90 path
# in the source list for a target. Thus, an association is made from an .f90
# file to its corresponding .fpp file (if applicable) even though the
# generation is of the form .fpp -> .f90.
Expand All @@ -223,7 +223,7 @@ endif()
# one of them is modified).
#
# .fpp files in src/common are treated as if they were in src/<target> (not
# pre-processed to src/common/autogen/) so as not to clash with other targets'
# pre-processed to src/common/fypp/) so as not to clash with other targets'
# .fpp files (this has caused problems in the past).
#
# * Export, in the variable <target>_SRCs, a list of all source files (.f90)
Expand All @@ -250,7 +250,7 @@ macro(HANDLE_SOURCES target useCommon)
list(APPEND ${target}_SRCs ${common_F90s})
endif()

# src/[<target>,common]/*.fpp -> src/<target>/autogen/*.f90
# src/[<target>,common]/*.fpp -> src/<target>/fypp/*.f90
file(GLOB ${target}_FPPs CONFIGURE_DEPENDS "${${target}_DIR}/*.fpp")
if (${useCommon})
file(GLOB common_FPPs CONFIGURE_DEPENDS "${common_DIR}/*.fpp")
Expand All @@ -259,22 +259,22 @@ macro(HANDLE_SOURCES target useCommon)

# Locate src/[<target>,common]/include/*.fpp
file(GLOB ${target}_incs CONFIGURE_DEPENDS "${${target}_DIR}/include/*.fpp"
"${CMAKE_CURRENT_BINARY_DIR}/include/*.fpp")
"${CMAKE_BINARY_DIR}/include/${target}/*.fpp")

if (${useCommon})
file(GLOB common_incs CONFIGURE_DEPENDS "${common_DIR}/include/*.fpp")
list(APPEND ${target}_incs ${common_incs})
endif()

file(MAKE_DIRECTORY "${${target}_DIR}/autogen")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/fypp/${target}")
foreach(fpp ${${target}_FPPs})
cmake_path(GET fpp FILENAME fpp_filename)
set(f90 "${${target}_DIR}/autogen/${fpp_filename}.f90")
set(f90 "${CMAKE_BINARY_DIR}/fypp/${target}/${fpp_filename}.f90")

add_custom_command(
OUTPUT ${f90}
COMMAND ${FYPP_EXE} -m re
-I "${CMAKE_CURRENT_BINARY_DIR}/include"
-I "${CMAKE_BINARY_DIR}/include/${target}"
-I "${${target}_DIR}/include"
-I "${common_DIR}/include"
-I "${common_DIR}"
Expand Down
14 changes: 13 additions & 1 deletion src/simulation/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,19 @@ contains
call s_assign_default_values_to_user_inputs()
call s_read_input_file()
call s_check_input_file()
print '(" Simulating a "I0"x"I0"x"I0" case on "I0" rank(s)")', m, n, p, num_procs

print '(" Simulating a ", A, " ", I0, "x", I0, "x", I0, " case on ", I0, " rank(s) ", A, ".")', &
#:if not MFC_CASE_OPTIMIZATION
"regular", &
#:else
"case-optimized", &
#:endif
m, n, p, num_procs, &
#ifdef MFC_OpenACC
"with OpenACC offloading"
#else
"on CPUs"
#endif
end if

! Broadcasting the user inputs to all of the processors and performing the
Expand Down
21 changes: 10 additions & 11 deletions toolchain/mfc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ def __hash__(self) -> int:

# Get path to directory that will store the build files
def get_build_dirpath(self) -> str:
subdir = 'dependencies' if self.isDependency else CFG().make_slug()
if self.isDependency:
slug = self.name
else:
slug = f"{CFG().make_slug()}-{self.name}"

if not self.isDependency and ARG("case_optimization"):
m = hashlib.sha256()
m.update(input.load().get_fpp(self).encode())
subdir = f"{subdir}-{m.hexdigest()[:6]}"
if ARG("case_optimization"):
m = hashlib.sha256()
m.update(input.load().get_fpp(self).encode())

return os.sep.join([
os.getcwd(),
"build",
subdir,
self.name
])
slug = f"{slug}-{m.hexdigest()[:6]}"

return os.sep.join([os.getcwd(), "build", slug ])

# Get the directory that contains the target's CMakeLists.txt
def get_cmake_dirpath(self) -> str:
Expand Down
7 changes: 5 additions & 2 deletions toolchain/mfc/run/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def __contents_equal(str_a: str, str_b: str) -> bool:

return lhs == rhs

inc_dir = os.path.join(target.get_build_dirpath(), "include")
inc_dir = os.path.join(target.get_build_dirpath(), "include", target.name)
common.create_directory(inc_dir)

fpp_path = os.path.join(inc_dir, f"case.fpp")
fpp_path = os.path.join(inc_dir, "case.fpp")
opt_fpp = common.file_read(fpp_path) if os.path.exists(fpp_path) else ""

if __contents_equal(contents, opt_fpp):
Expand Down Expand Up @@ -210,6 +210,9 @@ def _default() -> str:
return result

def generate_fpp(self, target) -> None:
if target.isDependency:
return

cons.print(f"Generating [magenta]{build.get_target(target).name}/include/case.fpp[/magenta].")
cons.indent()

Expand Down

0 comments on commit fa49968

Please sign in to comment.