Skip to content

Commit

Permalink
add threading option
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanxw committed Apr 1, 2014
1 parent bb55db2 commit 1f311f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2014-04-01 Xiaowei Zhan <zhanxw@fantasia.csgstat.sph.umich.edu>

* New parallele computation option (--thread) in vcf2kinship

2014-03-30 Xiaowei Zhan <zhanxw@fantasia.csgstat.sph.umich.edu>

* Improve: allele frequency calculation is faster
Expand Down
3 changes: 2 additions & 1 deletion libVcf/VCFInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void VCFInputFile::init(const char* fn) {
this->fp = NULL;
this->tabixReader = NULL;
this->bcfReader = NULL;

this->autoMergeRange = false;

// check whether file exists.
FILE* fp = fopen(fn, "rb");
if (!fp) {
Expand Down
2 changes: 1 addition & 1 deletion src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

Logger* logger = NULL;

#define VERSION "20140330"
#define VERSION "20140401"

void banner(FILE* fp) {
const char* string =
Expand Down
21 changes: 19 additions & 2 deletions vcfUtils/vcf2kinship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifdef _OPENMP
#include <omp.h>
// #pragma message "Enable multithread using OpenMP"
int g_NumThread = 1;
#endif

class EmpiricalKinship{
Expand Down Expand Up @@ -241,7 +242,9 @@ class BaldingNicolsKinship: public EmpiricalKinship {
}
}
const size_t numG = g.size();
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (size_t i = 0; i < numG; ++i) {
if (geno[i] == 0.0) continue; // skip missing marker
for (size_t j = 0; j <= i; ++j) {
Expand Down Expand Up @@ -354,7 +357,9 @@ class BaldingNicolsKinshipForX: public EmpiricalKinship {
}

const size_t numG = g.size();
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (size_t i = 0; i < numG; ++i) {
if (geno[i] == 0.0) continue; // skip missing marker
for (size_t j = 0; j <= i; ++j) {
Expand Down Expand Up @@ -406,7 +411,7 @@ void usage(int argc, char** argv) {
}

#define PROGRAM "vcf2kinship"
#define VERSION "20140326"
#define VERSION "20140401"
void welcome() {
#ifdef NDEBUG
fprintf(stdout, "Thank you for using %s (version %s)\n", PROGRAM, VERSION);
Expand Down Expand Up @@ -460,6 +465,7 @@ int main(int argc, char** argv){
ADD_PARAMETER_GROUP(pl, "Other Function")
// ADD_BOOL_PARAMETER(pl, variantOnly, "--variantOnly", "Only variant sites from the VCF file will be processed.")
ADD_STRING_PARAMETER(pl, updateId, "--update-id", "Update VCF sample id using given file (column 1 and 2 are old and new id).")
ADD_DEFAULT_INT_PARAMETER(pl, thread, 1, "--thread", "Specify number of parallel threads to speed up")
ADD_BOOL_PARAMETER(pl, help, "--help", "Print detailed help message")
END_PARAMETER_LIST(pl)
;
Expand All @@ -483,7 +489,18 @@ int main(int argc, char** argv){
}
// PAR region setting
ParRegion parRegion(FLAG_xLabel, FLAG_xParRegion);

// Set threads
if (FLAG_thread < 1) {
fprintf(stderr, "Invalid thread number: %d\n", FLAG_thread);
abort();
} else if (FLAG_thread > 1){
fprintf(stderr, "Multiple ( %d ) threads will be used.\n", FLAG_thread);
}
g_NumThread = FLAG_thread;
#ifdef _OPENMP
omp_set_num_threads(g_NumThread);
#endif

// REQUIRE_STRING_PARAMETER(FLAG_inVcf, "Please provide input file using: --inVcf");
if (FLAG_inVcf.empty() && FLAG_ped.empty()) {
fprintf(stderr, "Please provide input file using: --inVcf or --ped");
Expand Down

0 comments on commit 1f311f8

Please sign in to comment.