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