Changeset - 6b468a948714
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-07-15 11:22:14
ohnobinki@ohnopublishing.net
struct blendjob*-ized blend_frame_watchdog()
1 file changed with 19 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -215,208 +215,215 @@ void status_report_generator(struct blen
 
	    {
 
	      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 startframe, unsigned int numframes) {
 
  int jobnum_new = highest_jobnum + 1; /* global vars will someday leave us  */
 
  unsigned int counter;
 

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

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

	
 
	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 + 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
 
void blend_frame_watchdog(struct blendjob *blendjob_head)
 
{
 
  unsigned short int watchdog_forgiveness; /*< seconds to wait on a frame before re-assigning it */
 
  struct blendjob *blendjob_ptr;
 
  unsigned int counter;
 

	
 
  int num1 = hcfjob + 1;
 
  watchdog_forgiveness = 3 * 60 * 60; /*< 3hr in seconds */
 
  blendjob_ptr = blendjob_head;
 

	
 
  while(num1 <= highest_jobnum){  // counts up through all the jobs
 
    int num2 = 0;
 
  for(blendjob_ptr = blendjob_head; blendjob_ptr; blendjob_ptr = blendjob_ptr->next)
 
    /* iterate through jobs */
 

	
 
    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
 
    for(counter = 0; counter < blendjob_ptr->total_frames; counter ++)
 
      /* iterate through all frames for this job*/
 
      {
 
	if((blendjob_ptr->frameset[counter].start_time + (watchdog_forgiveness * 3600)) < clock()) 
 
	  /*
 
	    If frame is not completed within the number of hours specified by watchdog_forgiveness 
 
	    Then change the frame status to unassigned
 
	  */
 
	  blendjob_ptr->frameset[counter].frame_status = 0;
 
      }
 

	
 
      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;
 
	           case 'c':
 
	             cvalue = optarg;
 
	             break;
 
	           case '?':
 
	             if (optopt == 'c')
 
	               fprintf (stderr, "Option -%c requires an argument.\n", optopt);
 
	             else if (isprint (optopt))
 
	               fprintf (stderr, "Unknown option `-%c'.\n", optopt);
 
	             else
 
	               fprintf (stderr,
 
	                        "Unknown option character `\\x%x'.\n",
 
	                        optopt);
 
	             return 1;
 
	           default:
 
	             abort ();
 
	           }
 

	
 
	       printf ("aflag = %d, bflag = %d, cvalue = %s\n",
 
	               aflag, bflag, cvalue);
 

	
 
	       for (index = optind; index < argc; index++)
 
	         printf ("Non-option argument %s\n", argv[index]);
 
//// End getopt sample
 

	
 

	
 
// Just wrote this to try and piece everything together after writing it on paper :D --ethanzonca
 
///////////////////// Semi-pseudo-code for server //////////////////////////////////////////
 
/*
 

	
 
start_data();
 
status_report_generator();
 
blend_frame_watchdog();
 

	
 
	if(client says "i ain't got nuthin to render!"){
 
		frame_finder() ==> returns jobnum/framenum that are sent to slave, "render jobnum framenum"
 
	}
 
	if(client says "done with frame # in job #"){
 
		finish_frame(jobnum, frame);
 
		frame_finder() ==> returns jobnum/framenum that are sent to slave, "render jobnum framenum"
 
	}
 

	
 
*/
 
///////////////////////////////////////////////////////////////////////////////////////
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 
// Begin non-working framework?
 
	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()
 
	  };
 
	  cfg_opt_t myopts[] =
 
	    {
 
	      CFG_SEC("listen",  /* this must be imported into struct listens (which must still be declared) */
 
		      myopts_listen
 
		      ,
 
		      CFGF_MULTI),
 
	      CFG_END()
 
	    };
 

	
 
	  config = malloc(sizeof(struct distrend_config));
 
	  options_init(argc, argv, &config->mycfg, myopts, "server", &config->options);
0 comments (0 inline, 0 general)