-
Notifications
You must be signed in to change notification settings - Fork 0
/
TS_multicore.m
executable file
·58 lines (46 loc) · 1.2 KB
/
TS_multicore.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% Test multicore speed gains
% Remember to start a new (or N-1 new, if you have N cores) Matlab
% processes (with -nojvm, if you like) with this directory as the PWD and
% addpath('../Multicore'), addpath('functions'), before running
% startmulticoreslave('mcDir'). All this before running this script.
%
% Remember to set the nCores parameter in 'fm.m'.
%% Setup
clear all;
close all;
% Domain dimensions
Lx = 100;
Ly = Lx;
Lz = Lx;
% Number of grid nodes in each direction
n = 20;
m = n;
o = n;
% Dxyz
dx = Lx/n;
dy = Ly/m;
dz = Lz/o;
Dxyz = [dx dy dz];
% Speed map
F = ones(m,n,o) + 0.2*rand(m,n,o);
% Source points
nSPs = 4;
SPs = diag([Lx Ly Lz]) * rand(3,nSPs);
%% Calculate Fast-marching solutions
% Run fm with one processor only
tic;
T1 = cell(1,nSPs);
eFlags1 = cell(1,nSPs);
for k=1:nSPs
[T1{k} eFlags1{k}] = ...
fm(F,SPs(:,k),Dxyz,'impl','C++','ord',1);
end
timeT1 = toc;
% Run fm on multiple processors
tic;
[T2 eFlags2] = fm(F,SPs,Dxyz,'impl','C++','useMC',1,'ord',1);
timeT2 = toc;
display([10 'Single time: ' num2str(timeT1)]);
display(['Multi time: ' num2str(timeT2)]);
display(['Single/Multi time ratio: ' num2str(timeT1/timeT2) '.']);
display(['Discrepancy:' num2str(sum(T1{1}(:)-T2{1}(:)))]);