diff --git a/cmake/modules/DunePerftoolMacros.cmake b/cmake/modules/DunePerftoolMacros.cmake index 545ec22d2436eb58ae6b9dafc69ff2e72f43a14e..8c8aa346eb97e62cdefaac552007473f8e769385 100644 --- a/cmake/modules/DunePerftoolMacros.cmake +++ b/cmake/modules/DunePerftoolMacros.cmake @@ -120,21 +120,28 @@ function(add_generated_executable) set(GEN_EXCLUDE_FROM_ALL "") endif() - # Generate a list of generated headers to teach CMake about + # Parse a mapping of operators to build and their respective filenames dune_execute_process(COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env python ${perftool_path}/deplist.py ${GEN_INIFILE} ${GEN_TARGET} - OUTPUT_VARIABLE header_deps + OUTPUT_VARIABLE depdata ) + parse_python_data(PREFIX depdata INPUT ${depdata}) - add_custom_command(OUTPUT ${header_deps} - COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env generate_operators - --project-basedir ${CMAKE_BINARY_DIR} - ${GEN_FORM_COMPILER_ARGS} - --uflfile ${GEN_UFLFILE} - --ini-file ${GEN_INIFILE} - --target-name ${GEN_TARGET} - DEPENDS ${GEN_UFLFILE} ${UFL2PDELAB_SOURCES} ${GEN_DEPENDS} ${DUNE_PERFTOOL_ADDITIONAL_PYTHON_SOURCES} - COMMENT "Generating operators for the target ${GEN_TARGET}" - ) + # Define build rules for all operator header files and gather a list of them + set(header_deps) + foreach(op ${depdata___operators}) + add_custom_command(OUTPUT ${depdata___${op}} + COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env generate_operators + --project-basedir ${CMAKE_BINARY_DIR} + ${GEN_FORM_COMPILER_ARGS} + --uflfile ${GEN_UFLFILE} + --ini-file ${GEN_INIFILE} + --target-name ${GEN_TARGET} + --operator-to-build ${op} + DEPENDS ${GEN_UFLFILE} ${UFL2PDELAB_SOURCES} ${GEN_DEPENDS} ${DUNE_PERFTOOL_ADDITIONAL_PYTHON_SOURCES} + COMMENT "Generating operator file ${depdata___${op}} for the target ${GEN_TARGET}" + ) + set(header_deps ${header_deps} ${depdata___${op}}) + endforeach() add_executable(${GEN_TARGET} ${GEN_EXCLUDE_FROM_ALL} ${GEN_SOURCE} ${GEN_DRIVER} ${header_deps}) target_include_directories(${GEN_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/cmake/modules/deplist.py b/cmake/modules/deplist.py index d0ff67dfa080439ff25a091223f846c7f01d237f..9cb5d7d42cbfc712e18e37798dffc2d553416f8c 100755 --- a/cmake/modules/deplist.py +++ b/cmake/modules/deplist.py @@ -2,20 +2,25 @@ # This is used by the build system, do not use this yourself! from dune.testtools.parser import parse_ini_file +from dune.testtools.cmakeoutput import printForCMake import sys ini = parse_ini_file(sys.argv[1]) section = ini["formcompiler"] operators = section.get("operators", "r") +operators = [i.strip() for i in operators.split(",")] -result = [] -for operator in [i.strip() for i in operators.split(",")]: +def get_filename(operator): ssection = ini.get("formcompiler.{}".format(operator), {}) if ssection.get("filename", None): - result.append(ssection["filename"]) + return ssection["filename"] else: classname = ssection.get("classname", "{}Operator".format(ssection.get("form", operator))) - result.append("{}_{}_file.hh".format(sys.argv[2], classname)) + return "{}_{}_file.hh".format(sys.argv[2], classname) -sys.stdout.write(" ".join(result)) +result = {"__{}".format(o): get_filename(o) for o in operators} +result["__operators"] = ";".join(operators) + +printForCMake(result) +sys.exit(0) diff --git a/python/dune/perftool/compile.py b/python/dune/perftool/compile.py index 208738165ab7e8d9940358b223f48bc8b5920c94..ed4c1310a9274528a3764f2739d7ee59c025ef21 100644 --- a/python/dune/perftool/compile.py +++ b/python/dune/perftool/compile.py @@ -118,15 +118,14 @@ def entry_generate_operators(): data = read_ufl(get_option("uflfile")) with global_context(data=data): - for operator in get_option("operators").split(","): - operator = operator.strip() - with global_context(form_identifier=operator): - # Make sure cache is empty - delete_cache_items() - - # Choose the form from the UFL input - kernels = generate_localoperator_kernels(operator) - - # Write the result to a file - filename = get_form_option("filename") - generate_localoperator_file(kernels, filename) + operator = get_option("operator_to_build") + with global_context(form_identifier=operator): + # Make sure cache is empty + delete_cache_items() + + # Choose the form from the UFL input + kernels = generate_localoperator_kernels(operator) + + # Write the result to a file + filename = get_form_option("filename") + generate_localoperator_file(kernels, filename) diff --git a/python/dune/perftool/options.py b/python/dune/perftool/options.py index e125c1918afee31717575e3447eea461430a2465..38a3be311037dedae17ab5db93393f6ea398fd29 100644 --- a/python/dune/perftool/options.py +++ b/python/dune/perftool/options.py @@ -51,6 +51,7 @@ class PerftoolGlobalOptionsArray(ImmutableRecord): overlapping = PerftoolOption(default=False, helpstr="Use an overlapping solver and constraints. You still need to make sure to construct a grid with overlap! The parallel option will be set automatically.") operators = PerftoolOption(default="r", helpstr="A comma separated list of operators, each name will be interpreted as a subsection name within the formcompiler section") target_name = PerftoolOption(default=None, helpstr="The target name from CMake") + operator_to_build = PerftoolOption(default=None, helpstr="The operators from the list that is about to be build now. CMake sets this one!!!") # Arguments that are mainly to be set by logic depending on other options max_vector_width = PerftoolOption(default=256, helpstr=None)