Skip to content
Snippets Groups Projects
Commit 733c1c82 authored by Ravi Tripathi's avatar Ravi Tripathi
Browse files

Merge branch 'master' of gitlab.rc.uab.edu:ravi89/Tutorial_parallelism

parents 95ab6879 3ad0f2bb
No related branches found
No related tags found
No related merge requests found
This repository contains a variety of examples of parallelism.
MATLAB
in the example script provided, "parforExample.m", the "for" command can be switched between "for" and "parfor". Changing to "parfor" will ask MATLAB to parallelize the loop if possible. In MATLAB r2018a, parpool is called by MATLAB with 12 threads as default if parfor is used without first calling parpool.
R
The text in Rparallel.txt is a set of R commands to be used to test out one version of parallelism in R.
install.packages("plyr")
install.packages("doMC")
library(plyr)
library(doMC)
doMC::registerDoMC(cores=24) # or however many cores you have access to
system.time(ddply(iris, .(Species), function(x) {
Sys.sleep(2)
nrow(x)
}))
# user system elapsed
# 0.005 0.001 6.016
system.time(ddply(iris, .(Species), function(x) {
Sys.sleep(2)
nrow(x)
}, .parallel = TRUE))
# user system elapsed
# 0.018 0.015 2.031
% Testing number of prime numbers in a given range
final=10^7; %upper limit
close all
%clear all
tic
count=[];
ratios=[];
l=[];
out=[];
disp('Please wait.. Finding number of primes.... ')
a=0;
parfor i=1:final
c=isprime(i);
if c==1
i;
a=a+c;
end
end
a;
ratio=a/final;
l=[l,final];
count=[count,a];
ratios=[ratios,ratio];
out=[l',count',ratios'];
toc
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment