def prepare_MPI_filtering(cls, filter_file: str) -> None: # Find which MPI functions to filter # Get all MPI functions (our filter_file is a WHITELIST) default_provider = D.BackendDefaults() mpi_funcs_dump = os.path.join(default_provider.instance.get_pira_dir(), 'mpi_funcs.dump') U.shell('wrap.py -d > ' + mpi_funcs_dump) all_MPI_functions_decls = U.read_file(mpi_funcs_dump).split('\n') all_MPI_functions = [] for fd in all_MPI_functions_decls: name = fd[fd.find(' '):fd.find('(')] all_MPI_functions.append(name.strip()) MPI_functions_to_filter = [] file_content = U.read_file(filter_file).split('\n') # We always want to measure MPI_Init and MPI_Finalize file_content.append('MPI_Init') file_content.append('MPI_Finalize') for l in file_content: if l.find('MPI_') > -1: L.get_logger().log( 'ScorepSystemHelper::prepare_MPI_filtering: Remove ' + l) # prevent double removal if l in all_MPI_functions: all_MPI_functions.remove(l) # Generate the .c file using the mpi wrap.py script L.get_logger().log( 'ScorepSystemHelper::prepare_MPI_filtering: About to filter ' + str(len(all_MPI_functions)) + ' MPI functions') wrap_script = '{{fn PIRA_Filter' for mpi_func in all_MPI_functions: wrap_script += ' ' + mpi_func wrap_script += '}}\n{{callfn}}\n{{endfn}}' default_provider = D.BackendDefaults() wrap_file = default_provider.get_wrap_w_file() if U.check_file(wrap_file): U.remove_file(wrap_file) U.write_file(wrap_file, wrap_script) wrap_c_path = default_provider.get_wrap_c_file() wrap_command = 'wrap.py -o ' + wrap_c_path + ' ' + wrap_file U.shell(wrap_command) # Compile it to .so file compile_mpi_wrapper_command = 'mpicc -shared -fPIC -o ' + default_provider.get_wrap_so_file( ) + ' ' + wrap_c_path U.shell(compile_mpi_wrapper_command)
def prepare_scorep_filter_file(self, filter_file: str) -> None: ''' Prepares the file that Score-P uses to include or exclude. NOTE: The filter_file is a positive list! We want to include these functions! ''' file_dir = U.get_base_dir(filter_file) file_content = U.read_file(filter_file) scorep_filter_file_content = self.append_scorep_footer( self.prepend_scorep_header(file_content)) scorep_filter_file_name = file_dir + '/scorep_filter_file.txt' U.write_file(scorep_filter_file_name, scorep_filter_file_content) return scorep_filter_file_name
def load_conf(self, config_file: str) -> PiraConfiguration: if config_file in self.config_cache: return self.config_cache[config_file] try: file_content = U.read_file(config_file) json_tree = json.loads(file_content) configuration = self.construct_from_json(json_tree) self.config_cache[config_file] = configuration return configuration except PiraConfigurationErrorException as e: L.get_logger().log(str(e), level='error') sys.exit() except Exception as e: print('Exception occured ' + str(e))
def load_conf(self, config_file: str) -> PiraConfiguration: if not U.is_file(config_file): raise RuntimeError( 'SimplifiedConfigurationLoader::load_conf: Invalid config file location "' + config_file + '" [no such file].') config_abs = U.get_absolute_path(config_file) config_abs_path = config_abs[:config_abs.rfind('/')] self._config.set_absolute_base_path(config_abs_path) try: file_content = U.read_file(config_file) json_tree = json.loads(file_content) self.parse_from_json(json_tree) except Exception as e: L.get_logger().log( 'SimplifiedConfigurationLoader::load_conf: Caught exception "' + str(e)) return PiraConfigurationAdapter(self._config)