PaStiX Handbook  6.2.1
solver_comm_matrix.c
Go to the documentation of this file.
1 /**
2  *
3  * @file solver_comm_matrix.c
4  *
5  * PaStiX communication matrix handler.
6  *
7  * @copyright 1998-2021 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.2.1
11  * @author Nolan Bredel
12  * @date 2021-07-02
13  *
14  **/
15 #include "common/common.h"
17 
18 #if !defined(PASTIX_COMMUNICATION_MATRIX)
19 #error "PASTIX_COMMUNICATION_MATRIX option is disabled"
20 #endif
21 
22 /**
23  *******************************************************************************
24  *
25  * @brief Initialize the communication matrix.
26  *
27  *******************************************************************************
28  *
29  * @param[inout] solvmtx
30  * The solver structure to which to attach the communication vector.
31  *
32  *******************************************************************************/
33 void
34 solverComMatrixInit( SolverMatrix *solvmtx )
35 {
36  solvmtx->com_vector = calloc( solvmtx->clustnbr, sizeof( size_t ) );
37 }
38 
39 /**
40  *******************************************************************************
41  *
42  * @brief Free the communication matrix.
43  *
44  *******************************************************************************
45  *
46  * @param[inout] solvmtx
47  * The solver structure to which to free the communication vector.
48  *
49  *******************************************************************************/
50 void
51 solverComMatrixExit( SolverMatrix *solvmtx )
52 {
53  free( solvmtx->com_vector );
54  solvmtx->com_vector = NULL;
55 }
56 
57 /**
58  *******************************************************************************
59  *
60  * @brief Gather the volume of communication and save it as a csv.
61  *
62  *******************************************************************************
63  *
64  * @param[inout] solvmtx
65  * The solver structure with the communication vector to gather.
66  *
67  *******************************************************************************/
68 void
69 solverComMatrixGather( SolverMatrix *solvmtx )
70 {
71  size_t *com_matrix = NULL;
72  int src;
73  FILE * file;
74 
75  MPI_Comm_rank( solvmtx->solv_comm, &src );
76  if ( src == 0 ) {
77  com_matrix = malloc( solvmtx->clustnbr * solvmtx->clustnbr * sizeof( size_t ) );
78  }
79 
80  MPI_Gather( solvmtx->com_vector, solvmtx->clustnbr, MPI_UNSIGNED_LONG,
81  com_matrix, solvmtx->clustnbr, MPI_UNSIGNED_LONG,
82  0, solvmtx->solv_comm );
83 
84  if ( src == 0 )
85  {
86  file = pastix_fopenw( ".", "com_matrix.csv", "w" );
87 
88  /* header */
89  int p;
90  for ( p = 0; p < solvmtx->clustnbr; p++ ) {
91  fprintf( file, "R%d, ", p );
92  }
93  fprintf( file, "\n" );
94 
95  int i;
96  for ( i = 0; i < ( solvmtx->clustnbr * solvmtx->clustnbr ); i++ ) {
97  fprintf( file, "%lu, ", com_matrix[i] );
98  if ( ( ( i + 1 ) % solvmtx->clustnbr ) == 0 ) {
99  fprintf( file, "\n" );
100  }
101  }
102  fclose(file);
103  }
104  free( com_matrix );
105 }
solver_comm_matrix.h
solverComMatrixExit
void solverComMatrixExit(SolverMatrix *solvmtx)
Free the communication matrix.
Definition: solver_comm_matrix.c:51
pastix_fopenw
FILE * pastix_fopenw(const char *dirname, const char *filename, const char *mode)
Open a file in the unique directory of the pastix instance.
Definition: api.c:232
solverComMatrixGather
void solverComMatrixGather(SolverMatrix *solvmtx)
Gather the volume of communication and save it as a csv.
Definition: solver_comm_matrix.c:69
solverComMatrixInit
void solverComMatrixInit(SolverMatrix *solvmtx)
Initialize the communication matrix.
Definition: solver_comm_matrix.c:34