Created
April 8, 2017 22:45
-
-
Save dpastoor/89566240ddbc35ec73aee707f4e27f93 to your computer and use it in GitHub Desktop.
parallelization gone bad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(future) | |
| library(PKPDmisc) | |
| huge_df <- map_df(1:100000, ~ Theoph %>% mutate(REP = .x)) | |
| pryr::object_size(huge_df) | |
| parallelization_benchmark <- lapply(seq(2, 64, 2), function(ncore) { | |
| PKPDmisc::jprint("starting on: ", ncore) | |
| start_time <- Sys.time() | |
| plan(tweak(multiprocess, workers = as.integer(ncore))) | |
| res <- huge_df %>% | |
| chunk_df(REP, .nchunks = ncore) %>% | |
| split(.$sim_chunk) %>% | |
| map(function(.x) { | |
| future({ | |
| .x %>% group_by(Subject, REP) %>% | |
| summarize_at(vars(conc), funs(min, mean, max)) | |
| }) | |
| }) %>% map_df(values) | |
| print(difftime(Sys.time(), start_time)) | |
| return(difftime(Sys.time(), start_time)) | |
| }) | |
| ggplot(data_frame(x = seq(2, 64, 2), y = unlist(parallelization_benchmark)) %>% filter(x > 2), aes(x,y)) + geom_line() + | |
| labs(x = "Threads", y = "Time, seconds") + | |
| theme_bw() + | |
| base_theme() | |
Author
dpastoor
commented
Apr 8, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment