Changeset - f44df7a5711b
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-07-12 20:56:07
ohnobinki@ohnopublishing.net
added global variable named general_info
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
/*
 
  Copyright 2009 Nathan Phillip Brink, Ethan Zonca, Matthew Orlando
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
/* This file contains the code which both processes (renders) jobs as a slave, and the code which distributes frames to slaves after receiving them from the client portion of the codebase. */
 

	
 
 /* Just some notes -- Ethan Zonca
 
 * ++ Make data availible for other apps to parse
 
 * Server<==>Client Communication
 
 * Upload while rendering
 
 */
 

	
 

	
 
#include "execio.h"
 
#include "options.h"
 
#include <confuse.h>
 
#include <stdio.h>
 
#include <malloc.h>
 
#include <unistd.h> /* getopt */
 
#include <time.h>
 

	
 

	
 
#define MAX_BLENDJOBS 100 // maximum number of stored jobs in memory, per job type (lux/blend). Eventually we can dump this data to disk, or atleast the remainder not in memory...
 

	
 
/* internally defined funcs */
 
void status_report_generator();
 

	
 

	
 
// Global Vars, try to cut down on these
 
int jobnum = 0; // The next job number to create in the queue
 
int hcfjob; // Highest consecutively finished job
 
int highest_jobnum; // The job number of the most recently created job, this is used when creating new jobs
 

	
 
/* ******************* Structs ************************ */
 

	
 
// Stores config info? editmycomment
 
struct distrend_config
 
{
 
  cfg_t *mycfg;
 
  struct options_common *options;
 
  struct distrend_listen **listens; /*< Null terminated array of structs */
 
};
 

	
 

	
 

	
 
/*
 
 frame[frame] Status Assignments:
 
  "NULL" - don't render me
 
  "0" - canceled
 
  "1" - unassigned
 
  "2" - assigned to slave
 
  "3" - completed by slave and uploaded
 

	
 
 Have a script crawl through each job in the arrays, priority-biased, and assign a frame to each slave.
 
 Then we will need some sort of watchdog to monitor slaves on the main server to check for stales. Maybe not worry about this for now.
 
*/
 

	
 
struct general_info {
 
	short int jobs_in_queue; //
 
	unsigned short int free_clients;
 
	unsigned short int rendering_clients;//
 
	unsigned short int total_finished_jobs; //
 
	unsigned int total_frames_rendered; //
 
};
 
} general_info;
 

	
 
// 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 jobnum, int frame){
 
  blendjob[jobnum].frameset[frame].frame_status = 2;
 

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

	
 
  general_info.total_frames_rendered++;
 
}
 

	
 

	
 
// **** 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;
 
    blendjob[jobnum].frameset = frameset;
 
  }
 
  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
 
// 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
 
	unsigned short int workers_working; // used to count the total number of workers working
 

	
 

	
 
	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[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[num1].frameset[num2].frame_status == 1){ // If the frame is assigned
 
						pending_frames++;
 
						workers_working++;
 
					}
 
					num2++;
 
				}
 

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