File: testFullAdj2.c

package info (click to toggle)
spooles 2.2-11
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,656 kB
  • ctags: 3,690
  • sloc: ansic: 146,836; sh: 7,571; csh: 3,615; makefile: 1,968; perl: 74
file content (265 lines) | stat: -rw-r--r-- 7,590 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*  testFullAdj2.c  */

#include "../InpMtx.h"
#include "../../Drand.h"

/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
   ----------------------------------------------------------
   generate random InpMtx object for matrices A and B
   return an IVL object with the structure of (A+B) + (A+B)^T

   created -- 97nov05, cca
   ----------------------------------------------------------
*/
{
Drand    *drand ;
int      msglvl, ient, ii, irow, isHere, jcol, nedgesMissing,
         nentA, nentB, nvtx, seed, size ;
int      *colidsA, *colidsB, *list, *rowidsA, *rowidsB ;
InpMtx   *inpmtxA, *inpmtxB ;
FILE     *msgFile ;
IVL      *adjIVL ;

if ( argc != 7 ) {
   fprintf(stdout, 
      "\n\n usage : testFullAdj2 msglvl msgFile nvtx nentA nentB seed"
      "\n    msglvl  -- message level"
      "\n    msgFile -- message file"
      "\n    nvtx    -- number of rows and columns"
      "\n    nentA   -- bound on number of entries in A"
      "\n    nentB   -- bound on number of entries in B"
      "\n    seed    -- random number seed"
      "\n") ;
   return(0) ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n unable to open file %s\n",
           argv[0], argv[2]) ;
   return(-1) ;
}
nvtx  = atoi(argv[3]) ;
nentA = atoi(argv[4]) ;
nentB = atoi(argv[5]) ;
seed  = atoi(argv[6]) ;
fprintf(msgFile, 
        "\n testIO "
        "\n msglvl   -- %d" 
        "\n msgFile  -- %s" 
        "\n nvtx     -- %d" 
        "\n nentA    -- %d" 
        "\n nentB    -- %d" 
        "\n seed     -- %d" 
        "\n",
        msglvl, argv[2], nvtx, nentA, nentB, seed) ;
fflush(msgFile) ;
/*
   --------------------------------------
   initialize the random number generator
   --------------------------------------
*/
drand = Drand_new() ;
Drand_setSeed(drand, seed) ;
Drand_setUniform(drand, 0, nvtx) ;
/*
   -----------------------------------
   initialize the InpMtx object for A
   -----------------------------------
*/
inpmtxA = InpMtx_new() ;
InpMtx_init(inpmtxA, INPMTX_BY_ROWS, INPMTX_INDICES_ONLY, nentA, nvtx) ;
/*
   ----------------------
   load with random edges
   ----------------------
*/
rowidsA = IVinit(nentA, -1) ;
colidsA = IVinit(nentA, -1) ;
Drand_fillIvector(drand, nentA, rowidsA) ;
Drand_fillIvector(drand, nentA, colidsA) ;
for ( ient = 0 ; ient < nentA ; ient++ ) {
   irow = rowidsA[ient] ;
   jcol = colidsA[ient] ;
   if ( msglvl > 0 ) {
      fprintf(msgFile, "\n loading (%5d,%5d)", irow, jcol) ;
      fflush(msgFile) ;
   }
   InpMtx_inputEntry(inpmtxA, irow, jcol) ;
}
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n\n after loading raw data") ;
   InpMtx_writeForHumanEye(inpmtxA, msgFile) ;
   fflush(msgFile) ;
}
/*
   ----------------------------------------
   sort, compress and change to vector form
   ----------------------------------------
*/
InpMtx_sortAndCompress(inpmtxA) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n\n after sort and compress") ;
   InpMtx_writeForHumanEye(inpmtxA, msgFile) ;
   fflush(msgFile) ;
}
InpMtx_convertToVectors(inpmtxA) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n\n after convert to vectors") ;
   InpMtx_writeForHumanEye(inpmtxA, msgFile) ;
   fflush(msgFile) ;
}
/*
   -----------------------------------
   initialize the InpMtx object for B
   -----------------------------------
*/
inpmtxB = InpMtx_new() ;
InpMtx_init(inpmtxB, INPMTX_BY_ROWS, INPMTX_INDICES_ONLY, nentB, nvtx) ;
/*
   ----------------------
   load with random edges
   ----------------------
*/
rowidsB = IVinit(nentB, -1) ;
colidsB = IVinit(nentB, -1) ;
Drand_fillIvector(drand, nentB, rowidsB) ;
Drand_fillIvector(drand, nentB, colidsB) ;
for ( ient = 0 ; ient < nentB ; ient++ ) {
   irow = rowidsB[ient] ;
   jcol = colidsB[ient] ;
   if ( msglvl > 0 ) {
      fprintf(msgFile, "\n loading (%5d,%5d)", irow, jcol) ;
      fflush(msgFile) ;
   }
   InpMtx_inputEntry(inpmtxB, irow, jcol) ;
}
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n\n after loading raw data") ;
   InpMtx_writeForHumanEye(inpmtxB, msgFile) ;
   fflush(msgFile) ;
}
/*
   ----------------------------------------
   sort, compress and change to vector form
   ----------------------------------------
*/
InpMtx_sortAndCompress(inpmtxB) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n\n after sort and compress") ;
   InpMtx_writeForHumanEye(inpmtxB, msgFile) ;
   fflush(msgFile) ;
}
InpMtx_convertToVectors(inpmtxB) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n\n after convert to vectors") ;
   InpMtx_writeForHumanEye(inpmtxB, msgFile) ;
   fflush(msgFile) ;
}
/*
   ---------------------------------------------------
   get the full adjacency structure of (A+B) + (A+B)^T
   ---------------------------------------------------
*/
fprintf(msgFile, "\n inpmtxA = %p, inpmtxB = %p", inpmtxA, inpmtxB) ;
adjIVL = InpMtx_fullAdjacency2(inpmtxA, inpmtxB) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n\n full adjacency IVL object") ;
   IVL_writeForHumanEye(adjIVL, msgFile) ;
   fflush(msgFile) ;
}
/*
   -----------------------------------------------------------
   check that each (irow,jcol) from A is in the full adjacency
   -----------------------------------------------------------
*/
for ( ient = 0, nedgesMissing = 0 ; ient < nentA ; ient++ ) {
   irow = rowidsA[ient] ;
   jcol = colidsA[ient] ;
   IVL_listAndSize(adjIVL, irow, &size, &list) ;
   for ( ii = 0, isHere = 0 ; ii < size ; ii++ ) {
      if ( list[ii] == jcol ) {
         isHere = 1 ;
         break ;
      }
   }
   if ( isHere != 1 ) {
      fprintf(stderr, "\n fatal error, (%d,%d) not in adjIVL",
              irow, jcol) ;
      nedgesMissing++ ;
   }
   IVL_listAndSize(adjIVL, jcol, &size, &list) ;
   for ( ii = 0, isHere = 0 ; ii < size ; ii++ ) {
      if ( list[ii] == irow ) {
         isHere = 1 ;
         break ;
      }
   }
   if ( isHere != 1 ) {
      fprintf(stderr, "\n fatal error, (%d,%d) not in adjIVL",
              irow, jcol) ;
      nedgesMissing++ ;
   }
}
fprintf(msgFile, "\n %d edges of A missing from adjIVL", 
        nedgesMissing) ;
/*
   -----------------------------------------------------------
   check that each (irow,jcol) from B is in the full adjacency
   -----------------------------------------------------------
*/
for ( ient = 0, nedgesMissing = 0 ; ient < nentB ; ient++ ) {
   irow = rowidsB[ient] ;
   jcol = colidsB[ient] ;
   IVL_listAndSize(adjIVL, irow, &size, &list) ;
   for ( ii = 0, isHere = 0 ; ii < size ; ii++ ) {
      if ( list[ii] == jcol ) {
         isHere = 1 ;
         break ;
      }
   }
   if ( isHere != 1 ) {
      fprintf(stderr, "\n fatal error, (%d,%d) not in adjIVL",
              irow, jcol) ;
      nedgesMissing++ ;
   }
   IVL_listAndSize(adjIVL, jcol, &size, &list) ;
   for ( ii = 0, isHere = 0 ; ii < size ; ii++ ) {
      if ( list[ii] == irow ) {
         isHere = 1 ;
         break ;
      }
   }
   if ( isHere != 1 ) {
      fprintf(stderr, "\n fatal error, (%d,%d) not in adjIVL",
              irow, jcol) ;
      nedgesMissing++ ;
   }
}
fprintf(msgFile, "\n %d edges of B missing from adjIVL", 
        nedgesMissing) ;
/*
   -------------
   free the data
   -------------
*/
IVfree(colidsA) ;
IVfree(rowidsA) ;
InpMtx_free(inpmtxA) ;
IVfree(colidsB) ;
IVfree(rowidsB) ;
InpMtx_free(inpmtxB) ;
IVL_free(adjIVL) ;
Drand_free(drand) ;

fprintf(msgFile, "\n") ;
fclose(msgFile) ;

return(1) ; }

/*--------------------------------------------------------------------*/