def test_find_resource_hierarchies_scattere4(): h0 = [[(1, 16)], [(17, 32)]] h1 = [[(1, 8)], [(9, 16)], [(17, 24)], [(25, 32)]] h2 = [[(1, 4)], [(5, 8)], [(8, 12)], [(13, 16)], [(17, 20)], [(21, 24)], [(25, 28)], [(29, 32)]] x = find_resource_hierarchies_scattered([(1, 32)], [h0, h1, h2], [2, 1, 1]) assert x == [(1, 4), (17, 20)]
def find_resource_hierarchies_job(itvs_slots, hy_res_rqts, hy): ''' Find resources in interval for all resource subrequests of a moldable instance of a job ''' result = [] for hy_res_rqt in hy_res_rqts: (hy_level_nbs, constraints) = hy_res_rqt hy_levels = [] hy_nbs = [] for hy_l_n in hy_level_nbs: (l_name, n) = hy_l_n hy_levels.append(hy[l_name]) hy_nbs.append(n) itvs_cts_slots = intersec(constraints, itvs_slots) result.extend(find_resource_hierarchies_scattered(itvs_cts_slots, hy_levels, hy_nbs)) return result
def estimate_job_nb_resources(resource_request, j_properties): '''returns an array with an estimation of the number of resources that can be used by a job: (resources_available, [(nbresources => int, walltime => int)]) ''' # estimate_job_nb_resources estimated_nb_resources = [] resource_available = False resource_set = ResourceSet() resources_itvs = resource_set.roid_itvs for mld_idx, mld_resource_request in enumerate(resource_request): resource_desc, walltime = mld_resource_request if not walltime: walltime = default_job_walltime result = [] for prop_res in resource_desc: jrg_grp_property = prop_res['property'] resource_value_lst = prop_res['resources'] # # determine resource constraints # if (not j_properties) and (not jrg_grp_property or (jrg_grp_property == "type = 'default'")): constraints = deepcopy(resource_set.roid_itvs) else: if not j_properties or not jrg_grp_property: and_sql = "" else: and_sql = " AND " sql_constraints = j_properties + and_sql + jrg_grp_property try: request_constraints = db.query(Resource.id).filter(text(sql_constraints)).all() except exc.SQLAlchemyError: print_error('Bad resource SQL constraints request:', sql_constraints) print_error('SQLAlchemyError: ', exc) result = [] break roids = [resource_set.rid_i2o[int(y[0])] for y in request_constraints] constraints = unordered_ids2itvs(roids) hy_levels = [] hy_nbs = [] for resource_value in resource_value_lst: res_name = resource_value['resource'] value = resource_value['value'] hy_levels.append(resource_set.hierarchy[res_name]) hy_nbs.append(int(value)) cts_resources_itvs = intersec(constraints, resources_itvs) res_itvs = find_resource_hierarchies_scattered(cts_resources_itvs, hy_levels, hy_nbs) if res_itvs: result.extend(res_itvs) else: result = [] break if result: resource_available = True estimated_nb_res = itvs_size(result) estimated_nb_resources.append((estimated_nb_res, walltime)) print_info('Moldable instance: ', mld_idx, ' Estimated nb resources: ', estimated_nb_res, ' Walltime: ', walltime) if not resource_available: print_error("There are not enough resources for your request") sub_exit(-5) return(resource_available, estimated_nb_resources)
def test_find_resource_hierarchies_scattere1(): h0 = [[(1, 16)], [(17, 32)]] x = find_resource_hierarchies_scattered([(1, 32)], [h0], [2]) assert x == [(1, 32)]
def test_find_resource_hierarchies_scattere3(): h0 = [[(1, 16)], [(17, 32)]] h1 = [[(1, 8)], [(9, 16)], [(17, 24)], [(25, 32)]] x = find_resource_hierarchies_scattered([(1, 12), (17, 28)], [h0, h1], [2, 1]) assert x == [(1, 8), (17, 24)]