7.0
general documentation
cs_crystal_router.c File Reference
#include "cs_defs.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bft_mem.h"
#include "bft_error.h"
#include "bft_printf.h"
#include "cs_assert.h"
#include "cs_block_dist.h"
#include "cs_log.h"
#include "cs_timer.h"
#include "cs_crystal_router.h"
+ Include dependency graph for cs_crystal_router.c:

Functions

cs_crystal_router_tcs_crystal_router_create_s (size_t n_elts, int stride, cs_datatype_t datatype, int flags, const void *elt, const cs_lnum_t *src_id, const cs_lnum_t *dest_id, const int dest_rank[], MPI_Comm comm)
 Create a Crystal Router for strided data. More...
 
cs_crystal_router_tcs_crystal_router_create_i (size_t n_elts, cs_datatype_t datatype, int flags, const cs_lnum_t *elt_idx, const void *elt, const cs_lnum_t *src_id, const cs_lnum_t *dest_id, const int dest_rank[], MPI_Comm comm)
 Create a Crystal Router for indexed data. More...
 
void cs_crystal_router_destroy (cs_crystal_router_t **cr)
 Destroy a Crystal Router. More...
 
void cs_crystal_router_exchange (cs_crystal_router_t *cr)
 Exchange data with a Crystal Router. More...
 
cs_lnum_t cs_crystal_router_n_elts (const cs_crystal_router_t *cr)
 Get number of elements associated with Crystal Router. More...
 
cs_lnum_t cs_crystal_router_n_recv_elts (const cs_crystal_router_t *cr)
 Get number of elements received with Crystal Router. More...
 
void cs_crystal_router_get_data (cs_crystal_router_t *cr, int **src_rank, cs_lnum_t **dest_id, cs_lnum_t **src_id, cs_lnum_t **data_index, void **data)
 Get data elements associated with a Crystal Router. More...
 
size_t cs_crystal_router_get_max_sizes (cs_crystal_router_t *cr, size_t *max_sizes)
 Query maximum buffer sizes reached by a Crystal Router. More...
 
void cs_crystal_router_log_finalize (void)
 Log performance information relative to Crystal Router exchange. More...
 

Detailed Description

Crystal Router parallel exchange algorithm based operations.

The Crystal Router is described in [3] .

Function Documentation

◆ cs_crystal_router_create_i()

cs_crystal_router_t* cs_crystal_router_create_i ( size_t  n_elts,
cs_datatype_t  datatype,
int  flags,
const cs_lnum_t elt_idx,
const void *  elt,
const cs_lnum_t src_id,
const cs_lnum_t dest_id,
const int  dest_rank[],
MPI_Comm  comm 
)

Create a Crystal Router for indexed data.

If the flags constant contains CS_CRYSTAL_ROUTER_USE_DEST_ID, data exchanged will be ordered by the array passed to the dest_id argument. For n total values received on a rank (as given by cs_crystal_router_n_elts), those destination ids must be in the range [0, n[.

If the flags bit mask matches CS_CRYSTAL_ROUTER_ADD_SRC_ID, source ids are added. If it matches CS_CRYSTAL_ROUTER_ADD_SRC_RANK, source rank metadata is added.

Parameters
[in]n_eltsnumber of elements
[in]datatypetype of data considered
[in]flagsadd destination id ?
[in]elt_idxelement values start and past-the-last index
[in]eltelement values
[in]src_idoptional parent element id (indirection for elt and elt_idx arrays), or NULL
[in]dest_idelement destination id, or NULL
[in]dest_rankdestination rank for each element
[in]commassociated MPI communicator
Returns
pointer to new Crystal Router structure.

◆ cs_crystal_router_create_s()

cs_crystal_router_t* cs_crystal_router_create_s ( size_t  n_elts,
int  stride,
cs_datatype_t  datatype,
int  flags,
const void *  elt,
const cs_lnum_t src_id,
const cs_lnum_t dest_id,
const int  dest_rank[],
MPI_Comm  comm 
)

Create a Crystal Router for strided data.

If the flags constant contains CS_CRYSTAL_ROUTER_USE_DEST_ID, data exchanged will be ordered by the array passed to the dest_id argument. For n total values received on a rank (as given by cs_crystal_router_n_elts), those destination ids must be in the range [0, n[.

If the flags bit mask matches CS_CRYSTAL_ROUTER_ADD_SRC_ID, source ids are added. If it matches CS_CRYSTAL_ROUTER_ADD_SRC_RANK, source rank metadata is added.

Parameters
[in]n_eltsnumber of elements
[in]stridenumber of values per entity (interlaced)
[in]datatypetype of data considered
[in]flagsadd destination id ?
[in]eltelement values
[in]src_idoptional parent element id (indirection for elt array), or NULL
[in]dest_idelement destination id, or NULL
[in]dest_rankdestination rank for each element
[in]commassociated MPI communicator
Returns
pointer to new Crystal Router structure.

◆ cs_crystal_router_destroy()

void cs_crystal_router_destroy ( cs_crystal_router_t **  cr)

Destroy a Crystal Router.

Parameters
[in,out]crpointer to associated Crystal Router

◆ cs_crystal_router_exchange()

void cs_crystal_router_exchange ( cs_crystal_router_t cr)

Exchange data with a Crystal Router.

Order of data from a same source rank is preserved.

Parameters
[in,out]crpointer to associated Crystal Router

◆ cs_crystal_router_get_data()

void cs_crystal_router_get_data ( cs_crystal_router_t cr,
int **  src_rank,
cs_lnum_t **  dest_id,
cs_lnum_t **  src_id,
cs_lnum_t **  data_index,
void **  data 
)

Get data elements associated with a Crystal Router.

Depending on the creation options, some elements may be available or not.

For each element type, a pointer to a pointer to a buffer is provided. If the pointer to the buffer is non-null, the buffer must be of sufficient size for the number of elements returned by cs_crystal_router_n_elts.

If no buffer is provided, one is allocated automatically, and transferred to the caller (who is responsible for freeing it when no longer needed).

Note also that if the destination id is provided in the Crystal Router, it will be applied automatically to the data and data_index arrays. The dest_id array itself is always in receive order. If the Crystal Router does not contain destination id info but the dest_id argument points to a non-NULL value, the provided id will be used to order extracted data. This allows saving the destination id on the receive side, and not re-sending it (saving bandwidth) for subsequent calls with a similar Crystal Router.

If all destination ids appear only once, or the CS_CRYSTAL_ROUTER_USE_DEST_ID is not set, dest_id is also applied to src_rank and src_id. Otherwise, those arrays are kept in buffer order. This can be checked by comparing the output of cs_crystal_router_n_elts and cs_crystal_router_n_recv_elts.

With this behavior, for reverse exchange, src_id and src_rank can be used as dest_id and dest_rank respectively in the call to cs_crystal_router_create_s, while NULL is passed to elt_id with single ids, and dest_id passed in case of duplicate ids.

Parameters
[in]crpointer to associated Crystal Router
[out]src_rankpointer to (pointer to) source rank array, or NULL
[in,out]dest_idpointer to (pointer to) destination id array, or NULL
[out]src_idpointer to (pointer to) source id array, or NULL
[out]data_indexpointer to (pointer to) destination index, or NULL
[out]datapointer to (pointer to) destination data, or NULL

◆ cs_crystal_router_get_max_sizes()

size_t cs_crystal_router_get_max_sizes ( cs_crystal_router_t cr,
size_t *  max_sizes 
)

Query maximum buffer sizes reached by a Crystal Router.

Order of data from a same source rank is preserved.

Parameters
[in]crpointer to associated Crystal Router
[out]max_sizespointer to maximum local/receive (max_sizes[0]) and send (max_sizes[1]) sizes, or NULL
Returns
maximum total allocated buffer memory

◆ cs_crystal_router_log_finalize()

void cs_crystal_router_log_finalize ( void  )

Log performance information relative to Crystal Router exchange.

Call count is based on Crystal router creation calls, as the number of exchange and data access calls should be identical.

◆ cs_crystal_router_n_elts()

cs_lnum_t cs_crystal_router_n_elts ( const cs_crystal_router_t cr)

Get number of elements associated with Crystal Router.

The number of elements is the number of elements received after exchange.

Parameters
[in]crpointer to associated Crystal Router
Returns
number of elements associated with distributor.

◆ cs_crystal_router_n_recv_elts()

cs_lnum_t cs_crystal_router_n_recv_elts ( const cs_crystal_router_t cr)

Get number of elements received with Crystal Router.

The number of elements is the number of elements received in the exchange. In most cases this is the same as that returned using cs_crystal_router_n_elts, but may be larger when a destination id is used and multiple elements point to a same destination (for example when distributing from partitioned data with elements duplicated on partition boundaries to blocks with a single occurence of elements).

Parameters
[in]crpointer to associated Crystal Router
Returns
number of elements associated with distributor.