Code:
void *alignDNS(void *t){
long tid;
tid = (long)t;
//TO DO: int division check intervalls
int tInterval = 1+(rows/2)/NUM_THREADS;
int myStart, myEnd;
myStart = tInterval*(int)tid;
myEnd = myStart+tInterval;
int myHits[tInterval];
int i;
string temp;
for (vector<string>::size_type i = myStart; i <= myEnd; i++) {
if(ref.find(searchVector.at(i)) != std::string::npos){
printf("FRONT : My id: %d, myStart: %d, myEnd: %d, Sträng: \n", tid, myStart, myEnd, searchVector.at(i).c_str() );
myHits[i] = ref.find(searchVector.at(i));
} else if (ref.find(reverseString(searchVector.at(i))) != std::string::npos ){
printf("BACKWARD: My id: %d, myStart: %d, myEnd: %d, Sträng: \n", tid, myStart, myEnd, searchVector.at(i).c_str() );
myHits[i] = ref.find(reverseString(searchVector.at(i)));
} else {
myHits[i] = 0;
printf("MISS : My id: %d, myStart: %d, myEnd: %d, Sträng: \n", tid, myStart, myEnd, searchVector.at(i).c_str() );
}
}
pthread_mutex_lock(&mutexDNS);
//update allHits
pthread_mutex_unlock(&mutexDNS);
//Addera trådens träffar till träffar.
// pthread_exit((void*) t);
}
int main()
{
ref = file2String("reference.fa");
cout << "Enter how many rows your chunkfile has: ";
cin >> rows;
searchVector.resize(rows/2);
ifstream searchFile("test_part.fa");
string line;
int i = 0;
while(getline(searchFile, line))
{
if(line.find(">")){
searchVector.at(i) = line;
i++;
}
}
// printChunks();
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc;
long t;
void *status;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_mutex_init(&mutexDNS, NULL);
for(t=0; t<NUM_THREADS; t++) {
// printf("Main: creating thread %ld\n", t);
rc = pthread_create(&thread[t], &attr, alignDNS, (void *)t);
if (rc) {
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
// Free attribute and wait for the other threads
pthread_mutex_destroy(&mutexDNS);
pthread_attr_destroy(&attr);
for(t=0; t<NUM_THREADS; t++) {
rc = pthread_join(thread[t], &status);
if (rc) {
printf("ERROR; return code from pthread_join() is %d\n", rc);
exit(-1);
}
}
}
EDIT, forgot the out put.
Code:
FRONT : My id: 2, myStart: 8, myEnd: 12, Sträng:
FRONT : My id: 1, myStart: 4, myEnd: 8, Sträng:
FRONT : My id: 3, myStart: 12, myEnd: 16, Sträng:
FRONT : My id: 0, myStart: 0, myEnd: 4, Sträng:
MISS : My id: 4, myStart: 0, myEnd: 20, Sträng:
MISS : My id: 2, myStart: 8, myEnd: 12, Sträng:
MISS : My id: 1, myStart: 4, myEnd: 8, Sträng:
FRONT : My id: 1, myStart: 4, myEnd: 8, Sträng:
MISS : My id: 3, myStart: 12, myEnd: 16, Sträng:
FRONT : My id: 3, myStart: 12, myEnd: 16, Sträng:
etc.
etc...
Should be
Code:
FRONT : My id: 2, myStart: 8, myEnd: 12, Sträng: String with approx 30 characters.
etc...
etc.