Ice Sheet System Model  4.18
Code documentation
Functions
DetermineLocalSize.cpp File Reference
#include <stdio.h>
#include <math.h>
#include "../../../shared/shared.h"

Go to the source code of this file.

Functions

int DetermineLocalSize (int global_size, ISSM_MPI_Comm comm)
 

Function Documentation

◆ DetermineLocalSize()

int DetermineLocalSize ( int  global_size,
ISSM_MPI_Comm  comm 
)

Definition at line 9 of file DetermineLocalSize.cpp.

9  {
10 
11  /*output: */
12  int local_size;
13 
14  /*intermediary: */
15  int i;
16  int row_rest;
17  int* num_local_rows=NULL;
18 
19  /*from MPI: */
20  int num_procs;
21  int my_rank;
22 
23  /*recover my_rank*/
24  ISSM_MPI_Comm_rank(comm,&my_rank);
25  ISSM_MPI_Comm_size(comm,&num_procs);
26 
27  /* TODO replace the following with ->
28 
29  local_size=global_size/num_procs; // integer division
30  if (global_size%num_procs>my_rank) local_size++; // distribute the remainder
31  return local_size;
32 
33  <- to here */
34 
35  /*We are not bound by any library, just use what seems most logical*/
36  num_local_rows=xNew<int>(num_procs);
37 
38  for (i=0;i<num_procs;i++){
39  /*Here, we use floor. We under distribute rows. The rows
40  left are then redistributed, therefore resulting in a
41  more even distribution.*/
42  num_local_rows[i]=(int)floor((double)global_size/(double)num_procs);
43  }
44 
45  /*There may be some rows left. Distribute evenly.*/
46  row_rest=global_size - num_procs*(int)floor((double)global_size/(double)num_procs);
47  for (i=0;i<row_rest;i++){
48  num_local_rows[i]++;
49  }
50  local_size=num_local_rows[my_rank];
51 
52  /*free ressources: */
53  xDelete<int>(num_local_rows);
54 
55  /*return size: */
56  return local_size;
57 
58 }
ISSM_MPI_Comm_rank
int ISSM_MPI_Comm_rank(ISSM_MPI_Comm comm, int *rank)
Definition: issmmpi.cpp:198
ISSM_MPI_Comm_size
int ISSM_MPI_Comm_size(ISSM_MPI_Comm comm, int *size)
Definition: issmmpi.cpp:209