Skip to content

Commit

Permalink
openMP_checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudaraka88 authored and Sudaraka88 committed Jul 18, 2024
1 parent 2ded16e commit fc5a4f6
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
*.o
.DS_Store
*.Rmd
Makevars
3 changes: 2 additions & 1 deletion R/BacGWES.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ LDWeaver = function(dset, aln_path, aln_has_all_bases = T, pos = NULL, gbk_path
######## Welcome message ########
{
timestamp()
cat("\n ***** This is LDWeaver", as.character(packageVersion(pkg = "LDWeaver")), " *****")
cat("\n ***** This is LDWeaver", as.character(packageVersion(pkg = "LDWeaver")), " *****\n")
test_openmp()
if(ncores > 1) cat(paste("\n\n Performing GWES analysis on:", dset, " - using", ncores, "cores\n\n"))
if(ncores == 1) cat(paste("\n\n Performing GWES analysis on:", dset, "\n\n"))
if(perform_SR_analysis_only) cat("Only short-range analysis requested. \n")
Expand Down
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
.Call('_LDWeaver_extractRef', PACKAGE = 'LDWeaver', file)
}

test_openmp <- function() {
invisible(.Call('_LDWeaver_test_openmp', PACKAGE = 'LDWeaver'))
}

.readFasta <- function(file, pos_len) {
.Call('_LDWeaver_readFasta', PACKAGE = 'LDWeaver', file, pos_len)
}
Expand Down
10 changes: 5 additions & 5 deletions R/performPopulationStuctureCorrection.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ estimate_Hamming_distance_weights = function(snp.dat, threshold = 0.1, mega_dset

}
} else {
snpmat_t = as(snp.dat$snp.matrix_A, 'dgCMatrix')
snpmat_t = as(snp.dat$snp.matrix_A, 'lgeMatrix')
# shared.snps = MatrixExtra::crossprod((snpmat_t))
shared.snps = crossprod((snpmat_t))

snpmat_t = as(snp.dat$snp.matrix_C, 'dgCMatrix')
snpmat_t = as(snp.dat$snp.matrix_C, 'lgeMatrix')
shared.snps = shared.snps + crossprod((snpmat_t))

snpmat_t = as(snp.dat$snp.matrix_G, 'dgCMatrix')
snpmat_t = as(snp.dat$snp.matrix_G, 'lgeMatrix')
shared.snps = shared.snps + crossprod((snpmat_t))

snpmat_t = as(snp.dat$snp.matrix_T, 'dgCMatrix')
snpmat_t = as(snp.dat$snp.matrix_T, 'lgeMatrix')
shared.snps = shared.snps + crossprod((snpmat_t))

snpmat_t = as(snp.dat$snp.matrix_N, 'dgCMatrix')
snpmat_t = as(snp.dat$snp.matrix_N, 'lgeMatrix')
shared.snps = shared.snps + crossprod((snpmat_t))

hdw = 1/( Matrix::colSums( (snp.dat$nsnp - shared.snps) < thresh) + 1)
Expand Down
13 changes: 13 additions & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CXX_STD=CXX11

CXX1X=$(shell ${R_HOME}/bin/R CMD config CXX11)

PKG_LIBS = $(shell $(R_HOME)/bin/Rscipt.exe -e "Rcpp:::LdFlags()") -lz

ifeq ($(shell $(CXX1X) -fopenmp -E -xc++ - 2>&1 >/dev/null && echo 'true'), true)
PKG_CXXFLAGS=$(SHLIB_OPENMP_CXXFLAGS) -DARMA_64BIT_WORD
PKG_LIBS=$(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
else
PKG_CXXFLAGS=-DARMA_64BIT_WORD
PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
endif
10 changes: 10 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// test_openmp
void test_openmp();
RcppExport SEXP _LDWeaver_test_openmp() {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
test_openmp();
return R_NilValue;
END_RCPP
}
// readFasta
List readFasta(std::string file, int pos_len);
RcppExport SEXP _LDWeaver_readFasta(SEXP fileSEXP, SEXP pos_lenSEXP) {
Expand All @@ -152,6 +161,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_LDWeaver_extractAlnParam", (DL_FUNC) &_LDWeaver_extractAlnParam, 4},
{"_LDWeaver_extractSNPs", (DL_FUNC) &_LDWeaver_extractSNPs, 4},
{"_LDWeaver_extractRef", (DL_FUNC) &_LDWeaver_extractRef, 1},
{"_LDWeaver_test_openmp", (DL_FUNC) &_LDWeaver_test_openmp, 0},
{"_LDWeaver_readFasta", (DL_FUNC) &_LDWeaver_readFasta, 2},
{NULL, NULL, 0}
};
Expand Down
16 changes: 16 additions & 0 deletions src/openMP_tester.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <Rcpp.h>
#ifdef _OPENMP
#include <omp.h>
// [[Rcpp::plugins(openmp)]]
#endif


// [[Rcpp::export]]
void test_openmp() {
#ifdef _OPENMP
int nthreads = omp_get_max_threads();
Rcpp::Rcout << "with OpenMP support - system supports up to: " << nthreads << " cores" << std::endl;
#else
Rcpp::Rcout << "without OpenMP support - WARNING! Some functions will run slower..." << std::endl;
#endif
}

0 comments on commit fc5a4f6

Please sign in to comment.