added taskAllocate() function to assign tasks to workers based on id
git-svn-id: svn://anubis/gvsu@168 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
c452c1eecb
commit
744e2ad392
@ -32,6 +32,34 @@ void usage(char * prog)
|
|||||||
exit(42);
|
exit(42);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* taskAllocate() will divide a set of total_tasks tasks into
|
||||||
|
* total_workers groups, as evenly as possible
|
||||||
|
* Parameters:
|
||||||
|
* total_tasks : IN : the total number of tasks to divide up
|
||||||
|
* total_workers : IN : the total number of workers to allocate tasks to (>0)
|
||||||
|
* this_id : IN : the id (base 0) of the task calling us for work
|
||||||
|
* first_task_id : OUT : the id (base 0) of the first task for this worker
|
||||||
|
* num : OUT : the number of tasks assigned to this worker
|
||||||
|
*/
|
||||||
|
inline void taskAllocate(int total_tasks, int total_workers, int this_id,
|
||||||
|
int * first_task_id, int * num)
|
||||||
|
{
|
||||||
|
int l_num;
|
||||||
|
int leftovers = total_tasks % total_workers; /* num of "leftover" tasks */
|
||||||
|
if (this_id < leftovers)
|
||||||
|
{
|
||||||
|
l_num = total_tasks / total_workers + 1; /* do one of the leftovers */
|
||||||
|
*first_task_id = l_num * this_id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l_num = total_tasks / total_workers;
|
||||||
|
*first_task_id = l_num * this_id + leftovers;
|
||||||
|
}
|
||||||
|
*num = l_num;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
vector<char> files[2];
|
vector<char> files[2];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user