1 /* Copyright 2004,2007,2010 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       : library_geom.c                          **/
35 /**                                                        **/
36 /**   AUTHOR     : Francois PELLEGRINI                     **/
37 /**                                                        **/
38 /**   FUNCTION   : This module is the API for the geom     **/
39 /**                graph handling routines of the          **/
40 /**                libSCOTCH library.                      **/
41 /**                                                        **/
42 /**   DATES      : # Version 3.4  : from : 10 oct 1999     **/
43 /**                                 to     01 nov 2001     **/
44 /**                # Version 4.0  : from : 18 dec 2001     **/
45 /**                                 to     19 jan 2004     **/
46 /**                # Version 5.1  : from : 17 nov 2010     **/
47 /**                                 to     17 nov 2010     **/
48 /**                                                        **/
49 /************************************************************/
50 
51 /*
52 **  The defines and includes.
53 */
54 
55 #define LIBRARY
56 
57 #include "module.h"
58 #include "common.h"
59 #include "geom.h"
60 #include "graph.h"
61 #include "scotch.h"
62 
63 /****************************************/
64 /*                                      */
65 /* These routines are the C API for the */
66 /* graph geometry handling routines.    */
67 /*                                      */
68 /****************************************/
69 
70 /*+ This routine reserves a memory area
71 *** of a size sufficient to store a
72 *** geometry structure.
73 *** It returns:
74 *** - !NULL  : if the initialization succeeded.
75 *** - NULL   : on error.
76 +*/
77 
78 SCOTCH_Geom *
SCOTCH_geomAlloc()79 SCOTCH_geomAlloc ()
80 {
81   return ((SCOTCH_Geom *) memAlloc (sizeof (SCOTCH_Geom)));
82 }
83 
84 /*+ This routine initializes the opaque
85 *** geom structure used to handle graph
86 *** geometry in the Scotch library.
87 *** It returns:
88 *** - 0   : if the initialization succeeded.
89 *** - !0  : on error.
90 +*/
91 
92 int
SCOTCH_geomInit(SCOTCH_Geom * const geomptr)93 SCOTCH_geomInit (
94 SCOTCH_Geom * const         geomptr)
95 {
96   if (sizeof (SCOTCH_Num) != sizeof (Gnum)) {
97     errorPrint ("SCOTCH_geomInit: internal error (1)");
98     return     (1);
99   }
100   if (sizeof (SCOTCH_Geom) < sizeof (Geom)) {
101     errorPrint ("SCOTCH_geomInit: internal error (2)");
102     return     (1);
103   }
104 
105   return (geomInit ((Geom *) geomptr));
106 }
107 
108 /*+ This routine frees the contents of the
109 *** given opaque geometry structure.
110 *** It returns:
111 *** - VOID  : in all cases.
112 +*/
113 
114 void
SCOTCH_geomExit(SCOTCH_Geom * const geomptr)115 SCOTCH_geomExit (
116 SCOTCH_Geom * const         geomptr)
117 {
118   geomExit ((Geom *) geomptr);
119 }
120 
121 /*+ This routine accesses all of the geometry data.
122 *** NULL pointers on input indicate unwanted
123 *** data. NULL pointers on output indicate
124 *** unexisting arrays.
125 *** It returns:
126 *** - VOID  : in all cases.
127 +*/
128 
129 void
SCOTCH_geomData(const SCOTCH_Geom * const geomptr,SCOTCH_Num * const dimnptr,double ** const geomtab)130 SCOTCH_geomData (
131 const SCOTCH_Geom * const   geomptr,              /* Geometry structure to read */
132 SCOTCH_Num * const          dimnptr,              /* Number of dimensions       */
133 double ** const             geomtab)              /* Geometry array [vertnbr]   */
134 {
135   const Geom *        srcgeomptr;                 /* Pointer to source geometry structure */
136 
137   srcgeomptr = (const Geom *) geomptr;
138 
139   if (dimnptr != NULL)
140     *dimnptr = srcgeomptr->dimnnbr;
141   if (geomtab != NULL)
142     *geomtab = (double *) srcgeomptr->geomtab;
143 }
144