📄 allocations.c
字号:
(void)sprintf(log_buffer, "Error: %s: unable to open %s for read.", id, schd_CurrentFilename); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); } else { linenum = 0; while (fgets(buffer, sizeof buffer, fp)) { ++linenum; ret = sscanf(buffer, "%s %s %d %f", uid, /* user name (string) */ gid, /* group name (string) */ &jobs, /* nbr of jobs */ &nodes_used); /* node-hours */ if (ret != 4) { /* oops */ (void)sprintf(log_buffer,syntax, linenum, schd_CurrentFilename); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); continue; } /* XXX check ranges (esp. signed) on jobs and cpu */ /* Find data for this group in our table */ for (i = 0; i < schd_NumAllocation; ++i) if (!strcmp(schd_GroupTable[i].gname, gid)) break; if (i == schd_NumAllocation) { /* Group not found in table */ (void)sprintf(log_buffer, "Warning: no allocation for %s", gid); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); continue; } /* Add group's "current" usage into the table. */ schd_GroupTable[i].total_usage += nodes_used; } fclose(fp); } schd_NeedToGetYTDInfo = 0; table_modified = 1;skip_ytd_info: if (table_modified) { for (i = 0; i < schd_NumAllocation; i++) { alloc = schd_GroupTable[i].allocation; if (alloc > 0.0) { /* Calculate percentage of allocation used at this point. */ pct = schd_GroupTable[i].total_usage; pct /= alloc; pct *= 100.0; sprintf(used, "%3.2f %%", pct); sprintf(alloc_line, "%.2f", alloc); } else { used[0] = '\0'; if (alloc < 0.0) strcpy(alloc_line, "N/A"); else strcpy(alloc_line, "0.00"); } (void)sprintf(log_buffer, "%s: %-8s Used: %16.4f Allocation: %10s %s", id, schd_GroupTable[i].gname, schd_GroupTable[i].total_usage, alloc_line, used); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); } }}static int cmp_gname(const void *a, const void *b){ Alloc_Group *alloc_group_a; Alloc_Group *alloc_group_b; alloc_group_a = (Alloc_Group *)a; alloc_group_b = (Alloc_Group *)b; return strcmp(alloc_group_a->gname, alloc_group_b->gname);}/* * Check if group has exceeded their allocation. If the group has no * allocations, refuse the job. If they have an unlimited (negative) * allocation, then they have used 0% of their allocations. Otherwise, * return either a '0' -- the group is under allocation, or the integer * percentage they've used so far (i.e. 107 for 107% usage). */int schd_is_over_alloc(char *group){ int percent_used; float alloc, used; /* If the group isn't found in the allocations file, reject the job. */ if (!get_allocation(group, &alloc)) return (100); /* Used 100% of the non-existent allocation. */ /* Negative allocations mean "unlimited usage". Always okay. */ if (alloc < 0.0) return (0); /* * Compute percentage of their allocation that has been used this FY. * If no record is found for usage, they have a zero usage. */ if (!get_FY_used(group, &used)) used = 0.0; percent_used = (int)((used / alloc * 100.0) + 0.5); if (percent_used < 100) return (0); /* Are not over allocation. */ else return (percent_used); /* Return percent allocation used (100+%) */}/* * The group to which this job belongs is over their allocation. Send * the owner of the job a nastygram and ask the JMS to delete the job. */int schd_reject_over_alloc(Job *job){ char *id = "schd_reject_over_alloc"; char buffer[4 * MAX_TXT + 1]; char *unknown = "???"; float alloc, used; char *group; int rc = 0; char *nastygram = "Allocation Exceeded.\n" "\n" "Your PBS job %s would exceed the group\n" "or project allocation given for this operational year.\n" "\n" "This limit has been imposed on you because your group (%s)\n" "has used %3.2f node-hours of its allocation of %3.2f node-hours.\n" "\n" "Please contact the Principal Investigator (PI) for your group\n" "for additional information. The PI should contact their HPCCP\n" "Resource Monitor to apply for an allocation increase.\n" "\n"; /* Get the group's allocation and usage statistics. */ group = (job->group != NULL) ? job->group : unknown; /* * Get the current allocation for this group. If the group does not * have an allocation entry, assume it's zero. */ if (!get_allocation(group, &alloc)) alloc = 0.0; /* * Get the current usage for this group. If the group does not have a * current usage entry, assume it's zero -- a job may never have been * run by this group, if the allocation is 0.0 (not allowed). */ if (!get_FY_used(group, &used)) used = 0.0; /* This should not be called if the group is below its allocation. */ if (used < alloc) { (void)sprintf(log_buffer, "group %s (job %s) below allocation ???", group, job->jobid); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); return (1); } /* * User has used up allocation, so we get to delete this job. But we * need to log the deletion, and notify the user via email why the job * was terminated. Don't perform the deletion if this is a remote job. */ (void)sprintf(log_buffer, "rejecting %s because group %s over allocation (%3.1f/%3.1f)", job->jobid, group, used, alloc); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); DBPRT(("%s: %s\n", id, log_buffer)); sprintf(buffer, nastygram, job->jobid, group, used, alloc); /* * Since the job cannot run inside allocations, delete it. The JMS * will deliver the notification (the string in 'buffer') to the user. */ if (schd_reject_job(job, buffer)) { (void)sprintf(log_buffer, "schd_reject_job failed: %d", rc); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); } return (0);}/* * Look for the total_usage for the requested group. If not found, return * zero. Otherwise, put the usage into *used, and return 1. */static int get_FY_used(char *gname, float *used){ int i; for (i = 0; i < schd_NumAllocation; i++) /* If the right group is found, return the total usage. */ if (!strcmp(schd_GroupTable[i].gname, gname)) { *used = schd_GroupTable[i].total_usage; return (1); } return (0); /* Requested group not found. */}/* * Look for the allocations for the requested group. If not found, return * zero. Otherwise, put the allocation into *alloc, and return 1. */static int get_allocation(char *gname, float *alloc){ int i = 0; for (i = 0; i < schd_NumAllocation; i++) /* If the right group is found, return the allocation. */ if (!strcmp(schd_GroupTable[i].gname, gname)) { *alloc = schd_GroupTable[i].allocation; return (1); } return (0); /* Requested group not found. */}/* * Remove leading and trailing whitespace from a string. Returns a pointer * to the first non-whitespace character in the string and replaces the first * trailing space with a '\0'. Returns an empty string (*p = '\0') if all * whitespace. */static char *trim_whitespace(char *string){ int i; /* Trim off any whitespace on the end of the string. */ for (i = (int)strlen(string) - 1; i >= 0 && isspace((int)string[i]); i--) string[i] = '\0'; /* Find first non-whitespace character in the string. */ for (i = 0; string[i] != '\0'; i++) if (!isspace((int)string[i])) break;; return &string[i];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -