@@ -113,6 +113,12 @@ static void ParseOptions(int argc, char *argv[]) {
113
113
if (options.num_cpu_threads == 0 ) {
114
114
options.num_cpu_threads = omp_get_max_threads ();
115
115
}
116
+ // must set the number of threads before the parallel hash_map declared
117
+ if (options.num_cpu_threads > 1 ) {
118
+ omp_set_num_threads (options.num_cpu_threads - 1 );
119
+ } else {
120
+ omp_set_num_threads (1 );
121
+ }
116
122
} catch (std::exception &e) {
117
123
std::cerr << e.what () << std::endl;
118
124
std::cerr << " Usage: " << argv[0 ] << " [options]" << std::endl;
@@ -254,10 +260,15 @@ static void ReadContigsAndBuildHash(IterateGlobalData &globals, bool is_addi_con
254
260
}
255
261
256
262
pthread_create (&input_thread, NULL , ReadContigsThread, &input_thread_data);
257
- omp_set_num_threads (globals.num_cpu_threads - 1 );
263
+ if (globals.num_cpu_threads == 1 ) {
264
+ pthread_join (input_thread, NULL );
265
+ }
258
266
259
267
while (true ) {
260
- pthread_join (input_thread, NULL );
268
+ if (globals.num_cpu_threads > 1 ) {
269
+ pthread_join (input_thread, NULL );
270
+ }
271
+
261
272
if (packages[input_thread_index].size () == 0 ) {
262
273
break ;
263
274
}
@@ -267,6 +278,10 @@ static void ReadContigsAndBuildHash(IterateGlobalData &globals, bool is_addi_con
267
278
pthread_create (&input_thread, NULL , ReadContigsThread, &input_thread_data);
268
279
ContigPackage &cur_package = packages[input_thread_index ^ 1 ];
269
280
281
+ if (globals.num_cpu_threads == 1 ) {
282
+ pthread_join (input_thread, NULL );
283
+ }
284
+
270
285
if (!is_addi_contigs) {
271
286
#pragma omp parallel for
272
287
for (unsigned i = 0 ; i < cur_package.size (); ++i) {
@@ -414,10 +429,16 @@ static void ReadReadsAndProcess(IterateGlobalData &globals) {
414
429
pthread_create (&input_thread, NULL , ReadReadsThread, &input_thread_data);
415
430
globals.iterative_edges .reserve (globals.crusial_kmers .size () * 10 );
416
431
AtomicBitVector is_aligned;
417
- omp_set_num_threads (globals.num_cpu_threads - 1 );
418
432
419
- while ( true ) {
433
+ if (globals. num_cpu_threads == 1 ) {
420
434
pthread_join (input_thread, NULL );
435
+ }
436
+
437
+ while (true ) {
438
+ if (globals.num_cpu_threads > 1 ) {
439
+ pthread_join (input_thread, NULL );
440
+ }
441
+
421
442
if (packages[input_thread_index].num_of_reads == 0 ) {
422
443
break ;
423
444
}
@@ -428,6 +449,10 @@ static void ReadReadsAndProcess(IterateGlobalData &globals) {
428
449
ReadPackage &cur_package = packages[input_thread_index ^ 1 ];
429
450
is_aligned.reset (cur_package.num_of_reads );
430
451
452
+ if (globals.num_cpu_threads == 1 ) {
453
+ pthread_join (input_thread, NULL );
454
+ }
455
+
431
456
#pragma omp parallel for
432
457
for (unsigned i = 0 ; i < (unsigned )cur_package.num_of_reads ; ++i) {
433
458
int length = cur_package.length (i);
0 commit comments