PaStiX Handbook  6.2.1
graph_io.c
Go to the documentation of this file.
1 /**
2  *
3  * @file graph_io.c
4  *
5  * PaStiX graph IO routines
6  *
7  * @copyright 2004-2021 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.2.1
11  * @author Xavier Lacoste
12  * @author Pierre Ramet
13  * @author Mathieu Faverge
14  * @author Tony Delarue
15  * @date 2021-06-14
16  *
17  **/
18 #include "common.h"
19 #include "graph/graph.h"
20 #include <spm.h>
21 
22 /**
23  *******************************************************************************
24  *
25  * @ingroup pastix_graph
26  *
27  * @brief Load a graph from a file
28  *
29  * The file is named 'graphname' in the local directory.
30  *
31  *******************************************************************************
32  *
33  * @param[in] pastix_data
34  * The pointer to the solver instance to get options as rank,
35  * communicators, ...
36  *
37  * @param[inout] graph
38  * The graph structure to store the loaded graph.
39  * The graph is read from the file named by the environment variable
40  * PASTIX_FILE_GRAPH, and if PASTIX_FILE_GRAPH is not defined, the
41  * default filename "graphname" in the local directory is used.
42  *
43  *******************************************************************************/
44 void
45 graphLoad( const pastix_data_t *pastix_data,
46  pastix_graph_t *graph )
47 {
48  char *filename = NULL;
49  int env = 1;
50 
51  /* Parameter checks */
52  if ( graph == NULL ) {
53  return;
54  }
55 
56  /*
57  * Get the environment variable as second option
58  */
59  filename = pastix_getenv( "PASTIX_FILE_GRAPH" );
60  env = 1;
61 
62  /*
63  * Get the default name as third option
64  */
65  if ( filename == NULL ) {
66  filename = "graphname";
67  env = 0;
68  }
69 
70  spmLoad( graph, filename );
71 
72  if (env) {
73  pastix_cleanenv( filename );
74  }
75 
76  (void)pastix_data;
77 }
78 
79 /**
80  *******************************************************************************
81  *
82  * @ingroup pastix_graph
83  *
84  * @brief Save a graph to file.
85  *
86  * The file is named 'graphgen' in the local directory.
87  *
88  *******************************************************************************
89  *
90  * @param[in] pastix_data
91  * The pointer to the solver instance to get options as rank,
92  * communicators, ...
93  *
94  * @param[in] graph
95  * The graph structure to store the loaded graph.
96  * The graph is written to the file named by the environment variable
97  * PASTIX_FILE_GRAPH, and if PASTIX_FILE_GRAPH is not defined, the
98  * default filename "graphname" in the local directory is used.
99  *
100  *******************************************************************************/
101 void
102 graphSave( pastix_data_t *pastix_data,
103  const pastix_graph_t *graph )
104 {
105  char *filename = NULL;
106  char *fullname = NULL;
107  int env = 1;
108 
109  /* Parameter checks */
110  if ( graph == NULL ) {
111  return;
112  }
113 
114  /*
115  * Get the environment variable as first option
116  */
117  filename = pastix_getenv( "PASTIX_FILE_GRAPH" );
118 
119  /*
120  * Get the default name as second option
121  */
122  if ( filename == NULL ) {
123  filename = "graphgen";
124  env = 0;
125  }
126 
127  pastix_gendirectories( pastix_data );
128  fullname = pastix_fname( pastix_data->dir_local, filename );
129  if ( fullname ) {
130  spmSave( graph, fullname );
131  free( fullname );
132  }
133 
134  if ( env ) {
135  pastix_cleanenv( filename );
136  }
137 }
pastix_gendirectories
void pastix_gendirectories(pastix_data_t *pastix_data)
Generate a unique temporary directory to store output files.
Definition: api.c:69
graphSave
void graphSave(pastix_data_t *pastix_data, const pastix_graph_t *graph)
Save a graph to file.
Definition: graph_io.c:102
graph.h
graphLoad
void graphLoad(const pastix_data_t *pastix_data, pastix_graph_t *graph)
Load a graph from a file.
Definition: graph_io.c:45
pastix_fname
char * pastix_fname(const char *dirname, const char *filename)
Generate the full filename within local or global directory.
Definition: api.c:189