Line | |
---|
1 | function [i1,i2]=parallelrange(rank,numprocs,globalsize)
|
---|
2 | %PARALLELRANGE from a rank, and a number of processors, figure out a range, for parallel tasks.
|
---|
3 | %
|
---|
4 | % usage: [i1,i1]=parallelrange(rank,numprocs,globalsize)
|
---|
5 | %
|
---|
6 |
|
---|
7 | num_local_rows=zeros(numprocs,1);
|
---|
8 |
|
---|
9 | for i=1:numprocs,
|
---|
10 |
|
---|
11 | %we use floor. we under distribute rows. The rows left are then redistributed, therefore resulting in a more even distribution.
|
---|
12 | num_local_rows(i)=floor(globalsize/numprocs);
|
---|
13 |
|
---|
14 | end
|
---|
15 |
|
---|
16 |
|
---|
17 | %There may be some rows left. Distribute evenly.
|
---|
18 | row_rest=globalsize - numprocs*floor(globalsize/numprocs);
|
---|
19 |
|
---|
20 | for i=1:row_rest,
|
---|
21 | num_local_rows(i)=num_local_rows(i)+1;
|
---|
22 | end
|
---|
23 |
|
---|
24 | i1=sum(num_local_rows(1:rank-1))+1;
|
---|
25 | i2=i1+num_local_rows(rank)-1;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.