finally got pointer syntax correct for F pointing to a common multi-dim array
git-svn-id: svn://anubis/gvsu@166 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
5696656386
commit
86e44617bf
@ -20,12 +20,15 @@ typedef struct
|
||||
vector<char> * s;
|
||||
vector<char> * t;
|
||||
int id;
|
||||
void * matrix;
|
||||
} SMArg;
|
||||
|
||||
void usage(char * prog);
|
||||
void * similarityMatrix(void * arg);
|
||||
void * calcSimMatrixThread(void * arg);
|
||||
bool readFile(char * fileName, vector<char> & v);
|
||||
|
||||
pthread_barrier_t barrier;
|
||||
|
||||
/* Print basic usage information */
|
||||
void usage(char * prog)
|
||||
{
|
||||
@ -62,6 +65,8 @@ int main(int argc, char * argv[])
|
||||
usage(argv[0]);
|
||||
|
||||
pthread_t * threads = new pthread_t[num_threads];
|
||||
int * similarityMatrix = new int[files[0].size() * files[1].size()];
|
||||
pthread_barrier_init(&barrier, NULL, num_threads);
|
||||
|
||||
for (int i = 0; i < num_threads; i++)
|
||||
{
|
||||
@ -69,8 +74,9 @@ int main(int argc, char * argv[])
|
||||
arg->s = &files[0];
|
||||
arg->t = &files[1];
|
||||
arg->id = i;
|
||||
arg->matrix = similarityMatrix;
|
||||
|
||||
int ret = pthread_create(&threads[i], NULL, &similarityMatrix, arg);
|
||||
int ret = pthread_create(&threads[i], NULL, &calcSimMatrixThread, arg);
|
||||
if (ret)
|
||||
{
|
||||
cerr << "Error " << ret << " when creating thread!" << endl;
|
||||
@ -83,6 +89,8 @@ int main(int argc, char * argv[])
|
||||
pthread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
pthread_barrier_destroy(&barrier);
|
||||
|
||||
delete[] threads;
|
||||
return 0;
|
||||
}
|
||||
@ -102,43 +110,43 @@ bool readFile(char * fileName, vector<char> & v)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Compute the similarity matrix between two character arrays */
|
||||
void * similarityMatrix(void * arg)
|
||||
/* Compute portions of the similarity matrix between two character arrays */
|
||||
void * calcSimMatrixThread(void * arg)
|
||||
{
|
||||
SMArg * smarg = (SMArg *) arg;
|
||||
int s_size = smarg->s->size();
|
||||
int t_size = smarg->t->size();
|
||||
int F[s_size][t_size];
|
||||
int (*F)[s_size][t_size] = (int (*) [s_size][t_size]) smarg->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;
|
||||
(*F)[0][i] = 0;
|
||||
for (int i = 0; i < s_size; i++) /* set first column to 0's */
|
||||
F[i][0] = 0;
|
||||
(*F)[i][0] = 0;
|
||||
for (int i = 1; i < s_size; i++)
|
||||
{
|
||||
for (int j = 1; j < t_size; j++)
|
||||
{
|
||||
/* Compute the value for the matrix */
|
||||
F[i][j] =
|
||||
(*F)[i][j] =
|
||||
max(
|
||||
max(
|
||||
F[i][j-1] - 2,
|
||||
F[i-1][j-1] +
|
||||
(*F)[i][j-1] - 2,
|
||||
(*F)[i-1][j-1] +
|
||||
(eq(smarg->s->at(i), smarg->t->at(j)) ? 1 : -1)
|
||||
),
|
||||
max(
|
||||
F[i-1][j] - 2,
|
||||
(*F)[i-1][j] - 2,
|
||||
0
|
||||
)
|
||||
);
|
||||
/* See if we found a new maximum value */
|
||||
if (F[i][j] > max_val)
|
||||
if ((*F)[i][j] > max_val)
|
||||
{
|
||||
max_val = F[i][j];
|
||||
max_val = (*F)[i][j];
|
||||
max_x = i;
|
||||
max_y = j;
|
||||
}
|
||||
else if (F[i][j] == max_val)
|
||||
else if ((*F)[i][j] == max_val)
|
||||
{
|
||||
/* If we found a value the same as our current maximum
|
||||
* value, see if it has a greater i+j value */
|
||||
|
Loading…
x
Reference in New Issue
Block a user