1 /* Copyright 2007,2012 IPB, Universite de Bordeaux, 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       : library_dgraph_build.c                  **/
35 /**                                                        **/
36 /**   AUTHOR     : Francois PELLEGRINI                     **/
37 /**                                                        **/
38 /**   FUNCTION   : This module is the API for the distri-  **/
39 /**                buted source graph handling routines of **/
40 /**                the libSCOTCH library.                  **/
41 /**                                                        **/
42 /**   DATES      : # Version 5.0  : from : 23 feb 2007     **/
43 /**                                 to     18 jul 2007     **/
44 /**                # Version 6.0  : from : 29 nov 2012     **/
45 /**                                 to     29 nov 2012     **/
46 /**                                                        **/
47 /************************************************************/
48 
49 /*
50 **  The defines and includes.
51 */
52 
53 #define LIBRARY
54 
55 #include "module.h"
56 #include "common.h"
57 #include "dgraph.h"
58 #include "ptscotch.h"
59 
60 /****************************************/
61 /*                                      */
62 /* These routines are the C API for the */
63 /* distributed graph handling routines. */
64 /*                                      */
65 /****************************************/
66 
67 /*+ This routine fills the contents of the given
68 *** opaque distributed graph structure with the
69 *** data provided by the user. The base value
70 *** allows the user to set the graph base to 0 or 1.
71 *** It returns:
72 *** - 0   : on success.
73 *** - !0  : on error.
74 +*/
75 
76 int
SCOTCH_dgraphBuild(SCOTCH_Dgraph * const grafptr,const Gnum baseval,const Gnum vertlocnbr,const Gnum vertlocmax,Gnum * const vertloctab,Gnum * const vendloctab,Gnum * const veloloctab,Gnum * const vlblloctab,const Gnum edgelocnbr,const Gnum edgelocsiz,Gnum * const edgeloctab,Gnum * const edgegsttab,Gnum * const edloloctab)77 SCOTCH_dgraphBuild (
78 SCOTCH_Dgraph * const       grafptr,              /* Distributed graph structure to fill  */
79 const Gnum                  baseval,              /* Base for indexing                    */
80 const Gnum                  vertlocnbr,           /* Number of local vertices             */
81 const Gnum                  vertlocmax,           /* Maximum number of local vertices     */
82 Gnum * const                vertloctab,           /* Local vertex begin array             */
83 Gnum * const                vendloctab,           /* Local vertex end array               */
84 Gnum * const                veloloctab,           /* Local vertex load array (if any)     */
85 Gnum * const                vlblloctab,           /* Local vertex label array (if any)    */
86 const Gnum                  edgelocnbr,           /* Number of local edges                */
87 const Gnum                  edgelocsiz,           /* Size of local edge array             */
88 Gnum * const                edgeloctab,           /* Local edge array                     */
89 Gnum * const                edgegsttab,           /* Ghost edge array (if any); not const */
90 Gnum * const                edloloctab)           /* Local edge load array (if any)       */
91 {
92   Dgraph *                    srcgrafptr;         /* Pointer to source graph structure */
93   Gnum *                      vertloctax;
94   Gnum *                      vendloctax;
95   Gnum *                      veloloctax;
96   Gnum *                      vlblloctax;
97   Gnum *                      edgeloctax;
98   Gnum *                      edgegsttax;
99   Gnum *                      edloloctax;
100 
101 #ifdef SCOTCH_DEBUG_LIBRARY1
102   if (sizeof (SCOTCH_Dgraph) < sizeof (Dgraph)) {
103     errorPrint ("SCOTCH_dgraphBuild: internal error");
104     return     (1);
105   }
106 #endif /* SCOTCH_DEBUG_LIBRARY1 */
107   if ((baseval < 0) || (baseval > 1)) {
108     errorPrint ("SCOTCH_dgraphBuild: invalid base parameter");
109     return     (1);
110   }
111 
112   srcgrafptr = (Dgraph *) grafptr;                /* Use structure as source graph */
113 
114   vertloctax = (Gnum *) vertloctab - baseval;
115   vendloctax = ((vendloctab == NULL) || (vendloctab == vertloctab + 1)) ? vertloctax + 1 : (Gnum *) vendloctab - baseval;
116   veloloctax = ((veloloctab == NULL) || (veloloctab == vertloctab)) ? NULL : (Gnum *) veloloctab - baseval;
117   vlblloctax = ((vlblloctab == NULL) || (vlblloctab == vertloctab)) ? NULL : (Gnum *) vlblloctab - baseval;
118   edgeloctax = (Gnum *) edgeloctab - baseval;
119   edgegsttax = ((edgegsttab == NULL) || (edgegsttab == edgeloctab)) ? NULL : (Gnum *) edgegsttab - baseval;
120   edloloctax = ((edloloctab == NULL) || (edloloctab == edgeloctab)) ? NULL : (Gnum *) edloloctab - baseval;
121 
122   return (dgraphBuild (srcgrafptr, baseval,
123                        vertlocnbr, vertlocmax, vertloctax, vendloctax, veloloctax, NULL, vlblloctax,
124                        edgelocnbr, edgelocsiz, edgeloctax, edgegsttax, edloloctax));
125 }
126