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
 
@@ -74,6 +74,7 @@ void distrenjob_remove(struct distrenjob
 

	
 
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
 
@@ -151,14 +152,45 @@ int start_data(){
 
}
 

	
 
/** 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
 
@@ -175,10 +207,10 @@ void prepare_distrenjob(struct frameset 
 
  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)
 
@@ -194,32 +226,11 @@ void prepare_distrenjob(struct frameset 
 
    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) {
 
@@ -246,7 +257,7 @@ 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;
 
@@ -290,15 +301,13 @@ int frame_finder(struct distrenjob *head
 

	
 
  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;
 
@@ -308,8 +317,6 @@ int frame_finder(struct distrenjob *head
 
              break;
 
            }
 
        }
 
    }
 

	
 

	
 
// end of while statement... job must be found or linked list must be ended to get out of here
 
      if(!found)
 
@@ -320,7 +327,7 @@ int frame_finder(struct distrenjob *head
 

	
 
    // 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);
 
@@ -520,7 +527,7 @@ int main(int argc, char *argv[])
 
      /* 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);
0 comments (0 inline, 0 general)