Changeset - 73e1c0d6e315
[Not reviewed]
default
0 1 0
LordOfWar - 16 years ago 2009-09-16 22:45:54

-fixed a minor error in finish_frame() where the amount of assigned frames was increased 1 instead of decreased 1.
-mortition() now decreases general_info.jobs_in_queue by one if the job is done and it calls distrenjob_remove() to remove the job from the linked list database.
-frame_finder() now increases the amount of assigned_frames by 1 if a frame to render is found
-distrenjob_remove() now decreases the amount of general_info.jobs_in_queue by 1
-prepare_distrenjob() now initializes assigned_frames and completed_frames at 0
1 file changed with 9 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -146,27 +146,29 @@ int start_data(){
 
    general_info.total_finished_jobs = 0;
 
    general_info.total_frames_rendered = 0;
 
    fprintf(stderr,"Can't find XML dump, starting up fresh.\n");
 
    return 2;
 
  }
 
  free(&buffer); // @TODO: Is this pointless?
 
}
 

	
 
/** Finish-Setter: Sets a frame to the "completed" status.*/
 
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?
 
  /* TODO: calculating the average render time like this may have a small amount of error, because the number is truncated to an integer of seconds every time... does it matter? */
 
  /* we could keep track of the total render time... would make calculation a lot easier and more accurate */
 
  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++;
 
  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;
 
@@ -180,45 +182,49 @@ void mortition(struct distrenjob *head, 
 
      sprintf(path_and_number, "stor/job%d/out/%d.%s", job->jobnum, (counter + job->frameset[0].num), 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);
 
      general_info.jobs_in_queue--;
 
    }
 
}
 

	
 
/**
 
   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)
 
{
 
  int counter2;
 
  int counter;
 

	
 
  struct distrenjob *distrenjob;
 

	
 
  distrenjob->type = 1;
 
  distrenjob->name = name;
 
  distrenjob->submitter = submitter;
 
  distrenjob->email = email;
 
  distrenjob->priority = priority;
 
  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);
 

	
 
  distrenjob->assigned_frames = 0;
 
  distrenjob->completed_frames = 0;
 

	
 
  /* @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");
 
  */
 

	
 
  /* prepares all the frames by setting that status to "unassigned" */
 
  counter2 = start_frame;
 
  for(counter = 0; counter <= (end_frame- start_frame + 1); counter++){
 
    distrenjob->frameset[counter].num = counter2;
 
    distrenjob->frameset[counter].status = 0;
 
@@ -305,24 +311,25 @@ int frame_finder(struct distrenjob *head
 
  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 = 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();
 
              distrenjob_ptr->assigned_frames++;
 
              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
 
@@ -399,24 +406,25 @@ void distrenjob_remove(struct distrenjob
 

	
 
      for(previous_distrenjob = *head;
 
        previous_distrenjob
 
          && previous_distrenjob->next != bj; /*< stop on the distrenjob that comes before bj */
 
          previous_distrenjob = previous_distrenjob->next)
 
	/* all of the action is in the definition of the for loop itself */;
 

	
 
      /*
 
	This removes references to bj from the linked list. I.E., we now skip bj when iterating through the list
 
       */
 
      previous_distrenjob->next = bj->next;
 
    }
 
  general_info.jobs_in_queue--;
 
}
 

	
 

	
 
/* Grabs config info from confs */
 
int distrend_do_config(int argc, char *argv[], struct distrend_config **config)
 
{
 
  cfg_opt_t myopts_listen[] =
 
    {
 
      CFG_SIMPLE_STR("type", NULL),
 
      CFG_SIMPLE_STR("path", NULL),
 
      CFG_SIMPLE_INT("port", NULL),
 
      CFG_END()
0 comments (0 inline, 0 general)