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

« back to all changes in this revision

Viewing changes to src/libscotch/bgraph_check.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       : bgraph_check.c                          **/
 
35
/**                                                        **/
 
36
/**   AUTHOR     : Francois PELLEGRINI                     **/
 
37
/**                                                        **/
 
38
/**   FUNCTION   : This module contains the bipartition    **/
 
39
/**                graph consistency checking routine.     **/
 
40
/**                                                        **/
 
41
/**   DATES      : # Version 4.0  : from : 08 jan 2004     **/
 
42
/**                                 to     07 dec 2005     **/
 
43
/**                                                        **/
 
44
/************************************************************/
 
45
 
 
46
/*
 
47
**  The defines and includes.
 
48
*/
 
49
 
 
50
#define BGRAPH
 
51
 
 
52
#include "module.h"
 
53
#include "common.h"
 
54
#include "graph.h"
 
55
#include "arch.h"
 
56
#include "bgraph.h"
 
57
 
 
58
/*************************/
 
59
/*                       */
 
60
/* These routines handle */
 
61
/* bipartition graphs.   */
 
62
/*                       */
 
63
/*************************/
 
64
 
 
65
/* This routine checks the consistency
 
66
** of the given bipartition graph.
 
67
** It returns:
 
68
** - 0   : if graph data are consistent.
 
69
** - !0  : on error.
 
70
*/
 
71
 
 
72
int
 
73
bgraphCheck (
 
74
const Bgraph * restrict const grafptr)
 
75
{
 
76
  int * restrict      flagtax;                    /* Frontier flag array       */
 
77
  Gnum                vertnum;                    /* Number of current vertex  */
 
78
  Gnum                fronnum;                    /* Number of frontier vertex */
 
79
  Gnum                compload[2];
 
80
  Gnum                compsize[2];
 
81
  Gnum                commcut[2];
 
82
  Gnum                commloadintn;
 
83
  Gnum                commloadextn;
 
84
  Gnum                commgainextn;
 
85
  Gnum                edloval;
 
86
 
 
87
  if ((flagtax = memAlloc (grafptr->s.vertnbr * sizeof (Gnum))) == NULL) {
 
88
    errorPrint ("bgraphCheck: out of memory");
 
89
    return     (1);
 
90
  }
 
91
  memSet (flagtax, ~0, grafptr->s.vertnbr * sizeof (Gnum));
 
92
  flagtax -= grafptr->s.baseval;
 
93
 
 
94
  if (grafptr->compload0 != (grafptr->compload0avg + grafptr->compload0dlt)) {
 
95
    errorPrint ("bgraphCheck: invalid balance");
 
96
    return     (1);
 
97
  }
 
98
 
 
99
  for (vertnum = grafptr->s.baseval; vertnum < grafptr->s.vertnnd; vertnum ++) {
 
100
    if (grafptr->parttax[vertnum] > 1) {
 
101
      errorPrint ("bgraphCheck: invalid part array");
 
102
      return     (1);
 
103
    }
 
104
  }
 
105
 
 
106
  if ((grafptr->fronnbr < 0) ||
 
107
      (grafptr->fronnbr > grafptr->s.vertnbr)) {
 
108
    errorPrint ("bgraphCheck: invalid number of frontier vertices");
 
109
    return     (1);
 
110
  }
 
111
  for (fronnum = 0; fronnum < grafptr->fronnbr; fronnum ++) {
 
112
    Gnum                vertnum;
 
113
    Gnum                edgenum;
 
114
    Gnum                commcut;
 
115
    int                 partval;
 
116
 
 
117
    vertnum = grafptr->frontab[fronnum];
 
118
    if ((vertnum < grafptr->s.baseval) || (vertnum >= grafptr->s.vertnnd)) {
 
119
      errorPrint ("bgraphCheck: invalid vertex index in frontier array");
 
120
      return     (1);
 
121
    }
 
122
    if (flagtax[vertnum] != ~0) {
 
123
      errorPrint ("bgraphCheck: duplicate vertex in frontier array");
 
124
      return     (1);
 
125
    }
 
126
    flagtax[vertnum] = 0;
 
127
    partval = grafptr->parttax[vertnum];
 
128
 
 
129
    for (edgenum = grafptr->s.verttax[vertnum], commcut = 0;
 
130
         edgenum < grafptr->s.vendtax[vertnum]; edgenum ++) {
 
131
      int                 partdlt;
 
132
 
 
133
      partdlt  = grafptr->parttax[grafptr->s.edgetax[edgenum]] ^ partval;
 
134
      commcut += partdlt;
 
135
    }
 
136
    if (commcut == 0) {
 
137
      errorPrint ("bgraphCheck: invalid vertex in frontier array");
 
138
      return     (1);
 
139
    }
 
140
  }
 
141
 
 
142
  compload[0]  =
 
143
  compload[1]  = 0;
 
144
  compsize[0]  =
 
145
  compsize[1]  = 0;
 
146
  commloadintn = 0;
 
147
  commloadextn = grafptr->commloadextn0;
 
148
  commgainextn = 0;
 
149
  edloval      = 1;                               /* Assume edges are not weighted */
 
150
  for (vertnum = grafptr->s.baseval; vertnum < grafptr->s.vertnnd; vertnum ++) {
 
151
    Gnum                partval;                  /* Part of current vertex */
 
152
    Gnum                edgenum;                  /* Number of current edge */
 
153
 
 
154
    partval = (Gnum) grafptr->parttax[vertnum];
 
155
    if (grafptr->veextax != NULL) {
 
156
      Gnum                veexval;
 
157
 
 
158
      veexval = grafptr->veextax[vertnum];
 
159
      commloadextn += veexval * partval;
 
160
      commgainextn += veexval * (1 - 2 * partval);
 
161
    }
 
162
 
 
163
    compload[partval] += (grafptr->s.velotax == NULL) ? 1 : grafptr->s.velotax[vertnum];
 
164
    compsize[partval] ++;
 
165
 
 
166
    commcut[0] =
 
167
    commcut[1] = 0;
 
168
    for (edgenum = grafptr->s.verttax[vertnum]; edgenum < grafptr->s.vendtax[vertnum]; edgenum ++) {
 
169
      int                 partend;
 
170
      int                 partdlt;
 
171
 
 
172
      if (grafptr->s.edlotax != NULL)
 
173
        edloval = grafptr->s.edlotax[edgenum];
 
174
      partend = grafptr->parttax[grafptr->s.edgetax[edgenum]];
 
175
      partdlt = partval ^ partend;
 
176
      commcut[partend] ++;
 
177
      commloadintn += partdlt * edloval * partend; /* Only count loads once, when (partend == 1) */
 
178
    }
 
179
 
 
180
    if ((commcut[0] != 0) && (commcut[1] != 0) && /* If vertex should be in separator */
 
181
        (flagtax[vertnum] != 0)) {
 
182
      errorPrint ("bgraphCheck: vertex should be in separator");
 
183
      return     (1);
 
184
    }
 
185
  }
 
186
  if (compsize[0] != grafptr->compsize0) {
 
187
    errorPrint ("bgraphCheck: invalid part size");
 
188
    return     (1);
 
189
  }
 
190
  if ((commloadintn * grafptr->domdist + commloadextn) != grafptr->commload) {
 
191
    errorPrint ("bgraphCheck: invalid communication loads");
 
192
    return     (1);
 
193
  }
 
194
  if (commgainextn != grafptr->commgainextn) {
 
195
    errorPrint ("bgraphCheck: invalid communication gains");
 
196
    return     (1);
 
197
  }
 
198
 
 
199
  memFree (flagtax + grafptr->s.baseval);
 
200
 
 
201
  return (0);
 
202
}