-
Notifications
You must be signed in to change notification settings - Fork 0
/
DPSNN_synListSort.c
192 lines (161 loc) · 3.85 KB
/
DPSNN_synListSort.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
189
190
191
192
// DPSNN_sort.c
// Distributed Plastic Spiking Neural Network, Simulation Engine
// DPSNN_*.*
// AUTHOR: Pier Stanislao Paolucci (Roma, Italy, 2011-...),
// AUTHOR: Elena Pastorelli (2013-...)
// AUTHOR: ...
// AUTHOR: plus other members of INFN Lab, Roma, Italy
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include "DPSNN_debug.h"
#include "DPSNN_dataStructDims.h"
#include "DPSNN_localNet.h"
void localNetClass::sortTargetHostInForwardSynList(
synapseClass *synList, synapseClass *q1,
uint32_t synCount)
{
//if globH==1 no sort needed
if(lnp_par.globH > 1) {//sort needed
DPSNNverboseStart(false,1,0);
printf("h=%03d, BEFORE radixSort START on %d synapses\n",
lnp_par.loc_h, synCount);
fflush(stdout);
DPSNNverboseEnd();
#define LSDradixSort
#ifdef LSDradixSort
radixSortBinForwardSynList(synList, q1, synCount);
#else
#define bubbleSort
#ifdef bubbleSort
//BEGIN sort of synapses according to the target host
//this version is absolutely not optimized
forwardSynClass swapLocation;
uint32_t i,j;
for (i=0;i<synCount;i++) {
for(j=0;j<(synCount-1-i);j++) {
if ((synList[j].post_glob_n / lnp_par.locN) >
(synList[j+1].post_glob_n / lnp_par.locN)) {
swapLocation=synList[j];
synList[j]=synList[j+1];
synList[j+1]=swapLocation;
}
}
}
#endif
#undef bubbleSort
#endif
};
};
void localNetClass::radixSortBinForwardSynList(synapseClass *a, synapseClass *q1, uint32_t n)
{
//the sort key is post_loc_h
//NOTE: initially, it sorts from key max to key min
//then it reverts the order
uint32_t i;
//synapseClass q0[DSD__maxForwardLocSyn];
//forwardSynClass q1[DSD__maxForwardLocSyn];
uint32_t c0, c1;
uint32_t m;
uint32_t exp = 1;
DPSNNverboseStart(false,1,0);
printf("h=%03d, radixSort START\n",
lnp_par.loc_h);
DPSNNverboseEnd();
m = a[0].post_glob_n / lnp_par.locN;
for (i = 0; i < n; i++)
{
if ((a[i].post_glob_n/lnp_par.locN) > m)
m = a[i].post_glob_n/lnp_par.locN;
}
DPSNNverboseStart(false,1,0);
printf("h=%03d radixSort max post_glob_n/lnp_par.locN detected=%d\n",
lnp_par.loc_h, m);
DPSNNverboseEnd();
while (m / exp > 0)
{
c0=0;
c1=0;
for (i = 0; i < n; i++) {
if((((a[i].post_glob_n/lnp_par.locN) / exp) % 2) == 0) {
a[c0++]=a[i];
}else{
q1[c1++]=a[i];
}
};
if(c0+c1!=n) {
printf("ERROR c0+c1 in radix synSort\n");
fflush(stdout);
exit(0);
};
for (i = c0; i < n; i++)
a[i]=q1[i-c0];
exp *= 2;
};
};
/* basic algo inserted as doc
#define MAX 8
#define SHOWPASS
struct r {int key; float value;};
void print(struct r *a, int n)
{
int i;
for (i = 0; i < n; i++) {
printf("{%d %03.0f}\t", a[i].key, a[i].value);
}
}
void radixSortBinStruct(r *a, int n)
{
int i;
r q0[MAX], q1[MAX], b[MAX];
int c0, c1;
int m = a[0].key;
int exp = 1;
for (i = 0; i < n; i++)
{
if (a[i].key > m)
m = a[i].key;
}
while (m / exp > 0)
{
c0=0;
c1=0;
for (i = 0; i < n; i++) {
if((a[i].key / exp) % 2) {
q0[c0++]=a[i];
}else{
q1[c1++]=a[i];
}
}
if(c0+c1!=n) printf("ERROR c0+c1\n");
for (i = 0; i < c0; i++)
a[i]=q0[i];
for (i = c0; i < n; i++)
a[i]=q1[i-c0];
exp *= 2;
#ifdef SHOWPASS
printf("\nPASS : ");
print(a, n);
#endif
}
}
int main()
{
r arr[MAX];
int i, n;
printf("Enter total elements (n < %d) : ", MAX);
scanf("%d", &n);
printf("Enter %d Elements : ", n);
for (i = 0; i < n; i++)
scanf("%d", &(arr[i].key));
for (i = 0; i < n; i++)
arr[i].value = (float) (arr[i].key * 10);
printf("\nARRAY : ");
print(arr, n);
radixSortBinStruct(arr, n);
printf("\nSORTED : ");
print(arr, n);
printf("\n");
return 0;
}
*/