when I run this program it gives me assertation failed, subscript out of range. I tried to use debugging method and I found that in element constructor when it wants to calculate the
tmp_coordinates[i].push_back(Nodes[i_node].get_x());
it will crash. when I continue debugging it goes to the get_x() function of Node class says vector out of range, why the same method is working for Nodes vector but for elements vector no?
coord is a local variable which looses scope at the end of the for body. Hence it is a new variable every time around the loop - which may or may not have a different address.
node is taking the address of coord and setting coordinates equal to this passed pointer using a shallow copy. But this pointer is only valid within the scope of the for loop body. Once the body ends and the next for iteration takes place, &coord is invalid. Depending upon the phase of the moon and star alignment, this might or might not 'appear' to work. But it isn't really.
Within the for loop L72 - 77, these saved addresses are de-referenced to get x and y - but these saved addressed are no longer valid. Hence the crash.
Have the Node class store its own copy of the data it needs from coord, rather than a pointer to coord.
EDIT: If you absolutely must have it be a pointer to something that it doesn't own, then make sure it's pointing to something that you can be absolutely sure will remain valid for the lifetime of the Node object.
That follows my second suggestion, not my first. You still have Node storing nothing more than a pointer to the vector of co-ordinates, but at least you're making sure that the thing it's pointing to (an element of coord) persists for longer than the lifetime of the pointer itself.
Or are you? What's the lifespan of Nodes? If it outlives coord, then you'll still have pointers to memory that's no longer valid.
Just make Node own its own copy of the coordinates vector, rather than pointing to something it doesn't own.
There is text file containing all the mesh properties(connectivity and coordinate).Also, There is class Named Mesh responsible for reading the text file. The object of this class will be Global_Mesh. Then I send chunk of elements to each processor and that would be Local_mesh.
Both global and Local are of type Mesh.