Ice Sheet System Model  4.18
Code documentation
DetermineRowRankFromLocalSize.cpp
Go to the documentation of this file.
1 /* \file DetermineRowRankFromLocalSize.cpp
2  * \brief: routine to determine, from local size of a matrix or vector (in terms of number
3  * of rows), a vector of global size which for each row of the matrix or vector, determines
4  * what cpu this row belong to.
5  */
6 
7 #include <stdio.h>
8 #include <math.h>
9 #include "../../../shared/shared.h"
10 #include "../../../shared/Numerics/types.h"
11 
12 int* DetermineRowRankFromLocalSize(int global_size,int localsize,ISSM_MPI_Comm comm){
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
DetermineRowRankFromLocalSize
int * DetermineRowRankFromLocalSize(int global_size, int localsize, ISSM_MPI_Comm comm)
Definition: DetermineRowRankFromLocalSize.cpp:12
ISSM_MPI_Comm
int ISSM_MPI_Comm
Definition: issmmpi.h:118
ISSM_MPI_Comm_size
int ISSM_MPI_Comm_size(ISSM_MPI_Comm comm, int *size)
Definition: issmmpi.cpp:209