Skip to content

Commit f5224a6

Browse files
committed
Merge branch 'omp_bugfix' into dev
Conflicts: .gitignore iterate_edges.cpp
2 parents 76e2a08 + 00c5a21 commit f5224a6

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

.gitignore

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,4 @@ megahit_iter_k124
3333
megahit_iter_k61
3434
megahit_iter_k92
3535
sdbg_builder_cpu
36-
test/ecoli_ref-500k.fastq.gz
37-
test/ecoliMG1655.fa
38-
test/megahit_out/final.contigs.fa
39-
test/megahit_out/log
40-
test/megahit_out/tmp/k21.counting
41-
test/megahit_out/tmp/k21.final.contigs.fa
42-
test/megahit_out/tmp/k31.final.contigs.fa
43-
test/megahit_out/tmp/k41.final.contigs.fa
44-
test/megahit_out/tmp/k51.final.contigs.fa
45-
test/megahit_out/tmp/k61.final.contigs.fa
46-
test/megahit_out/tmp/k71.final.contigs.fa
47-
test/megahit_out/tmp/k81.final.contigs.fa
48-
test/megahit_out/tmp/k91.final.contigs.fa
49-
test/megahit_out/tmp/k99.final.contigs.fa
36+
test/*

iterate_edges.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ static void ParseOptions(int argc, char *argv[]) {
113113
if (options.num_cpu_threads == 0) {
114114
options.num_cpu_threads = omp_get_max_threads();
115115
}
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+
}
116122
} catch (std::exception &e) {
117123
std::cerr << e.what() << std::endl;
118124
std::cerr << "Usage: " << argv[0] << " [options]" << std::endl;
@@ -254,10 +260,15 @@ static void ReadContigsAndBuildHash(IterateGlobalData &globals, bool is_addi_con
254260
}
255261

256262
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+
}
258266

259267
while (true) {
260-
pthread_join(input_thread, NULL);
268+
if (globals.num_cpu_threads > 1) {
269+
pthread_join(input_thread, NULL);
270+
}
271+
261272
if (packages[input_thread_index].size() == 0) {
262273
break;
263274
}
@@ -267,6 +278,10 @@ static void ReadContigsAndBuildHash(IterateGlobalData &globals, bool is_addi_con
267278
pthread_create(&input_thread, NULL, ReadContigsThread, &input_thread_data);
268279
ContigPackage &cur_package = packages[input_thread_index ^ 1];
269280

281+
if (globals.num_cpu_threads == 1) {
282+
pthread_join(input_thread, NULL);
283+
}
284+
270285
if (!is_addi_contigs) {
271286
#pragma omp parallel for
272287
for (unsigned i = 0; i < cur_package.size(); ++i) {
@@ -414,10 +429,16 @@ static void ReadReadsAndProcess(IterateGlobalData &globals) {
414429
pthread_create(&input_thread, NULL, ReadReadsThread, &input_thread_data);
415430
globals.iterative_edges.reserve(globals.crusial_kmers.size() * 10);
416431
AtomicBitVector is_aligned;
417-
omp_set_num_threads(globals.num_cpu_threads - 1);
418432

419-
while (true) {
433+
if (globals.num_cpu_threads == 1) {
420434
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+
421442
if (packages[input_thread_index].num_of_reads == 0) {
422443
break;
423444
}
@@ -428,6 +449,10 @@ static void ReadReadsAndProcess(IterateGlobalData &globals) {
428449
ReadPackage &cur_package = packages[input_thread_index ^ 1];
429450
is_aligned.reset(cur_package.num_of_reads);
430451

452+
if (globals.num_cpu_threads == 1) {
453+
pthread_join(input_thread, NULL);
454+
}
455+
431456
#pragma omp parallel for
432457
for (unsigned i = 0; i < (unsigned)cur_package.num_of_reads; ++i) {
433458
int length = cur_package.length(i);

megahit

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import multiprocessing
3333
from datetime import datetime, date, time
3434

3535
usage_message = '''
36-
megahit version: 0.1.3
36+
megahit version: 0.1.3-bugfix2
3737
Copyright (c) The University of Hong Kong
3838
3939
Usage:
@@ -191,6 +191,10 @@ def check_opt():
191191
if low_local_ratio <= 0 or low_local_ratio > 0.5:
192192
print >> sys.stderr, "low_local_ratio should be in (0, 0.5]."
193193
exit(1)
194+
if num_cpu_threads > multiprocessing.cpu_count():
195+
print >> sys.stderr, "Maximum number of available CPU thread is %d." % multiprocessing.cpu_count();
196+
print >> sys.stderr, "Number of thread is reset to the %d." % multiprocessing.cpu_count();
197+
num_cpu_threads = multiprocessing.cpu_count()
194198
if num_cpu_threads == 0:
195199
num_cpu_threads = multiprocessing.cpu_count()
196200
if num_cpu_threads <= 1:
@@ -579,7 +583,7 @@ def main(argv = None):
579583
check_bin()
580584

581585
start_time = datetime.now()
582-
print >> sys.stderr, "MEGAHIT version 0.1.3"
586+
print >> sys.stderr, "MEAGHIT v0.1.3-bugfix2"
583587
print >> sys.stderr, "[%s] Start assembly. Number of CPU threads %d." % (start_time.strftime("%c"), num_cpu_threads)
584588

585589
make_out_dir()

0 commit comments

Comments
 (0)