File: decomp.c

package info (click to toggle)
mpich 1.1.0-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 22,116 kB
  • ctags: 27,349
  • sloc: ansic: 193,435; sh: 11,172; fortran: 6,545; makefile: 5,801; cpp: 5,020; tcl: 3,548; asm: 3,536; csh: 1,079; java: 614; perl: 183; awk: 168; sed: 70; f90: 62
file content (33 lines) | stat: -rw-r--r-- 955 bytes parent folder | download | duplicates (2)
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
#include "mpi.h"
#include "mpe.h"
/*
  This file contains a routine for producing a decomposition of a 1-d array
  when given a number of processors.  It may be used in "direct" product
  decomposition.  The values returned assume a "global" domain in [1:n]
 */
/*@
  MPE_Decomp1d - Compute a balanced decomposition of a 1-D array

  Input Parameters:
. n  - Length of the array
. size - Number of processors in decomposition
. rank - Rank of this processor in the decomposition (0 <= rank < size)

  Output Parameters:
. s,e - Array indices are s:e, with the original array considered as 1:n.  
@*/
int MPE_Decomp1d( n, size, rank, s, e )
int n, size, rank, *s, *e;
{
    int nlocal, deficit;

    nlocal	= n / size;
    *s	= rank * nlocal + 1;
    deficit	= n % size;
    *s	= *s + ((rank < deficit) ? rank : deficit);
    if (rank < deficit) nlocal++;
    *e      = *s + nlocal - 1;
    if (*e > n || rank == size-1) *e = n;
    return MPI_SUCCESS;
}