-
Notifications
You must be signed in to change notification settings - Fork 0
/
DPSNN_localNet_init.c
1165 lines (997 loc) · 40.9 KB
/
DPSNN_localNet_init.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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DPSNN_localNet_init.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 Computation with Spikes"
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/sysinfo.h>
#include "DPSNN_debug.h"
#include "DPSNN_random.h"
#include "DPSNN_neuron.h"
#include "DPSNN_messagePassing.h"
#include "DPSNN_spike.h"
#include "DPSNN_chrono.h"
#include "DPSNN_memMeasure.h"
#include "DPSNN_localNet.h"
#include "DPSNN_LIFCAconnectome.h"
#ifdef LIFCAneuron
#include "erflib.h"
#include "randdev.h"
#endif
void localNetClass::prepareForwardSynapses()
{
if((lnp_par.synGen == default_random_synGen_1)||
(lnp_par.synGen == simpleCorticalModule_synGen_2)||
(lnp_par.synGen == randTable_simpleCorticalModule_synGen_3)||
(lnp_par.synGen == LIFCACorticalModule_synGen_4)) {
simpleCM_prepareForwardSynapses();
}else {
printf("ERROR unrecognized syn Gen option\n");fflush(stdout);exit(0);
};
};
void localNetClass::init(
const struct DPSNN_parameters lnp_par_initValue,
messagePassingClass * pMessagePassing_initValue,
stopWatchClass * pStopWatch_initValue,
statClass *pStat_initValue)
{
// initializes a network of locN neurons stored and managed by the host named loc_h
uint32_t i;//,j,k,r,exists;
lnp_par = lnp_par_initValue;
struct sysinfo si;
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf(
"-100- init() loc_h=%d start,locN=%d,M=%d,H=%d,CFT=%d,CFX=%d,CFY=%d\n",
lnp_par.loc_h, lnp_par.locN, lnp_par.M,
lnp_par.globH, lnp_par.globCFT, lnp_par.globCFX, lnp_par.globCFY);
DPSNNverboseEnd();
DPSNNverboseStart(true,1,0);
//freeMemory=system ("free");
sysinfo (&si);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
lnp_par.freeMemAtStart = si.freeram/1024;
if(lnp_par.loc_h==0){
//freeMemory=system ("free");
printf ("MEMORY: At init start the free memory on %s is %d kB \n",
lnp_par.hostName, lnp_par.freeMemAtStart);
}
DPSNNverboseEnd();
if(DSD__maxBackwardLocSyn != DSD__maxForwardLocSyn) {
printf(
"ERROR: after mem optim DSD__maxBackwardLocSyn should be equal to forward\n");
fflush(stdout);exit(0);
}
memPoolA = (uint8_t *)new synapseClass [DSD__maxBackwardLocSyn];
memPoolB = (uint8_t *)new synapseClass [DSD__maxBackwardLocSyn];
DPSNNverboseStart(false,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h==0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: AFTER memPoolA and B new the used memory on %s is %lu kB \n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
pMessagePassing = pMessagePassing_initValue;
pStopWatch = pStopWatch_initValue;
pStat = pStat_initValue;
localSynCount=0;
forwardSynCount=0;
backwardSynCount=0;
reportCount=0;
N_firingsTotInFrame = 0;
clearFiringsInChronoWindow();
for(i=0;i<lnp_par.globCFT*lnp_par.subPopNumber;i++)
N_firingsPerPop[i] = 0;
DPSNNverboseStart(true,1,0);
if(lnp_par.loc_h==0)
printf ("Random seed for simulation: %d \n",lnp_par.globalSeed);
DPSNNverboseEnd();
localNetRandDev.SetRandomSeed(lnp_par.globalSeed);
simpleCM_connectome.initLocalNetRandDevPointer(&localNetRandDev);
DPSNNverboseStart(false,0,0);
if(lnp_par.loc_h==0) {
memMeasure.clear();
memMeasure.measure(lnp_par);
memMeasure.report(lnp_par);
};
DPSNNverboseEnd();
clearAllChronometers();
initChronoWindow();
check_lnp_par_initValues();
localSynList = (synapseClass*)&memPoolA[0];
forwardSynList = (synapseClass*)&memPoolB[0];
DPSNNverboseStart(false,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h == 0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: BEFORE prepareForward Synapses the used memory on %s is %lu kB \n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
prepareForwardSynapses();
DPSNNverboseStart(false,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h == 0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: AFTER prepareForward Synapses the used memory on %s is %lu kB \n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
DPSNNverboseStart(false,1,0);
printf("-400- init() h=%03d globH=%d locN=%d\n",
lnp_par.loc_h, lnp_par.globH, lnp_par.locN);
DPSNNverboseEnd();
for(i=0;i<lnp_par.subPopNumber;i++)
neuSubPopCount[i] = neuSubPopParam[i].count;
DPSNNverboseStart(false,1,0);
reportLocalNetAfterInit();
DPSNNverboseEnd();
DPSNNverboseStart(true,1,0);
chronoSendReceiveSynList.clearAndStartChrono();
DPSNNverboseEnd();
sendReceiveSynListWithOtherLocalNets();
//NOTE: backwardSynList is in memPoolA
//memPoolB can be deallocated
delete [] memPoolB;
DPSNNverboseStart(false,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h == 0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: AFTER delete memPoolB free on %s is %lu kB \n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
DPSNNverboseStart(true,1,0);
chronoSendReceiveSynList.stopChrono();
DPSNNverboseEnd();
DPSNNverboseStart(false,1,0);
printf("-600- init() h=%03d globH=%d locN=%d\n",
lnp_par.loc_h, lnp_par.globH, lnp_par.locN);
DPSNNverboseEnd();
#if defined(makeActiveLTD) || defined (makeActiveLTP)
DPSNNverboseStart(true,1,0);
if(lnp_par.loc_h==0 && i==0) {
printf("localNet_init: initializing Plasticity on h=0, local neuron 0\n)");fflush(stdout);
}
DPSNNverboseEnd();
for (i=0;i<lnp_par.locN;i++) {
//clear the counter of incoming syapses before adding the list of requested incoming syapses
n[i].clearBackwardSynList();
//we have to put the last spike eons ago
//otherwise at the sim start (t=0) LTP LTD and activity would be wrong
n[i].setLastEmittedSpikeTime_ms(-100000);
n[i].initLongTermPlasticity();
};
for (i=0;i<lnp_par.locN;i++) {
n[i].initBackwardSynListPointer(backwardSynList);
};
{/* adding the incoming synapses */
uint32_t synOffset, i;
synapseClass backwardSyn;
for(synOffset=0;synOffset<backwardSynCount;synOffset++) {
backwardSyn=backwardSynList[synOffset];
i = backwardSyn.post_glob_n % lnp_par.locN;
if((backwardSyn.post_glob_n / lnp_par.locN) != lnp_par.loc_h) {
printf("ERROR wrong post_glob_n when adding incoming synapses\n");
fflush(stdout);exit(0);
}
n[i].addBackwardSyn(synOffset);
};
};
#endif
#ifndef LIFCAneuron
for (i=0;i<lnp_par.locN;i++)
n[i].set_hashId();
#endif
DPSNNverboseStart(false,1,0);
writeIniFiles();
DPSNNverboseEnd();
DPSNNverboseStart(false,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h == 0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: BEFORE axonalSpikeScheduler.reset() free on %s is %lu kB \n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
prepareAxonalSpikeBuffers();
//EPA - 2015-03-10
//Allocate memory for inputCurrents buffer of each neuron
for(i=0;i<lnp_par.locN;i++) {
n[i].inputCurrents = (inputCurrentClass *)new inputCurrentClass [DSD__maxSimultaneousSpikesOnSameTarget];
}
for (i=0;i<lnp_par.locN;i++) {
n[i].initRandDevPointer(&localNetRandDev);
};
DPSNNverboseStart(false,1,0);
{
uint64_t counterRandGenerated;
counterRandGenerated = localNetRandDev.Statistics();
printf("On h=%d after init %lu random numbers have been generated \n",lnp_par.loc_h,counterRandGenerated);
}
DPSNNverboseEnd();
localNetRandDev.SetRandomSeed(lnp_par.loc_h);
DPSNNverboseStart(false,1,0);
printf("-700- init() h=%03d globH=%d locN=%d\n",
lnp_par.loc_h, lnp_par.globH, lnp_par.locN);
DPSNNverboseEnd();
DPSNNverboseStart(true,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h == 0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: End of init phase the used memory on %s is %lu kB \n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
#if defined(makeActiveLTD) || defined (makeActiveLTP)
DPSNNverboseStart(false,1,0);
checkBackwardSynCountAfterInit();
DPSNNverboseEnd();
#endif
};
//-------END OF INIT METHOD ----------------//
void localNetClass::sendReceiveSynListWithOtherLocalNets()
{//BEGIN send list of synaptic connections to different hosts
uint32_t i;
uint32_t backwardRemoteSynCount;
struct sysinfo si;
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("-510- h=%03d sendReceiveSynList: START\n", lnp_par.loc_h);
DPSNNverboseEnd();
DPSNNverboseStart(false,1,0);
printf("520- h=%03d sendReceiveSynList: BEFORE check BEFORE sort\n",
lnp_par.loc_h);
DPSNNverboseEnd();
DPSNNverboseStart(false,1,0);
printf("521- h=%03d localSynCount=%d, forwardSynCount=%d, totSynNum=%d\n",
lnp_par.loc_h, localSynCount, forwardSynCount, projectedSynCount);
DPSNNverboseEnd();
if(localSynCount + forwardSynCount != projectedSynCount ) {
printf(
"ERROR h=%03d localNet_init localSynCount %d + forwardSynCount %d != projectedSynCount %d\n",
lnp_par.loc_h, localSynCount,
forwardSynCount, projectedSynCount );
fflush(stdout); exit(0);
};
//check list (only thiose toward remote processes) before sort
DPSNNverboseStart(true,1,0);
checkForwardSynListInitValues(forwardSynList, forwardSynCount);
DPSNNverboseEnd();
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("530- h=%03d sendReceiveSynList: AFTER check BEFORE sort\n",
lnp_par.loc_h);
DPSNNverboseEnd();
DPSNNverboseStart(true,1,0);
chronoSortTargetHostInForwardSynList.clearAndStartChrono();
DPSNNverboseEnd();
//HERE THE SORT of forwardSynList according to targetHost
//we put q1 in the second part of memPoolB, the first part is used
//by forwardSynList
//this is only about synapses toward remote processes
q1 = (synapseClass *)&memPoolA[sizeof(synapseClass) * localSynCount];
sortTargetHostInForwardSynList(forwardSynList, q1, forwardSynCount);
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("539- h=%03d sendReceiveSynList: AFTER sortTargetHostInForwardSynList BEFORE sort\n",
lnp_par.loc_h);
DPSNNverboseEnd();
//this is only about synapses toward remote processes
checkSortedSynListAndCreateSynapticDistribution(
forwardSynList, &synTargetHostDistribution, forwardSynCount);
// CHECK the sum of synHostDistribution.synCount[x]
// must be equal to synCount
//this is only about synapses toward remote processes
checkTotalSynCountInSynapticDistribution(&synTargetHostDistribution,
forwardSynCount);
DPSNNverboseStart(true,1,0);
chronoSortTargetHostInForwardSynList.stopChrono();
DPSNNverboseEnd();
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
//warning this report is only about synapses toward remote processes
forwardSynListReport(forwardSynList, forwardSynCount,0);
DPSNNverboseEnd();
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("540- h=%03d sendReceiveSynList: AFTER sort BEFORE CHECK\n",
lnp_par.loc_h);
DPSNNverboseEnd();
//check list after sort
DPSNNverboseStart(false,1,0);
checkForwardSynListInitValues(forwardSynList, forwardSynCount);
DPSNNverboseEnd();
//debug report
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("560- h=%03d is going to call pMessagePassing->init()\n", lnp_par.loc_h);
DPSNNverboseEnd();
//print distribution of forward synapses
//(from each source to each target)
DPSNNverboseStart(false,16,lnp_par.loc_h);
for(i=0;i<lnp_par.globH;i++) {
uint32_t synCount;
if(i!=lnp_par.loc_h) {
synCount = synTargetHostDistribution.synCount[i];
}else{
synCount = localSynCount;
};
printf("570- S_h=%03d -> T_h=%03d - %d syn, forwOff in remoteTargeDistrib %d\n",
lnp_par.loc_h, i, synCount, synTargetHostDistribution.synOffset[i] );
fflush(stdout);
};
DPSNNverboseEnd();
//check of TargetHostDistribution before message passing
DPSNNverboseStart(false,1,0);
{
uint32_t checkGlobalForwardSynCount;
checkGlobalForwardSynCount=0;
for(i=0;i<lnp_par.globH;i++) {
checkGlobalForwardSynCount += synTargetHostDistribution.synCount[i];
}
checkGlobalForwardSynCount += localSynCount;
if((checkGlobalForwardSynCount >= DSD__maxForwardLocSyn) ||
(checkGlobalForwardSynCount != (forwardSynCount + localSynCount))) {
printf(
"ERROR h=%03d in localNet::init() error checking globalForwardSynCount=%d\n",
lnp_par.loc_h,checkGlobalForwardSynCount);
fflush(stdout);exit(0);
};
if((synTargetHostDistribution.synOffset[lnp_par.globH-1] +
synTargetHostDistribution.synCount[lnp_par.globH-1] + localSynCount) !=
(forwardSynCount + localSynCount))
{
printf(
"ERROR h=%03d in localNet::init() error checking globalForwardSynOffset o%d c%d l%d f%d \n",
lnp_par.loc_h,
synTargetHostDistribution.synOffset[lnp_par.globH-1],
synTargetHostDistribution.synCount[lnp_par.globH-1],
localSynCount,
forwardSynCount);
fflush(stdout);
exit(0);
};
}
DPSNNverboseEnd();
//HERE IS THE MESSAGE PASSING OF THE EXPECTED DISTRIBUTION OF SYNAPSES
//NOTE: synapses directed toward same process are non considered here
pMessagePassing->sendForwardSynListDimToRemoteHosts(
&synTargetHostDistribution,
&synSourceHostDistribution,0);
if((synTargetHostDistribution.synCount[lnp_par.loc_h]!=0 )||
(synSourceHostDistribution.synCount[lnp_par.loc_h]!=0 )){
printf(
"ERROR h=%03d in localNet::init() erroneous local transfer of %d to %d syn\n",
lnp_par.loc_h,
synTargetHostDistribution.synCount[lnp_par.loc_h],
synSourceHostDistribution.synCount[lnp_par.loc_h]);
fflush(stdout);exit(0);
}
backwardRemoteSynCount=
synSourceHostDistribution.synOffset[lnp_par.globH-1] +
synSourceHostDistribution.synCount[lnp_par.globH-1];
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("300- h=%03d - MPI_Alltoall told %d total remote syn will arrive\n",
lnp_par.loc_h, backwardRemoteSynCount);
DPSNNverboseEnd();
//EPA PSP this check should be more restricted e.g. to DSD__maxRemoteM
if(backwardRemoteSynCount >= DSD__maxBackwardLocSyn){
printf(
"ERROR on loc_h=%d in localNet::init() backwardSynCount > DSD__maxBackwardLocSyn\n",lnp_par.loc_h);
fflush(stdout);exit(0);
};
DPSNNverboseStart(false,4,lnp_par.loc_h);
for(i=0;i<lnp_par.globH;i++) {
uint32_t synCount;
if(i!=lnp_par.loc_h) {
synCount = synSourceHostDistribution.synCount[i];
}else{
synCount = localSynCount;
};
printf("580- S_h=%03d -> T_h=%03d - %d back syn after dim message passing\n",
i, lnp_par.loc_h, synCount);
fflush(stdout);
}
DPSNNverboseEnd();
{
//intermSynList is placed in the second part of memPoolA
//the first part of memPoolA is used by localSynList
intermSynList=(synapseClass *) &memPoolA[
sizeof (synapseClass) * localSynCount];
DPSNNverboseStart(false,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h==0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: BEFORE send/rec the used memory on %s is %lu kB\n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
pMessagePassing->sendForwardSynListToRemoteHosts(
forwardSynList, &synTargetHostDistribution,
intermSynList, &synSourceHostDistribution, 0);
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("590- h=%03d sendReceiveSynList: BEFORE check AFTER MESSAGE PASS\n",
lnp_par.loc_h);
DPSNNverboseEnd();
//before the following line backwardSynCount, was about obly the
//synapses transferred by message passing
backwardSynCount = backwardRemoteSynCount + localSynCount;
//now backward syn count is about the total pool of incoming synapses
//forwardSynList (allocated on memPoolB is not anymore necessary
//from now on memPoolB is used for backwardSynList
backwardSynList=(synapseClass*)&memPoolB[0];
{//inserting localSynList in the middle of the full list
//rebuilding a single full backwardSynList
//EPA - PSP correggere qui almeno il count delle forward syn
uint32_t h,s;
uint32_t backwardSynOffset;
uint32_t intermSynOffset;
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("591- h=%03d localNet_init start inclusion local in middle\n",
lnp_par.loc_h);
DPSNNverboseEnd();
backwardSynOffset=0; intermSynOffset=0;
synSourceHostDistribution.synOffset[0]=0;
for(h=0;h<lnp_par.loc_h;h++) {
for(s=0;s<synSourceHostDistribution.synCount[h];s++) {
backwardSynList[backwardSynOffset++] =
intermSynList[intermSynOffset++];
};
};
for(s=0;s<localSynCount;s++) {
backwardSynList[backwardSynOffset++] = localSynList[s];
};
synSourceHostDistribution.synCount[lnp_par.loc_h]=localSynCount;
if(lnp_par.loc_h > 0) {
synSourceHostDistribution.synOffset[lnp_par.loc_h]=
synSourceHostDistribution.synOffset[lnp_par.loc_h-1]+
synSourceHostDistribution.synCount[lnp_par.loc_h-1];
};
for(h=lnp_par.loc_h+1;h<lnp_par.globH;h++) {
for(s=0;s<synSourceHostDistribution.synCount[h];s++) {
backwardSynList[backwardSynOffset++] =
intermSynList[intermSynOffset++];
};
synSourceHostDistribution.synOffset[h]=
synSourceHostDistribution.synOffset[h-1]+
synSourceHostDistribution.synCount[h-1];
};
if(backwardSynCount!=backwardSynOffset) {
printf(
"ERROR h=%d localNet_init backSynCount=%d != backSynOffset=%d\n",
lnp_par.loc_h, backwardSynCount, backwardSynOffset);
fflush(stdout); exit(0);
}
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("592- h=%03d localNet_init END inclusion local in middle\n",
lnp_par.loc_h);
DPSNNverboseEnd();
};
// memPoolB contains the full backwardSynList (both local and remote)
// reordered per source_h
inflateIntermToBackwardSynList(
(synapseClass*) &memPoolB[0],
(synapseClass*) &memPoolA[0], backwardSynCount);
backwardSynList=(synapseClass*)&memPoolA[0];
DPSNNverboseStart(true,1,0);
//MPI_Barrier(MPI_COMM_WORLD);
pMessagePassing->barrier();
if(lnp_par.loc_h==0){
//freeMemory=system ("free");
sysinfo (&si);
printf ("MEMORY: AFTER inflate the used memory on %s is %lu kB\n",
lnp_par.hostName, lnp_par.freeMemAtStart-si.freeram/1024);
}
DPSNNverboseEnd();
}
DPSNNverboseStart(false,1,0);
printf("593- h=%03d localSynCount=%d, backwardSynCount=%d, totSynNum=%d\n",
lnp_par.loc_h, localSynCount, backwardRemoteSynCount, backwardSynCount);
fflush(stdout);
DPSNNverboseEnd();
DPSNNverboseStart(true,1,0);
synapticListReport(backwardSynList, backwardSynCount, -1);
DPSNNverboseEnd();
DPSNNverboseStart(false,1,0);
checkSynListInitValues(backwardSynList, backwardSynCount);
DPSNNverboseEnd();
//The delivery of axonal spikes requires to know if there are synapses directed
//roward the same process
//the offset should be not ceseccary, because the fowardSynList
//has been overwritten by previous memPools management
synTargetHostDistribution.synCount[lnp_par.loc_h]=localSynCount;
};
void localNetClass::inflateIntermToBackwardSynList(
const synapseClass *intermSynList,
synapseClass *backwardSynList, const uint32_t backwardSynCount) {
uint32_t i,j;
uint32_t source_h, delay;
uint32_t delayCntExpected[lnp_par.D-1];
uint32_t delayCntActual[lnp_par.D-1];
uint32_t offsetd[lnp_par.D-1];
uint64_t neuId;
FILE *fp_output;
char reportName[80];
// uint32_t seedForLIFCAWeightInit;
//struct sysinfo si;
uint32_t synSourceCount;
for (i=0;i<lnp_par.D;i++){
delayCntExpected[i]=0;
delayCntActual[i]=0;
}
for (i=0;i<backwardSynCount;i++)
delayCntExpected[intermSynList[i].delay]++;
offsetd[0]=0;
for (i=1;i<lnp_par.D;i++)
offsetd[i]=offsetd[i-1]+delayCntExpected[i-1];
for(i=0;i<backwardSynCount;i++){
j=offsetd[intermSynList[i].delay]+delayCntActual[intermSynList[i].delay];
delayCntActual[intermSynList[i].delay]++;
backwardSynList[j].pre_glob_n =
intermSynList[i].pre_glob_n ;
backwardSynList[j].post_glob_n =
intermSynList[i].post_glob_n ;
backwardSynList[j].delay =
intermSynList[i].delay;
backwardSynList[j].preSynNeuralKind =
intermSynList[i].preSynNeuralKind;
backwardSynList[j].weight =
intermSynList[i].weight;
#if defined(makeActiveLTD) || defined (makeActiveLTP)
backwardSynList[j].lastActivationTime = 0;
backwardSynList[j].timeDerivative = (weightType)0.0;
#endif
delay = backwardSynList[j].delay;
source_h = backwardSynList[j].pre_glob_n / lnp_par.locN;
synDelaySourceHostDistribution.synCount[delay][source_h]++;
}
for(delay=0;delay<lnp_par.D;delay++){
synDelaySourceHostDistribution.synOffset[delay][0]=offsetd[delay];
for(source_h=1;source_h<lnp_par.globH;source_h++)
synDelaySourceHostDistribution.synOffset[delay][source_h]=
synDelaySourceHostDistribution.synOffset[delay][source_h-1]+
synDelaySourceHostDistribution.synCount[delay][source_h-1];
}
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
for (i=0;i<lnp_par.D;i++)
printf("BackwardSynList h=%d: delayCntExpected[%d]=%d, delayCntActual[%d]=%d, offsetd[%d]=%d\n",
lnp_par.loc_h,i,delayCntExpected[i],i,delayCntActual[i],i,offsetd[i]);
DPSNNverboseEnd();
for (i=0;i<lnp_par.D;i++){
if(delayCntExpected[i]!=delayCntActual[i])
printf("ERROR in BackwardSynList: mismatch between expected=%d and actual=%d synapses with delay %d in process h=%d \n",
delayCntExpected[i],delayCntActual[i],i,lnp_par.loc_h);
}
for (j=0;j<lnp_par.locN*lnp_par.globH;j++){
synSourceCount = synSourceHostDistribution.synCount[j/lnp_par.locN];
if(synSourceCount != 0) {
for (i=0;i<lnp_par.D;i++)
backwardSynOffsetInSynList[j].offsetByDelay[i] = -1;
}
}
// Calculate synapse offsets in the reordered backward synaptic list
// for each synapse: 1 offset for each delay
neuId = (uint64_t)-1;
for (i=0;i<lnp_par.D;i++){
for (j=0;j<delayCntActual[i];j++){
if(backwardSynList[j+offsetd[i]].pre_glob_n != neuId){
neuId = backwardSynList[j+offsetd[i]].pre_glob_n;
synSourceCount = synSourceHostDistribution.synCount[neuId/lnp_par.locN];
if(synSourceCount != 0)
backwardSynOffsetInSynList[neuId].offsetByDelay[i] = offsetd[i] + j;
}
}
neuId = (uint64_t)-1;
}
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
sprintf(reportName,"OffsetSynList_h%d.txt",lnp_par.loc_h);
fp_output=fopen(reportName,"w");
fprintf(fp_output,"Offsets by delay for process H=%d\n",lnp_par.loc_h);
for(i=0;i<lnp_par.locN*lnp_par.globH;i++){
fprintf(fp_output,
"neuId=%d offset[0]=%d offset[1]=%d offset[2]=%d offset[3]=%d offset[4]=%d \n",i,
backwardSynOffsetInSynList[i].offsetByDelay[0],
backwardSynOffsetInSynList[i].offsetByDelay[1],
backwardSynOffsetInSynList[i].offsetByDelay[2],
backwardSynOffsetInSynList[i].offsetByDelay[3],
backwardSynOffsetInSynList[i].offsetByDelay[4]);
}
DPSNNverboseEnd();
};
void localNetClass::check_lnp_par_initValues() {
if(lnp_par.D>DSD__maxD) {
printf("ERROR: localNet::init - maximum delay D=%d out of range\n", lnp_par.D);
fflush(stdout);exit(0);}
if(lnp_par.locN>DSD__maxLocN) {
printf("ERROR: localNet::init - locN=%d wrong value out of range\n", lnp_par.locN);
fflush(stdout);exit(0);}
if(lnp_par.loc_h>=DSD__maxGlobH||lnp_par.loc_h>=lnp_par.globH) {
printf("ERROR: localNet::init - loc_h=%d wrong value out of range\n", lnp_par.loc_h);
fflush(stdout);exit(0);}
};
void localNetClass::forwardSynListReport(
synapseClass *synList,
uint32_t synCount, uint32_t repNum) {
FILE *fp_output;
char reportName[80];
instrumentedSynapse instrumentedSynapseDummy;
uint32_t i;
sprintf(reportName,"localNet_h%d_N%d_SynapticList_FORWARD_R%d.dat",
lnp_par.loc_h,lnp_par.locN,repNum);
fp_output=fopen(reportName,"w");
fprintf(fp_output,
"localNet::statusReport - list in localNet::forwardSynList \n");
for (i=0;i<synCount;i++) {
instrumentedSynapseDummy.report(synList[i],fp_output,
lnp_par.locN,lnp_par.factorWeightType_2_Float);
}
fclose(fp_output);
};
void localNetClass::synapticListReport(synapseClass *synList,
uint32_t synCount, uint32_t repNum) {
FILE *fp_output;
char reportName[80];
instrumentedSynapse instrumentedSynapseDummy;
uint32_t i;
DPSNNverboseStart(false,1,0);
if(lnp_par.loc_h==0) {
printf("loc_h = %d, synapticListReport starting\n", lnp_par.loc_h);
fflush(stdout); }
DPSNNverboseEnd();
if(lnp_par.loc_h==0) {
sprintf(reportName,"localNet_h%d_N%d_SynapticList_BACKWARD_R%d.dat",
lnp_par.loc_h,lnp_par.locN,repNum);
fp_output=fopen(reportName,"w");
//fprintf(fp_output,
//"localNet::statusReport - list in localNet::SynapticList \n");
for (i=0;i<synCount;i++) {
instrumentedSynapseDummy.report(synList[i],fp_output,
lnp_par.locN,lnp_par.factorWeightType_2_Float);
}
fclose(fp_output);
};
DPSNNverboseStart(false,1,0);
if(lnp_par.loc_h==0) {
printf("loc_h = %d, synapticListReport ending\n", lnp_par.loc_h);
fflush(stdout); }
DPSNNverboseEnd();
};
void localNetClass::checkTotalSynCountInSynapticDistribution(
synapticDistributionClass *pSynapticDistribution,
uint32_t expectedSynCount) {
// CHECK the sum of synTargetHostDistribution.synCount[x]
// must be equal to synCount
uint32_t synCountCheck, i;
synCountCheck=0;
for (i=0;i<lnp_par.globH;i++) {
synCountCheck+=pSynapticDistribution->synCount[i];
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf(
"checkTotalSynCount on loc_h=%d - synCount=%d syn toward host %d starts at synOffset=%d\n",
lnp_par.loc_h,
pSynapticDistribution->synCount[i],
i, pSynapticDistribution->synOffset[i]);
DPSNNverboseEnd();
};
if(expectedSynCount!=synCountCheck) {
printf(
"ERROR total =%d syn toward all host targets does not amount to expected %d, \n",
synCountCheck, expectedSynCount);
fflush(stdout);
exit(0);
};
};
void localNetClass::checkSortedSynListAndCreateSynapticDistribution(
synapseClass synList[],
synapticDistributionClass *pSynHostDistribution,
uint32_t synCount)
{
//MUST BE EXECUTED AFTER THE SORT OF THE SYN LIST BY TARGET HOST
if(lnp_par.globH==1) {
pSynHostDistribution->synCount[0]=synCount;
pSynHostDistribution->synOffset[0]=0;
}else{
//counts the number of synapses connected to each host target and verifies the sorting
//clear the bins in the target host distribution histogram
uint32_t currentTargetHost, i;
for (i=0;i<lnp_par.globH;i++) {
pSynHostDistribution->synCount[i]=0;
pSynHostDistribution->synOffset[i]=0;
};
//the first column in the histogram
//under scrutiny is obviously the #0
currentTargetHost=0;
//i is the counter of synapses in the list (already sorted by targetHost)
for (i=0;i<synCount;i++) {
//for each synapse there are 3 possibilities:
//A- the synapse has the same target host of the previous synapse
// (increase the count in the current histogramm bin)
//B- the synapse is in the next bin (NO HOLES)
// (increase the histogram bin counter, set to 1 the counter
//C- there are holes in the histogram
// (skip the bins, setting to zero the height and copying the offset)
//case A - same histogram bin of previous synapse
if((synList[i].post_glob_n / lnp_par.locN) == currentTargetHost) {
pSynHostDistribution->synCount[currentTargetHost]++;
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf(
"synDistr A - h=%d: another synapse %d added to total %d of synapses directed to host %d\n",
lnp_par.loc_h, i,
pSynHostDistribution->synCount[currentTargetHost],
currentTargetHost);
DPSNNverboseEnd();
} else if((synList[i].post_glob_n / lnp_par.locN)==(currentTargetHost+1)) {
//case B - next histogram bin
// (in this case no holes in the distribution)
currentTargetHost++;
pSynHostDistribution->synOffset[currentTargetHost] = i;
pSynHostDistribution->synCount[currentTargetHost] = 1;
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf(
"synDistr B - h=%d: first synapse %d added to total %d of synapses directed to host %d\n",
lnp_par.loc_h, i,
pSynHostDistribution->synCount[currentTargetHost],
currentTargetHost);
DPSNNverboseEnd();
} else if((synList[i].post_glob_n / lnp_par.locN)>(currentTargetHost+1)) {
//case C - set empty columns in the histogram
// in this case there are holes in the distribution:
//i.e. this source host does not project synapses
//neither to currentTargetHost (case A),
//nor to currentTargetHost+1 (case B)
do {
currentTargetHost++;
pSynHostDistribution->synCount[currentTargetHost]=0;
//the offset does not move
pSynHostDistribution->synOffset[currentTargetHost]=
pSynHostDistribution->synOffset[currentTargetHost-1] +
pSynHostDistribution->synCount[currentTargetHost-1];
DPSNNverboseStart(false,0,lnp_par.debugPrintEnable_ms);
printf("synDistr C - h=%d: skip target host %d\n",
lnp_par.loc_h, currentTargetHost);
fflush(stdout);
DPSNNverboseEnd();
} while ((currentTargetHost+1)!=(synList[i].post_glob_n / lnp_par.locN));
//now we should have skipped all the empty bins
currentTargetHost++; //this should be good...
if(currentTargetHost == (synList[i].post_glob_n / lnp_par.locN)) {
// ...and now set the offset and count of the first synapse
// directed to this existing target
pSynHostDistribution->synOffset[currentTargetHost]=i;
pSynHostDistribution->synCount[currentTargetHost]++;
} else {
if (currentTargetHost>=lnp_par.globH) {
printf("ERROR currentTargetHost error - 1\n");fflush(stdout);exit(0);
};
};
} else if ((synList[i].post_glob_n / lnp_par.locN)<currentTargetHost) {
// we are after the sort so we must not go backwards
printf("ERROR synSort not performed\n"); fflush(stdout); exit(0);
} else if((synList[i].post_glob_n / lnp_par.locN) >= lnp_par.globH) {
// the target host of the synapse must be in range
printf("ERROR: target host too big\n"); fflush(stdout); exit(0);
};
if (currentTargetHost>=lnp_par.globH) {
// the current bin of the histogram must be in range
printf("ERROR currentTargetHost error -2 \n");fflush(stdout);exit(0);
};
};//end of for i over synapses
//there could be processes not reached by any of the synapses
//one or more "holes" at the end of h ordering
{
//setting the a valid offset for all final targets processes
//not receiving synapses
uint32_t h;
for(h = currentTargetHost+1; h < lnp_par.globH ; h ++)
pSynHostDistribution->synOffset[h]=
pSynHostDistribution->synOffset[h-1] +
pSynHostDistribution->synCount[h-1];
}
};//end of if about globH==1 (single process)
};
void localNetClass::checkForwardSynListInitValues(
synapseClass *synList,
uint32_t synCount)
{
uint32_t i;
if(synCount >= DSD__maxForwardLocSyn){
printf("ERROR on loc_h=%d - checkForwardSynListInitValues - too many %d forward syn generated\n",
lnp_par.loc_h,synCount);fflush(stdout);exit(0);
}
for (i=0;i<synCount;i++) {
if (synList[i].pre_glob_n>=lnp_par.globN)
{printf("ERROR on loc_h=%d - checkForwardSynListInitValues - pre_glob_n\n",
lnp_par.loc_h);fflush(stdout);exit(0);};
if (synList[i].post_glob_n>=lnp_par.globN)
{printf("ERROR on loc_h=%d - checkForwardSynListInitValues - post_glob_n\n",
lnp_par.loc_h);fflush(stdout);exit(0);};
if (synList[i].delay > lnp_par.D)
{printf("ERROR on loc_h=%d - checkForwardSynListInitValues - delay (synList[%d].delay=%d)\n",
lnp_par.loc_h,i,synList[i].delay);fflush(stdout);exit(0);};
#ifdef LIFCAneuron
/*PSP 2017-plasticity if (!((synList[i].preSynNeuralKind == excitatoryLbExc) ||
(synList[i].preSynNeuralKind == excitatoryLaExc) ||
(synList[i].preSynNeuralKind == inhibitoryLaInh)))
{printf("ERROR on loc_h=%d -chkSynListInitVal (1) - preSynNeuralKind\n",
lnp_par.loc_h); fflush(stdout); exit(0);};*/
#else
if (!((synList[i].preSynNeuralKind == excitatoryRS) ||
(synList[i].preSynNeuralKind == inhibitoryFS)))
{printf("ERROR on loc_h=%d -chkSynListInitVal - preSynNeuralKind \n",
lnp_par.loc_h); fflush(stdout); exit(0);};
#endif
};
};
void localNetClass::checkSynListInitValues(
synapseClass *synList,
uint32_t synCount)
{
uint32_t i;
for (i=0;i<synCount;i++) {
if (synList[i].pre_glob_n>=lnp_par.globN)
{printf("ERROR on loc_h=%d - checkSynListInitValues - pre_glob_n\n",
lnp_par.loc_h);fflush(stdout);exit(0);};
if (synList[i].post_glob_n>=lnp_par.globN)
{printf("ERROR on loc_h=%d - checkSynListInitValues - post_glob_n\n",
lnp_par.loc_h);fflush(stdout);exit(0);};
if (synList[i].delay > lnp_par.D)
{printf("ERROR on loc_h=%d - checkSynListInitValues - delay \n",
lnp_par.loc_h);fflush(stdout);exit(0);};
#ifdef LIFCAneuron
/*PSP 2017-plasticity if (!((synList[i].preSynNeuralKind == excitatoryLbExc) ||
(synList[i].preSynNeuralKind == excitatoryLaExc) ||
(synList[i].preSynNeuralKind == inhibitoryLaInh)))
{printf("ERROR on loc_h=%d -chkSynListInitVal - preSynNeuralKind \n",