我必须从两个 .dat 文件中读取数据,但我的控制台输出功能有问题,而且我的 C++ 技能仍然生疏,有人可以帮忙吗?
使用条带化从 Residences.dat 中读取地址记录的子集。对于 n > 个进程,每个进程根据每第 n 个记录评估一个唯一的记录子集。此子集中的记录数应约为 #-of-residence-records /#-of-processes。在所有使用的并行进程中,不应省略任何地址,并且不应多次处理 >none。另请注意,任何进程一次只能将一条记录存储在内存中;不要将整个数据集读入内存中的数据结构,因为这完全没有必要并且会消耗太多 RAM!
数据示例
329267.349 4847214.382
318141.019 4851350.892
319526.06 4850474.347
322666.48 4840244.995
316578.529 4837299.827
320090.607 4840439.088
//read file and populate the vectors
ifstream foodbankFile("/Users/abdallaelnajjar/Documents/XCodeProjects/cpp_projects/MPI_Project2/foodbanks.dat");
ifstream residenceFile("/Users/abdallaelnajjar/Documents/XCodeProjects/cpp_projects/MPI_Project2/residences.dat");
// populate datavector
std::vector<Foodbank> foodbankData((std::istream_iterator<Foodbank>(foodbankFile)),
std::istream_iterator<Foodbank>());
//std::vector<Residence> residenceData((std::istream_iterator<Residence>(residenceFile)),
//std::istream_iterator<Residence>());
std::vector<double> distancess;
string file_contents;
Residence res;
int numProcs = 1;
int recCount = 0;
//pseudo code that I trying to implement
// While(there are more records){
// If record count % numProcs == myID
// ProcessRecord
// else
// Increment file stream pointer forward one record without processing
// Increment Record Count
//}
int numLines = 1;
while(!residenceFile.eof())
{
residenceFile >> res.x >>res.y;
//distancess.push_back(populate_distancesVector(res,foodbankData));
if ( recCount % numProcs == numLines)
{
//call the process
distancess.push_back(populate_distancesVector(res,foodbankData));
}
else
++numLines;
++recCount;
}