fixed Makefile, added task distribution logic to threaded

git-svn-id: svn://anubis/gvsu@177 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-09-27 15:29:52 +00:00
parent 1c3b6ac652
commit b59e2667c1
2 changed files with 37 additions and 7 deletions

View File

@ -11,7 +11,7 @@ test: all
./sequential e1.* ./sequential e1.*
./threaded e1.* ./threaded e1.*
./sequential e2.* ./sequential e2.*
./sequential e2.* ./threaded e2.*
clean: clean:
-rm -f $(PROGS) *~ *.o -rm -f $(PROGS) *~ *.o

View File

@ -143,7 +143,7 @@ void * calcSimMatrixThread(void * arg)
int s_size = s->size(); int s_size = s->size();
int t_size = t->size(); int t_size = t->size();
int last_step = s_size + t_size; int last_step = s_size + t_size;
int (*F)[s_size][t_size] = (int (*) [s_size][t_size]) matrix; int (*F)[s_size+1][t_size+1] = (int (*) [s_size+1][t_size+1]) matrix;
int max_x = 0, max_y = 0, max_val = 0; int max_x = 0, max_y = 0, max_val = 0;
int first_task_id, num_tasks; int first_task_id, num_tasks;
taskAllocate(t_size+1, num_threads, id, &first_task_id, &num_tasks); taskAllocate(t_size+1, num_threads, id, &first_task_id, &num_tasks);
@ -153,13 +153,32 @@ void * calcSimMatrixThread(void * arg)
for (int i = 0, idx = first_task_id; i < num_tasks; i++, idx++) for (int i = 0, idx = first_task_id; i < num_tasks; i++, idx++)
(*F)[idx][0] = 0; /* set first column to 0's */ (*F)[idx][0] = 0; /* set first column to 0's */
pthread_barrier_wait(&barrier); pthread_barrier_wait(&barrier);
for (int step = 2; i <= last_step; i++) for (int step = 2; step <= last_step; step++)
{ {
/* TODO: figure out how many tasks there are in this step */ int first_i = step - 1;
/* TODO: call taskAllocate() to get mine */ int first_j = 1;
/* TODO: loop over tasks assigned by taskAllocate() */ int last_i = 1;
int last_j = step - 1;
if (first_i > s_size)
{
first_j += (first_i - s_size);
first_i = s_size;
}
if (last_j > t_size)
{
last_i += (last_j - t_size);
last_j = t_size;
}
num_tasks = (last_j - first_j) + 1;
taskAllocate(num_tasks, num_threads, id, &first_task_id, &num_tasks);
for (int i = first_i - first_task_id,
j = first_j + first_task_id,
task_id = 0;
task_id < num_tasks;
i--,
j++,
task_id++)
{ {
/* TODO: figure out i, j from step and task */
/* Compute the value for the matrix */ /* Compute the value for the matrix */
(*F)[i][j] = (*F)[i][j] =
max( max(
@ -194,6 +213,17 @@ void * calcSimMatrixThread(void * arg)
pthread_barrier_wait(&barrier); pthread_barrier_wait(&barrier);
} }
#if 0
cout << "Matrix: " << s_size+1 << " x " << t_size+1 << endl;
for (int i = 0; i <= s_size; i++)
{
for (int j = 0; j <= t_size; j++)
{
printf("%2d ", (*F)[i][j]);
}
printf("\n");
}
#endif
cout << "Maximum value is " << max_val << " at position (" cout << "Maximum value is " << max_val << " at position ("
<< max_x << ", " << max_y << ")" << endl; << max_x << ", " << max_y << ")" << endl;