diff --git a/.gitignore b/.gitignore index 1fc7913..22f4212 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ tests/integration/__pycache__/ fftma_module/gen/build/ tools/connec/conec2d tools/connec/conec3d +utilities/__pycache__/ diff --git a/mpirunner.py b/mpirunner.py index cd27910..504a772 100755 --- a/mpirunner.py +++ b/mpirunner.py @@ -5,8 +5,11 @@ from tools.generation.config import DotheLoop, get_config import os import sys from tools.Prealization import realization +from utilities.conditional_decorator import * +from memory_profiler import profile CONFIG_FILE_PATH = 'config.ini' if 'CONFIG_FILE_PATH' not in os.environ else os.environ['CONFIG_FILE_PATH'] +IS_TEST = False if 'TEST' not in os.environ else True def main(): comm = MPI.COMM_WORLD @@ -22,8 +25,7 @@ def main(): worker() return - -@profile +@conditional_decorator(profile, IS_TEST) def sequential(): comm = MPI.COMM_WORLD conffile = CONFIG_FILE_PATH @@ -49,7 +51,7 @@ def manager(): return -@profile +@conditional_decorator(profile, IS_TEST) def worker(): comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/tests/integration/test.py b/tests/integration/test.py index 124a115..997a989 100644 --- a/tests/integration/test.py +++ b/tests/integration/test.py @@ -35,7 +35,7 @@ class TestIntegration(unittest.TestCase): def setUpClass(cls): os.chdir('../..') config_file = os.path.abspath("./tests/integration/conf_test.ini") - os.system("CONFIG_FILE_PATH="+ config_file + " mpirun -np 1 python3 mpirunner.py") + os.system(f"CONFIG_FILE_PATH={config_file} mpirun -np 1 python3 mpirunner.py") binary_results = {} for binary in BINARIES: diff --git a/tests/performance/connectivity.py b/tests/performance/connectivity.py index 29110a6..c71634c 100644 --- a/tests/performance/connectivity.py +++ b/tests/performance/connectivity.py @@ -36,9 +36,9 @@ with Benchmarker() as bench: @bench(f"Connectivity 1 core with size {size}") def _(bm): global index_1 - os.system("CONFIG_FILE_PATH="+ GEN_CONFIG_FILES[index_1] + " mpirun -oversubscribe -np 1 python3 -m memory_profiler mpirunner.py") + os.system(f"CONFIG_FILE_PATH={GEN_CONFIG_FILES[index_1]} TEST=True mpirun -oversubscribe -np 1 python3 mpirunner.py") with bm: - os.system("CONFIG_FILE_PATH="+ CONN_CONFIG_FILES[index_1] + " mpirun -oversubscribe -np 1 python3 -m memory_profiler mpirunner.py") + os.system(f"CONFIG_FILE_PATH={CONN_CONFIG_FILES[index_1]} TEST=True mpirun -oversubscribe -np 1 python3 mpirunner.py") ## teardown os.system("rm -rf ./tests/performance/tmp_gen_output") @@ -47,9 +47,9 @@ with Benchmarker() as bench: @bench(f"Connectivity 8 core with size {size}") def _(bm): global index_8 - os.system("CONFIG_FILE_PATH="+ GEN_CONFIG_FILES[index_8] + " mpirun -oversubscribe -np 8 python3 -m memory_profiler mpirunner.py") + os.system(f"CONFIG_FILE_PATH={GEN_CONFIG_FILES[index_8]} TEST=True mpirun -oversubscribe -np 8 python3 mpirunner.py") with bm: - os.system("CONFIG_FILE_PATH="+ CONN_CONFIG_FILES[index_8] + " mpirun -oversubscribe -np 8 python3 -m memory_profiler mpirunner.py") + os.system(f"CONFIG_FILE_PATH={CONN_CONFIG_FILES[index_8]} TEST=True mpirun -oversubscribe -np 8 python3 mpirunner.py") ## teardown os.system("rm -rf ./tests/performance/tmp_gen_output") diff --git a/tests/performance/generation.py b/tests/performance/generation.py index 76cfbab..837467d 100644 --- a/tests/performance/generation.py +++ b/tests/performance/generation.py @@ -25,7 +25,7 @@ with Benchmarker() as bench: global index_1 config_file = CONFIG_FILES[index_1] with bm: - os.system("CONFIG_FILE_PATH="+ config_file + " mpirun -oversubscribe -np 1 python3 -m memory_profiler mpirunner.py") + os.system(f"CONFIG_FILE_PATH={config_file} TEST=True mpirun -oversubscribe -np 1 python3 mpirunner.py") ## teardown os.system("rm -rf ./tests/performance/tmp_gen_output") @@ -36,7 +36,7 @@ with Benchmarker() as bench: global index_8 config_file = CONFIG_FILES[index_8] with bm: - os.system("CONFIG_FILE_PATH="+ config_file + " mpirun -oversubscribe -np 8 python3 -m memory_profiler mpirunner.py") + os.system(f"CONFIG_FILE_PATH={config_file} TEST=True mpirun -oversubscribe -np 8 python3 mpirunner.py") ## teardown os.system("rm -rf ./tests/performance/tmp_gen_output") diff --git a/utilities/conditional_decorator.py b/utilities/conditional_decorator.py new file mode 100644 index 0000000..5e0b3e8 --- /dev/null +++ b/utilities/conditional_decorator.py @@ -0,0 +1,7 @@ +def conditional_decorator(dec, condition): + def decorator(func): + if not condition: + # Return the function unchanged, not decorated. + return func + return dec(func) + return decorator \ No newline at end of file