#include #include #include #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" #include "bqp_data.h" #include "BQP.h" #define DEBUG 1 CCTK_INT BQP_GetResources(CCTK_INT * NumRes, char * ResNames, char * Separator) { int rc, i, numres; /* bqp_res is a struct (see bqp.h) which defines a 'resource' for the api. */ bqp_res *theres; /* the first thing we may want to do is get a list of supported machines and queues. after bqp_get_resources completes, 'theres' will be an array of bqp_res structs */ rc = bqp_get_resources(&theres, &numres); if (rc <= 0) { CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "ERROR: bqp_get_resources %d", rc); return rc; } (*NumRes) = numres; for (i=0; i BestPrediction) { BestMachine = i; BestQueue = j; BestPrediction = prediction; } } } strcpy(ResName, theres[BestMachine].resource); strcpy(Queue, theres[BestMachine].queues[BestQueue]); (*Prediction) = BestPrediction; return 0; } CCTK_INT BQP_GetBestFromList(char *MachineNameList, char *Seperator, CCTK_INT NodeCount, CCTK_INT RequiredTime, CCTK_INT Deadline, char *ResName, char *Queue, CCTK_REAL* Prediction) { int rc, i, j, numres; int BestMachine, BestQueue; CCTK_REAL prediction, BestPrediction=0; char *tempMachine = NULL; /* bqp_res is a struct (see bqp.h) which defines a 'resource' for the api. */ bqp_res *theres; /* the first thing we may want to do is get a list of supported machines and queues. after bqp_get_resources completes, 'theres' will be an array of bqp_res structs */ rc = bqp_get_resources(&theres, &numres); if (rc <= 0) { CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "ERROR: bqp_get_resources %d\n", rc); return -1; } tempMachine = strtok(MachineNameList, Seperator); while(tempMachine!=NULL) { for (i=0; i BestPrediction) { BestMachine = i; BestQueue = j; BestPrediction = prediction; } } } } tempMachine = strtok(NULL, Seperator); } strcpy(ResName, theres[BestMachine].resource); strcpy(Queue, theres[BestMachine].queues[BestQueue]); (*Prediction) = BestPrediction; return 0; } CCTK_INT BQP_GetTimeInQueue(char *MachineNameList, char *Seperator, CCTK_INT NodeCount, CCTK_INT RequiredTime, char *ResName, char *Queue, CCTK_INT *TimeInQueue) { int rc, i, j, numres; int BestMachine, BestQueue, BestTimeInQueue=1024; CCTK_REAL prediction, BestPrediction=0; CCTK_INT Deadline = 0; char *tempMachine = NULL; /* bqp_res is a struct (see bqp.h) which defines a 'resource' for the api. */ bqp_res *theres; /* the first thing we may want to do is get a list of supported machines and queues. after bqp_get_resources completes, 'theres' will be an array of bqp_res structs */ rc = bqp_get_resources(&theres, &numres); if (rc <= 0) { CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, "ERROR: bqp_get_resources %d\n", rc); return -1; } tempMachine = strtok(MachineNameList, Seperator); while(tempMachine!=NULL) { for (i=0; i=0.8) break; } #ifdef DEBUG printf("\t value of prediction is:%f\n",prediction); #endif if (Deadline < BestTimeInQueue) { BestMachine = i; BestQueue = j; BestPrediction = prediction; (*TimeInQueue)=Deadline; } } } } tempMachine = strtok(NULL, Seperator); } strcpy(ResName, theres[BestMachine].resource); strcpy(Queue, theres[BestMachine].queues[BestQueue]); return 0; }