Changeset - 5a6af7ed2d6f
[Not reviewed]
default
0 1 0
NEO - 16 years ago 2009-07-12 04:54:30

-added clock_t start_time; to frameset structure
-added int time_to_render; to frameset structure
-added unsigned int time_remaining; to blendjob structure
-added int avg_render_time; to blendjob structure

-added statement to frame_finder() function to add the start time of the frame to the frameset structure
-added statement to finish_frame() function to find the seconds it took the frame to render
-added statements to status_report_generator() to find the average render time per frame and estimated remaining time for each job
-added comments to status_report_generator()

-added entire blend_frame_watchdog() fucntion

- I will debug it tomorrow, its 5am as of this commit
1 file changed with 41 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -73,44 +73,51 @@ struct distrend_config
 

	
 

	
 
// Stores Blender Job Info
 
struct blendjob {
 
  char *name;
 
  char *submitter;
 
  char *email;
 
  int priority;  // 1 is lowest, 10 is highest, 0 is done
 
  int percent_done;
 
  int completed_frames; // number of completed frames for stats/etc
 
  int assigned_frames; // number of assigned frames (that are not yet completed) for stats/etc
 
  int total_frames; // how many frames are in the animation for stats/etc
 
  int avg_render_time; // average seconds it took to render a frame
 
  unsigned int time_remaining; // estimated seconds remaining till render is complete (up to 49, 710 days)
 
							   // we can have the client computer convert it into days, hours, etc if they wish to view it
 
  struct frameset *frameset;
 
} blendjob[MAX_BLENDJOBS];
 

	
 

	
 
// Frameset Structure
 
struct frameset {
 
	int frame_num; // frame number to render
 
	char slave_name; // user that frame is assigned to
 
	int frame_status; // status of frame, 0= unassigned, 1= taken, 2= done
 
	clock_t start_time; // time the frame was started
 
	int time_to_render; // the total seconds it took to render the frame
 
} frameset[]; // Frameset array is generated by status_report_generator function
 
                         // Using this method to save memory, because if animation starts on a high frame number, it would waste a lot of RAM on empty structures
 

	
 

	
 

	
 

	
 
/* ********************** Functions ************************* */
 

	
 
// **** Finish-Setter: Sets a frame to the "completed" status.
 
void finish_frame(int frame){
 
void finish_frame(int jobnum, int frame){
 
  blendjob[jobnum].frameset[frame].frame_status = 2;
 

	
 
  blendjob[jobnum].frameset[frame].time_to_render = (clock() - blendjob[jobnum].frameset[frame].start_time);
 
}
 

	
 

	
 
// **** Queuer: Adds files to the queue
 
void queue(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){
 
    blendjob[jobnum].name = name;
 
    blendjob[jobnum].submitter = submitter;
 
    blendjob[jobnum].email = email;
 
    blendjob[jobnum].priority = priority;
 
@@ -122,53 +129,63 @@ void queue(int type, char *name, char *s
 
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
 
// This uses pointers, so when it is run it updates certain values in memory
 
void status_report_generator(){
 

	
 
	while(blendjob[(hcfjob+1)].priority == 0)  //If the job after the highest consecutively finished job is finished
 
		hcfjob++;  // adds 1 to the highest consecutively finished job and checks the next one, till the job after the hcfjob is not done
 

	
 
	int num1 = hcfjob+1; // to scan through jobs
 
	int num2 = 0;		 // to scan through frames
 

	
 

	
 
	while(num1 <= highest_jobnum){
 
			if(blendjob[num1].priority != 0){ // If the job is not done, scan it
 

	
 
				int num2 = 0;  // to scan through frames
 
				float finished_frames = 0; // variable that counts the completed frames
 
				int pending_frames = 0; // variable that counts the assigned frames
 
				float percent = 0;  // variable that stores the percent done of the blendjob
 
				unsigned int total_time = 0;  // total time taken to render all the completed frames for a job
 

	
 
				while(num2 <= blendjob[jobnum].total_frames){ // If
 
					if(blendjob[jobnum].frameset[num2].frame_status == 2)
 
				while(num2 <= blendjob[num1].total_frames){ // scans through frames, based on their status it runs a statement(s)
 
					if(blendjob[num1].frameset[num2].frame_status == 2){ // If the frame is done
 
						finished_frames++;
 
						total_time = total_time + blendjob[num1].frameset[num2].time_to_render;
 
					}
 

	
 
					if(blendjob[jobnum].frameset[num2].frame_status == 1)
 
					if(blendjob[num1].frameset[num2].frame_status == 1) // If the frame is assigned
 
						pending_frames++;
 

	
 
					num2++;
 
				}
 

	
 
				// find the percent of completed frames
 
				percent = (finished_frames / blendjob[num1].total_frames) * 100;
 

	
 
				// updates values in the blendjob struct for jobnum held by the variable num1
 
				blendjob[num1].completed_frames = finished_frames;
 
				blendjob[num1].assigned_frames = pending_frames;
 
				blendjob[num1].percent_done = percent;
 
				blendjob[num1].avg_render_time = (total_time / finished_frames);
 
				blendjob[num1].time_remaining = (blendjob[num1].avg_render_time * (blendjob[num1].total_frames - finished_frames));
 

	
 
				if(finished_frames == blendjob[num1].total_frames)  // If all frames are complete, set priority to zero to indicate job is complete
 
					blendjob[num1].priority = 0;
 
			}
 

	
 
			num1++;
 
		}
 

	
 
	}
 

	
 

	
 
// **** 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(int sframe, int eframe) {
 
	int jobnum_new = highest_jobnum + 1;
 
	int total = (sframe - eframe) +1;  // total number of frames
 
	int fcount = sframe; // Used to create all the frames in the structure from sframe to eframe
 
	int x = 0;
 

	
 
	blendjob[jobnum_new].total_frames = total; // sets the total number of frames in animation for status purposes
 

	
 
@@ -217,28 +234,46 @@ int frame_finder(){
 
			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
 
		   int aflag = 0;
 
	       int bflag = 0;
 
	       char *cvalue = NULL;
 
	       int index;
 
	       int c;
0 comments (0 inline, 0 general)