-
Notifications
You must be signed in to change notification settings - Fork 5
/
verification.c
188 lines (157 loc) · 5.97 KB
/
verification.c
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
/*
* OpenSHMEM version:
*
* Copyright (c) 2011 - 2015
* University of Houston System and UT-Battelle, LLC.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* o Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* o Neither the name of the University of Houston System,
* UT-Battelle, LLC. nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <hpcc.h>
#include "RandomAccess.h"
#include <stdio.h>
#include <shmem.h>
/* Verification phase: local buckets to sort into */
#define BUCKET_SIZE 1024
#define SLOT_CNT 1
#define FIRST_SLOT 2
void
HPCC_Power2NodesSHMEMRandomAccessCheck(u64Int logTableSize,
u64Int TableSize,
u64Int LocalTableSize,
u64Int GlobalStartMyProc,
int logNumProcs,
int NumProcs,
int MyProc,
u64Int ProcNumUpdates,
s64Int *NumErrors)
{
u64Int Ran;
u64Int RanTmp;
s64Int NextSlot;
s64Int WhichPe;
s64Int PeBucketBase;
s64Int SendCnt;
s64Int errors;
int i;
int j;
s64Int *PeCheckDone;
int LocalAllDone = HPCC_FALSE;
static int sAbort, rAbort;
u64Int *LocalBuckets; /* buckets used in verification phase */
u64Int *GlobalBuckets; /* buckets used in verification phase */
static long int ipSync[_SHMEM_BCAST_SYNC_SIZE];
static int ipWrk[_SHMEM_REDUCE_SYNC_SIZE];
static long int lpSync[_SHMEM_BCAST_SYNC_SIZE];
static long lpWrk[_SHMEM_REDUCE_SYNC_SIZE];
const int slot_size = BUCKET_SIZE+FIRST_SLOT;
for (i = 0; i < _SHMEM_BCAST_SYNC_SIZE; i += 1){
ipSync[i] = _SHMEM_SYNC_VALUE;
lpSync[i] = _SHMEM_SYNC_VALUE;
}
LocalBuckets = shmalloc(sizeof(u64Int)*NumProcs*(slot_size));
sAbort = 0; if (! LocalBuckets) sAbort = 1;
shmem_barrier_all();
shmem_int_sum_to_all(&rAbort, &sAbort, 1, 0, 0, NumProcs,ipWrk,ipSync );
shmem_barrier_all();
if (rAbort > 0) {
if (MyProc == 0) fprintf(stderr, "Failed to allocate memory for local buckets.\n");
goto failed_localbuckets;
}
GlobalBuckets = shmalloc(sizeof(u64Int)*NumProcs*(slot_size));
sAbort = 0; if (! GlobalBuckets) sAbort = 1;
shmem_barrier_all();
shmem_int_sum_to_all(&rAbort, &sAbort, 1, 0, 0, NumProcs,ipWrk,ipSync );
shmem_barrier_all();
if (rAbort > 0) {
if (MyProc == 0) fprintf(stderr, "Failed to allocate memory for global buckets.\n");
goto failed_globalbuckets;
}
SendCnt = ProcNumUpdates; /* SendCnt = 4 * LocalTableSize; */
Ran = starts (4 * GlobalStartMyProc);
PeCheckDone = XMALLOC ( s64Int, NumProcs);
for (i=0; i<NumProcs; i++)
PeCheckDone[i] = HPCC_FALSE;
while(LocalAllDone == HPCC_FALSE){
if (SendCnt > 0) {
/* Initalize local buckets */
for (i=0; i<NumProcs; i++){
PeBucketBase = i * (slot_size);
LocalBuckets[PeBucketBase+SLOT_CNT] = FIRST_SLOT;
LocalBuckets[PeBucketBase+HPCC_DONE] = HPCC_FALSE;
}
/* Fill local buckets until one is full or out of data */
NextSlot = FIRST_SLOT;
while(NextSlot != (BUCKET_SIZE+FIRST_SLOT) && SendCnt>0 ) {
Ran = (Ran << 1) ^ ((s64Int) Ran < ZERO64B ? POLY : ZERO64B);
WhichPe = (Ran >> (logTableSize - logNumProcs)) & (NumProcs - 1);
PeBucketBase = WhichPe * (slot_size);
NextSlot = LocalBuckets[PeBucketBase+SLOT_CNT];
LocalBuckets[PeBucketBase+NextSlot] = Ran;
LocalBuckets[PeBucketBase+SLOT_CNT] = ++NextSlot;
SendCnt--;
}
if (SendCnt == 0)
for (i=0; i<NumProcs; i++)
LocalBuckets[i*(slot_size)+HPCC_DONE] = HPCC_TRUE;
} /* End of sending loop */
shmem_barrier_all();
LocalAllDone = HPCC_TRUE;
/* Now move all the buckets to the appropriate pe */
for (i=0 ; i<NumProcs ; i++)
shmem_longlong_put(&GlobalBuckets[slot_size*MyProc],&LocalBuckets[slot_size*i],
slot_size,i);
shmem_barrier_all();
for (i = 0; i < NumProcs; i ++) {
if(PeCheckDone[i] == HPCC_FALSE) {
PeBucketBase = i * (BUCKET_SIZE+FIRST_SLOT);
PeCheckDone[i] = GlobalBuckets[PeBucketBase+HPCC_DONE];
for (j = FIRST_SLOT; j < GlobalBuckets[PeBucketBase+SLOT_CNT]; j ++) {
RanTmp = GlobalBuckets[PeBucketBase+j];
HPCC_Table[RanTmp & (LocalTableSize-1)] ^= RanTmp;
}
LocalAllDone &= PeCheckDone[i];
}
}
}
errors = 0;
for (i=0; i<LocalTableSize; i++){
if (HPCC_Table[i] != i + GlobalStartMyProc)
errors++;
}
*NumErrors = errors;
free( PeCheckDone );
shfree( GlobalBuckets );
failed_globalbuckets:
shfree( LocalBuckets );
failed_localbuckets:
return;
}