resizable_array *parse_exec_hosts( char *exec_hosts_param) { char *slash; char *host_tok; char *exec_hosts = strdup(exec_hosts_param); char *str_ptr = exec_hosts; char *delims = "+"; char *prev_host_tok = NULL; host_req *hr; resizable_array *host_req_list = initialize_resizable_array(100); while ((host_tok = threadsafe_tokenizer(&str_ptr, delims)) != NULL) { if ((slash = strchr(host_tok, '/')) != NULL) *slash = '\0'; /* skip this host - the login shouldn't be part of the alps reservation */ if ((strcmp(mom_host, host_tok)) && (strcmp(mom_alias, host_tok))) { if ((prev_host_tok != NULL) && (!strcmp(prev_host_tok, host_tok))) { hr = (host_req *)host_req_list->slots[host_req_list->last].item; hr->ppn += 1; } else { prev_host_tok = host_tok; hr = get_host_req(host_tok); insert_thing(host_req_list, hr); } } } free(exec_hosts); return(host_req_list); } /* END parse_exec_hosts() */
hash_map *get_hash_map( int size_param) { hash_map *hm = calloc(1, sizeof(hash_map)); int size; if (size_param == -1) size = INITIAL_HASH_MAP_SIZE; else size = size_param; hm->hm_ra = initialize_resizable_array(size); hm->hm_ht = create_hash(size); hm->hm_mutex = calloc(1, sizeof(pthread_mutex_t)); pthread_mutex_init(hm->hm_mutex, NULL); return(hm); } /* END get_hash_map() */
resizable_array *sort_exec_hosts( resizable_array *exec_hosts, const char *mppnodes) { if(mppnodes == NULL) { return exec_hosts; } char *tmp = strdup(mppnodes); char *tmp_str = tmp; resizable_array *tmp_host_list = initialize_resizable_array(100); char *tok; int iter; host_req *pHr; while((tok = threadsafe_tokenizer(&tmp_str,",")) != NULL) { iter = -1; while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL) { if(strcmp(pHr->hostname,tok) == 0) { insert_thing(tmp_host_list,pHr); remove_thing(exec_hosts,pHr); break; } } } iter = -1; while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL) { insert_thing(tmp_host_list,pHr); } free_resizable_array(exec_hosts); free(tmp); return tmp_host_list; }
void initialize_all_tasks_array( all_tasks *at) /* O */ { at->ra = initialize_resizable_array(INITIAL_ALL_TASKS_SIZE); if (at->ra == NULL) { log_err(ENOMEM, __func__, "Cannot allocate space for array...FAILURE"); } at->alltasks_mutex = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t)); if (at->alltasks_mutex == NULL) { log_err(ENOMEM, __func__, "Cannot allocate space for mutex...FAILURE"); } else { pthread_mutex_init(at->alltasks_mutex,NULL); } } /* END initialize_all_tasks_array() */
int add_network_entry( mom_hierarchy_t *nt, char *name, struct addrinfo *addr_info, unsigned short rm_port, int path, int level) { int rc; node_comm_t *nc = (node_comm_t *)calloc(1, sizeof(node_comm_t)); resizable_array *levels; resizable_array *node_comm_entries; /* check if the path is already in the array */ if (nt->paths->num > path) levels = (resizable_array *)nt->paths->slots[path+1].item; else { /* insert a new path */ levels = initialize_resizable_array(INITIAL_SIZE_NETWORK); if (levels == NULL) { free(nc); return(-1); } if ((rc = insert_thing(nt->paths,levels)) < 0) { free(nc); return(rc); } } /* check if the level is in the array already */ if (levels->num > level) node_comm_entries = (resizable_array *)levels->slots[level+1].item; else { /* insert a new level */ node_comm_entries = initialize_resizable_array(INITIAL_SIZE_NETWORK); if (node_comm_entries == NULL) return(-1); if ((rc = insert_thing(levels,node_comm_entries)) < 0) { free(nc); return(rc); } } /* finally, insert the entry into the node_comm_entries */ /* initialize the node comm entry */ nc->sock_addr.sin_addr = ((struct sockaddr_in *)addr_info->ai_addr)->sin_addr; nc->sock_addr.sin_family = AF_INET; nc->sock_addr.sin_port = htons(rm_port); nc->stream = -1; if ((nc->name = (char *)calloc(1, strlen(name) + 1)) == NULL) { free(nc); return(ENOMEM); } else strcpy(nc->name,name); if ((rc = insert_thing(node_comm_entries,nc)) < 0) return(rc); else return(PBSE_NONE); } /* END add_network_entry() */