# PetscGatherMessageLengths
Computes information about messages that an MPI rank will receive, including (from-id,length) pairs for each message. 
## Synopsis
```
#include "petscsys.h"  
PetscErrorCode PetscGatherMessageLengths(MPI_Comm comm, PetscMPIInt nsends, PetscMPIInt nrecvs, const PetscMPIInt ilengths[], PetscMPIInt **onodes, PetscMPIInt **olengths)
```
Collective


## Input Parameters

- ***comm      -*** Communicator
- ***nsends    -*** number of messages that are to be sent.
- ***nrecvs    -*** number of messages being received
- ***ilengths  -*** an array of integers of length sizeof(comm)
a non zero ilengths[i] represent a message to i of length ilengths[i]



## Output Parameters

- ***onodes    -*** list of node-ids from which messages are expected
- ***olengths  -*** corresponding message lengths





## Notes
With this info, the correct `MPI_Irecv()` can be posted with the correct
from-id, with a buffer with the right amount of memory required.

The calling function deallocates the memory in onodes and olengths

To determine nrecvs, one can use `PetscGatherNumberOfMessages()`


## See Also
 `PetscGatherNumberOfMessages()`, `PetscGatherMessageLengths2()`, `PetscCommBuildTwoSided()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/utils/mpimesg.c.html#PetscGatherMessageLengths">src/sys/utils/mpimesg.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/utils/mpimesg.c)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
