PaStiX Handbook  6.3.2
parsec.c
Go to the documentation of this file.
1 /**
2  *
3  * @file parsec.c
4  *
5  * @copyright 2014-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6  * Univ. Bordeaux. All rights reserved.
7  *
8  * PaStiX PaRSEC routines
9  *
10  * @version 6.3.2
11  * @author Xavier Lacoste
12  * @author Pierre Ramet
13  * @author Mathieu Faverge
14  * @date 2023-07-21
15  *
16  * @addtogroup pastix_parsec
17  * @{
18  *
19  **/
20 #ifndef DOXYGEN_SHOULD_SKIP_THIS
21 #ifndef _GNU_SOURCE
22 #define _GNU_SOURCE 1
23 #endif
24 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
25 #include "common.h"
26 #if !defined(PASTIX_WITH_PARSEC)
27 #error "This file should not be compiled if PaRSEC is not enabled"
28 #endif
29 #include <stdio.h>
30 #include <parsec.h>
31 #include "parsec/utils/mca_param.h"
32 #if defined(PASTIX_WITH_CUDA)
33 #include <cublas.h>
34 #endif
35 
36 /**
37  *******************************************************************************
38  *
39  * @brief Startup the PaRSEC runtime system.
40  *
41  * This function initialize and startup the PaRSEC runtime system with PaStix
42  * configuration variables
43  *
44  *******************************************************************************
45  *
46  * @param[inout] pastix
47  * The main pastix_data structure.
48  *
49  * @param[inout] argc
50  * The number of arguments of the main program.
51  *
52  * @param[inout] argv
53  * The list of argument given to the main program.
54  *
55  * @param[in] bindtab
56  * The binding array of size the number of threads if a specific
57  * binding is required, NULL otherwise.
58  *
59  ******************************************************************************/
60 void
62  int *argc, char **argv[],
63  const int *bindtab )
64 {
65  extern char **environ;
66  pastix_int_t *iparm = pastix->iparm;
67  char **parsec_argv = (argv == NULL) ? NULL : *argv;
68  char *value;
69  int rc, thrdnbr;
70 
71  thrdnbr = iparm[IPARM_THREAD_NBR];
72 
73  /* Force no GPUs if CUDA has not been enabled in PaStiX */
74 #if !defined(PASTIX_WITH_CUDA)
75  iparm[IPARM_GPU_NBR] = 0;
76 #endif
77 
78  if (iparm[IPARM_GPU_NBR] >= 0) {
79 #if defined(PASTIX_GENERATE_MODEL)
80  pastix_print( pastix->procnum, 0,
81  "WARNING: PaStiX compiled with -DPASTIX_GENERATE_MODEL forces:\n"
82  " - a single event per stream\n"
83  " - a single stream per GPU\n"
84  " - restore the automatic detection of the number of threads\n" );
85 
86  thrdnbr = -1;
87  parsec_setenv_mca_param( "device_cuda_max_streams", "3", &environ );
88  parsec_setenv_mca_param( "device_cuda_max_events_per_stream", "1", &environ );
89 #endif
90 
91  rc = asprintf(&value, "%d", (int)(iparm[IPARM_GPU_NBR]));
92  parsec_setenv_mca_param( "device_cuda_enabled", value, &environ );
93  free(value);
94 
95  rc = asprintf(&value, "%d", (int)(iparm[IPARM_GPU_MEMORY_BLOCK_SIZE]));
96  parsec_setenv_mca_param( "device_cuda_memory_block_size", value, &environ );
97  free(value);
98 
99  rc = asprintf(&value, "%d", (int)(iparm[IPARM_GPU_MEMORY_PERCENTAGE]));
100  parsec_setenv_mca_param( "device_cuda_memory_use", value, &environ );
101  free(value);
102 
103  if (iparm[IPARM_GPU_NBR] > 0) {
104  if (iparm[IPARM_VERBOSE] > 2) {
105  parsec_setenv_mca_param( "device_show_statistics", "1", &environ );
106  }
107  if (iparm[IPARM_VERBOSE] > 3) {
108  parsec_setenv_mca_param( "device_show_capabilities", "1", &environ );
109  }
110  }
111 
112 #if defined(PASTIX_WITH_CUDA)
113  cublasInit();
114 #endif
115  }
116 
117  if ( bindtab != NULL ) {
118  char *valtmp;
119  int i;
120 
121  rc = asprintf( &value, "%d", bindtab[0] );
122  for(i=1; i<iparm[IPARM_THREAD_NBR]; i++ ) {
123  valtmp = value;
124  rc = asprintf( &value, "%s:%d", valtmp, bindtab[i] );
125  free(valtmp);
126  }
127 
128  if (parsec_argv == NULL) {
129  parsec_argv = malloc( 4 * sizeof(char*) );
130  parsec_argv[0] = strdup( "./pastix" );
131  parsec_argv[1] = strdup( "--parsec_bind" );
132  parsec_argv[2] = value;
133  parsec_argv[3] = NULL;
134  *argc = 3;
135  }
136  else {
137  void *new_ptr = realloc( parsec_argv, (*argc+3) * sizeof(char*) );
138  /* Silent cppcheck warning of realloc failure */
139  if ( new_ptr != NULL ) {
140  parsec_argv = new_ptr;
141  }
142  parsec_argv[*argc ] = strdup( "--parsec_bind" );
143  parsec_argv[*argc + 1] = value;
144  parsec_argv[*argc + 2] = NULL;
145  *argc = *argc + 2;
146  }
147  argv = &parsec_argv;
148  }
149  pastix->parsec = parsec_init( thrdnbr, argc, argv );
150 
151  if ( bindtab != NULL ) {
152  assert( *argc >= 3 );
153 
154  free( parsec_argv[*argc - 1] );
155  free( parsec_argv[*argc - 2] );
156  if ( *argc == 3 ) {
157  free( parsec_argv[*argc - 3] );
158  free( parsec_argv );
159  }
160  }
161  (void)rc;
162 }
163 
164 /**
165  *******************************************************************************
166  *
167  * @brief Finalize the PaRSEC runtime system.
168  *
169  * This function stop the PaRSEC runtime system.
170  *
171  *******************************************************************************
172  *
173  * @param[inout] pastix
174  * The main pastix_data structure.
175  *
176  ******************************************************************************/
177 void
179 {
180  if (pastix->parsec != NULL) {
181  parsec_fini( (parsec_context_t**)&(pastix->parsec) );
182  }
183 }
184 
185 /**
186  * @}
187  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
BEGIN_C_DECLS int pastix(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm, pastix_int_t n, pastix_int_t *colptr, pastix_int_t *rowptr, void *values, pastix_int_t *perm, pastix_int_t *invp, void *B, pastix_int_t nrhs, pastix_int_t *iparm, double *dparm)
Main function for compatibility with former releases.
Definition: pastix.c:103
@ IPARM_GPU_NBR
Definition: api.h:123
@ IPARM_GPU_MEMORY_BLOCK_SIZE
Definition: api.h:125
@ IPARM_GPU_MEMORY_PERCENTAGE
Definition: api.h:124
@ IPARM_VERBOSE
Definition: api.h:36
@ IPARM_THREAD_NBR
Definition: api.h:118
void pastix_parsec_init(pastix_data_t *pastix, int *argc, char **argv[], const int *bindtab)
Startup the PaRSEC runtime system.
Definition: parsec.c:61
void pastix_parsec_finalize(pastix_data_t *pastix)
Finalize the PaRSEC runtime system.
Definition: parsec.c:178
Main PaStiX data structure.
Definition: pastixdata.h:67