Add conditional decorator

migrate_fortran
chortas 3 years ago
parent ab87cc8099
commit 7c40bde80c

1
.gitignore vendored

@ -16,3 +16,4 @@ tests/integration/__pycache__/
fftma_module/gen/build/
tools/connec/conec2d
tools/connec/conec3d
utilities/__pycache__/

@ -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()

@ -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:

@ -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")

@ -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")

@ -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
Loading…
Cancel
Save