parallelized initialization of the first row and first column of the matrix

git-svn-id: svn://anubis/gvsu@169 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-09-26 17:35:56 +00:00
parent 744e2ad392
commit 79d3a53fd1

View File

@ -88,8 +88,6 @@ int main(int argc, char * argv[])
if (file_to_read != 2)
usage(argv[0]);
s = &files[0];
t = &files[1];
pthread_t * threads = new pthread_t[num_threads];
matrix = new int[files[0].size() * files[1].size()];
pthread_barrier_init(&barrier, NULL, num_threads);
@ -139,10 +137,18 @@ void * calcSimMatrixThread(void * arg)
int t_size = t->size();
int (*F)[s_size][t_size] = (int (*) [s_size][t_size]) matrix;
int max_x = 0, max_y = 0, max_val = 0;
for (int i = 0; i < t_size; i++) /* set first row to 0's */
(*F)[0][i] = 0;
for (int i = 0; i < s_size; i++) /* set first column to 0's */
(*F)[i][0] = 0;
int first_task_id, num_tasks;
taskAllocate(t_size, num_threads, id, &first_task_id, &num_tasks);
for (int i = 0, idx = first_task_id;
i < num_tasks;
i++, idx++)
(*F)[0][idx] = 0; /* set first row to 0's */
taskAllocate(s_size, num_threads, id, &first_task_id, &num_tasks);
for (int i = 0, idx = first_task_id;
i < num_tasks;
i++, idx++) /* set first column to 0's */
(*F)[idx][0] = 0;
pthread_barrier_wait(&barrier);
for (int i = 1; i < s_size; i++)
{
for (int j = 1; j < t_size; j++)