00001
00007
00008
00009
00010
00011 #include <stdlib.h>
00012 #include <stdio.h>
00013
00014 #include "utility.h"
00015 #include "server.h"
00016 #include "agent.h"
00017 #include "gs_storage.h"
00018 #include "problem.h"
00019 #include "comm_data.h"
00020
00021 extern gs_agent_scheduler_t gs_agent_scheduler_selection;
00022 extern int global_taskid;
00023 extern int htm_scheduler_sync;
00024
00025 int
00026 gs_agent_htm_schedule(gs_problem_t * problem, int num_servers,
00027 gs_server_t ** server_list)
00028 {
00029 char task_id[TASK_ID_LEN], cid_string[2 * CID_LEN + 1];
00030 gs_htm_task *t, **tasks = NULL;
00031 gs_htm_server **sl;
00032 int i, j, count;
00033 double start_time;
00034
00035 sl = (gs_htm_server **)malloc(num_servers * sizeof(gs_htm_server *));
00036
00037 for(i = 0; i < num_servers; i++) {
00038 sl[i] = gs_htm_new_empty_server(server_list[i]->componentid, server_list[i]);
00039 sl[i]->agent_assigned_score = server_list[i]->score;
00040
00041 proxy_cid_to_str(cid_string, server_list[i]->componentid);
00042
00043 gs_get_tasks_for_server(cid_string, &tasks, &count, htm_scheduler_sync);
00044
00045 if(count < 0) {
00046 ERRPRINTF("failed to get list of all tasks\n");
00047 return -1;
00048 }
00049
00050 for(j=0;j<count;j++)
00051 gs_htm_add_task(sl[i], tasks[j]);
00052
00053 #ifdef OMIT_GS_DEBUG
00054 printf("---- task list for server %s: \n", server_list[i]->hostname);
00055 for(j=0;j<count;j++) {
00056 printf("id: %s\n", tasks[j]->id);
00057 printf(" s=%g, d=%g, r=%g, e=%g, a=%d, f=%d\n", tasks[j]->start,
00058 tasks[j]->duration, tasks[j]->remaining,tasks[j]->end,
00059 tasks[j]->active, tasks[j]->finished);
00060 }
00061 printf("---- end of task list ----\n");
00062 #endif
00063 }
00064
00065 sprintf(task_id, DUMMY_TASKID);
00066
00067 start_time = get_time_since_startup();
00068
00069 t = gs_htm_new_task(task_id, start_time, sl[0]->agent_assigned_score);
00070
00071 switch(gs_agent_scheduler_selection) {
00072 case GS_HTM_ML:
00073 LOGPRINTF("Scheduling using HTM Minimum Length\n");
00074 gs_htm_ML(sl, num_servers, t);
00075 break;
00076 case GS_HTM_MSF:
00077 LOGPRINTF("Scheduling using HTM Minimum Sumflow\n");
00078 gs_htm_MSF(sl, num_servers, t);
00079 break;
00080 case GS_HTM_HMCT:
00081 LOGPRINTF("Scheduling using HTM Historical Minimum Completion Time\n");
00082 gs_htm_HMCT(sl, num_servers, t);
00083 break;
00084 case GS_HTM_MP:
00085 LOGPRINTF("Scheduling using HTM Minimum Perturbation\n");
00086 gs_htm_MP(sl, num_servers, t);
00087 break;
00088 case GS_DEFAULT_MCT:
00089 case GS_INVALID_SCHEDULER:
00090 ERRPRINTF("shouldn't reach here. invalid scheduler specified.\n");
00091 ERRPRINTF("scheduler not called.\n");
00092 break;
00093 }
00094
00095
00096
00097 for(i = 0; i < num_servers; i++)
00098 server_list[i] = sl[i]->sptr;
00099
00100 return 0;
00101 }
00102
00114 static int
00115 gs_agent_server_compare_function(const void *p1, const void *p2)
00116 {
00117 gs_server_t *s1, *s2;
00118
00119 if(!p1 || !p2) return 0;
00120
00121 s1 = *((gs_server_t **) p1);
00122 s2 = *((gs_server_t **) p2);
00123
00124 if(s1->score > s2->score)
00125 return 1;
00126 if(s1->score < s2->score)
00127 return -1;
00128
00129 return 0;
00130 }
00131
00146 int
00147 gs_agent_scheduler(gs_problem_t * problem, int count,
00148 gs_server_t ** server_list)
00149 {
00150 int i;
00151
00152
00153 if(count <= 1)
00154 return 0;
00155
00156 if(!problem || !server_list) {
00157 ERRPRINTF("Invalid args\n");
00158 return -1;
00159 }
00160
00161 DBGPRINTF("Generating complexity scores for servers\n");
00162
00163 for(i = 0; i < count; i++)
00164 if(server_list[i])
00165 server_list[i]->score = gs_agent_get_server_score(problem, server_list[i]);
00166
00167 #ifdef OMIT_GS_DEBUG
00168 DBGPRINTF("Servers before scheduling\n");
00169 for(i = 0; i < count; i++)
00170 gs_server_dump(server_list[i]);
00171 #endif
00172
00173 if(gs_agent_scheduler_selection == GS_DEFAULT_MCT) {
00174 LOGPRINTF("Using default GridSolve scheduling\n");
00175 qsort(server_list, count, sizeof(gs_server_t *),
00176 gs_agent_server_compare_function);
00177 }
00178 else
00179 gs_agent_htm_schedule(problem, count, server_list);
00180
00181 #ifdef OMIT_GS_DEBUG
00182 DBGPRINTF("Servers after scheduling\n");
00183 for(i = 0; i < count; i++)
00184 gs_server_dump(server_list[i]);
00185 #endif
00186
00187 return 0;
00188 }