i loop parallelized: bad

This commit is contained in:
Celine Mercier
2019-05-25 18:37:56 +02:00
parent a04588da31
commit debf59b266

View File

@ -183,6 +183,7 @@ int obi_clean(const char* dms_name,
char status; char status;
byte_t* alignment_result_array = NULL; byte_t* alignment_result_array = NULL;
byte_t* ali_result_array = NULL;
byte_t ali_result; byte_t ali_result;
int* complete_sample_count_array = NULL; int* complete_sample_count_array = NULL;
@ -211,6 +212,7 @@ int obi_clean(const char* dms_name,
bool stop = false; bool stop = false;
int max_threads = 1; int max_threads = 1;
int thread_id = 0;
#ifdef _OPENMP #ifdef _OPENMP
max_threads = omp_get_max_threads(); max_threads = omp_get_max_threads();
@ -375,7 +377,7 @@ int obi_clean(const char* dms_name,
// Allocate alignment result array (byte at 0 if not aligned yet, // Allocate alignment result array (byte at 0 if not aligned yet,
// 1 if sequence at index has a similarity above the threshold with the current sequence, // 1 if sequence at index has a similarity above the threshold with the current sequence,
// 2 if sequence at index has a similarity below the threshold with the current sequence) // 2 if sequence at index has a similarity below the threshold with the current sequence)
alignment_result_array = (byte_t*) calloc(seq_count, sizeof(byte_t)); alignment_result_array = (byte_t*) calloc(thread_count*seq_count, sizeof(byte_t));
if (alignment_result_array == NULL) if (alignment_result_array == NULL)
{ {
obi_set_errno(OBI_MALLOC_ERROR); obi_set_errno(OBI_MALLOC_ERROR);
@ -399,12 +401,23 @@ int obi_clean(const char* dms_name,
} }
} }
#pragma omp parallel shared(seq_count, blob_array, complete_sample_count_array, alignment_result_array, stop) \
private(ali_result_array, thread_id, i, j, blob1, blob2, s1_count, s2_count, \
sample_count_array, sample, yes, no, above_threshold, ali_result, score)
{
#ifdef _OPENMP
thread_id = omp_get_thread_num();
ali_result_array = alignment_result_array+thread_id;
#endif
#pragma omp for schedule(dynamic, 100)
for (i=0; i< (seq_count-1); i++) for (i=0; i< (seq_count-1); i++)
{ {
if (i%1000 == 0) if (i%1000 == 0)
{ {
p = (i/(float)seq_count)*100; p = (i/(float)(seq_count/(float)thread_count))*100;
fprintf(stderr,"\rDone : %f %% ",p); fprintf(stderr,"\rDone : %f %% ",p);
} }
@ -414,7 +427,7 @@ int obi_clean(const char* dms_name,
if (blob1 == NULL) if (blob1 == NULL)
{ {
obidebug(1, "\nError retrieving sequences to align"); obidebug(1, "\nError retrieving sequences to align");
return -1; stop = true;
} }
for (sample=0; sample < sample_count; sample++) for (sample=0; sample < sample_count; sample++)
@ -425,9 +438,6 @@ int obi_clean(const char* dms_name,
s1_count = sample_count_array[i]; s1_count = sample_count_array[i];
//s1_count = obi_get_int_with_elt_idx_and_col_p_in_view(i_view, sample_column, i, sample); // slower //s1_count = obi_get_int_with_elt_idx_and_col_p_in_view(i_view, sample_column, i, sample); // slower
#pragma omp parallel for shared(i, seq_count, s1_count, sample, blob_array, sample_count_array, alignment_result_array, stop) \
private(j, blob2, s2_count, yes, no, above_threshold, ali_result, score)
for (j=i+1; j < seq_count; j++) for (j=i+1; j < seq_count; j++)
{ {
// Get second sequence // Get second sequence
@ -452,7 +462,7 @@ int obi_clean(const char* dms_name,
yes = 0; yes = 0;
no = 0; no = 0;
above_threshold = false; above_threshold = false;
ali_result = alignment_result_array[j]; ali_result = ali_result_array[j];
if (ali_result > 0) // already aligned if (ali_result > 0) // already aligned
{ {
if (ali_result == 2) if (ali_result == 2)
@ -482,7 +492,7 @@ int obi_clean(const char* dms_name,
{ {
if (yes == 0) if (yes == 0)
// Set ali result as above the threshold (value 1) // Set ali result as above the threshold (value 1)
alignment_result_array[j] = 1; ali_result_array[j] = 1;
// Might be worth having arrays to read values too for some datasets but unlikely // Might be worth having arrays to read values too for some datasets but unlikely
// label as head or internal // label as head or internal
@ -511,14 +521,13 @@ int obi_clean(const char* dms_name,
} }
else if (no == 0) else if (no == 0)
// Set ali result as above the threshold (value 2) // Set ali result as above the threshold (value 2)
alignment_result_array[j] = 2; ali_result_array[j] = 2;
} }
} }
if (stop)
return -1;
} }
// Reset ali result array to 0 // Reset ali result array to 0
memset(alignment_result_array, 0, seq_count); memset(ali_result_array, 0, seq_count);
}
} }
free_kmer_tables(ktable, seq_count); free_kmer_tables(ktable, seq_count);
@ -528,6 +537,9 @@ int obi_clean(const char* dms_name,
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (stop)
return -1;
if (heads_only) if (heads_only)
{ {
line_selection = malloc((o_view->infos)->line_count * sizeof(index_t)); line_selection = malloc((o_view->infos)->line_count * sizeof(index_t));