📄 check.c
字号:
* * res - the resource to check * * returns the available amount of the resource * */sch_resource_t dynamic_avail( resource *res ){ if( res -> max == INFINITY && res -> avail == UNSPECIFIED ) return INFINITY; else return ( res -> avail == UNSPECIFIED ? (res -> max - res -> assigned) : (res -> avail - res -> assigned) );}/* * * count_by_user - count the amount of jobs a user has in a job array * * jobs - job array * user - the username * * returns the count * */int count_by_user( job_info **jobs, char *user ){ int count = 0; /* the accumulator to count the user's jobs */ int i; if( jobs != NULL ) { for( i = 0; jobs[i] != NULL; i++ ) if( !strcmp( user, jobs[i] -> account) ) count++; } return count;}/* * * * count_by_group - count number of jobs a group has in job array * * jobs - array of jobs * group - group name * * returns the count * */int count_by_group( job_info **jobs, char *group ){ int i; int count = 0; /* an accumulator to count the group's jobs */ if( jobs != NULL ) { for( i = 0; jobs[i] != NULL; i++ ) { if( !strcmp( jobs[i] -> group, group ) ) count++; } } return count;}/* * * check_ded_time_boundry - check to see if a job would cross into * dedicated time * * jinfo - the job * * returns 0: will not cross a ded time boundry * CROSS_DED_TIME_BOUNDRY: will cross a ded time boundry * */int check_ded_time_boundry( job_info *jinfo ){ resource_req *res; /* used to get jobs walltime request */ sch_resource_t finish_time; /* the finish time of the job */ if( conf.ded_time[0].from ) { res = find_resource_req(jinfo -> resreq, "walltime"); if( res != NULL ) { finish_time = cstat.current_time + res -> amount; if(!cstat.is_ded_time && finish_time > conf.ded_time[0].from) return CROSS_DED_TIME_BOUNDRY; else if( cstat.is_ded_time && finish_time > conf.ded_time[0].to ) return CROSS_DED_TIME_BOUNDRY; else return 0; } else /* no walltime found for the job. We have to assume it will cross a * dedtime boundry */ return CROSS_DED_TIME_BOUNDRY; } return 0;}/* * * check_nodes - check to see if there is suficient nodes available to * run a job. * * pbs_sd - communication descriptor to the pbs server * jinfo - job to check * ninfo_arr - the node array * * returns 0 if the job can run * NOT_ENOUGH_NODES_AVAIL if the job can not run * SCHD_ERROR on error * */int check_nodes( int pbs_sd, job_info *jinfo, node_info **ninfo_arr ){ resource_req *nodes; /* pointer for the nodes resource requested */ int av; /* are the nodes available */ int al, res, down; /* unused variables passed into pbs_rescquery */ char *node_str; /* pointer to node string */ char *tmp; /* needed to make buf a char ** the call */ char errbuf[256]; int rc; /* return code */ nodes = find_resource_req(jinfo -> resreq, "nodes"); if( nodes != NULL ) { /* pbs_rescquery needs a char ** for its second argument. Since buf is * on the stack &buf == buf. The tmp variable is used to provide the * char ** */ /* 7 = strlen("nodes=") + '\0' */ if( ( node_str = malloc( strlen(nodes -> res_str) + 7 ) ) == NULL ) return SCHD_ERROR; sprintf(node_str, "nodes=%s", nodes -> res_str ); tmp = node_str; if( (rc = pbs_rescquery(pbs_sd, &tmp, 1, &av, &al, &res, &down)) != 0 ) { sprintf(errbuf, "pbs_resquery error: %d", rc); log(PBSEVENT_SYSTEM, PBS_EVENTCLASS_NODE, jinfo -> name, errbuf ); return SCHD_ERROR; } else { /* the requested nodes will never be available */ if( av < 0 ) jinfo -> can_never_run = 1; if( av > 0 ) return 0; else return NOT_ENOUGH_NODES_AVAIL; } } return check_node_availability( jinfo, ninfo_arr );}/* * * check_node_availability - determine that there is a timesharing node * available to run the job * * jinfo - the job to run * ninfo_arr - the array of nodes to check in * * returns * 0: if we are load balancing and there is a node available or * we are not load balancing * NO_AVAILABLE_NODE: if there is no node available to run the job * */int check_node_availability( job_info *jinfo, node_info **ninfo_arr ){ int rc = NO_AVAILABLE_NODE; /* return code */ resource_req *req; /* used to get resource values */ sch_resource_t ncpus; /* number of CPUS job requested */ sch_resource_t mem; /* amount of memory job requested */ char *arch; /* arch the job requested */ char *host; /* host name the job requested */ int i; if( cstat.load_balancing || cstat.load_balancing_rr ) { if( jinfo != NULL && ninfo_arr != NULL ) { if( ( req = find_resource_req( jinfo -> resreq, "ncpus" ) ) == NULL ) ncpus = 1; else ncpus = req -> amount; if( ( req = find_resource_req( jinfo -> resreq, "mem" ) ) == NULL ) mem = 0; else mem = req -> amount; if( ( req = find_resource_req( jinfo -> resreq, "arch" ) ) == NULL ) arch = NULL; else arch = req -> res_str; if( ( req = find_resource_req( jinfo -> resreq, "host" ) ) == NULL ) host = NULL; else host = req -> res_str; for(i = 0; ninfo_arr[i] != NULL && rc != 0; i++) { if( ninfo_arr[i] -> is_free && (host == NULL || !strcmp(host, ninfo_arr[i] -> name) ) && (arch == NULL || !strcmp(arch, ninfo_arr[i] -> arch) ) && mem <= ninfo_arr[i] -> physmem ) { if(ninfo_arr[i] -> loadave + ncpus <= ninfo_arr[i] -> max_load) rc = 0; } } } else rc = 0; /* no nodes */ } else rc = 0; /* we are not load balancing */ return rc;}/* * * check_ded_time_queue - check if it is the approprate time to run jobs * in a dedtime queue * * qinfo - the queue * * returns: * 0: if it is dedtime and qinfo is a dedtime queue or * if it is not dedtime and qinfo is not a dedtime queue * * DED_TIME: if jobs can not run in queue because of dedtime restrictions * */int check_ded_time_queue( queue_info *qinfo ){ int rc = 0; /* return code */ if( cstat.is_ded_time ) { if( qinfo -> dedtime_queue ) rc = 0; else rc = DED_TIME; } else { if( qinfo -> dedtime_queue ) rc = DED_TIME; else rc = 0; } return rc;}/* * * check_queue_max_run - check to see if queues max run has been reached * * qinfo - the queue to check * * returns * 0 : limit has not been reached * QUEUE_JOB_LIMIT_REACHED : limit has been reached * */check_queue_max_run( queue_info *qinfo ){ if( qinfo->max_run == INFINITY ) return 0; else if( qinfo -> max_run > qinfo -> sc.running ) return 0; else return QUEUE_JOB_LIMIT_REACHED;}/* * * check_server_max_run - check to see if the server max_running limit has * been reached * * sinfo - the server to check * * returns * 0: if the limit has not been reached * SERVER_JOB_LIMIT_REACHED: if the limit has been reached * */check_server_max_run( server_info *sinfo ){ if( sinfo -> max_run == INFINITY ) return 0; else if( sinfo -> max_run > sinfo -> sc.running ) return 0; else return SERVER_JOB_LIMIT_REACHED;}/* * * check_starvation - if there is a starving job, don't allow jobs to run * until the starving job runs. * * jinfo - the current job to check * * returns * 0: if the job is the starving job or no jobs are starving * JOB_STARVING: if it is not the starving job * */int check_starvation( job_info *jinfo ){ if( cstat.starving_job == NULL || cstat.starving_job == jinfo ) return 0; else return JOB_STARVING;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -