SpM Handbook 1.2.4
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spm_redistribute.c File Reference
#include "common.h"

Go to the source code of this file.

Functions

SPM distribution subroutines
int spmRedistribute (const spmatrix_t *spm, spm_int_t new_n, const spm_int_t *newl2g, spmatrix_t *newspm)
 Create a copy of a given SPM with a new distribution corresponding to the given loc2glob array.
 
#define COLTAG   97
 Internal tag for colptr array communications.
 
#define ROWTAG   98
 Internal tag for rowptr array communications.
 
#define VALTAG   99
 Internal tag for values array communications.
 
typedef struct spm_req_manager_s spm_req_manager_t
 Data structure to manage the communication requests.
 
static void spm_redist_reqmanager_test (spm_req_manager_t *reqmanager)
 Make the communications progress in the request manager structure.
 
static void spm_redist_reqmanager_wait (spm_req_manager_t *reqmanager)
 Wait for all the communications to be completed.
 
static spm_int_tspm_redist_get_newg2l (const spmatrix_t *oldspm, spm_int_t new_n, const spm_int_t *newl2g)
 Get the new glob2loc array.
 
static void spm_redist_extract_local (const spmatrix_t *oldspm, const spm_int_t *newg2l, int distribution, spm_int_t *sendsizes, spm_int_t *recvsizes, spmatrix_t *newspm)
 Extract the local information and compute the volumes to exchange.
 
static void spm_redist_post_recv (spmatrix_t *newspm, const spm_int_t *recvsizes, int distribution, spm_req_manager_t *reqmanager)
 Allocate the reqtab array and post all the required receptions for each process.
 
static void spm_redist_reqmanager_try_sendone (spm_req_manager_t *reqmanager, struct spm_send_data_s *sendproc, int dest, MPI_Comm comm)
 Submit the send request if the buffers are filled.
 
static void spm_redist_send_loop_csx (const spmatrix_t *oldspm, const spm_int_t *newg2l, struct spm_send_data_s *senddata, spm_req_manager_t *reqmanager)
 Fill all the send arrays from CSC/CSR format to IJV buffers and submit the send.
 
static void spm_redist_send_loop_ijv (const spmatrix_t *oldspm, const spm_int_t *newg2l, struct spm_send_data_s *senddata, spm_req_manager_t *reqmanager, int distribution)
 Fill all the send arrays from IJV format to IJV buffers and submit the send.
 
static void spm_redist_send (const spmatrix_t *oldspm, const spm_int_t *newg2l, const spm_int_t *sendsizes, spm_req_manager_t *reqmanager, int distribution)
 Fill all the send arrays and send them.
 
static void spm_redist_finalize (const spmatrix_t *oldspm, spmatrix_t *newspm, const spm_int_t *newg2l, const spm_int_t *newl2g, spm_int_t new_n)
 Finalize the compuration of the newspm to correspond to oldspm redistributed thanks to newl2g.
 

Detailed Description

SPM subroutines to redistribute a given SPM with a new distribution.

Version
1.2.4
Author
Pierre Ramet
Mathieu Faverge
Tony Delarue
Alycia Lisito
Date
2024-06-25

Definition in file spm_redistribute.c.

Macro Definition Documentation

◆ COLTAG

#define COLTAG   97

Internal tag for colptr array communications.

Definition at line 33 of file spm_redistribute.c.

◆ ROWTAG

#define ROWTAG   98

Internal tag for rowptr array communications.

Definition at line 34 of file spm_redistribute.c.

◆ VALTAG

#define VALTAG   99

Internal tag for values array communications.

Definition at line 35 of file spm_redistribute.c.

Function Documentation

◆ spm_redist_reqmanager_test()

static void spm_redist_reqmanager_test ( spm_req_manager_t reqmanager)
static

Make the communications progress in the request manager structure.

Parameters
[in,out]reqmanagerThe data structure that holds the requests to test for progress. On exit, the array if compacted in release mode.

Definition at line 59 of file spm_redistribute.c.

Referenced by spm_redist_reqmanager_try_sendone().

◆ spm_redist_reqmanager_wait()

static void spm_redist_reqmanager_wait ( spm_req_manager_t reqmanager)
static

Wait for all the communications to be completed.

Parameters
[in,out]reqmanagerThe data structure that holds the requests to wait for completion.

Definition at line 101 of file spm_redistribute.c.

Referenced by spm_redist_send().

◆ spm_redist_get_newg2l()

static spm_int_t * spm_redist_get_newg2l ( const spmatrix_t oldspm,
spm_int_t  new_n,
const spm_int_t newl2g 
)
static

Get the new glob2loc array.

Parameters
[in]oldspmThe sparse matrix to redistribute.
[in]new_nThe size of newl2g
[in]newl2gThe new loc2glob.
Returns
The new glob2loc array

Definition at line 153 of file spm_redistribute.c.

References spmatrix_s::baseval, spmatrix_s::comm, spmatrix_s::glob2loc, spmatrix_s::gN, spmatrix_s::loc2glob, spmatrix_s::n, spmatrix_s::replicated, spm_getandset_glob2loc(), and spmInitDist().

Referenced by spmRedistribute().

◆ spm_redist_extract_local()

static void spm_redist_extract_local ( const spmatrix_t oldspm,
const spm_int_t newg2l,
int  distribution,
spm_int_t sendsizes,
spm_int_t recvsizes,
spmatrix_t newspm 
)
static

Extract the local information and compute the volumes to exchange.

This function create a copy of the matrix in which it extracts the local information, while it computes the number of data to exchange with everyone. On exit, the new spm is allocated to its final size in the IJV format to receive information from the other nodes.

Parameters
[in]oldspmThe original sparse matrix to redistribute.
[in]newg2lThe new spm glob2loc array of size oldspm->gN and 0-based. The array is generated with spm_redist_get_newg2l() and shifted to match the oldspm baseval.
[in]distributionThe distribution of thne original matrix as computed by spm_get_distribution().
[in,out]sendsizesOn entry, array of size (2*clustnbr) that must be allocated. On exit, the array stores the couple (nbelts, nbvals) of the number of elements/values to send to each remote process.
[in,out]recvsizesOn entry, array of size (2*clustnbr) that must be allocated. On exit, the array stores the couple (nbelts, nbvals) of the number of elements/values to reacv from each remote process.
[in,out]newspmInitialize the redistributed spm.

Definition at line 212 of file spm_redistribute.c.

References spmatrix_s::baseval, spmatrix_s::clustnbr, spmatrix_s::clustnum, spmatrix_s::colptr, spmatrix_s::comm, spmatrix_s::dof, spmatrix_s::dofs, spmatrix_s::flttype, spmatrix_s::fmttype, spmatrix_s::loc2glob, spmatrix_s::mtxtype, spmatrix_s::n, spmatrix_s::nnz, spmatrix_s::nnzexp, spmatrix_s::replicated, spmatrix_s::rowptr, SPM_MPI_INT, spm_size_of(), SpmDistByColumn, SpmIJV, spmInitDist(), and spmatrix_s::values.

Referenced by spmRedistribute().

◆ spm_redist_post_recv()

static void spm_redist_post_recv ( spmatrix_t newspm,
const spm_int_t recvsizes,
int  distribution,
spm_req_manager_t reqmanager 
)
static

Allocate the reqtab array and post all the required receptions for each process.

Parameters
[in,out]newspmThe new spm in which to store the reception. Must be in IJV format. On entry, it is allocated to store all the information that will be received, and on exit, it may be partially updated by the reception asynchronously.
[in]recvsizesAmount of recvs for each process. {ptr_recvs, val_recvs}
[in]distributionThe distribution of the original sparse matrix.
[in,out]reqmanagerOn entry, an allocated request manager structure. On exit, the data structure is initialized and the first requests are associated to the submitted reception.

Definition at line 416 of file spm_redistribute.c.

References spmatrix_s::clustnbr, spmatrix_s::clustnum, spmatrix_s::colptr, COLTAG, spmatrix_s::comm, spmatrix_s::flttype, spmatrix_s::rowptr, ROWTAG, SPM_MPI_INT, spm_size_of(), SpmDistByColumn, SpmPattern, VALTAG, and spmatrix_s::values.

Referenced by spmRedistribute().

◆ spm_redist_reqmanager_try_sendone()

static void spm_redist_reqmanager_try_sendone ( spm_req_manager_t reqmanager,
struct spm_send_data_s *  sendproc,
int  dest,
MPI_Comm  comm 
)
static

Submit the send request if the buffers are filled.

Parameters
[in,out]reqmanagerThe data structure that holds the requests to wait for completion.
[in,out]sendprocThe data structure that holds the data to send.
[in]destThe destination rank of the communications.
[in]commThe MPI communicator to use for the communication

Definition at line 535 of file spm_redistribute.c.

References COLTAG, ROWTAG, SPM_MPI_INT, spm_redist_reqmanager_test(), and VALTAG.

Referenced by spm_redist_send_loop_csx(), and spm_redist_send_loop_ijv().

◆ spm_redist_send_loop_csx()

static void spm_redist_send_loop_csx ( const spmatrix_t oldspm,
const spm_int_t newg2l,
struct spm_send_data_s *  senddata,
spm_req_manager_t reqmanager 
)
static

Fill all the send arrays from CSC/CSR format to IJV buffers and submit the send.

Parameters
[in]oldspmThe original sparse matrix to redistribute.
[in]newg2lThe new spm glob2loc array [-baseval].
[in,out]senddataThe allocated data structure to holds the information to send. On exit, the buffers are filled and associated send requests are submitted but may not be completed.
[in,out]reqmanagerThe data structure that holds the requests to wait for completion.

Definition at line 598 of file spm_redistribute.c.

References spmatrix_s::baseval, spmatrix_s::clustnum, spmatrix_s::colptr, spmatrix_s::comm, spmatrix_s::dof, spmatrix_s::dofs, spmatrix_s::flttype, spmatrix_s::fmttype, spmatrix_s::loc2glob, spmatrix_s::n, spmatrix_s::rowptr, spm_redist_reqmanager_try_sendone(), spm_size_of(), SpmCSC, and spmatrix_s::values.

Referenced by spm_redist_send().

◆ spm_redist_send_loop_ijv()

static void spm_redist_send_loop_ijv ( const spmatrix_t oldspm,
const spm_int_t newg2l,
struct spm_send_data_s *  senddata,
spm_req_manager_t reqmanager,
int  distribution 
)
static

Fill all the send arrays from IJV format to IJV buffers and submit the send.

Parameters
[in]oldspmThe original sparse matrix to redistribute.
[in]newg2lThe new spm glob2loc array [-baseval].
[in,out]senddataThe allocated data structure to holds the information to send. On exit, the buffers are filled and associated send requests are submitted but may not be completed.
[in,out]reqmanagerThe data structure that holds the requests to wait for completion.
[in]distributionThe distribution of the original sparse matrix.

Definition at line 693 of file spm_redistribute.c.

References spmatrix_s::baseval, spmatrix_s::clustnum, spmatrix_s::colptr, spmatrix_s::comm, spmatrix_s::dof, spmatrix_s::dofs, spmatrix_s::flttype, spmatrix_s::nnz, spmatrix_s::rowptr, spm_redist_reqmanager_try_sendone(), spm_size_of(), SpmDistByColumn, and spmatrix_s::values.

Referenced by spm_redist_send().

◆ spm_redist_send()

static void spm_redist_send ( const spmatrix_t oldspm,
const spm_int_t newg2l,
const spm_int_t sendsizes,
spm_req_manager_t reqmanager,
int  distribution 
)
static

Fill all the send arrays and send them.

Parameters
[in]oldspmThe sparse matrix to redistribute.
[in]newg2lThe new glob2loc array.
[in]sendsizesThe array that store the number of elements to send for each process : {col_sends, row_sends, val_sends}
[in,out]reqmanagerThe data structure that holds the requests to wait for completion.
[in]distributionThe distribution of the original sparse matrix.

Definition at line 776 of file spm_redistribute.c.

References spmatrix_s::baseval, spmatrix_s::clustnbr, spmatrix_s::clustnum, spmatrix_s::flttype, spmatrix_s::fmttype, spm_redist_reqmanager_wait(), spm_redist_send_loop_csx(), spm_redist_send_loop_ijv(), spm_size_of(), and SpmIJV.

Referenced by spmRedistribute().

◆ spm_redist_finalize()

static void spm_redist_finalize ( const spmatrix_t oldspm,
spmatrix_t newspm,
const spm_int_t newg2l,
const spm_int_t newl2g,
spm_int_t  new_n 
)
static

Finalize the compuration of the newspm to correspond to oldspm redistributed thanks to newl2g.

Parameters
[in]oldspmThe sparse matrix to redistribute.
[in,out]newspmThe new spm.
[in]newg2lThe new glob2loc array. Will be stored in the newspm.
[in]newl2gThe new loc2glob array. Will be copied in the newspm.
[in]new_nSize of the new loc2glob.

Definition at line 850 of file spm_redistribute.c.

References spmatrix_s::baseval, spmatrix_s::dof, spmatrix_s::dofs, spmatrix_s::flttype, spmatrix_s::fmttype, spmatrix_s::glob2loc, spmatrix_s::gN, spmatrix_s::gNexp, spmatrix_s::gnnz, spmatrix_s::gnnzexp, spmatrix_s::layout, spmatrix_s::loc2glob, spmatrix_s::mtxtype, spmatrix_s::n, spmConvert(), SpmIJV, spmSort(), and spmUpdateComputedFields().

Referenced by spmRedistribute().