Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use multi-threaded work to increase the speed of calculations? #30

Open
baoyulinn opened this issue Jun 2, 2024 · 1 comment

Comments

@baoyulinn
Copy link

Dear professor
Is it possible to use multi-threaded work to increase the speed of calculations?

@Ali-mhm
Copy link

Ali-mhm commented Oct 24, 2024

Dear professor Is it possible to use multi-threaded work to increase the speed of calculations?

hi, you can use these line of code to increase number of CPUs' cores

library(MRPRESSO)
library(parallel)
library(data.table)
# Load your summary statistics from a file
t<-fread("C:/Users/pc/Downloads/Compressed/presso.csv")
t<-t[!duplicated(t$SNP),]
snp<-as.data.frame(t$SNP)
t<-t[,-7]
t<-as.data.frame(t(t))
colnames(t)<-snp$`t$SNP`
t<-as.data.frame(t(t))
# Replace 'your_file_path.txt' with the actual path to your file
SummaryStats <- t
# Set the number of cores you want to use
num_cores <- 20
# Create a cluster with the specified number of cores
cl <- makeCluster(num_cores)

# Export necessary objects and libraries to the cluster
clusterExport(cl, c("SummaryStats", "mr_presso"))
clusterEvalQ(cl, library(MRPRESSO))

# Define a function to run mr_presso
run_mr_presso <- function(i) {
  mr_presso(BetaOutcome = "Y_effect", 
            BetaExposure = "E1_effect", 
            SdOutcome = "Y_se", 
            SdExposure = "E1_se", 
            OUTLIERtest = TRUE, 
            DISTORTIONtest = TRUE, 
            data = SummaryStats, 
            NbDistribution = 6000,  
            SignifThreshold = 0.05)
}

# Run the function in parallel
results_list <- parLapply(cl, 1:num_cores, run_mr_presso)

# Stop the cluster
stopCluster(cl)

i hope this let you to increase speed of calculation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants