⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node_info.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  char errbuf[256];  int i;  if( ninfo != NULL && !ninfo -> is_down )  {    if( ( mom_sd = openrm(ninfo -> name, pbs_rm_port) ) < 0 )    {      log(PBSEVENT_SYSTEM, PBS_EVENTCLASS_REQUEST, ninfo -> name, "Can not open connection to mom");      return 1;    }    for(i = 0; i < num_resget; i++)      addreq(mom_sd, (char *) res_to_get[i]);        for( i = 0; i < num_resget && (mom_ans = getreq(mom_sd)) != NULL; i++ )    {      if( !strcmp(res_to_get[i], "max_load") )      {	testd = strtod(mom_ans, &endp);	if( *endp == '\0' )	  ninfo -> max_load = testd;	else 	  ninfo -> max_load = ninfo -> ncpus;	free(mom_ans);      }      else if( !strcmp(res_to_get[i], "ideal_load") )      {	testd = strtod(mom_ans, &endp);	if( *endp == '\0' )	  ninfo -> ideal_load = testd;	else	  ninfo -> ideal_load = ninfo -> ncpus;	free(mom_ans);      }      else if( !strcmp(res_to_get[i], "arch") )	ninfo -> arch = mom_ans;      else if( !strcmp(res_to_get[i], "ncpus") )      {	testi = strtol(mom_ans, &endp, 10);	if( *endp == '\0' )	  ninfo -> ncpus = testi;	else	  ninfo -> ncpus = 1;	free(mom_ans);      }      else if( !strcmp(res_to_get[i], "physmem") )      {	ninfo -> physmem = res_to_num( mom_ans );	free(mom_ans);      }      else if( !strcmp( res_to_get[i], "loadave") )      {	testd = strtod(mom_ans, &endp);	if( *endp == '\0' )	  ninfo -> loadave = testd;	else 	  ninfo -> loadave = -1.0;	free(mom_ans);      }      else      {	sprintf(errbuf, "Unknown resource value[%d]: %s", i, mom_ans);	log(PBSEVENT_SCHED, PBS_EVENTCLASS_NODE, ninfo -> name, errbuf);      }    }    closerm(mom_sd);  }  return 0;}/* * *	node_filter - filter a node array and return a new filterd array * *	  nodes - the array to filter *	  size  - size of nodes * 	  filter_func - pointer to a function that will filter the nodes *		- returns 1: job will be added to filtered array *		- returns 0: job will NOT be added to filtered array *	  arg - an optional arg passed to filter_func * *	returns pointer to filtered array * *	filter_func prototype: int func( node_info *, void * ) * */node_info **node_filter( node_info **nodes, int size, 			 int (*filter_func) (node_info*, void*), void *arg ){  node_info **new_nodes = NULL;			/* the new node array */  int i, j;  if( ( new_nodes = (node_info **) malloc( ( size + 1) * sizeof( node_info *) ) ) == NULL )  {    perror("Memory Allocation Error");    return NULL;  }  for(i = 0, j = 0; i < size; i++)  {    if( filter_func( nodes[i], arg) )    {      new_nodes[j] = nodes[i];      j++;    }  }  new_nodes[j] = NULL;  if( j == 0 )  {    free(new_nodes);    new_nodes = NULL;  }  else if( (new_nodes = realloc(new_nodes, (j+1) * sizeof( node_info * ) ) ) == NULL)  {    perror( "Memory Allocation Error" );    free(new_nodes);  }  return new_nodes;}/* * *      is_node_timeshared - check if a node is timeshared * *        node - node to check *        arg  - unused argument * *      returns  *        1: is a timeshared node *        0: is not a timeshared node * *      NOTE: this function used for node_filter * */int is_node_timeshared( node_info *node, void *arg ){  if( node != NULL )    return node -> is_timeshare;  return 0;} /* * *	find_best_node - find the best node to run a job * *	  jinfo - the job to run *	  ninfo_arr - array of nodes to find the best of * *	returns the node to run the job on * */node_info *find_best_node( job_info *jinfo, node_info **ninfo_arr ){  node_info *possible_node = NULL;	/* node which under max node not ideal*/  node_info *good_node = NULL;		/* node which is under ideal load */  resource_req *req;			/* used to find requested resources */  sch_resource_t ncpus;			/* used for number of CPUS on nodes */  sch_resource_t mem;			/* used for memory on the nodes */  char *arch;				/* used for the architecture of nodes */  char *host;				/* used for the node name */  int i, c;				/* index & loop vars */  int ln_i;				/* index of the last node in ninfo_arr*/  float good_node_la = 1.0e10;		/* the best load ave found yet */  float proj_la;			/* the projected load average */  char logbuf[256];			/* buffer for log messages */  /* name of the last node a job ran on - used in load balance round robin */  static char last_node_name[PBS_MAXSVRJOBID];  if( ninfo_arr == NULL || jinfo == NULL )    return NULL;    /* if the job is requesting nodes, then don't try and load balance it */  if( find_resource_req( jinfo -> resreq, "nodes" ) != NULL )    return 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;  if( last_node_name[0] == '\0' && ninfo_arr[0] != NULL )    strcpy(last_node_name, ninfo_arr[0] -> name);  if( cstat.load_balancing_rr )  {    log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_NODE, last_node_name, "Last node a job was run on");    /* find the node we last ran a job on */    for(ln_i = 0; ninfo_arr[ln_i] != NULL &&     	strcmp(ninfo_arr[ln_i] -> name, last_node_name); ln_i++)      ;    /* if the last node has been deleted since the last scheduling cycle */    if( ninfo_arr[ln_i] == NULL )    {      strcpy(last_node_name, ninfo_arr[0] -> name);      ln_i = 0;    }    /* if the last node is at the end of the list, cycle back to the front */    else if( ninfo_arr[ln_i+1] == NULL)      i = 0;    /* start one after the last node */    else      i = ln_i + 1;  }   else  {    i = 0;    ln_i = jinfo -> queue -> server -> num_nodes;  }  for( c = 0; c < jinfo -> queue -> server -> num_nodes; c++ )  {    /* if the job didn't specify memory, it will default to 0, and if      * the mom didn't return physmem, it defaults to 0.     */    if( ninfo_arr[i] -> is_free  &&	(arch == NULL || !strcmp(arch, ninfo_arr[i] -> arch)) &&	(host == NULL || !strcmp(host, ninfo_arr[i] -> name)) &&	mem <= ninfo_arr[i] -> physmem )    {      proj_la = ninfo_arr[i] -> loadave + ncpus;      if(cstat.load_balancing)      {	if(proj_la <= ninfo_arr[i] -> ideal_load) 	{	  if(ninfo_arr[i] -> loadave < good_node_la) 	  {	    sprintf(logbuf, "Possible low-loaded node load: %6.2f proj load: %6.2f ideal_load: %6.2f last good ideal: %6.2f", ninfo_arr[i] -> loadave, proj_la, ninfo_arr[i] -> ideal_load, good_node_la);	    good_node = ninfo_arr[i];	    good_node_la = ninfo_arr[i] -> loadave;	  }	  else	    sprintf(logbuf, "Node Rejected, Load higher then last possible node: load: %6.2f last good ideal: %6.2f", ninfo_arr[i] -> loadave, good_node_la);	} 	else if( possible_node == NULL && proj_la <= ninfo_arr[i] -> max_load)	{	  if(ninfo_arr[i] -> loadave < good_node_la) 	  {	    sprintf(logbuf, "Possible medium-loaded node load: %6.2f max_load: %6.2f proj load: %6.2f last good ideal: %6.2f", ninfo_arr[i] -> loadave, ninfo_arr[i] -> max_load, proj_la, good_node_la);	    possible_node = ninfo_arr[i];	    good_node_la = ninfo_arr[i] -> loadave;	  }	  else	    sprintf(logbuf, "Node Rejected, Load higher then last possible node: load: %6.2f last good ideal: %6.2f", ninfo_arr[i] -> loadave, good_node_la);	}	else	  sprintf(logbuf, "Node Rejected, Load too high: load: %6.2f proj load: %6.2f max_load: %6.2f", ninfo_arr[i] -> loadave, proj_la, ninfo_arr[i] -> max_load);      }      else       {	if( ninfo_arr[i] -> loadave + proj_la  < ninfo_arr[i] -> max_load )	{	  good_node = ninfo_arr[i];	  break;	}	else	  sprintf(logbuf, "Node Rejected, Load too high: load: %6.2f proj load: %6.2f max_load: %6.2f", ninfo_arr[i] -> loadave, proj_la, ninfo_arr[i] -> max_load);      }    }    else      sprintf(logbuf, "Node Rejected, node does not fit job requirements.");    log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_NODE, ninfo_arr[i] -> name, logbuf);    logbuf[0] = '\0';    i++;    if( ninfo_arr[i] == NULL )      i = 0;  }  if( good_node == NULL )  {    if( cstat.load_balancing_rr )      strcpy(last_node_name, possible_node -> name);    log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_NODE, possible_node -> name, "Node Chosen to run job on");    return possible_node;  }  else  {    if( cstat.load_balancing_rr )      strcpy(last_node_name, good_node -> name);    log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_NODE, good_node -> name, "Node Chosen to run job on");    return good_node;  }  return NULL;		/* should never get here */}/* * *	find_node_info - find a node in a node array * *	  nodename - the node to find *	  ninfo_arr - the array of nodes to look in * *	returns the node or NULL of not found * */node_info *find_node_info( char *nodename, node_info **ninfo_arr ){  int i;  if( nodename != NULL && ninfo_arr != NULL )  {    for(i = 0; ninfo_arr[i] != NULL &&     				strcmp(ninfo_arr[i] -> name, nodename); i++)      ;    return ninfo_arr[i];  }  return NULL;}/* * *	print_node - print all the information in a node.  Mainly used for  * 		     debugging purposes  * *	  ninfo - the node to print *	  brief - boolean: only print the name ? * *	returns nothing * */void print_node( node_info *ninfo, int brief ){  int i;  if( ninfo != NULL )  {    if( ninfo -> name != NULL )      printf("Node: %s\n", ninfo -> name);        if( !brief )    {      printf("is_down: %s\n", ninfo -> is_down ? "TRUE" : "FALSE");      printf("is_free: %s\n", ninfo -> is_free ? "TRUE" : "FALSE");       printf("is_offline: %s\n", ninfo -> is_offline ? "TRUE" : "FALSE");       printf("is_unknown: %s\n", ninfo -> is_unknown ? "TRUE" : "FALSE");       printf("is_reserved: %s\n", ninfo -> is_reserved ? "TRUE" : "FALSE");       printf("is_exclusive: %s\n", ninfo -> is_exclusive ? "TRUE" : "FALSE");       printf("is_sharing: %s\n", ninfo -> is_sharing ? "TRUE" : "FALSE");       printf("is_timeshare: %s\n", ninfo -> is_timeshare ? "TRUE" : "FALSE");       printf("is_cluster: %s\n", ninfo -> is_cluster ? "TRUE" : "FALSE");       if( ninfo -> properties != NULL )      {	printf("Properties: ");	for( i = 0; ninfo -> properties[i] != NULL; i++ )	{	  if( i )	    printf(", ");	  printf("%s", ninfo -> properties[i]);	}	printf("\n");      }      if( ninfo -> jobs != NULL )      {	printf("Running Jobs: ");	for( i = 0; ninfo -> jobs[i] != NULL; i++ )	{	  if( i )	    printf(", ");	  printf("%s", ninfo -> jobs[i]);	}      }    }  }}	  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -