1 /* Copyright 2008,2010-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_map_f.c                  **/
35 /**                                                        **/
36 /**   AUTHOR     : Francois PELLEGRINI                     **/
37 /**                                                        **/
38 /**   FUNCTION   : This module is the Fortran API for the  **/
39 /**                parallel mapping routines of the        **/
40 /**                libSCOTCH library.                      **/
41 /**                                                        **/
42 /**   DATES      : # Version 5.1  : from : 28 jun 2008     **/
43 /**                                 to     31 aug 2011     **/
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 "ptscotch.h"
58 
59 /**************************************/
60 /*                                    */
61 /* These routines are the Fortran API */
62 /* for the parallel mapping routines. */
63 /*                                    */
64 /**************************************/
65 
66 /*
67 **
68 */
69 
70 FORTRAN (                                       \
71 SCOTCHFDGRAPHMAPINIT, scotchfdgraphmapinit, (   \
72 const SCOTCH_Dgraph * const grafptr,            \
73 SCOTCH_Dmapping * const     mapptr,             \
74 const SCOTCH_Arch * const   archptr,            \
75 SCOTCH_Num * const          termloctab,         \
76 int * const                 revaptr),           \
77 (grafptr, mapptr, archptr, termloctab, revaptr))
78 {
79   *revaptr = SCOTCH_dgraphMapInit (grafptr, mapptr, archptr, termloctab);
80 }
81 
82 /*
83 **
84 */
85 
86 FORTRAN (                                       \
87 SCOTCHFDGRAPHMAPEXIT, scotchfdgraphmapexit, (   \
88 const SCOTCH_Dgraph * const grafptr,            \
89 SCOTCH_Dmapping * const     mapptr),            \
90 (grafptr, mapptr))
91 {
92   SCOTCH_dgraphMapExit (grafptr, mapptr);
93 }
94 
95 /*
96 **
97 */
98 
99 FORTRAN (                                       \
100 SCOTCHFDGRAPHMAPSAVE, scotchfdgraphmapsave, (   \
101 const SCOTCH_Dgraph * const grafptr,            \
102 SCOTCH_Dmapping * const     mapptr,             \
103 int * const                 fileptr,            \
104 int * const                 revaptr),           \
105 (grafptr, mapptr, fileptr, revaptr))
106 {
107   FILE *              stream;                     /* Stream to build from handle */
108   int                 filenum;                    /* Duplicated handle           */
109   int                 o;
110 
111   if ((filenum = dup (*fileptr)) < 0) {           /* If cannot duplicate file descriptor */
112     errorPrint ("SCOTCHFDGRAPHMAPSAVE: cannot duplicate handle");
113 
114     *revaptr = 1;                                 /* Indicate error */
115     return;
116   }
117   if ((stream = fdopen (filenum, "w")) == NULL) { /* Build stream from handle */
118     errorPrint ("SCOTCHFDGRAPHMAPSAVE: cannot open output stream");
119     close      (filenum);
120     *revaptr = 1;
121     return;
122   }
123 
124   o = SCOTCH_dgraphMapSave (grafptr, mapptr, stream);
125 
126   fclose (stream);                                /* This closes filenum too */
127 
128   *revaptr = o;
129 }
130 
131 /*
132 **
133 */
134 
135 FORTRAN (                                           \
136 SCOTCHFDGRAPHMAPCOMPUTE, scotchfdgraphmapcompute, ( \
137 SCOTCH_Dgraph * const       grafptr,                \
138 SCOTCH_Dmapping * const     mapptr,                 \
139 SCOTCH_Strat * const        stratptr,               \
140 int * const                 revaptr),               \
141 (grafptr, mapptr, stratptr, revaptr))
142 {
143   *revaptr = SCOTCH_dgraphMapCompute (grafptr, mapptr, stratptr);
144 }
145 
146 /*
147 **
148 */
149 
150 FORTRAN (                                       \
151 SCOTCHFDGRAPHMAP, scotchfdgraphmap, (           \
152 SCOTCH_Dgraph * const       grafptr,            \
153 const SCOTCH_Arch * const   archptr,            \
154 SCOTCH_Strat * const        stratptr,           \
155 SCOTCH_Num * const          termloctab,         \
156 int * const                 revaptr),           \
157 (grafptr, archptr, stratptr, termloctab, revaptr))
158 {
159   *revaptr = SCOTCH_dgraphMap (grafptr, archptr, stratptr, termloctab);
160 }
161 
162 /*
163 **
164 */
165 
166 FORTRAN (                                       \
167 SCOTCHFDGRAPHPART, scotchfdgraphpart, (         \
168 SCOTCH_Dgraph * const       grafptr,            \
169 const SCOTCH_Num * const    partptr,            \
170 SCOTCH_Strat * const        stratptr,           \
171 SCOTCH_Num * const          termloctab,         \
172 int * const                 revaptr),           \
173 (grafptr, partptr, stratptr, termloctab, revaptr))
174 {
175   *revaptr = SCOTCH_dgraphPart (grafptr, *partptr, stratptr, termloctab);
176 }
177 
178 /* String lengths are passed at the very
179 ** end of the argument list.
180 */
181 
182 FORTRAN (                                       \
183 SCOTCHFSTRATDGRAPHMAP, scotchfstratdgraphmap, ( \
184 SCOTCH_Strat * const        stratptr,           \
185 const char * const          string,             \
186 int * const                 revaptr,            \
187 const int                   strnbr),            \
188 (stratptr, string, revaptr, strnbr))
189 {
190   char * restrict     strtab;                     /* Pointer to null-terminated string */
191 
192   if ((strtab = (char *) memAlloc (strnbr + 1)) == NULL) { /* Allocate temporary space */
193     errorPrint ("SCOTCHFSTRATDGRAPHMAP: out of memory (1)");
194     *revaptr = 1;
195   }
196   memCpy (strtab, string, strnbr);                /* Copy string contents */
197   strtab[strnbr] = '\0';                          /* Terminate string     */
198 
199   *revaptr = SCOTCH_stratDgraphMap (stratptr, strtab); /* Call original routine */
200 
201   memFree (strtab);
202 }
203 
204 /*
205 **
206 */
207 
208 FORTRAN (                                                 \
209 SCOTCHFSTRATDGRAPHMAPBUILD, scotchfstratdgraphmapbuild, ( \
210 SCOTCH_Strat * const        stratptr,                     \
211 const SCOTCH_Num * const    flagval,                      \
212 const SCOTCH_Num * const    procnbr,                      \
213 const SCOTCH_Num * const    partnbr,                      \
214 const double * const        kbalval,                      \
215 int * const                 revaptr),                     \
216 (stratptr, flagval, procnbr, partnbr, kbalval, revaptr))
217 {
218   *revaptr = SCOTCH_stratDgraphMapBuild (stratptr, *flagval, *procnbr, *partnbr, *kbalval);
219 }
220 
221 /*
222 **
223 */
224 
225 FORTRAN (                                                         \
226 SCOTCHFSTRATDGRAPHCLUSTERBUILD, scotchfstratdgraphclusterbuild, ( \
227 SCOTCH_Strat * const        stratptr,                             \
228 const SCOTCH_Num * const    flagval,                              \
229 const SCOTCH_Num * const    procnbr,                              \
230 const SCOTCH_Num * const    pwgtval,                              \
231 const double * const        densval,                              \
232 const double * const        bbalval,                              \
233 int * const                 revaptr),                             \
234 (stratptr, flagval, procnbr, pwgtval, densval, bbalval, revaptr))
235 {
236   *revaptr = SCOTCH_stratDgraphClusterBuild (stratptr, *flagval, *procnbr, *pwgtval, *densval, *bbalval);
237 }
238