Changeset - 66a0bab210f1
[Not reviewed]
default
0 1 0
LordOfWar - 16 years ago 2009-09-16 22:19:29

created mortition(), compares frames the server has to the frames that are done, and will change the status of any needed frames to \"unassigned\"

went around fixing random warnings, most due to parameters of (**meh) and so I changed the calling functions to (&pointer) which I think was how it supposed to work but I don't know...
1 file changed with 40 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -71,12 +71,13 @@ struct general_info {
 
  internally defined funcs's prototypes
 
*/
 
void distrenjob_remove(struct distrenjob **head, struct distrenjob *bj);
 

	
 
struct distrenjob *distrenjob_get(struct distrenjob *head, jobnum_t jobnum);
 
void distrenjob_enqueue(struct distrenjob *head, struct distrenjob *job);
 
void mortition(struct distrenjob *head, struct distrenjob *job);
 

	
 
/* Global Vars, try to cut down on these */
 
jobnum_t jobnum = 0; // The next job number to create in the queue
 
int hcfjob; // Highest consecutively finished job
 
int highest_jobnum; // The job number of the most recently created job, this is used when creating new jobs
 

	
 
@@ -148,20 +149,51 @@ int start_data(){
 
    return 2;
 
  }
 
  free(&buffer); // @TODO: Is this pointless?
 
}
 

	
 
/** Finish-Setter: Sets a frame to the "completed" status.*/
 
void finish_frame(struct distrenjob *distrenjob, int frame){
 
void finish_frame(struct distrenjob *head, struct distrenjob *distrenjob, int frame){
 
  distrenjob->frameset[frame].status = 2;
 
  distrenjob->frameset[frame].time_to_render = (clock() - distrenjob[jobnum].frameset[frame].start_time); // Consider changing time-to-render to time-for-frame or something?
 
  distrenjob->avg_render_time = ((distrenjob->avg_render_time*(distrenjob->completed_frames - 1)) + distrenjob->frameset[frame].time_to_render)/distrenjob->completed_frames;
 
  distrenjob->avg_render_time = ((distrenjob->avg_render_time*(distrenjob->completed_frames)) + distrenjob->frameset[frame].time_to_render)/(distrenjob->completed_frames + 1);
 
  distrenjob->completed_frames++;
 
  distrenjob->assigned_frames++;
 
  general_info.total_frames_rendered++; // Increase total frames var for stats
 

	
 
  if(distrenjob->completed_frames == distrenjob->total_frames)
 
    {
 
      mortition(head, distrenjob);
 
    }
 
}
 

	
 
/** mortition check to see if a job is actually done by scanning the folder of the job to make sure all frames are present*/
 
// called mortition because it checks the finished "dead" job
 
void mortition(struct distrenjob *head, struct distrenjob *job){
 
  short int isJobDone;
 
  int counter;
 
  char path_and_number[20];
 
  struct stat buffer;
 

	
 
  isJobDone = 1; // set isJobDone to true
 
  for(counter = 0; counter < job->total_frames; counter++)
 
    {
 
      sprintf(path_and_number, "stor/job%d/out/%d.%s", job->jobnum, counter, job->output_format);
 
      if(stat(path_and_number, &buffer) != -1)
 
        {
 
          job->frameset[counter].status = 0;
 
          job->completed_frames--;
 
          isJobDone = 0; // if a missing frame is found, set isJobDone to false
 
        }
 
    }
 

	
 
  if(isJobDone)
 
    {
 
      distrenjob_remove(&head, job);
 
    }
 
}
 

	
 
/**
 
   creates a structure from starting data, then calls another function to actually add that struct to the queue
 
*/
 
void prepare_distrenjob(struct frameset *head, int type, char *name, char *submitter, char *email, int priority, int start_frame, int end_frame)
 
{
 
@@ -172,16 +204,16 @@ void prepare_distrenjob(struct frameset 
 

	
 
  distrenjob->type = 1;
 
  distrenjob->name = name;
 
  distrenjob->submitter = submitter;
 
  distrenjob->email = email;
 
  distrenjob->priority = priority;
 
  distrenjob->frameset = malloc(end_frame - start_frame + 1);
 
  distrenjob->total_frames = (end_frame - start_frame + 1); // sets the total number of frames in animation for status purposes
 
  distrenjob->frameset = malloc(distrenjob->total_frames);
 

	
 
  /* @TODO: what does this do? frameset array is declared above */
 
  /* @TODO: should the aove be malloc(sizeof(struct frameset) * distrenjob->total_frames? */
 
  /*
 
  distrenjob->frameset = malloc(sizeof(struct frameset) * numframes);
 
  if(!job->frameset)
 
    fprintf(stderr, "Error allocating memory\n");
 
  */
 

	
 
@@ -191,38 +223,17 @@ void prepare_distrenjob(struct frameset 
 
    distrenjob->frameset[counter].num = counter2;
 
    distrenjob->frameset[counter].status = 0;
 

	
 
    counter2++;
 
  }
 

	
 
  /* @TODO: change frame_num_struct_builder to add_blendjob_to_queue */
 
  distrenjob_enqueue(head, distrenjob);
 

	
 
  general_info.jobs_in_queue++;
 
}
 

	
 
/** -- OLD -- Queuer: Adds files to the queue
 
int queue(struct distrenjob *distrenjob, int type, char *name, char *submitter, char *email, int priority, int mode, int spp, struct frameset *frameset) {
 
  // Type: 1 = blender, add more types later
 
  // jobnum is the next available job number
 
  if(type == 1){
 
    distrenjob->name = name;
 
    distrenjob->submitter = submitter;
 
    distrenjob->email = email;
 
    distrenjob->priority = priority;
 
    distrenjob->frameset = frameset;
 
  }
 
  else{
 
    // Throw error.
 
    fprintf(stderr,"You tried to queue a job type that isn't supported by this version of DistRen.\nI have no idea how this would happen, but it just did.\n");
 
    return 0; // fail
 
  }
 
jobnum++; // Advance the jobnumber for the next queued job
 
return 0; // OK
 
}*/
 

	
 

	
 
/* distrenjob_enqueue: This function adds the job to the queue based on its priority */
 
void distrenjob_enqueue(struct distrenjob *head, struct distrenjob *job) {
 
  struct distrenjob *prev_job = head; // create pointer to previous job
 
  struct distrenjob *current_job;     // create pointer to current_job (which job is being compared to)
 

	
 
@@ -243,13 +254,13 @@ void distrenjob_enqueue(struct distrenjo
 
}
 

	
 
/**
 
   @arg head I may end up changing the head if job == head
 
 */
 
void change_job_priority(struct distrenjob *head, struct distrenjob *job, int new_priority){
 
  distrenjob_remove(head, job);
 
  distrenjob_remove(&head, job);
 
  job->priority = new_priority;
 
  struct distrenjob *current_job;
 
  struct distrenjob *prev_job = head;
 

	
 
  if(job->frameset[0].status == 0){ // if job was not yet started
 
    distrenjob_enqueue(head, job);
 
@@ -287,43 +298,39 @@ int frame_finder(struct distrenjob *head
 
  int your_frame;  // your_frame is an integer value that will be given to the client as the frame number to render
 
  short int your_job_type;
 
  unsigned short int found;
 

	
 
  struct distrenjob *distrenjob_ptr;
 

	
 
  your_frame = 0;
 
  your_job_type = 0;
 
  found = 0;
 
  /* iterate through jobs from first to last */
 
  for(distrenjob_ptr = head->next; !found && !distrenjob_ptr; distrenjob_ptr = distrenjob_ptr->next)
 
    {
 
      // while frame hasn't been found, and your_frame is less than the length of the frameset array
 
      for(your_frame; !found && your_frame < distrenjob_ptr->total_frames; your_frame++)
 
        {
 
      for(your_frame = 0; !found && your_frame < distrenjob_ptr->total_frames; your_frame++)
 
          if(distrenjob_ptr->frameset[your_frame].status == 0)
 
            {
 
              found = 1;
 
              your_job_type = distrenjob_ptr->type;
 
              distrenjob_ptr->frameset[your_frame].status = 1;
 
              distrenjob_ptr->frameset[your_frame].start_time = clock();
 
              break;
 
            }
 
        }
 
    }
 

	
 

	
 
// end of while statement... job must be found or linked list must be ended to get out of here
 
      if(!found)
 
        {
 
          fprintf(stderr, "No more jobs to render\n");
 
          return 1;
 
        }
 

	
 
    // the actual frame number to be rendered by the client is start_frame + your_frame
 
    *job = distrenjob_ptr;
 
    *frame = distrenjob_ptr->frameset[your_frame];
 
    *frame = &distrenjob_ptr->frameset[your_frame];
 

	
 
      /* should the job be removed now? ANSWER: well, if a computer decides not to return their frame then we lost our data... so its not done yet. */
 
      fprintf(stderr, "Job %d is finished, this is probably the place to call the job-removal function\n", distrenjob_ptr->jobnum);
 
      /* @TODO: At this point, all slaves should be instructed to delete the source data for this job. */
 

	
 
  return 0;
 
@@ -517,13 +524,13 @@ int main(int argc, char *argv[])
 
	    remotio_send_to_client(frame->num, job->jobnum); // Pseudo-sends data to client
 
	}
 

	
 
      /* If the client states that they finished the frame */
 
      	if(clientsays == DISTREN_REQUEST_DONEFRAME){
 
      	  clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle
 
      	  finish_frame(&head, frame->num); // @TODO: Check that finish_frame really gets the jobnum somehow
 
      	  finish_frame(&head, job, frame->num); // @TODO: Check that finish_frame really gets the jobnum somehow (Matt: can we give it the pointer to the job?, if not we can use distrenjob_get(&head, jobnum))
 
      	}
 

	
 
      distrend_action_free(action);
 
    }
 

	
 
  distrend_unlisten(listenset);
0 comments (0 inline, 0 general)