1 /* Copyright 2004,2007,2010,2013 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       : vgraph_separate_vw.c                    **/
35 /**                                                        **/
36 /**   AUTHOR     : Francois PELLEGRINI                     **/
37 /**                                                        **/
38 /**   FUNCTION   : This module outputs the state of the    **/
39 /**                current partition on the form of a      **/
40 /**                Scotch mapping file.                    **/
41 /**                                                        **/
42 /**   DATES      : # Version 4.0  : from : 18 may 2004     **/
43 /**                                 to     18 may 2004     **/
44 /**                # Version 5.1  : from : 11 aug 2010     **/
45 /**                                 to     11 aug 2010     **/
46 /**                # Version 6.0  : from : 10 oct 2013     **/
47 /**                                 to     10 oct 2013     **/
48 /**                                                        **/
49 /************************************************************/
50 
51 /*
52 **  The defines and includes.
53 */
54 
55 #define VGRAPH_SEPARATE_VW
56 
57 #include "module.h"
58 #include "common.h"
59 #include "gain.h"
60 #include "graph.h"
61 #include "vgraph.h"
62 #include "vgraph_separate_vw.h"
63 
64 /*
65 **  The static variables.
66 */
67 
68 static int                  vgraphseparatevwfilenum = 0; /* Number of file to output */
69 
70 /*****************************/
71 /*                           */
72 /* This is the main routine. */
73 /*                           */
74 /*****************************/
75 
76 /* This routine outputs the mapping file.
77 ** It returns:
78 ** - 0   : if the file could be produced.
79 ** - !0  : on error.
80 */
81 
82 int
vgraphSeparateVw(Vgraph * restrict const grafptr)83 vgraphSeparateVw (
84 Vgraph * restrict const             grafptr)      /*+ Separation graph +*/
85 {
86   char                nametab[64];                /* File name */
87   FILE * restrict     fileptr;
88   Gnum                vertnum;                    /* Vertex number */
89 
90   sprintf (nametab, "vgraphseparatevw_output_%08d.map", vgraphseparatevwfilenum ++);
91   if ((fileptr = fopen (nametab, "w+")) == NULL) {
92     errorPrint ("vgraphSeparateVw: cannot open partition file");
93     return     (1);
94   }
95 
96   fprintf (fileptr, GNUMSTRING "\n",              /* Output size of mapping; test if failure later, in main loop */
97            (Gnum) grafptr->s.vertnbr);
98 
99   for (vertnum = grafptr->s.baseval; vertnum < grafptr->s.vertnnd; vertnum ++) {
100     if (fprintf (fileptr, GNUMSTRING "\t%d\n",
101                  (Gnum) ((grafptr->s.vnumtax != NULL) ? grafptr->s.vnumtax[vertnum] : vertnum),
102                  (int) grafptr->parttax[vertnum]) <= 0) {
103       errorPrint ("vgraphSeparateVw: bad output");
104       fclose     (fileptr);
105       return     (1);
106     }
107   }
108 
109   fclose (fileptr);
110   return (0);
111 }
112