The following algorithm runs iteratively in my program. running it without the two lines listed below takes 1.5X as long as it is absent. It is very surprising for me, as it is. The worst part is that working with these two lines increases completion to 4.4X work without them (6.6X the whole algorithm does not work). In addition, this leads to the fact that my program cannot scale beyond ~ 8 cores. In fact, when working on the same core, the two lines only increase the time to 1.7x, which is still too high, considering what they are doing. I ruled out that this is due to the influence of the changed data elsewhere in my program.
So I wonder what could be causing this. Is something like a cache possible?
void NetClass::Age_Increment(vector <synapse> & synapses, int k) { int size = synapses.size(); int target = -1; if(k > -1) { for(int q=0, x=0 ; q < size; q++) { if(synapses[q].active) synapses[q].age++; else { if(x==k)target=q; x++; } } /////////////////////////////////////Causing Bottleneck///////////// synapses[target].active = true; synapses[target].weight = .04 + (float (rand_r(seedp) % 17) / 100); //////////////////////////////////////////////////////////////////// } else { for(int q=0 ; q < size; q++) if(synapses[q].active) synapses[q].age++; } }
Update: Changing two problematic lines:
bool x = true; float y = .04 + (float (rand_r(seedp) % 17) / 100);
Removes a problem. Suggest perhaps this is related to memory access?
source share