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

« back to all changes in this revision

Viewing changes to src/libscotch/vgraph_store.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       : vgraph_store.c                          **/
 
35
/**                                                        **/
 
36
/**   AUTHOR     : Francois PELLEGRINI                     **/
 
37
/**                                                        **/
 
38
/**   FUNCTION   : This module contains the save data      **/
 
39
/**                structure handling routines for separa- **/
 
40
/**                tion graphs.                            **/
 
41
/**                                                        **/
 
42
/**   DATES      : # Version 3.3  : from : 17 oct 1998     **/
 
43
/**                                 to     17 oct 1998     **/
 
44
/**                # Version 3.4  : from : 11 dec 2001     **/
 
45
/**                                 to   : 11 dec 2001     **/
 
46
/**                # Version 4.0  : from : 01 jan 2002     **/
 
47
/**                                 to   : 06 jan 2002     **/
 
48
/**                                                        **/
 
49
/************************************************************/
 
50
 
 
51
/*
 
52
**  The defines and includes.
 
53
*/
 
54
 
 
55
#define VGRAPH_STORE
 
56
 
 
57
#include "module.h"
 
58
#include "common.h"
 
59
#include "graph.h"
 
60
#include "vgraph.h"
 
61
 
 
62
/**********************************/
 
63
/*                                */
 
64
/* Store graph handling routines. */
 
65
/*                                */
 
66
/**********************************/
 
67
 
 
68
/* This routine builds a save structure
 
69
** for the given active graph.
 
70
** It returns:
 
71
** - 0   : if allocation succeeded.
 
72
** - !0  : on error.
 
73
*/
 
74
 
 
75
int
 
76
vgraphStoreInit (
 
77
const Vgraph * restrict const grafptr,
 
78
VgraphStore * restrict const  storptr)
 
79
{
 
80
  Gnum                savsize;
 
81
 
 
82
  savsize = grafptr->s.vertnbr * (sizeof (GraphPart) + sizeof (Gnum)); /* Compute size for frontier and part arrays */
 
83
 
 
84
  if ((storptr->datatab = (byte *) memAlloc (savsize)) == NULL) { /* Allocate save structure */
 
85
    errorPrint ("vgraphStoreInit: out of memory");
 
86
    return     (1);
 
87
  }
 
88
 
 
89
  return (0);
 
90
}
 
91
 
 
92
/* This routine frees a save structure.
 
93
** It returns:
 
94
** - VOID  : in all cases.
 
95
*/
 
96
 
 
97
void
 
98
vgraphStoreExit (
 
99
VgraphStore * const         storptr)
 
100
{
 
101
  memFree (storptr->datatab);
 
102
#ifdef SCOTCH_DEBUG_VGRAPH2
 
103
  storptr->datatab = NULL;
 
104
#endif /* SCOTCH_DEBUG_VGRAPH2 */
 
105
}
 
106
 
 
107
/* This routine saves partition data from the
 
108
** given active graph to the given save structure.
 
109
** It returns:
 
110
** - VOID  : in all cases.
 
111
*/
 
112
 
 
113
void
 
114
vgraphStoreSave (
 
115
const Vgraph * const        grafptr,
 
116
VgraphStore * const         storptr)
 
117
{
 
118
  byte *              parttab;                    /* Pointer to part data save area     */
 
119
  byte *              frontab;                    /* Pointer to frontier data save area */
 
120
 
 
121
  storptr->fronnbr     = grafptr->fronnbr;        /* Save partition parameters */
 
122
  storptr->comploaddlt = grafptr->comploaddlt;
 
123
  storptr->compload[0] = grafptr->compload[0];
 
124
  storptr->compload[1] = grafptr->compload[1];
 
125
  storptr->compsize0   = grafptr->compsize[0];
 
126
 
 
127
  frontab = storptr->datatab;                     /* Compute data offsets within save structure */
 
128
  parttab = frontab + grafptr->fronnbr * sizeof (Gnum);
 
129
 
 
130
  memCpy (frontab, grafptr->frontab, grafptr->fronnbr * sizeof (Gnum));
 
131
  memCpy (parttab, grafptr->parttax + grafptr->s.baseval, grafptr->s.vertnbr * sizeof (GraphPart));
 
132
}
 
133
 
 
134
/* This routine updates partition data of the
 
135
** given active graph, using the given save graph.
 
136
** It returns:
 
137
** - VOID  : in all cases.
 
138
*/
 
139
 
 
140
void
 
141
vgraphStoreUpdt (
 
142
Vgraph * const              grafptr,
 
143
const VgraphStore * const   storptr)
 
144
{
 
145
  byte *              frontab;                    /* Pointer to frontier data save area */
 
146
  byte *              parttab;                    /* Pointer to part data save area     */
 
147
 
 
148
  grafptr->compload[0] = storptr->compload[0];    /* Load partition parameters */
 
149
  grafptr->compload[1] = storptr->compload[1];
 
150
  grafptr->compload[2] = grafptr->s.velosum - (storptr->compload[0] + storptr->compload[1]);
 
151
  grafptr->comploaddlt = storptr->comploaddlt;
 
152
  grafptr->compsize[0] = storptr->compsize0;
 
153
  grafptr->compsize[1] = grafptr->s.vertnbr - (storptr->compsize0 + storptr->fronnbr);
 
154
  grafptr->fronnbr     = storptr->fronnbr;
 
155
 
 
156
  frontab = storptr->datatab;                     /* Compute data offsets within save structure */
 
157
  parttab = frontab + grafptr->fronnbr * sizeof (Gnum);
 
158
 
 
159
  memCpy (grafptr->frontab, frontab, grafptr->fronnbr * sizeof (Gnum));
 
160
  memCpy (grafptr->parttax + grafptr->s.baseval, parttab, grafptr->s.vertnbr * sizeof (GraphPart));
 
161
 
 
162
#ifdef SCOTCH_DEBUG_VGRAPH2
 
163
  if (vgraphCheck (grafptr) != 0)
 
164
    errorPrint ("vgraphStoreUpdt: inconsistent graph data");
 
165
#endif /* SCOTCH_DEBUG_VGRAPH2 */
 
166
}