My Project
programmer's documentation
Functions
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 *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 *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...
 
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...
 
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 [2] .

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 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]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 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]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 all extracted arrays, except the dest_id array itself, which 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.

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_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.