--- title: "HPC Final Project Analysis" author: - "JP Appel" output: html_document: toc: true toc_float: false number_sections: false theme: readable highlight: espresso code_folding: hide fig_width: 10 fig_height: 8 fig_caption: true df_print: paged --- ```{r setup, include=FALSE} library(tidyverse) library(plotly) library(modelsummary) ``` # Hypotheses 1. Computing complex fractals parallelizes very well. 2. The runtime has a linear relation with the number of samples. # Data Each data point is an average of 5 runtimes collected from running the program. To recreate out data, compile the programs using the instructions in `README.md` then run `gather_data` in the `analysis` directory from the project root. After the the SLURM jobs are finished, run `analysis/collate_data` to collect the data into a single file `analysis/data.csv`. Note that the SLURM scripts are unique to MU Cluster and will need to be tweaked to work on other systems. ```{r data_ingest, include=FALSE} full_data <- read_csv("data.csv") %>% mutate(samples = horizontal_samples * vertical_samples, program = gsub("^build/(.*?)-fractals$", "\\1", program), threads = ifelse(program == "cuda", 1024, threads)) %>% select(program, threads, fractal, samples, runtime) ``` For a raw csv view of the data see `data.csv`. We collected data for the following fractals: * Mandelbrot * Burning Ship * Tricorn * Multibrot * Multicorn * Julia Using a maximum iterations of 25. We collect 3 data points per serial experiment, and 5 data points per shared and CUDA experiment. For a more detailed view of our collection methods see the scripts in `analysis/scripts`. The runtimes for CUDA experiments include the time to copy the data to and from the GPU for reasons that will become apparent later. Note the block size is set to $16x16$ for all CUDA experiments since we found a maxium percentage difference of $0.2%$ between $16x16$ and other block sizes that yield the maximum number of warps. ```{r data_table, echo=FALSE} full_data ``` # Runtimes ## Sampling's Effect on Runtimes The following plots are interactive, allowing you to zoom in on the data. By clicking on the legend you can hide or show data for each fractal. Each plot has a line representing the median runtime for each fractal and program. ### Serial, Shared, CUDA For larger sample sizes we see the GPU with memory copy overhead is far faster than the CPU implementations. Without the memory copy overhead the CUDA runtimes are barely measurable. We expect this result, since each value in the fractal is computed independently, which is the type of task the GPU is designed for. Observe that the fractals that require complex exponentiation, such as the Multibrot and Multicorn, have the longest runtimes. We expect this, since the complex exponentiation is the most computationally expensive part of the fractal generation. Also take note of how linear the runtimes are with respect to the number of samples. We explore this further in the linear models section. ```{r sampling_effect} full_plot <- full_data %>% ggplot(aes(x = samples, y = runtime, color = program, shape = factor(threads))) + geom_point() + facet_wrap(~fractal, scales = "free_y") + stat_summary(fun = median, geom = "line", aes(group = interaction(program, threads))) + labs(title = "Sampling's Effect on Runtimes", x = "Samples", y = "Runtime (s)", shape = "Threads", color = "Implementation") ggplotly(full_plot) ``` ### Serial ```{r serial_sampling} serial_plot <- full_data %>% filter(program == "serial") %>% ggplot(aes(x = samples, y = runtime, color = fractal)) + geom_point() + stat_summary(fun = median, geom = "line", aes(group = fractal)) + labs(title = "Serial Sampling's Effect on Runtimes", x = "Samples", y = "Runtime (s)", color = "Fractal") ggplotly(serial_plot) ``` ### Shared ```{r shared_sampling} shared_plot <- full_data %>% filter(program == "shared") %>% rename(Threads = threads) %>% ggplot(aes(x = samples, y = runtime, color = fractal)) + geom_point() + stat_summary(fun = median, geom = "line", aes(group = fractal)) + facet_wrap(~Threads, scales = "free_y", labeller = label_both) + labs(title = "Shared Sampling's Effect on Runtimes", x = "Samples", y = "Runtime (s)", color = "Fractal") ggplotly(shared_plot) ``` ### CUDA ```{r cuda_sampling} cuda_plot <- full_data %>% filter(program == "cuda") %>% ggplot(aes(x = samples, y = runtime, color = fractal)) + geom_point() + stat_summary(fun = median, geom = "line", aes(group = fractal)) + labs(title = "CUDA Sampling's Effect on Runtimes", x = "Samples", y = "Runtime (s)", color = "Fractal") ggplotly(cuda_plot) ``` ## Linear Models We fit linear models to the data to test our hypothesis that the runtime has a linear relationship with the number of samples. By doing so we can give with a high confidence models for computing the runtime of a fractal given the number of samples. In all the models below, the $R^2$ value is very close to 1, indicating that the model fits the data very well. ### Serial ```{r serial_models, include=FALSE} serial_mandelbrot_model <- full_data %>% filter(program == "serial", fractal == "mandelbrot") %>% lm(runtime ~ samples, data = .) serial_burning_ship_model <- full_data %>% filter(program == "serial", fractal == "burning ship") %>% lm(runtime ~ samples, data = .) serial_tricorn_model <- full_data %>% filter(program == "serial", fractal == "tricorn") %>% lm(runtime ~ samples, data = .) serial_multibrot_model <- full_data %>% filter(program == "serial", fractal == "multibrot") %>% lm(runtime ~ samples, data = .) serial_multicorn_model <- full_data %>% filter(program == "serial", fractal == "multicorn") %>% lm(runtime ~ samples, data = .) serial_julia_model <- full_data %>% filter(program == "serial", fractal == "julia") %>% lm(runtime ~ samples, data = .) ```