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

Go to the source code of this file.

Functions

int * DetermineRowRankFromLocalSize (int global_size, int localsize, ISSM_MPI_Comm comm)
 

Function Documentation

◆ DetermineRowRankFromLocalSize()

int* DetermineRowRankFromLocalSize ( int  global_size,
int  localsize,
ISSM_MPI_Comm  comm 
)

Definition at line 12 of file DetermineRowRankFromLocalSize.cpp.

12  {
13 
14  /*intermediary: */
15  int i,j;
16  int my_rank=0;
17  int num_procs=0;
18  int lower_row,upper_row;
19 
20  /*output: */
21  int* RowRank=NULL;
22 
23  ISSM_MPI_Comm_rank(comm,&my_rank);
24  ISSM_MPI_Comm_size(comm,&num_procs);
25 
26  /*allocate: */
27  RowRank=xNew<int>(global_size);
28 
29  /*Gather all local_size values into alllocalsizes, for all cpus*/
30  int* alllocalsizes=xNew<int>(num_procs);
31  ISSM_MPI_Allgather(&localsize,1,ISSM_MPI_INT,alllocalsizes,1,ISSM_MPI_INT,comm);
32 
33  /*From all localsizes, get lower row and upper row*/
34  lower_row=0;
35  upper_row=lower_row+alllocalsizes[0];
36  for(j=lower_row;j<upper_row;j++)RowRank[j]=0;
37 
38  for(i=1;i<num_procs;i++){
39  lower_row=lower_row+alllocalsizes[i-1];
40  upper_row=upper_row+alllocalsizes[i];
41  for(j=lower_row;j<upper_row;j++)RowRank[j]=i;
42  }
43  xDelete<int>(alllocalsizes);
44 
45  return RowRank;
46 }
ISSM_MPI_Comm_rank
int ISSM_MPI_Comm_rank(ISSM_MPI_Comm comm, int *rank)
Definition: issmmpi.cpp:198
ISSM_MPI_INT
#define ISSM_MPI_INT
Definition: issmmpi.h:127
ISSM_MPI_Allgather
int ISSM_MPI_Allgather(void *sendbuf, int sendcount, ISSM_MPI_Datatype sendtype, void *recvbuf, int recvcount, ISSM_MPI_Datatype recvtype, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:45
ISSM_MPI_Comm_size
int ISSM_MPI_Comm_size(ISSM_MPI_Comm comm, int *size)
Definition: issmmpi.cpp:209