# %% LICENSE_SALOME_CEA_BEGIN
# Copyright (C) 2008-2016 CEA/DEN
-#
+#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
-#
+#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
-#
+#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
+#
# See http://www.salome-platform.org or email : webmaster.salome@opencascade.com
# %% LICENSE_END
"""
import os
+import platform
import sys
import time
-import platform
+
import argparse as AP
-import pprint as PP #pretty print
-import subprocess as SP #Popen
-import multiprocessing as MP #cpu_count
+import multiprocessing as MP # cpu_count
+import pprint as PP # pretty print
+import subprocess as SP # Popen
+
verbose = False
OK = "ok"
KO = "KO"
-OKSYS = 0 #for linux
-KOSYS = 1 #for linux
+OKSYS = 0 # for linux
+KOSYS = 1 # for linux
+
+NB_PROCS = MP.cpu_count() # current cpu number of proc
+NAME_OS = platform.system() # 'Linux' or 'Windows'
-NB_PROCS = MP.cpu_count() #current cpu number of proc
-NAME_OS = platform.system() #'Linux' or 'Windows'
-
##########################################################################
# utilities
def okToSys(aResult, verbose=False):
"""to get windows or linux result of script"""
-
+
def extendList(alist):
"""utility extend list of lists of string results with ok or KO"""
- #bad: list(itertools.chain.from_list(alist)) iterate on str
+ # bad: list(itertools.chain.from_list(alist)) iterate on str
res = []
if type(alist) != list:
return [alist]
else:
res.extend(extendList(i))
return res
-
+
resList = extendList(aResult)
if resList == []:
if verbose: print("WARNING: result no clear: []")
return KOSYS
-
+
rr = OK
for ri in resList:
if ri[0:2] != OK:
- if verbose: print ri
+ if verbose: print(ri)
rr = KO
- if verbose: print("INFO: result: %s" % rr)
+ if verbose: print(("INFO: result: %s" % rr))
if rr == OK:
return OKSYS
else:
def exec_command(cmd, verbose=False):
"""Exec ONE command with popen"""
- time.sleep(3) #wait for (MPI) flush files
- if verbose: print("launch process:\n %s" % cmd)
+ time.sleep(3) # wait for (MPI) flush files
+ if verbose: print(("launch process:\n %s" % cmd))
try:
- pipe = SP.Popen(cmd, shell=True, stdout=SP.PIPE, stderr=SP.PIPE )
+ pipe = SP.Popen(cmd, shell=True, stdout=SP.PIPE, stderr=SP.PIPE)
except Exception as e:
result = KO + " ERROR: we have a problem popen on: %s" % PP.pformat(cmd)
return result
-
+
(out, error) = pipe.communicate()
pipe.wait()
-
+
print(out)
print(error)
-
+
result = OK + " INFO: seems final ok for: %s" % PP.pformat(cmd)
- time.sleep(3) #wait for (MPI) flush files
+ time.sleep(3) # wait for (MPI) flush files
return result
#export PATH=/export/home/prerequisites_SALOME_780_LAURENT/openmpi-1.8.4/FROM_nothing/bin:$PATH
#do not work prefer set before salome launch
OPENMPI_INSTALL_DIR = "/export/home/prerequisites_SALOME_780_LAURENT/openmpi-1.8.4/FROM_nothing/bin"
- sys.path.insert(0, OPENMPI_INSTALL_DIR)
+ sys.path.insert(0, OPENMPI_INSTALL_DIR)
#INSTALL_DIR = /export/home/prerequisites_SALOME_780_LAURENT/openmpi-1.8.4/FROM_nothing
for i in sys.path[0:10]: print "PATH",i
"""
##########################################################################
def launchMultithread(args):
- if verbose: print("INFO: launchMultithread for %s" % NAME_OS)
-
+ if verbose: print(("INFO: launchMultithread for %s" % NAME_OS))
+
if NAME_OS == 'Linux':
- #--out is ONE file: basename_tetra_hpc.mesh
- outputMulti = os.path.splitext(args.inputFile)[0] + "_tetra_hpc.mesh" #only one file if Multithread
+ # --out is ONE file: basename_tetra_hpc.mesh
+ outputMulti = os.path.splitext(args.inputFile)[0] + "_tetra_hpc.mesh" # only one file if Multithread
outputs = os.path.splitext(args.outputFiles)[0]
- outputMultiAsMpi = os.path.splitext(args.outputFiles)[0] + ".000001.mesh" #create one output file named as only one from mpi
+ outputMultiAsMpi = os.path.splitext(args.outputFiles)[0] + ".000001.mesh" # create one output file named as only one from mpi
cmd = "mg-tetra_hpc.exe --max_number_of_threads %i --in %s --gradation %s --max_size %s --min_size %s; cp %s %s; ls -alt %s*; " % \
(args.number, args.inputFile, args.gradation, args.max_size, args.min_size, outputMulti, outputMultiAsMpi, outputs)
else:
- return KO + " ERROR: unknown operating system: %s" % NAME_OS
-
+ return KO + " ERROR: unknown operating system: %s" % NAME_OS
+
result = exec_command(cmd, verbose=True)
return result
##########################################################################
def launchMpi(args):
- if verbose: print("INFO: launchMpi for %s" % NAME_OS)
-
- if NAME_OS == 'Linux':
- cmd = ""
-
+ if verbose: print(("INFO: launchMpi for %s" % NAME_OS))
+
+ if NAME_OS == 'Linux':
+ cmd = ""
+
""" compile libmeshgems_mpi.so: no needs
COMPILDIR=os.getenv("MESHGEMSHOME") + "/stubs"
TARGETDIR=os.getenv("MESHGEMSHOME") + "/lib/Linux_64"
cmd += "mpirun -n %i mg-tetra_hpc_mpi.exe --in %s --out %s --gradation %s --max_size %s --min_size %s; ls -alt %s*; " % \
(args.number, args.inputFile, args.outputFiles, args.gradation, args.max_size, args.min_size, outputs)
else:
- return KO + " ERROR: unknown operating system: %s" % NAME_OS
-
+ return KO + " ERROR: unknown operating system: %s" % NAME_OS
+
result = exec_command(cmd, verbose=True)
return result
if __name__ == '__main__':
parser = AP.ArgumentParser(description='launch tetra_hpc.exe or tetra_hpc_mpi.exe mesh computation', argument_default=None)
- #./mg-tetra_hpc.py -n 3 --in=/tmp/GHS3DPRL.mesh --out=/tmp/GHS3DPRL_out.mesh --gradation=1.05 --min_size=0.001 --max_size=1.1 --multithread no > /tmp/tetrahpc.log
+ # ./mg-tetra_hpc.py -n 3 --in=/tmp/GHS3DPRL.mesh --out=/tmp/GHS3DPRL_out.mesh --gradation=1.05 --min_size=0.001 --max_size=1.1 --multithread no > /tmp/tetrahpc.log
parser.add_argument(
- '-v', '--verbose',
+ '-v', '--verbose',
help='set verbose, for debug',
action='store_true',
)
parser.add_argument(
- '-n', '--number',
+ '-n', '--number',
help='if multithread: number of threads, else distributed: number of processes MPI',
choices=[ArgRange(1, 999999)],
type=int,
default=1,
)
parser.add_argument(
- '-m', '--multithread',
+ '-m', '--multithread',
help='launch tetra_hpc multithread instead tetra_hpc distributed (MPI)',
choices=["no", "yes"],
default='no',
)
parser.add_argument(
- '-g', '--gradation',
+ '-g', '--gradation',
help='size ratio adjacent cell, default 0 is 1.05',
type=float,
choices=[ArgRange(0.0, 3.0)],
default='0'
)
parser.add_argument(
- '-si', '--min_size',
+ '-si', '--min_size',
help='min size cell, default 0 is no constraint',
type=float,
choices=[ArgRange(0.0, 9e99)],
default='0'
)
parser.add_argument(
- '-sa', '--max_size',
+ '-sa', '--max_size',
help='max size cell, default 0 is no constraint',
type=float,
choices=[ArgRange(0.0, 9e99)],
default='0'
)
parser.add_argument(
- '-i', '--inputFile',
+ '-i', '--inputFile',
help='input file name',
- #nargs='?',
+ # nargs='?',
metavar='.../inputFile.mesh'
)
parser.add_argument(
- '-o', '--outputFiles',
+ '-o', '--outputFiles',
help='output basename file(s) name',
- #nargs='?',
+ # nargs='?',
metavar='.../outputFile.mesh'
)
"""
parser.add_argument(
- '-x', '--xoneargument',
+ '-x', '--xoneargument',
nargs='?',
metavar='0|1',
choices=['0', '1'],
default='0'
)
"""
-
-
+
+
"""
- args is Namespace, may use it as global to store
+ args is Namespace, may use it as global to store
parameters, data, used arrays and results and other...
"""
args = parser.parse_args()
-
+
verbose = args.verbose
- if verbose: print("INFO: args:\n%s" % PP.pformat(args.__dict__))
+ if verbose: print(("INFO: args:\n%s" % PP.pformat(args.__dict__)))
- if len(sys.argv) == 1: #no args as --help
+ if len(sys.argv) == 1: # no args as --help
parser.print_help()
sys.exit(KOSYS)
if args.inputFile == None:
- print("\nERROR: Nothing to do: no input files\n\n%s\n" % PP.pformat(args))
+ print(("\nERROR: Nothing to do: no input files\n\n%s\n" % PP.pformat(args)))
parser.print_help()
sys.exit(KOSYS)
if args.outputFiles == None:
tmp, _ = os.path.splitext(args.inputFile)
args.outputFiles = tmp + "_out.mesh"
- print("\nWARNING: Default ouput files: %s" % args.outputFiles)
-
+ print(("\nWARNING: Default ouput files: %s" % args.outputFiles))
+
force_DISTENE_LICENSE_FILE()
- print("INFO: mg-tetra_hpc.py assume licence file set:\n DLIM8VAR=%s\n DISTENE_LICENSE_FILE=%s" % \
- (os.getenv("DLIM8VAR"), os.getenv("DISTENE_LICENSE_FILE")))
-
- if args.multithread == "yes":
+ print(("INFO: mg-tetra_hpc.py assume licence file set:\n DLIM8VAR=%s\n DISTENE_LICENSE_FILE=%s" % \
+ (os.getenv("DLIM8VAR"), os.getenv("DISTENE_LICENSE_FILE"))))
+
+ if args.multithread == "yes":
result = launchMultithread(args)
else:
result = launchMpi(args)
sys.exit(okToSys(result, verbose=True))
-
+