fixed threaded version to read file correctly and match examples

git-svn-id: svn://anubis/gvsu@175 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-09-27 14:25:57 +00:00
parent 23319c77d2
commit a2c1631657

View File

@ -91,7 +91,7 @@ int main(int argc, char * argv[])
s = &files[0];
t = &files[1];
pthread_t * threads = new pthread_t[num_threads];
matrix = new int[files[0].size() * files[1].size()];
matrix = new int[(files[0].size() + 1) * (files[1].size() + 1)];
pthread_barrier_init(&barrier, NULL, num_threads);
for (int i = 0; i < num_threads; i++)
@ -124,10 +124,12 @@ bool readFile(char * fileName, vector<char> & v)
ifstream in(fileName);
if (!in.is_open())
return false;
while (!in.eof())
for(;;)
{
char chr;
in >> chr;
if (in.eof())
break;
v.push_back(chr);
}
return true;
@ -143,16 +145,16 @@ void * calcSimMatrixThread(void * arg)
int (*F)[s_size][t_size] = (int (*) [s_size][t_size]) matrix;
int max_x = 0, max_y = 0, max_val = 0;
int first_task_id, num_tasks;
taskAllocate(t_size, num_threads, id, &first_task_id, &num_tasks);
taskAllocate(t_size+1, 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);
taskAllocate(s_size+1, num_threads, id, &first_task_id, &num_tasks);
for (int i = 0, idx = first_task_id; i < num_tasks; i++, idx++)
(*F)[idx][0] = 0; /* set first column to 0's */
pthread_barrier_wait(&barrier);
for (int i = 1; i < s_size; i++)
for (int i = 1; i <= s_size; i++)
{
for (int j = 1; j < t_size; j++)
for (int j = 1; j <= t_size; j++)
{
/* Compute the value for the matrix */
(*F)[i][j] =
@ -160,7 +162,7 @@ void * calcSimMatrixThread(void * arg)
max(
(*F)[i][j-1] - 2,
(*F)[i-1][j-1] +
(eq(s->at(i), t->at(j)) ? 1 : -1)
(eq(s->at(i-1), t->at(j-1)) ? 1 : -1)
),
max(
(*F)[i-1][j] - 2,