mpi - C++: How is it possible that reading data can affect memory? -
I am going deeper in C ++ and my worms are complex.
I have a vector of objects, each object has a vector of floats. I decided that I need to make another flat array which contains a float value of all the items. Compared to this, it is a bit more complicated but the essence of the problem is that when I loop to remove the float value through my objects, at some point the object of my vector is changed, or some strange way Is corrupted by (My read operations are all the constant functions)
Another example was with the MPI I was just starting, so I run the exact same code on two different nodes with my own separate memory Wanted and no data transfer is happening, all very simple For my surprise, I found split errors, and after tracking the hours, I came to know that an assignment of a variable was completely setting different variables.
So I'm curious, how is it possible that the reading operation might be affected by my data structures, thus it seems that how unrelated operations can affect someone else. I could not expect to solve my problems with those brief details, but any advice would be greatly appreciated.
Update: Here is a section of code, I did not originally posted because I'm not sure it can be removed from without understanding the whole system.
One thing I have discovered is that when I stopped specifying the value for my flat array and just cout'ed instead, seg errors disappeared. So maybe I am declaring my array wrong, but even though I could not believe how it would affect the object vector.
void xlMasterSlaveGpuEA :: FillFlatGenes () {int stringLength = pop- & gt; GetGenome (0) .GetLength (); For (Int i = 0; I for & lt; pop- & gt; GetPopSize (); i ++) for (int j = 0; j & lt; string lang; j ++) flatways [(I * string Lang) + j] & lt; & Lt; Pop & gt; GetGenome (i) .GetFloatGene (J); } Float xlVectorGenome :: GetFloatGene (unsigned int i) const {return GetGene (i); } My flat is a member function
float * flatFitness; In this way the creator is intrinsically:
flatFitness = new float (popsype); Update 2:
I just want to say that the above two examples are not related, first of all there is no multi threaded. The second MPI example is technically, but memory is delivered to the MPI and I deliberately try the simplest implementation which I could think of, that the machines are running code independently. However, there is an additional statement, I put in a strict word
If node 1 is the lower half of the loop then node 1 then top half Memory should be separated, they should work as they do not know anything about each other. But by removing this conditional and making both ends, make all the cubes, eliminate the error. / P>
This is an array creator Not:
float * flatFitness; FlatFitness = new float (pop-shaped); You are creating a float on the heap, the value has been started with the popSize . If you want an array of float then you need to use brackets instead of brackets:
float * flatFitness = new float [popSize]; This can easily be the problems you have described. Also, remember that when you create an array, you need to use delete [] (ultimately):
delete [] flatFitness; If you just use delete , it can work, but the behavior is undefined.
If you want to completely avoid using array syntax, why not use std :: vector ? You can create a vector of PopCar elements like this:
#include & lt; Vector & gt; Std :: vector & lt; Float & gt; FlatFitness (popSize); When it gets out of the scope, it will be automatically free, so you should know about new or delete There is no need to worry about.
Update (re-comment): If you are already using std :: vectors in your code, then Std :: vector :: swap () . You can completely avoid copying things and just swap a vector vector behind and back between buffering for a CUDA, which you are doing here.
Comments
Post a Comment