diff --git a/bfps/__init__.py b/bfps/__init__.py index 435355db570b53259cb83c5ff31c41a4472dbcd3..550f00e6820ebd1672436108777409f7eff24616 100644 --- a/bfps/__init__.py +++ b/bfps/__init__.py @@ -40,14 +40,9 @@ try: except DistributionNotFound: __version__ = '' -machine_settings = pickle.load( +install_info = pickle.load( open(os.path.join(os.path.dirname(here), - 'machine_settings.pickle'), - 'r')) - -version_info = pickle.load( - open(os.path.join(os.path.dirname(here), - 'version_info.pickle'), + 'install_info.pickle'), 'r')) from .code import code diff --git a/bfps/code.py b/bfps/code.py index e38cdd37f159d786c2fc9ca5080df149d2cd3cb0..8cef4ab0e1464376a9a33b52395124669365f3e9 100644 --- a/bfps/code.py +++ b/bfps/code.py @@ -26,89 +26,6 @@ import os import shutil import pickle -class cluster_launcher: - def __init__( - self, - file_name = None, - queue = None, - environment = None, - envprocs = None, - nprocesses = None, - name_of_run = None, - command_atoms = None, - hours = None, - minutes = None, - seconds = None, - err_file = None, - out_file = None, - mail_address = None, - mail_events = None): - self.file_name = file_name - self.queue = queue - self.environment = environment - self.nprocesses = nprocesses - self.name_of_run = name_of_run - self.command_atoms = command_atoms - self.hours = hours - self.minutes = minutes - self.seconds = seconds - self.err_file = err_file - self.out_file = out_file - self.mail_address = mail_address - self.mail_events = mail_events - if type(envprocs) == type(None): - self.envprocs = self.nprocesses - return None - def write_pbs_file(self): - script_file = open(file_name, 'w') - script_file.write('#!/bin/tcsh\n' - + '#PBS -q ' + queue + '\n' - + '#PBS -l walltime={0}:{1}:{2}\n'.format(hours, minutes, seconds)) - if nprocesses%8 == 0: - script_file.write('#PBS -l nodes={0}:ppn=8\n'.format(nprocesses/8)) - else: - script_file.write('#PBS -l nodes={0}\n'.format(nprocesses)) - script_file.write('#PBS -j n\n' - + '#PBS -e ' + err_file + '\n' - + '#PBS -o ' + out_file + '\n' - + '#PBS -N ' + name_of_run + '\n\n') - if mail_address != None: - script_file.write('#PBS -M {0}\n'.format(mail_address)) - if mail_events != None: - script_file.write('#PBS -m {0}\n\n'.format(mail_events)) - script_file.write('cd $PBS_O_WORKDIR\n' - + 'setenv MPI_NPROCS `wc -l $PBS_NODEFILE`\n' - + 'echo "Workdir is $PBS_O_WORKDIR"\n' - + 'echo Start time is `date`\n' - + 'mpirun -machinefile $PBS_NODEFILE ' + name_of_executable + '\n' - + 'echo End time is `date`\n') - script_file.close() - return None - def write_sge_file(self): - script_file = open(self.file_name, 'w') - script_file.write('#!/bin/bash\n') - # export all environment variables - script_file.write('#$ -V\n') - # job name - script_file.write('#$ -N {0}\n'.format(self.name_of_run)) - # use current working directory - script_file.write('#$ -cwd\n') - # error file - if not type(self.err_file) == type(None): - script_file.write('#$ -e ' + self.err_file + '\n') - # output file - if not type(self.out_file) == type(None): - script_file.write('#$ -o ' + self.out_file + '\n') - if not type(self.environment) == type(None): - script_file.write('#$ -pe {0} {1}\n'.format(self.environment, self.envprocs)) - script_file.write('echo "got $NSLOTS slots."\n') - script_file.write('echo Start time is `date`\n') - script_file.write('mpiexec -machinefile $TMPDIR/machines -n {0} {1}\n'.format(self.nprocesses, ' '.join(self.command_atoms))) - script_file.write('echo End time is `date`\n') - script_file.write('exit 0\n') - script_file.close() - return None - class code(base): def __init__(self): super(code, self).__init__() @@ -164,6 +81,12 @@ class code(base): } //endcpp """ + self.host_info = {'type' : 'cluster', + 'environment' : None, + 'deltanprocs' : 1, + 'queue' : '', + 'mail_address': '', + 'mail_events' : None} return None def write_src(self): with open(self.name + '.cpp', 'w') as outfile: @@ -189,21 +112,28 @@ class code(base): command_strings = ['mpicxx'] command_strings += [self.name + '.cpp', '-o', self.name] - command_strings += ['-O2'] + bfps.machine_settings['extra_compile_args'] - command_strings += ['-I' + idir for idir in bfps.machine_settings['include_dirs']] + command_strings += ['-O2'] + bfps.install_info['extra_compile_args'] + command_strings += ['-I' + idir for idir in bfps.install_info['include_dirs']] command_strings.append('-I' + bfps.header_dir) - command_strings += ['-L' + ldir for ldir in bfps.machine_settings['library_dirs']] + command_strings += ['-L' + ldir for ldir in bfps.install_info['library_dirs']] command_strings.append('-L' + bfps.lib_dir) for libname in libraries: command_strings += ['-l' + libname] + print('compiling code with command\n' + ' '.join(command_strings)) return subprocess.call(command_strings) + def set_host_info( + self, + host_info = {}): + self.host_info.update(host_info) + return None def run(self, ncpu = 2, simname = 'test', iter0 = 0, out_file = 'out_file', err_file = 'err_file', - hostinfo = {'type' : ''}): + hours = 1, + minutes = 0): if self.compile_code() == 0: current_dir = os.getcwd() if not os.path.isdir(self.work_dir): @@ -214,25 +144,22 @@ class code(base): with open(self.name + '_version_info.txt', 'w') as outfile: outfile.write(self.version_message) os.chdir(current_dir) - command = ['mpirun', - '-np', - '{0}'.format(ncpu), - './' + self.name, - simname, - '{0}'.format(iter0)] - if hostinfo['type'] == 'cluster': - cl = cluster_launcher( + command_atoms = ['mpirun', + '-np', + '{0}'.format(ncpu), + './' + self.name, + simname, + '{0}'.format(iter0)] + if self.host_info['type'] == 'cluster': + self.write_sge_file( file_name = os.path.join(self.work_dir, 'run_' + simname + '.sh'), - environment = hostinfo['environment'], nprocesses = ncpu, name_of_run = self.name + '_' + simname, - command_atoms = command[3:], - hours = 1, - minutes = 0, - seconds = 0, + command_atoms = command_atoms[3:], + hours = hours, + minutes = minutes, out_file = out_file, err_file = err_file) - cl.write_sge_file() elif hostinfo['type'] == 'pc': os.chdir(self.work_dir) os.environ['LD_LIBRARY_PATH'] += ':{0}'.format(bfps.lib_dir) @@ -240,5 +167,43 @@ class code(base): stdout = open(out_file + '_' + simname, 'w'), stderr = open(err_file + '_' + simname, 'w')) os.chdir(current_dir) - return command + return None + def write_sge_file( + self, + file_name = None, + nprocesses = None, + name_of_run = None, + command_atoms = [], + hours = None, + minutes = None, + out_file = None, + err_file = None): + script_file = open(file_name, 'w') + script_file.write('#!/bin/bash\n') + # export all environment variables + script_file.write('#$ -V\n') + # job name + script_file.write('#$ -N {0}\n'.format(name_of_run)) + # use current working directory + script_file.write('#$ -cwd\n') + script_file.write('#$ -v LD_LIBRARY_PATH="' + + ':'.join([bfps.lib_dir] + bfps.install_info['library_dirs']) + '"\n') + # error file + if not type(err_file) == type(None): + script_file.write('#$ -e ' + err_file + '\n') + # output file + if not type(out_file) == type(None): + script_file.write('#$ -o ' + out_file + '\n') + if not type(self.host_info['environment']) == type(None): + envprocs = (nprocesses / self.host_info['deltanprocs'] + 1) * self.host_info['deltanprocs'] + script_file.write('#$ -pe {0} {1}\n'.format( + self.host_info['environment'], + envprocs)) + script_file.write('echo "got $NSLOTS slots."\n') + script_file.write('echo Start time is `date`\n') + script_file.write('mpiexec -machinefile $TMPDIR/machines -n {0} {1}\n'.format(nprocesses, ' '.join(command_atoms))) + script_file.write('echo End time is `date`\n') + script_file.write('exit 0\n') + script_file.close() + return None diff --git a/setup.py b/setup.py index b4d6f94c70056667457d6c79cd2c92c0c3178e07..12c072116b14d06beb6767fa013eab0d25b425ba 100644 --- a/setup.py +++ b/setup.py @@ -22,12 +22,6 @@ from machine_settings import include_dirs, library_dirs, extra_compile_args import pickle -pickle.dump( - {'include_dirs' : include_dirs, - 'library_dirs' : library_dirs, - 'extra_compile_args' : extra_compile_args}, - open('bfps/machine_settings.pickle', 'wb'), - protocol = 2) AUTHOR = 'Cristian C Lalescu' @@ -45,9 +39,12 @@ try: except: git_revision = '' pickle.dump( - {'install_date' : now, + {'include_dirs' : include_dirs, + 'library_dirs' : library_dirs, + 'extra_compile_args' : extra_compile_args, + 'install_date' : now, 'git_revision' : git_revision}, - open('bfps/version_info.pickle', 'wb'), + open('bfps/install_info.pickle', 'wb'), protocol = 2) VERSION = date_name @@ -91,8 +88,7 @@ setup( install_requires = ['numpy>=1.8', 'matplotlib>=1.3'], ext_modules = [libbfps], package_data = {'bfps': header_list + ['../machine_settings.py', - 'machine_settings.pickle', - 'version_info.pickle']}, + 'install_info.pickle']}, ######################################################################## # useless stuff folows ########################################################################