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:
parent
23319c77d2
commit
a2c1631657
@ -91,7 +91,7 @@ int main(int argc, char * argv[])
|
|||||||
s = &files[0];
|
s = &files[0];
|
||||||
t = &files[1];
|
t = &files[1];
|
||||||
pthread_t * threads = new pthread_t[num_threads];
|
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);
|
pthread_barrier_init(&barrier, NULL, num_threads);
|
||||||
|
|
||||||
for (int i = 0; i < num_threads; i++)
|
for (int i = 0; i < num_threads; i++)
|
||||||
@ -124,10 +124,12 @@ bool readFile(char * fileName, vector<char> & v)
|
|||||||
ifstream in(fileName);
|
ifstream in(fileName);
|
||||||
if (!in.is_open())
|
if (!in.is_open())
|
||||||
return false;
|
return false;
|
||||||
while (!in.eof())
|
for(;;)
|
||||||
{
|
{
|
||||||
char chr;
|
char chr;
|
||||||
in >> chr;
|
in >> chr;
|
||||||
|
if (in.eof())
|
||||||
|
break;
|
||||||
v.push_back(chr);
|
v.push_back(chr);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -143,16 +145,16 @@ void * calcSimMatrixThread(void * arg)
|
|||||||
int (*F)[s_size][t_size] = (int (*) [s_size][t_size]) matrix;
|
int (*F)[s_size][t_size] = (int (*) [s_size][t_size]) 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, 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++)
|
for (int i = 0, idx = first_task_id; i < num_tasks; i++, idx++)
|
||||||
(*F)[0][idx] = 0; /* set first row to 0's */
|
(*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++)
|
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 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 */
|
/* Compute the value for the matrix */
|
||||||
(*F)[i][j] =
|
(*F)[i][j] =
|
||||||
@ -160,7 +162,7 @@ void * calcSimMatrixThread(void * arg)
|
|||||||
max(
|
max(
|
||||||
(*F)[i][j-1] - 2,
|
(*F)[i][j-1] - 2,
|
||||||
(*F)[i-1][j-1] +
|
(*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(
|
max(
|
||||||
(*F)[i-1][j] - 2,
|
(*F)[i-1][j] - 2,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user