1 /* Copyright 2004,2007,2009 ENSEIRB, INRIA & CNRS
2 **
3 ** This file is part of the Scotch software package for static mapping,
4 ** graph partitioning and sparse matrix ordering.
5 **
6 ** This software is governed by the CeCILL-C license under French law
7 ** and abiding by the rules of distribution of free software. You can
8 ** use, modify and/or redistribute the software under the terms of the
9 ** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
10 ** URL: "http://www.cecill.info".
11 **
12 ** As a counterpart to the access to the source code and rights to copy,
13 ** modify and redistribute granted by the license, users are provided
14 ** only with a limited warranty and the software's author, the holder of
15 ** the economic rights, and the successive licensors have only limited
16 ** liability.
17 **
18 ** In this respect, the user's attention is drawn to the risks associated
19 ** with loading, using, modifying and/or developing or reproducing the
20 ** software by the user in light of its specific status of free software,
21 ** that may mean that it is complicated to manipulate, and that also
22 ** therefore means that it is reserved for developers and experienced
23 ** professionals having in-depth computer knowledge. Users are therefore
24 ** encouraged to load and test the software's suitability as regards
25 ** their requirements in conditions enabling the security of their
26 ** systems and/or data to be ensured and, more generally, to use and
27 ** operate it in the same conditions as regards security.
28 **
29 ** The fact that you are presently reading this means that you have had
30 ** knowledge of the CeCILL-C license and that you accept its terms.
31 */
32 /************************************************************/
33 /**                                                        **/
34 /**   NAME       : graph_graph.c                           **/
35 /**                                                        **/
36 /**   AUTHORS    : Francois PELLEGRINI                     **/
37 /**                                                        **/
38 /**   FUNCTION   : Part of a parallel direct block solver. **/
39 /**                These module holds the array graph      **/
40 /**                building routine.                       **/
41 /**                                                        **/
42 /**   DATES      : # Version 1.3  : from : 14 oct 2003     **/
43 /**                                 to     22 jan 2004     **/
44 /**                # Version 2.0  : from : 28 feb 2004     **/
45 /**                                 to     06 dec 2004     **/
46 /**                # Version 5.1  : from : 22 jan 2009     **/
47 /**                                 to     22 jan 2009     **/
48 /**                                                        **/
49 /************************************************************/
50 
51 /*
52 **  The defines and includes.
53 */
54 
55 #define GRAPH
56 
57 #include "common.h"
58 #ifdef SCOTCH_PTSCOTCH
59 #include "ptscotch.h"
60 #else /* SCOTCH_PTSCOTCH */
61 #include "scotch.h"
62 #endif /* SCOTCH_PTSCOTCH */
63 #include "graph.h"
64 
65 /********************************/
66 /*                              */
67 /* The graph handling routines. */
68 /*                              */
69 /********************************/
70 
71 /* This routine builds a graph
72 ** structure from the given
73 ** arrays.
74 ** It returns:
75 ** - 0   : on success.
76 ** - !0  : on error.
77 */
78 
79 int
graphBuildGraph(Graph * const grafptr,const INT baseval,const INT vertnbr,const INT edgenbr,INT * restrict verttab,INT * restrict velotab,INT * restrict edgetab)80 graphBuildGraph (
81 Graph * const               grafptr,              /*+ Graph to build                             +*/
82 const INT                   baseval,              /*+ Base value                                 +*/
83 const INT                   vertnbr,              /*+ Number of vertices                         +*/
84 const INT                   edgenbr,              /*+ Number of arcs                             +*/
85 INT * restrict              verttab,              /*+ Vertex array                               +*/
86 INT * restrict              velotab,              /*+ Array of vertex weights (DOFs) if not NULL +*/
87 INT * restrict              edgetab)              /*+ Edge array                                 +*/
88 {
89   if (sizeof (INT) != sizeof (SCOTCH_Num)) {      /* Check integer consistency */
90     errorPrint ("graphBuildGraph: inconsistent integer types");
91     return     (1);
92   }
93 
94   SCOTCH_graphBuild (grafptr, baseval, vertnbr, verttab, NULL, velotab,
95                      NULL, edgenbr, edgetab, NULL);
96 
97 #ifdef GRAPH_DEBUG
98   if (graphCheck (grafptr) != 0) {                /* Check graph consistency */
99     errorPrint ("graphBuildGraph: inconsistent graph data");
100     return     (1);
101   }
102 #endif /* GRAPH_DEBUG */
103 
104   return (0);
105 }
106 
107 /* This routine builds a graph
108 ** structure from the given
109 ** arrays, with full libScotch
110 ** features.
111 ** It returns:
112 ** - 0   : on success.
113 ** - !0  : on error.
114 */
115 
116 int
graphBuildGraph2(Graph * const grafptr,const INT baseval,const INT vertnbr,const INT edgenbr,INT * restrict verttab,INT * restrict vendtab,INT * restrict velotab,INT * restrict vlbltab,INT * restrict edgetab,INT * restrict edlotab)117 graphBuildGraph2 (
118 Graph * const               grafptr,              /*+ Graph to build                             +*/
119 const INT                   baseval,              /*+ Base value                                 +*/
120 const INT                   vertnbr,              /*+ Number of vertices                         +*/
121 const INT                   edgenbr,              /*+ Number of arcs                             +*/
122 INT * restrict              verttab,              /*+ Vertex array                               +*/
123 INT * restrict              vendtab,              /*+ Vertex end array                           +*/
124 INT * restrict              velotab,              /*+ Array of vertex weights (DOFs) if not NULL +*/
125 INT * restrict              vlbltab,              /*+ Array of vertex labels if not NULL         +*/
126 INT * restrict              edgetab,              /*+ Edge array                                 +*/
127 INT * restrict              edlotab)              /*+ Edge load array                            +*/
128 {
129   if (sizeof (INT) != sizeof (SCOTCH_Num)) {      /* Check integer consistency */
130     errorPrint ("graphBuildGraph2: inconsistent integer types");
131     return     (1);
132   }
133 
134   SCOTCH_graphBuild (grafptr, baseval, vertnbr, verttab, vendtab, velotab,
135                      vlbltab, edgenbr, edgetab, edlotab);
136 
137 #ifdef GRAPH_DEBUG
138   if (graphCheck (grafptr) != 0) {                /* Check graph consistency */
139     errorPrint ("graphBuildGraph2: inconsistent graph data");
140     return     (1);
141   }
142 #endif /* GRAPH_DEBUG */
143 
144   return (0);
145 }
146