]> git.donarmstrong.com Git - mothur.git/blobdiff - summaryqualcommand.cpp
fixed bug in windows summary.seqs and summary.qual paralellization. paralellized...
[mothur.git] / summaryqualcommand.cpp
index 2a40e0862ba0b0444db035246cdcb95409fe4923..a0d786f47518290bd71b88d15f386326d61acd64 100644 (file)
@@ -373,7 +373,7 @@ int SummaryQualCommand::createProcessesCreateSummary(vector<int>& position, vect
                //////////////////////////////////////////////////////////////////////////////////////////////////////
                //Windows version shared memory, so be careful when passing variables through the seqSumQualData struct. 
                //Above fork() will clone, so memory is separate, but that's not the case with windows, 
-               //Taking advantage of shared memory to allow both threads to add info to vectors.
+               //Taking advantage of shared memory to pass results vectors.
                //////////////////////////////////////////////////////////////////////////////////////////////////////
                
                vector<seqSumQualData*> pDataArray; 
@@ -384,12 +384,10 @@ int SummaryQualCommand::createProcessesCreateSummary(vector<int>& position, vect
                for( int i=0; i<processors; i++ ){
                        
                        // Allocate memory for thread data.
-                       seqSumQualData* tempSum = new seqSumQualData(&position, &averageQ, &scores, filename, m, lines[i].start, lines[i].end, namefile, nameMap);
+                       seqSumQualData* tempSum = new seqSumQualData(filename, m, lines[i].start, lines[i].end, namefile, nameMap);
                        pDataArray.push_back(tempSum);
                        processIDS.push_back(i);
-                       
-                       //MySeqSumThreadFunction is in header. It must be global or static to work with the threads.
-                       //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
+        
                        hThreadArray[i] = CreateThread(NULL, 0, MySeqSumQualThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]);   
                }
                
@@ -399,6 +397,18 @@ int SummaryQualCommand::createProcessesCreateSummary(vector<int>& position, vect
                //Close all thread handles and free memory allocations.
                for(int i=0; i < pDataArray.size(); i++){
                        numSeqs += pDataArray[i]->count;
+            int tempNum = pDataArray[i]->position.size();
+            if (position.size() < tempNum) { position.resize(tempNum, 0); }
+                       if (averageQ.size() < tempNum) { averageQ.resize(tempNum, 0); }
+                       if (scores.size() < tempNum) { 
+                               scores.resize(tempNum); 
+                               for (int i = 0; i < scores.size(); i++) { scores[i].resize(41, 0); }
+                       }
+            
+            for (int k = 0; k < tempNum; k++)                  {                position[k]    +=  pDataArray[i]->position[k];         }               
+                       for (int k = 0; k < tempNum; k++)                       {                averageQ[k]    +=  pDataArray[i]->averageQ[k];         }               
+                       for (int k = 0; k < tempNum; k++)                       {       for (int j = 0; j < 41; j++) {  scores[k][j] += pDataArray[i]->scores[k][j];   }        }
+
                        CloseHandle(hThreadArray[i]);
                        delete pDataArray[i];
                }