[FEM] Elmer: fixes for multi-threading

- load the results depending on the used cores, not always the multi-thread results
- avoid unnecessary console output - this info is already output in tasks.py
- handle number of cores as int to save in total 2 conversions
This commit is contained in:
Uwe
2022-08-13 16:27:56 +02:00
parent d1ffbc0ae9
commit b6cb5ffe4a
3 changed files with 21 additions and 19 deletions

View File

@@ -130,12 +130,12 @@ class Solve(run.Solve):
self.pushStatus("Number of CPU cores to be used for the solver run: {}\n"
.format(num_cores))
args = []
if int(num_cores) > 1:
if num_cores > 1:
if system() != "Windows":
args.extend(["mpirun"])
else:
args.extend(["mpiexec"])
args.extend(["-np", num_cores])
args.extend(["-np", str(num_cores)])
args.extend([binary])
if system() == "Windows":
self._process = subprocess.Popen(
@@ -283,16 +283,22 @@ class Results(run.Results):
possible_post_file_old = os.path.join(self.directory, "case0001.vtu")
possible_post_file_single = os.path.join(self.directory, "case_t0001.vtu")
possible_post_file_multi = os.path.join(self.directory, "case_t0001.pvtu")
# first try the multi-thread result, then single then old name
if os.path.isfile(possible_post_file_multi):
postPath = possible_post_file_multi
elif os.path.isfile(possible_post_file_single):
postPath = possible_post_file_single
elif os.path.isfile(possible_post_file_old):
postPath = possible_post_file_old
else:
self.report.error("Result file not found.")
self.fail()
# depending on the currently set number of cores we try to load either
# the multi-thread result or the single result
if settings.get_cores("ElmerSolver") > 1:
if os.path.isfile(possible_post_file_multi):
postPath = possible_post_file_multi
else:
self.report.error("Result file not found.")
self.fail()
else:
if os.path.isfile(possible_post_file_single):
postPath = possible_post_file_single
elif os.path.isfile(possible_post_file_old):
postPath = possible_post_file_old
else:
self.report.error("Result file not found.")
self.fail()
return postPath
## @}

View File

@@ -241,9 +241,9 @@ class Writer(object):
)
else:
subprocess.call(args, stdout=subprocess.DEVNULL)
if int(num_cores) > 1:
if num_cores > 1:
args = argsBasic
args.extend(["-partdual", "-metiskway", num_cores,
args.extend(["-partdual", "-metiskway", str(num_cores),
"-out", self.directory])
if system() == "Windows":
subprocess.call(

View File

@@ -116,10 +116,6 @@ def get_cores(name):
"""
if name in _SOLVER_PARAM:
cores = _SOLVER_PARAM[name].get_cores()
FreeCAD.Console.PrintMessage(
"Number of CPU cores to be used for the solver run: {}\n"
.format(cores)
)
return cores
else:
FreeCAD.Console.PrintError(
@@ -244,7 +240,7 @@ class _SolverDlg(object):
return the_found_binary
def get_cores(self):
cores = str(self.param_group.GetInt("UseNumberOfCores"))
cores = self.param_group.GetInt("UseNumberOfCores")
return cores
def get_write_comments(self):