Functions | Variables

agent_scheduler.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include "utility.h"
#include "server.h"
#include "agent.h"
#include "gs_storage.h"
#include "problem.h"
#include "comm_data.h"
Include dependency graph for agent_scheduler.c:

Go to the source code of this file.

Functions

int gs_agent_htm_schedule (gs_problem_t *problem, int num_servers, gs_server_t **server_list)
static int gs_agent_server_compare_function (const void *p1, const void *p2)
 Comparison function for use in sorting.
int gs_agent_scheduler (gs_problem_t *problem, int count, gs_server_t **server_list)
 Sort the list of servers by their complexity score.

Variables

gs_agent_scheduler_t gs_agent_scheduler_selection
int global_taskid
int htm_scheduler_sync

Detailed Description

Handle agent side scheduling.

Definition in file agent_scheduler.c.


Function Documentation

int gs_agent_htm_schedule ( gs_problem_t *  problem,
int  num_servers,
gs_server_t **  server_list 
)

Definition at line 26 of file agent_scheduler.c.

{
  char task_id[TASK_ID_LEN], cid_string[2 * CID_LEN + 1];
  gs_htm_task *t, **tasks = NULL;
  gs_htm_server **sl;
  int i, j, count;
  double start_time;

  sl = (gs_htm_server **)malloc(num_servers * sizeof(gs_htm_server *));

  for(i = 0; i < num_servers; i++) {
    sl[i] = gs_htm_new_empty_server(server_list[i]->componentid, server_list[i]);
    sl[i]->agent_assigned_score = server_list[i]->score;

    proxy_cid_to_str(cid_string, server_list[i]->componentid);

    gs_get_tasks_for_server(cid_string, &tasks, &count, htm_scheduler_sync);

    if(count < 0) {
      ERRPRINTF("failed to get list of all tasks\n");
      return -1;
    }

    for(j=0;j<count;j++)
      gs_htm_add_task(sl[i], tasks[j]);

#ifdef OMIT_GS_DEBUG
    printf("---- task list for server %s: \n", server_list[i]->hostname);
    for(j=0;j<count;j++) {
      printf("id: %s\n", tasks[j]->id);
      printf("  s=%g, d=%g, r=%g, e=%g, a=%d, f=%d\n", tasks[j]->start,
         tasks[j]->duration, tasks[j]->remaining,tasks[j]->end,
         tasks[j]->active, tasks[j]->finished);
    }
    printf("---- end of task list ----\n");
#endif
  }

  sprintf(task_id, DUMMY_TASKID);

  start_time = get_time_since_startup();

  t = gs_htm_new_task(task_id, start_time, sl[0]->agent_assigned_score);

  switch(gs_agent_scheduler_selection) {
    case GS_HTM_ML:
      LOGPRINTF("Scheduling using HTM Minimum Length\n");
      gs_htm_ML(sl, num_servers, t);
      break;
    case GS_HTM_MSF:
      LOGPRINTF("Scheduling using HTM Minimum Sumflow\n");
      gs_htm_MSF(sl, num_servers, t);
      break;
    case GS_HTM_HMCT:
      LOGPRINTF("Scheduling using HTM Historical Minimum Completion Time\n");
      gs_htm_HMCT(sl, num_servers, t);
      break;
    case GS_HTM_MP:
      LOGPRINTF("Scheduling using HTM Minimum Perturbation\n");
      gs_htm_MP(sl, num_servers, t);
      break;
    case GS_DEFAULT_MCT:
    case GS_INVALID_SCHEDULER:
      ERRPRINTF("shouldn't reach here.  invalid scheduler specified.\n");
      ERRPRINTF("scheduler not called.\n");
      break;
  }

  /* now reorder the server list */

  for(i = 0; i < num_servers; i++)
    server_list[i] = sl[i]->sptr;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_agent_scheduler ( gs_problem_t *  problem,
int  count,
gs_server_t **  server_list 
)

Sort the list of servers by their complexity score.

For each server, evaluate its complexity score. Then sort the servers using quicksort and return the server_list sorted.

param problem -- Pointer to the problem data structure param count -- Number of possible servers param server -- Pointer to a list of server data structures

Returns:
0 if OK, -1 on error, with the side effect that the servers in the server list are sorted by their complexity scores

Definition at line 147 of file agent_scheduler.c.

{
  int i;

  /* If 0 or 1 servers, return OK because the list is fine as it is */
  if(count <= 1)
    return 0;

  if(!problem || !server_list) {
    ERRPRINTF("Invalid args\n");
    return -1;
  }

  DBGPRINTF("Generating complexity scores for servers\n");

  for(i = 0; i < count; i++)
    if(server_list[i])
      server_list[i]->score = gs_agent_get_server_score(problem, server_list[i]);

#ifdef OMIT_GS_DEBUG
  DBGPRINTF("Servers before scheduling\n");
  for(i = 0; i < count; i++)
    gs_server_dump(server_list[i]);
#endif

  if(gs_agent_scheduler_selection == GS_DEFAULT_MCT) {
    LOGPRINTF("Using default GridSolve scheduling\n");
    qsort(server_list, count, sizeof(gs_server_t *), 
       gs_agent_server_compare_function);
  }
  else
    gs_agent_htm_schedule(problem, count, server_list);

#ifdef OMIT_GS_DEBUG
  DBGPRINTF("Servers after scheduling\n");
  for(i = 0; i < count; i++)
    gs_server_dump(server_list[i]);
#endif

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int gs_agent_server_compare_function ( const void *  p1,
const void *  p2 
) [static]

Comparison function for use in sorting.

This function is used by quicksort.

Parameters:
p1 -- A pointer to a server structure s1
p2 -- A pointer to a server structure s2
Returns:
1 if s1->score > s2->score, -1 if s1->score < s2->score, 0 otherwise

Definition at line 115 of file agent_scheduler.c.

{
  gs_server_t *s1, *s2;

  if(!p1 || !p2) return 0;

  s1 = *((gs_server_t **) p1);
  s2 = *((gs_server_t **) p2);

  if(s1->score > s2->score)
    return 1;
  if(s1->score < s2->score)
    return -1;

  return 0;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 64 of file agent.c.

gs_agent_scheduler_t gs_agent_scheduler_selection

Definition at line 57 of file agent.c.

Definition at line 65 of file agent.c.