#include /*I "petscsys.h" I*/ #undef __FUNCT__ #define __FUNCT__ "PetscGatherNumberOfMessages" /*@C PetscGatherNumberOfMessages - Computes the number of messages a node expects to receive Collective on MPI_Comm Input Parameters: + comm - Communicator . iflags - an array of integers of length sizeof(comm). A '1' in ilengths[i] represent a message from current node to ith node. Optionally PETSC_NULL - ilengths - Non zero ilengths[i] represent a message to i of length ilengths[i]. Optionally PETSC_NULL. Output Parameters: . nrecvs - number of messages received Level: developer Concepts: mpi utility Notes: With this info, the correct message lengths can be determined using PetscGatherMessageLengths() Either iflags or ilengths should be provided. If iflags is not provided (PETSC_NULL) it can be computed from ilengths. If iflags is provided, ilengths is not required. .seealso: PetscGatherMessageLengths() @*/ PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm comm,const PetscMPIInt iflags[],const PetscMPIInt ilengths[],PetscMPIInt *nrecvs) { PetscMPIInt size,rank,*recv_buf,i,*iflags_local = PETSC_NULL,*iflags_localm = PETSC_NULL; PetscErrorCode ierr; PetscFunctionBegin; ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); ierr = PetscMalloc2(size,PetscMPIInt,&recv_buf,size,PetscMPIInt,&iflags_localm);CHKERRQ(ierr); /* If iflags not provided, compute iflags from ilengths */ if (!iflags) { if (!ilengths) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Either iflags or ilengths should be provided"); iflags_local = iflags_localm; for (i=0; i