END_TEST START_TEST(set_ngpus_test) { struct pbsnode pnode; memset(&pnode, 0, sizeof(pnode)); fail_unless(set_ngpus(&pnode, 2) == 0, "Couldn't set ngpus to 2"); snprintf(buf, sizeof(buf), "ngpus should be 2 but id %d", pnode.nd_ngpus); fail_unless(pnode.nd_ngpus == 2, buf); pnode.nd_ngpus = 0; fail_unless(set_ngpus(&pnode, 4) == 0, "Couldn't set ngpus to 4"); snprintf(buf, sizeof(buf), "ngpus should be 4 but id %d", pnode.nd_ngpus); fail_unless(pnode.nd_ngpus == 4, buf); pnode.nd_ngpus = 0; fail_unless(set_ngpus(&pnode, 8) == 0, "Couldn't set ngpus to 8"); snprintf(buf, sizeof(buf), "ngpus should be 8 but id %d", pnode.nd_ngpus); fail_unless(pnode.nd_ngpus == 8, buf); }
int process_gpu_status( struct pbsnode *pnode, unsigned int &i, std::vector<std::string> &status_info) { pbs_attribute temp; int gpu_count = 0; int rc = PBSE_NONE; char buf[MAXLINE * 2]; std::string gpu_info = ""; memset(&temp, 0, sizeof(temp)); if ((rc = decode_arst(&temp, NULL, NULL, NULL, 0)) != PBSE_NONE) { log_record(PBSEVENT_DEBUG, PBS_EVENTCLASS_NODE, __func__, "cannot initialize attribute"); finish_gpu_status(i, status_info); return(rc); } /* move past the initial gpu status */ i++; for (; i < status_info.size(); i++) { if (!strcmp(status_info[i].c_str(), CRAY_GPU_STATUS_END)) break; if (!strncmp(status_info[i].c_str(), "gpu_id=", strlen("gpu_id="))) { snprintf(buf, sizeof(buf), "gpu[%d]=%s;", gpu_count, status_info[i].c_str()); gpu_info += buf; gpu_count++; } else { gpu_info += status_info[i].c_str(); gpu_info += ';'; } } set_ngpus(pnode, gpu_count); decode_arst(&temp, NULL, NULL, gpu_info.c_str(), 0); node_gpustatus_list(&temp, pnode, ATR_ACTION_ALTER); free_arst(&temp); return(rc); } /* END process_gpu_status() */
int process_gpu_status( struct pbsnode *pnode, char **str_ptr) { char *str = *str_ptr; pbs_attribute temp; int gpu_count = 0; int rc; char buf[MAXLINE * 2]; dynamic_string *gpu_info; memset(&temp, 0, sizeof(temp)); if ((gpu_info = get_dynamic_string(-1, NULL)) == NULL) { *str_ptr = finish_gpu_status(str); return(ENOMEM); } if ((rc = decode_arst(&temp, NULL, NULL, NULL, 0)) != PBSE_NONE) { log_record(PBSEVENT_DEBUG, PBS_EVENTCLASS_NODE, __func__, "cannot initialize attribute"); *str_ptr = finish_gpu_status(str); free_dynamic_string(gpu_info); return(rc); } /* move past the initial gpu status */ str += strlen(str) + 1; for (; str != NULL && *str != '\0'; str += strlen(str) + 1) { if (!strcmp(str, CRAY_GPU_STATUS_END)) break; if (!strncmp(str, "gpu_id=", strlen("gpu_id="))) { snprintf(buf, sizeof(buf), "gpu[%d]=%s;", gpu_count, str); rc = append_dynamic_string(gpu_info, buf); gpu_count++; } else { rc = append_dynamic_string(gpu_info, str); rc = append_char_to_dynamic_string(gpu_info, ';'); } if (rc != PBSE_NONE) { free_dynamic_string(gpu_info); *str_ptr = finish_gpu_status(str); return(rc); } } set_ngpus(pnode, gpu_count); decode_arst(&temp, NULL, NULL, gpu_info->str, 0); node_gpustatus_list(&temp, pnode, ATR_ACTION_ALTER); free_arst(&temp); free_dynamic_string(gpu_info); *str_ptr = str; return(PBSE_NONE); } /* END process_gpu_status() */