IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 4, 2005, 5:35:47 PM (21 years ago)
Author:
eugene
Message:

substantial dev work on scheduler/pcontrol/pclient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pantasks/JobOps.c

    r3140 r4450  
    1 # include "opihi.h"
    21# include "scheduler.h"
    32
     
    98
    109static Job *jobs;
    11 static int   Njobs;
    12 static int   NJOBS;
     10static int  Njobs;
     11static int  NJOBS;
    1312
    1413static char *JobName = dot;
     
    6564
    6665  for (i = 0; i < Njobs; i++) {
    67     fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i].task.name, jobs[i].JobID, jobs[i].task.argv[0], jobs[i].task.argv);
     66    fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i].task[0].name, jobs[i].JobID, jobs[i].argv[0], jobs[i].argv);
    6867  }
    6968  return;
     
    7574  int i;
    7675
    77   /* try for an exact match first */
     76  /* return job with matching JobID */
    7877  for (i = 0; i < Njobs; i++) {
    7978    if (jobs[i].JobID == JobID) {
     
    9089
    9190  jobs[Njobs].JobID = NextJobID ();
    92   jobs[Njobs].PID = 0;
    93   jobs[Njobs].task = task[0];
    94 
    95   /* we need our own copy of task[0].argv */
    96   ALLOCATE (jobs[Njobs].task.argv, char *, MAX (jobs[Njobs].task.argc, 1));
    97   for (i = 0; i < jobs[Njobs].task.argc; i++) {
    98     jobs[Njobs].task.argv[i] = strcreate (task[0].argv[i]);
    99   }
    100   jobs[Njobs].task.host = strcreate (task[0].host);
     91  jobs[Njobs].pid = 0;
     92  jobs[Njobs].mode = JOB_LOCAL;
     93  if (task[0].host != NULL) {
     94    jobs[Njobs].mode = JOB_CONTROLLER;
     95  }
     96
     97  /* we need our own copy of task[0].argv
     98   *  argc is the number of valid args, like the usual command line.
     99   *  we allocate one extra element, with value 0 to be passed to execvp
     100   */
     101  jobs[Njobs].argc = task[0].argc;
     102  ALLOCATE (jobs[Njobs].argv, char *, MAX (task[0].argc + 1, 1));
     103  for (i = 0; i < task[0].argc; i++) {
     104    jobs[Njobs].argv[i] = strcreate (task[0].argv[i]);
     105  }
     106  jobs[Njobs].argv[i] = 0;
     107
     108  /* other data from the task is needed by the job
     109     we carry a pointer back to the task.  this means we
     110     cannot modify the task once a job is created, or the changes will
     111     be applied to the existing jobs */
     112
     113  jobs[Njobs].task = task;
     114 
     115  /* if we decide we need to be able to dynamically set task qualities
     116     (like host, timeouts, etc), the we will need to have matched
     117     entries to these quantites in the job structure */
    101118
    102119  Njobs ++;
     
    108125}
    109126
     127void FreeJob (Job *job) {
     128 
     129  int i;
     130
     131  if (job == NULL) return;
     132
     133  if ((job[0].JobID >= 0) || (job[0].JobID < MAX_N_JOBS)) {
     134    JobIDList[job[0].JobID] = FALSE;
     135  }
     136
     137  for (i = 0; i < job[0].argc; i++) {
     138    free (job[0].argv[i]);
     139  }
     140  free (job[0].argv);
     141  return;
     142}
     143
    110144void SetCurrentJob (char *name) {
    111145  JobName = name;
     
    114148char *GetCurrentJob () {
    115149  return (JobName);
    116 }
    117 
    118 void FreeJob (Job *job) {
    119  
    120   int i;
    121 
    122   if (job == NULL) return;
    123 
    124   if ((job[0].JobID >= 0) || (job[0].JobID < MAX_N_JOBS)) {
    125     JobIDList[job[0].JobID] = FALSE;
    126   }
    127 
    128   for (i = 0; i < job[0].task.argc; i++) {
    129     free (job[0].task.argv[i]);
    130   }
    131   free (job[0].task.argv);
    132   free (job[0].task.host);
    133   return;
    134150}
    135151
     
    161177}
    162178
    163 /* this needs to:
    164    1) distinguish local from controller jobs
    165    2) fork the local jobs in the background
    166    3) send the controller jobs to the controller */
    167 
    168179int SubmitJob (Job *job) {
    169180
    170   int i, Nchar;
    171   char *string;
    172 
    173   Nchar = 0;
    174   for (i = 0; i < job[0].task.argc; i++) {
    175     Nchar += strlen (job[0].task.argv[i]) + 1;
    176   }
    177   ALLOCATE (string, char, Nchar);
    178   bzero (string, Nchar);
    179 
    180   strcat (string, job[0].task.argv[0]);
    181   for (i = 1; i < job[0].task.argc; i++) {
    182     strcat (string, " ");
    183     strcat (string, job[0].task.argv[i]);
    184   }
    185  
    186   fprintf (stderr, "executing job %d ...%s...\n", job[0].JobID, string);
    187   free (string);
     181  if (job[0].mode == JOB_LOCAL) {
     182    SubmitLocalJob (job);
     183  } else {
     184    SubmitControllerJob (job);
     185  }
    188186
    189187  /* reset clock for start and poll-test */
     
    196194int CheckJob (Job *job) {
    197195
    198   float f;
    199   f = drand48 ();
    200 
    201   if ((0.00 < f) && (f < 0.25)) {
    202     job[0].state = JOB_BUSY;
    203     job[0].exit_status = -1;
    204     return (JOB_BUSY);
    205   }
    206   if ((0.25 < f) && (f < 0.50)) {
    207     job[0].state = JOB_BUSY;
    208     job[0].exit_status = -1;
    209     return (JOB_CRASH);
    210   }
    211   if ((0.50 < f) && (f < 0.75)) {
    212     job[0].state = JOB_BUSY;
    213     job[0].exit_status = 0;
    214     return (JOB_EXIT);
    215   }
    216   if ((0.75 < f) && (f < 1.00)) {
    217     job[0].state = JOB_BUSY;
    218     job[0].exit_status = 1;
    219     return (JOB_EXIT);
    220   }
    221 }
     196  /* add checks for timeouts */
     197
     198  if (job[0].mode == JOB_LOCAL) {
     199    CheckLocalJob (job);
     200  } else {
     201    CheckControllerJob (job);
     202  }
     203  return (job[0].state);
     204}
Note: See TracChangeset for help on using the changeset viewer.