使用集合时我有一些非常奇怪的行为(它实际上是集合的 3d 向量)。我在循环结束时有以下内容(注释是第四次循环发生时的行为,所以它不会立即发生)
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
//returns 4
grid_locations[box_counter][0]=i*xgridlength;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
//returns 4
grid_locations[box_counter][1]=(i+1)*xgridlength;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
//returns 4
grid_locations[box_counter][2]=j*ygridlength;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
//returns 4
grid_locations[box_counter][3]=(j+1)*ygridlength;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
//returns 4
grid_locations[box_counter][4]=k*zgridlength;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
//returns 4
grid_locations[box_counter][5]=(k+1)*zgridlength;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
// returns 1071644672
grid_rank_lookup[box_counter]=use_rank;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
// returns 1071644672
box_counter++;
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
// returns 1071644672
use_rank=(use_rank+1)%world.size();
cout<<"size of set at 3 0 0 is "<<particles_celllist.at(3).at(0).at(0).size()<<endl;
// returns 1071644672
particles_celllist
、grid_rank_lookup
和的定义grid_locations
是:
vector<vector<vector<set<int> > > > particles_celllist;
map<int,vector<double> > grid_locations
map<int,int> grid_rank_lookup
注意:第一个是局部变量,而另外两个是函数的输入。
我不知道是什么原因造成的,甚至不知道如何找出问题所在。我在代码本身的范围内没有看到任何合乎逻辑的解释,所以也许这与内存有关?评论是当我在单个处理器上运行它时会发生什么,但如果我在 2 个处理器上执行它(它是一个 mpi 代码)它似乎在随机处理器上随机发生(我没有包括所有细节这里是因为代码很长,但是如果您觉得这里的信息不足以猜测出什么问题,我可以发布它)
谢谢