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

« back to all changes in this revision

Viewing changes to src/libscotch/graph.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       : graph.c                                 **/
 
35
/**                                                        **/
 
36
/**   AUTHOR     : Francois PELLEGRINI                     **/
 
37
/**                                                        **/
 
38
/**   FUNCTION   : This module handles the source graph    **/
 
39
/**                functions.                              **/
 
40
/**                                                        **/
 
41
/**   DATES      : # Version 0.0  : from : 01 dec 1992     **/
 
42
/**                                 to     18 may 1993     **/
 
43
/**                # Version 1.3  : from : 30 apr 1994     **/
 
44
/**                                 to     18 may 1994     **/
 
45
/**                # Version 2.0  : from : 06 jun 1994     **/
 
46
/**                                 to     31 oct 1994     **/
 
47
/**                # Version 3.0  : from : 07 jul 1995     **/
 
48
/**                                 to     28 sep 1995     **/
 
49
/**                # Version 3.1  : from : 28 nov 1995     **/
 
50
/**                                 to     08 jun 1996     **/
 
51
/**                # Version 3.2  : from : 07 sep 1996     **/
 
52
/**                                 to     15 sep 1998     **/
 
53
/**                # Version 3.3  : from : 22 sep 1998     **/
 
54
/**                                 to     31 dec 1998     **/
 
55
/**                # Version 4.0  : from : 24 nov 2001     **/
 
56
/**                                 to     22 apr 2004     **/
 
57
/**                                                        **/
 
58
/************************************************************/
 
59
 
 
60
/*
 
61
**  The defines and includes.
 
62
*/
 
63
 
 
64
#define GRAPH
 
65
 
 
66
#include "module.h"
 
67
#include "common.h"
 
68
#include "graph.h"
 
69
 
 
70
/****************************************/
 
71
/*                                      */
 
72
/* These routines handle source graphs. */
 
73
/*                                      */
 
74
/****************************************/
 
75
 
 
76
/* This routine initializes a source graph
 
77
** structure.
 
78
** It returns:
 
79
** - 0  : in all cases.
 
80
*/
 
81
 
 
82
int
 
83
graphInit (
 
84
Graph * const               grafptr)
 
85
{
 
86
  memSet (grafptr, 0, sizeof (Graph));            /* Initialize graph fields     */
 
87
  grafptr->flagval = GRAPHFREETABS;               /* By default, free all arrays */
 
88
 
 
89
  return (0);
 
90
}
 
91
 
 
92
/* This routine frees a source graph structure.
 
93
** It returns:
 
94
** - VOID  : in all cases.
 
95
*/
 
96
 
 
97
void
 
98
graphExit (
 
99
Graph * const               grafptr)
 
100
{
 
101
  graphFree (grafptr);                            /* Free graph data */
 
102
 
 
103
#ifdef SCOTCH_DEBUG_GRAPH2
 
104
  memSet (grafptr, ~0, sizeof (Graph));           /* Purge graph fields */
 
105
#endif /* SCOTCH_DEBUG_GRAPH2 */
 
106
}
 
107
 
 
108
/* This routine frees the graph data.
 
109
** It returns:
 
110
** - VOID  : in all cases.
 
111
*/
 
112
 
 
113
void
 
114
graphFree (
 
115
Graph * const               grafptr)
 
116
{
 
117
  if (((grafptr->flagval & GRAPHFREEEDGE) != 0) && /* If edgetab must be freed */
 
118
      (grafptr->edgetax != NULL))                 /* And if it exists          */
 
119
    memFree (grafptr->edgetax + grafptr->baseval); /* Free it                  */
 
120
 
 
121
  if ((grafptr->flagval & GRAPHFREEVERT) != 0) {  /* If verttab/vendtab must be freed                            */
 
122
    if ((grafptr->vendtax != NULL) &&             /* If vendtax is distinct from verttab                         */
 
123
        (grafptr->vendtax != grafptr->verttax + 1) && /* (if vertex arrays grouped, vendtab not distinct anyway) */
 
124
        ((grafptr->flagval & GRAPHVERTGROUP) == 0))
 
125
      memFree (grafptr->vendtax + grafptr->baseval); /* Then free vendtax                                 */
 
126
    if (grafptr->verttax != NULL)                 /* Free verttab anyway, as it is the array group leader */
 
127
      memFree (grafptr->verttax + grafptr->baseval);
 
128
  }
 
129
  if ((grafptr->flagval & GRAPHFREEVNUM) != 0) {  /* If vnumtab must be freed         */
 
130
    if ((grafptr->vnumtax != NULL) &&             /* And is not in vertex array group */
 
131
        ((grafptr->flagval & GRAPHVERTGROUP) == 0))
 
132
      memFree (grafptr->vnumtax + grafptr->baseval);
 
133
  }
 
134
  if ((grafptr->flagval & GRAPHFREEOTHR) != 0) {  /* If other arrays must be freed */
 
135
    if ((grafptr->velotax != NULL) &&             /* Free graph tables             */
 
136
        ((grafptr->flagval & GRAPHVERTGROUP) == 0))
 
137
      memFree (grafptr->velotax + grafptr->baseval);
 
138
    if (grafptr->vlbltax != NULL)
 
139
      memFree (grafptr->vlbltax + grafptr->baseval);
 
140
    if ((grafptr->edlotax != NULL) &&
 
141
        ((grafptr->flagval & GRAPHEDGEGROUP) == 0))
 
142
      memFree (grafptr->edlotax + grafptr->baseval);
 
143
  }
 
144
 
 
145
#ifdef SCOTCH_DEBUG_GRAPH2
 
146
  memSet (grafptr, ~0, sizeof (Graph));           /* Purge graph fields */
 
147
#endif /* SCOTCH_DEBUG_GRAPH2 */
 
148
}