Changeset - d246f9d7e4fb
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-07-15 11:13:16
ohnobinki@ohnopublishing.net
fixed frame numbering in frame_num_struct_builder()
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -146,206 +146,206 @@ void queue(struct blendjob *blendjob, in
 
  else{
 
    // Throw error.
 
  }
 
jobnum++; // Advance the jobnumber for the next queued job
 
}
 

	
 

	
 
/*
 
  Status Report Generator: figures out how much of the job is done, where jobnum corresponds to the job number
 
*/
 
void status_report_generator(struct blendjob *blendjobs_head)
 
{
 
  struct blendjob *blendjob_ptr;
 
  unsigned short workers_working; /*< used to count the total number of workers working */
 
  unsigned int numjobs; /*< used to track number of jobs */
 

	
 
  blendjob_ptr = blendjobs_head;
 
  workers_working = 0;
 
  numjobs = 0;
 
  
 
  while(blendjob_ptr)
 
    {
 
      if(blendjob_ptr->priority != 0)
 
	/* If the job is not done, scan it */
 
	{
 
	  unsigned int framecounter;  /*< to scan through frames */
 
	  unsigned long finished_frames; /*< variable that counts the completed frames */
 
	  unsigned int pending_frames; /*< variable that counts the assigned frames */
 
	  float percent_frames_finished;  /*< variable that stores the percent done of the blendjob */
 
	  unsigned int total_time;  /*< total time taken to render all the completed frames for a job */
 

	
 
	  framecounter = 0;
 
	  finished_frames = 0;
 
	  pending_frames = 0;
 
	  percent_frames_finished = 0;
 
	  total_time = 0;
 

	
 
	  while(framecounter < blendjob_ptr->total_frames)
 
	    /* scans through frames, based on their status it runs a statement(s) */
 
	    {
 
	      if(blendjob_ptr->frameset[framecounter].frame_status == 2)
 
		/* If the frame is done */
 
		{
 
		  finished_frames ++;
 
		  total_time += blendjob_ptr->frameset[framecounter].time_to_render;
 
		}
 
	      
 
	      if(blendjob_ptr->frameset[framecounter].frame_status == 1)
 
		/* If the frame is assigned */
 
		{
 
		  pending_frames ++;
 
		  workers_working ++;
 
		}
 
	      
 
	      framecounter ++;
 
	    } /* while(framecounter < blendjob_ptr->total_frames) */
 

	
 
	  // find the percent of completed frames
 
	  percent_frames_finished = (finished_frames / blendjob_ptr->total_frames) * 100; /*< @LordofWar: extraneous parentheses! */
 

	
 
	  /* updates values in the blendjob struct */
 
	  blendjob_ptr->completed_frames = finished_frames;
 
	  blendjob_ptr->assigned_frames = pending_frames;
 
	  blendjob_ptr->percent_done = percent_frames_finished;
 
	  blendjob_ptr->avg_render_time = (total_time / finished_frames); /*< extraneous parentheses! */
 
	  blendjob_ptr->time_remaining = (blendjob_ptr->avg_render_time * (blendjob_ptr->total_frames - finished_frames)); /*< extraneous parentheses! */
 

	
 
	  if(finished_frames == blendjob_ptr->total_frames)
 
	    /* If all frames are complete */
 
	    {
 
	      blendjob_ptr->priority = 0; /*< set priority to zero to indicate job is complete */
 
	      general_info.total_finished_jobs++; /*< add one to the total finished jobs */
 
	      
 
	    }
 
	  else if (finished_frames > blendjob_ptr->total_frames)
 
	    /* just in case ;-) */
 
	    {
 
	      fprintf(stderr, "%s:%d: finished_frames (%lu) > blendjob_ptr->total_frames (%d)",
 
		      __FILE__, __LINE__, 
 
		      finished_frames, 
 
		      blendjob_ptr->total_frames);
 
	      abort();
 
	    }
 
	}
 

	
 
      general_info.rendering_clients = workers_working; /*< should this be a +=? */
 
      
 
      blendjob_ptr = blendjob_ptr->next; /*< This is the essence of linked lists and iterating through them */
 
      numjobs ++;
 
    } /* while(blendjob_ptr) */
 
  
 
  general_info.jobs_in_queue = (highest_jobnum - general_info.total_finished_jobs); /*< extraneous parentheses! */
 
}
 

	
 

	
 
// **** Structure Builder: This function creates frame array based on the total number of frames to be rendered, which will then be parsed by function frame_farmer.
 
void frame_num_struct_builder(struct blendjob *job, unsigned int numframes) {
 
void frame_num_struct_builder(struct blendjob *job, unsigned int startframe, unsigned int numframes) {
 
  int jobnum_new = highest_jobnum + 1; /* global vars will someday leave us  */
 
	int counter;
 
  unsigned int counter;
 

	
 
	job->frameset = malloc(sizeof(struct frameset) * numframes);
 
	if(!job->frameset)
 
	  fprintf(stderr, "error allocating memory");
 

	
 
	job->total_frames = total; // sets the total number of frames in animation for status purposes
 
	job->total_frames = numframes; // sets the total number of frames in animation for status purposes
 
	job->jobnum = jobnum_new;
 

	
 
	for(counter = 0; counter < total; counter ++)
 
	for(counter = 0; counter < numframes; counter ++)
 
	  /* This builds the array, with the array starting at zero and the frame_num starting at sframe */
 
	  job->frameset[counter].frame_num = counter + 1;
 
	  job->frameset[counter].frame_num = counter + startframe;
 

	
 
	highest_jobnum++; // After it has created the job, it adds one to the highest_jobnum interger
 
}
 

	
 

	
 

	
 
// Frame Assigner: matches your computer up with a lovely frame to render
 
// Major issue here, the client needs to know the frame number, AND the job number!
 
int frame_finder(){
 
	int your_frame = 0;  // your_frame is an interger value that will be given to the client as the frame number to render
 
	int finder_jobnum = 0;
 
	int frameset_count = 0; // the frameset number, note* frames in an animation don't start at zero
 
	short int done = 0;
 
	short int priority = 10;
 

	
 
	while(priority >= 1){ // start the scan for the next job with the highest priority, decreases priority before it loops
 
		finder_jobnum = hcfjob + 1; // reset it to start scanning at first uncompleted job for the pass at each priority level
 

	
 
		while(finder_jobnum <= highest_jobnum){  // This keeps increasing the finder_jobnum until it is higher than the highest_jobnum
 
			if(blendjob[finder_jobnum].priority == priority){  // looks for a job with the current priority value
 
				done = 1;									  // notice it starts by looking at the oldest job first
 
				break;
 
			}
 

	
 
			if((done) == 1)  // If it has found a job with the current priority value, it will break out of the loop
 
				break;    // If none is found it goes to the next job to see if it is of the current priority value
 
			else
 
				finder_jobnum++;
 
		} // End of increasing finder_jobnum
 

	
 
		if(done == 1) // if job has been found, it lets it out of the priority changer loop
 
			break;
 

	
 
		priority--; // end of decreasing priority
 
	}
 

	
 
	while(your_frame < blendjob[finder_jobnum].total_frames){ // Finds the frameset number with a frame that needs to be rendered
 
		if (blendjob[finder_jobnum].frameset[frameset_count].frame_status == 0)  // If frame that is not assigned has been found, frameset_count is not changed
 
			break;																// and frameset_count is used to give the frame number later in this funciton
 

	
 
		frameset_count++;  // If frame is assigned or done, it goes to next frame
 
	}
 

	
 
blendjob[jobnum].frameset[frameset_count].frame_status++; // sets the value of the frame to 2, which means its taken
 

	
 
your_frame = blendjob[jobnum].frameset[frameset_count].frame_num; //  Takes the frameset found in the while statement above, and extracts the frame number from it and assigns it to the int your_frame
 

	
 
if(your_frame == 0)  // If that job had no open frames for some reason, run the status report generator so that
 
	status_report_generator();  //the job priority can be changed to 0
 

	
 
blendjob[jobnum].frameset[frameset_count].start_time = clock();
 

	
 
return your_frame; // your_frame is returned as the frame to be rendered
 
}
 

	
 
void blend_frame_watchdog(){
 
  short int watchdog_forgiveness = 3; // Hours to wait on a frame before re-assigning it
 

	
 
  int num1 = hcfjob + 1;
 

	
 
  while(num1 <= highest_jobnum){  // counts up through all the jobs
 
    int num2 = 0;
 

	
 
    while(num2 <= blendjob[num1].total_frames){ // Counts up through all the frames
 
      if((blendjob[num1].frameset[num2].start_time + (watchdog_forgiveness * 3600)) < clock()) // If frame is not completed within the number of hours specified by watchdog_forgiveness
 
			  blendjob[num1].frameset[num2].frame_status = 0;								   // Then change the frame status to unassigned
 

	
 
      num2++;
 
    }
 
    num1++;
 
  }
 
}
 

	
 

	
 
/* ************************** Main ************************* */
 

	
 
int main(int argc, char *argv[])
 
{
 
//// Begin Getopt Sample, EDITME!Sometime
 
		   int aflag = 0;
 
	       int bflag = 0;
 
	       char *cvalue = NULL;
 
	       int index;
 
	       int c;
 

	
 
	       opterr = 0;
 

	
 
	       while ((c = getopt (argc, argv, "abc:")) != -1)
 
	         switch (c)
 
	           {
 
	           case 'a':
 
	             aflag = 1;
 
	             break;
 
	           case 'b':
 
	             bflag = 1;
 
	             break;
0 comments (0 inline, 0 general)