~ubuntu-branches/ubuntu/trusty/scotch/trusty

« back to all changes in this revision

Viewing changes to src/libscotch/library_graph_f.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-01-25 09:13:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080125091353-zghdao60dfsyc2bt
Tags: upstream-5.0.1.dfsg
ImportĀ upstreamĀ versionĀ 5.0.1.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2004,2007 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_graph_f.c                       **/
 
35
/**                                                        **/
 
36
/**   AUTHOR     : Francois PELLEGRINI                     **/
 
37
/**                                                        **/
 
38
/**   FUNCTION   : This file contains the Fortran API for  **/
 
39
/**                the source graph handling routines of   **/
 
40
/**                the libSCOTCH library.                  **/
 
41
/**                                                        **/
 
42
/**   DATES      : # Version 3.4  : from : 02 dec 1999     **/
 
43
/**                                 to     15 nov 2001     **/
 
44
/**                # Version 4.0  : from : 11 dec 2001     **/
 
45
/**                                 to     17 mar 2005     **/
 
46
/**                # Version 5.0  : from : 11 jul 2007     **/
 
47
/**                                 to     11 jul 2007     **/
 
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 "scotch.h"
 
60
 
 
61
/**************************************/
 
62
/*                                    */
 
63
/* These routines are the Fortran API */
 
64
/* for the graph handling routines.   */
 
65
/*                                    */
 
66
/**************************************/
 
67
 
 
68
/*
 
69
**
 
70
*/
 
71
 
 
72
FORTRAN (                                       \
 
73
SCOTCHFGRAPHINIT, scotchfgraphinit, (           \
 
74
SCOTCH_Graph * const        grafptr,            \
 
75
int * const                 revaptr),           \
 
76
(grafptr, revaptr))
 
77
{
 
78
  *revaptr = SCOTCH_graphInit (grafptr);
 
79
}
 
80
 
 
81
/*
 
82
**
 
83
*/
 
84
 
 
85
FORTRAN (                                       \
 
86
SCOTCHFGRAPHEXIT, scotchfgraphexit, (           \
 
87
SCOTCH_Graph * const        grafptr),           \
 
88
(grafptr))
 
89
{
 
90
  SCOTCH_graphExit (grafptr);
 
91
}
 
92
 
 
93
/*
 
94
**
 
95
*/
 
96
 
 
97
FORTRAN (                                       \
 
98
SCOTCHFGRAPHFREE, scotchfgraphfree, (           \
 
99
SCOTCH_Graph * const        grafptr),           \
 
100
(grafptr))
 
101
{
 
102
  SCOTCH_graphFree (grafptr);
 
103
}
 
104
 
 
105
/* When an input stream is built from the given
 
106
** file handle, it is set as unbuffered, so as to
 
107
** allow for multiple stream reads from the same
 
108
** file handle. If it were buffered, too many
 
109
** input characters would be read on the first
 
110
** block read.
 
111
*/
 
112
 
 
113
FORTRAN (                                       \
 
114
SCOTCHFGRAPHLOAD, scotchfgraphload, (           \
 
115
SCOTCH_Graph * const        grafptr,            \
 
116
int * const                 fileptr,            \
 
117
const SCOTCH_Num * const    baseptr,            \
 
118
const SCOTCH_Num * const    flagptr,            \
 
119
int * const                 revaptr),           \
 
120
(grafptr, fileptr, baseptr, flagptr, revaptr))
 
121
{
 
122
  FILE *              stream;                     /* Stream to build from handle */
 
123
  int                 filenum;                    /* Duplicated handle           */
 
124
  int                 o;
 
125
 
 
126
  if ((filenum = dup (*fileptr)) < 0) {           /* If cannot duplicate file descriptor */
 
127
    errorPrint ("SCOTCHFGRAPHLOAD: cannot duplicate handle");
 
128
    *revaptr = 1;                                 /* Indicate error */
 
129
    return;
 
130
  }
 
131
  if ((stream = fdopen (filenum, "r+")) == NULL) { /* Build stream from handle */
 
132
    errorPrint ("SCOTCHFGRAPHLOAD: cannot open input stream");
 
133
    close      (filenum);
 
134
    *revaptr = 1;
 
135
    return;
 
136
  }
 
137
  setbuf (stream, NULL);                          /* Do not buffer on input */
 
138
 
 
139
  o = SCOTCH_graphLoad (grafptr, stream, *baseptr, *flagptr);
 
140
 
 
141
  fclose (stream);                                /* This closes filenum too */
 
142
 
 
143
  *revaptr = o;
 
144
}
 
145
 
 
146
/*
 
147
**
 
148
*/
 
149
 
 
150
FORTRAN (                                       \
 
151
SCOTCHFGRAPHSAVE, scotchfgraphsave, (           \
 
152
const SCOTCH_Graph * const  grafptr,            \
 
153
int * const                 fileptr,            \
 
154
int * const                 revaptr),           \
 
155
(grafptr, fileptr, revaptr))
 
156
{
 
157
  FILE *              stream;                     /* Stream to build from handle */
 
158
  int                 filenum;                    /* Duplicated handle           */
 
159
  int                 o;
 
160
 
 
161
  if ((filenum = dup (*fileptr)) < 0) {           /* If cannot duplicate file descriptor */
 
162
    errorPrint ("SCOTCHFGRAPHSAVE: cannot duplicate handle");
 
163
 
 
164
    *revaptr = 1;                                 /* Indicate error */
 
165
    return;
 
166
  }
 
167
  if ((stream = fdopen (filenum, "w+")) == NULL) { /* Build stream from handle */
 
168
    errorPrint ("SCOTCHFGRAPHSAVE: cannot open output stream");
 
169
    close      (filenum);
 
170
    *revaptr = 1;
 
171
    return;
 
172
  }
 
173
 
 
174
  o = SCOTCH_graphSave (grafptr, stream);
 
175
 
 
176
  fclose (stream);                                /* This closes filenum too */
 
177
 
 
178
  *revaptr = o;
 
179
}
 
180
 
 
181
/*
 
182
**
 
183
*/
 
184
 
 
185
FORTRAN (                                       \
 
186
SCOTCHFGRAPHBUILD, scotchfgraphbuild, (         \
 
187
SCOTCH_Graph * const        grafptr,            \
 
188
const SCOTCH_Num * const    baseptr,            \
 
189
const SCOTCH_Num * const    vertptr,            \
 
190
const SCOTCH_Num * const    verttab,            \
 
191
const SCOTCH_Num * const    vendtab,            \
 
192
const SCOTCH_Num * const    velotab,            \
 
193
const SCOTCH_Num * const    vlbltab,            \
 
194
const SCOTCH_Num * const    edgeptr,            \
 
195
const SCOTCH_Num * const    edgetab,            \
 
196
const SCOTCH_Num * const    edlotab,            \
 
197
int * const                 revaptr),           \
 
198
(grafptr, baseptr, vertptr, verttab, vendtab,   \
 
199
 velotab, vlbltab, edgeptr, edgetab, edlotab,   \
 
200
 revaptr))
 
201
{
 
202
  *revaptr = SCOTCH_graphBuild (grafptr, *baseptr, *vertptr, verttab, vendtab,
 
203
                                velotab, vlbltab, *edgeptr, edgetab, edlotab);
 
204
}
 
205
 
 
206
/*
 
207
**
 
208
*/
 
209
 
 
210
FORTRAN (                                       \
 
211
SCOTCHFGRAPHSIZE, scotchfgraphsize, (           \
 
212
const SCOTCH_Graph * const  grafptr,            \
 
213
SCOTCH_Num * const          vertptr,            \
 
214
SCOTCH_Num * const          edgeptr),           \
 
215
(grafptr, vertptr, edgeptr))
 
216
{
 
217
  SCOTCH_graphSize (grafptr, vertptr, edgeptr);
 
218
}
 
219
 
 
220
/*
 
221
**
 
222
*/
 
223
 
 
224
FORTRAN (                                       \
 
225
SCOTCHFGRAPHDATA, scotchfgraphdata, (           \
 
226
const SCOTCH_Graph * const  grafptr,            \
 
227
const SCOTCH_Num * const    indxptr,            \
 
228
SCOTCH_Num * const          baseptr,            \
 
229
SCOTCH_Num * const          vertptr,            \
 
230
SCOTCH_Num * const          vertidx,            \
 
231
SCOTCH_Num * const          vendidx,            \
 
232
SCOTCH_Num * const          veloidx,            \
 
233
SCOTCH_Num * const          vlblidx,            \
 
234
SCOTCH_Num * const          edgeptr,            \
 
235
SCOTCH_Num * const          edgeidx,            \
 
236
SCOTCH_Num * const          edloidx),           \
 
237
(grafptr, indxptr, baseptr,                     \
 
238
 vertptr, vertidx, vendidx, veloidx, vlblidx,   \
 
239
 edgeptr, edgeidx, edloidx))
 
240
{
 
241
  SCOTCH_Num *        verttab;                    /* Pointer to graph arrays */
 
242
  SCOTCH_Num *        vendtab;
 
243
  SCOTCH_Num *        velotab;
 
244
  SCOTCH_Num *        vlbltab;
 
245
  SCOTCH_Num *        edgetab;
 
246
  SCOTCH_Num *        edlotab;
 
247
 
 
248
  SCOTCH_graphData (grafptr, baseptr, vertptr, &verttab, &vendtab, &velotab, &vlbltab,
 
249
                    edgeptr, &edgetab, &edlotab);
 
250
  *vertidx = (verttab - indxptr) + 1;             /* Add 1 since Fortran indices start at 1 */
 
251
  *vendidx = (vendtab - indxptr) + 1;
 
252
  *veloidx = (velotab != NULL) ? (velotab - indxptr) + 1 : *vertidx;
 
253
  *vlblidx = (vlbltab != NULL) ? (vlbltab - indxptr) + 1 : *vertidx;
 
254
  *edgeidx = (edgetab - indxptr) + 1;
 
255
  *edloidx = (edlotab != NULL) ? (edlotab - indxptr) + 1 : *edgeidx;
 
256
}
 
257
 
 
258
/*
 
259
**
 
260
*/
 
261
 
 
262
FORTRAN (                                       \
 
263
SCOTCHFGRAPHSTAT, scotchfgraphstat, (           \
 
264
const SCOTCH_Graph * const  grafptr,            \
 
265
SCOTCH_Num * const          velominptr,         \
 
266
SCOTCH_Num * const          velomaxptr,         \
 
267
SCOTCH_Num * const          velosumptr,         \
 
268
double *                    veloavgptr,         \
 
269
double *                    velodltptr,         \
 
270
SCOTCH_Num * const          degrminptr,         \
 
271
SCOTCH_Num * const          degrmaxptr,         \
 
272
double *                    degravgptr,         \
 
273
double *                    degrdltptr,         \
 
274
SCOTCH_Num * const          edlominptr,         \
 
275
SCOTCH_Num * const          edlomaxptr,         \
 
276
SCOTCH_Num * const          edlosumptr,         \
 
277
double *                    edloavgptr,         \
 
278
double *                    edlodltptr),        \
 
279
(grafptr, velominptr, velomaxptr, velosumptr,   \
 
280
 veloavgptr, velodltptr, degrminptr,            \
 
281
 degrmaxptr, degravgptr, degrdltptr,            \
 
282
 edlominptr, edlomaxptr, edlosumptr,            \
 
283
 edloavgptr, edlodltptr))
 
284
{
 
285
  SCOTCH_graphStat (grafptr,
 
286
                    velominptr, velomaxptr, velosumptr, veloavgptr, velodltptr,
 
287
                    degrminptr, degrmaxptr, degravgptr, degrdltptr,
 
288
                    edlominptr, edlomaxptr, edlosumptr, edloavgptr, edlodltptr);
 
289
}