我收集缓冲区是空的? [英] My gather Buffer is Empty?
本文介绍了我收集缓冲区是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题,所有的过程来处理大师根收集的数据,我可以发送数据MPI_Bcast但上MPI_Gather我所有的问题在我countBuff调试我输出这是我所
输出 0 brodcast数据
1 brodcast数据
MPI_Gather数据等级0 1
从0到1.00 KM:-842150451,从1.00至2.00 KM:-842150451,从2.00到5.00 KM:-842150451,刨丝器比5.00公里-842150451
MPI_Type_free1
删除countBuff
MPI_Finalize
2 brodcast数据
MPI_Gather数据排名0 0
MPI_Gather数据等级0 2
从0到1.00 KM:-842150451,从1.00至2.00 KM:-842150451,从2.00到5.00 KM:-842150451,刨丝器比5.00公里-842150451
MPI_Type_free2
删除countBuff
MPI_Finalize 工作中止:
排名:节点:退出code [:错误信息]
0 :: -1073741819:进程0退出,而不调用的finalize
1 :: 123
2 :: 123
在code
无效ProcesData(INT排名,诠释numProcs)
{ 静态countType计数;
MPI_Datatype recType = createRecType();
//读取文件和填充矢量
ifstream的foodbankFile(foodbanks.dat);
ifstream的residenceFile(residences.dat); //填充替换dataVector
的std ::矢量<&Foodbank GT; foodbankData((的std :: istream_iterator< Foodbank>(foodbankFile))
的std :: istream_iterator< Foodbank>()); 住宅资源;
INT numLines = 0;
而(!residenceFile.eof())
{
residenceFile>> res.x>> res.y;
如果(numLines%numProcs ==排名)
{
//调用过程
// populate_distancesVector(RES,foodbankData);
analysis_range(populate_distancesVector(RES,foodbankData),计数); }
++ numLines; }
COUT<<&LT的brodcast数据;<&排名LT;< ENDL;
MPI_Bcast(安培;算,1,recType,职级,MPI_COMM_WORLD);
MPI_Type_free(安培; recType);
//性病::法院LT&;< 秩<<&排名LT;< 从0到1.00 KM:&所述;&所述; count.range1&所述;&下;,%&所述;&下;计数preSET1。
//<<,从1.00至2.00 KM:<< count.range2<<%<<计数preset2<<,从2.00到5.00 KM:
//<<count.range3<<\",%\"<<count.$p$pset3<<\",grater比5.00 KM:&LT;&LT; count.range4&LT;&LT;,% &LT;&LT;计数preset3&LT;&LT;的std :: ENDL;
}
INT主(INT ARGC,CHAR *的argv [])
{ 如果(MPI_INIT(安培; ARGC,&安培; argv的)== MPI_SUCCESS)
{
//获取进程的数目而这个过程的秩
INT procRank,numProcs;
MPI_Comm_size(MPI_COMM_WORLD,&安培; numProcs);
MPI_Comm_rank(MPI_COMM_WORLD,&安培; procRank);
ProcesData(procRank,numProcs);
//为传递REC阵列创建一个派生类型
MPI_Datatype recType = createRecType();
静态countType计数;
countType * countBuff =新countType [numProcs] MPI_Gather(安培;算,1,recType,&安培; countBuff,1,recType,0,MPI_COMM_WORLD);
COUT&LT;&LT;MPI_Gather数据排名0&LT;&LT; procRank&LT;&LT; ENDL;
// MPI_ALLGATHER(安培;算,1,recType,&安培; countBuff,1,recType,MPI_COMM_WORLD); 性病::法院LT&;&LT;从0到1.00 KM:&LT;&LT; countBuff [0] .range1&LT;&LT;,从1.00至2.00 KM:
&LT;&LT; countBuff [0] .range2&LT;&LT;,从2.00到5.00 KM:&LT;&LT; countBuff [0] .range3
&LT;&LT;,刨丝器比5.00 KM:&LT;&LT; countBuff [0] .range4&LT;&LT;的std :: ENDL;
COUT&LT;&LT;MPI_Type_free&LT;&LT; procRank&LT;&LT; ENDL;
MPI_Type_free(安培; recType);
COUT&LT;&LT;删除countBuff&LT;&LT; ENDL; COUT&LT;&LT;MPI_Finalize&LT;&LT; ENDL;
MPI_Finalize();
}
返回0;
}
解决方案
无效过程数据(INT排名,诠释numProcs)
{ 静态countType计数;
MPI_Datatype recType = createRecType(); //读取文件和填充矢量
ifstream的foodbankFile(foodbanks.dat);
ifstream的residenceFile(residences.dat); //填充替换dataVector
的std ::矢量&lt;&Foodbank GT; foodbankData((的std :: istream_iterator&LT; Foodbank&GT;(foodbankFile))
的std :: istream_iterator&LT; Foodbank&GT;()); 住宅资源;
INT numLines = 0;
而(!residenceFile.eof())
{
residenceFile&GT;&GT; res.x&GT;&GT; res.y;
如果(numLines%numProcs ==排名)
{ analysis_range(getShortestDistances(RES,foodbankData),计数); }
++ numLines; } countType * countBuff =新countType [numProcs]
MPI_Gather(安培;算,1,recType,countBuff,1,recType,0,MPI_COMM_WORLD);如果(排名== 0)
{ 静态countType countArggResult;
为(中间体p值= 0; P&下; numProcs ++ p)的
{
//放出来的结果
}
}
//自由virables
删除[] countBuff;
MPI_Type_free(安培; recType);
}
I have problem gathering data from all process to process master "root" I can send the data MPI_Bcast but the on MPI_Gather I have all the problem in my countBuff I debug my output and this is what I have
output
brodcast data of 0
brodcast data of 1
MPI_Gather data rank 0 1
from 0 to 1.00 KM:-842150451,from 1.00 to 2.00 KM:-842150451,from 2.00 to 5.00 KM:-842150451,grater than 5.00 KM:-842150451
MPI_Type_free1
delete countBuff
MPI_Finalize
brodcast data of 2
MPI_Gather data rank 0 0
MPI_Gather data rank 0 2
from 0 to 1.00 KM:-842150451,from 1.00 to 2.00 KM:-842150451,from 2.00 to 5.00 KM:-842150451,grater than 5.00 KM:-842150451
MPI_Type_free2
delete countBuff
MPI_Finalize
job aborted:
rank: node: exit code[: error message]
0:: -1073741819: process 0 exited without calling finalize
1:: 123
2:: 123
the code
void ProcesData(int rank,int numProcs)
{
static countType count;
MPI_Datatype recType = createRecType();
//read file and populate the vectors
ifstream foodbankFile("foodbanks.dat");
ifstream residenceFile("residences.dat");
// populate datavector
std::vector<Foodbank> foodbankData((std::istream_iterator<Foodbank>(foodbankFile)),
std::istream_iterator<Foodbank>());
Residence res;
int numLines = 0;
while(!residenceFile.eof())
{
residenceFile >> res.x >>res.y;
if ( numLines % numProcs == rank)
{
//call the process
//populate_distancesVector(res,foodbankData);
analysis_range(populate_distancesVector(res,foodbankData),count);
}
++numLines;
}
cout<<"brodcast data of "<<rank<<endl;
MPI_Bcast(&count, 1, recType, rank, MPI_COMM_WORLD);
MPI_Type_free(&recType);
//std::cout<< "for Rank"<<rank<< ",from 0 to 1.00 KM:"<<count.range1<<",%"<<count.preset1
//<<",from 1.00 to 2.00 KM:"<<count.range2<<",%"<<count.preset2<<",from 2.00 to 5.00 KM:"
//<<count.range3<<",%"<<count.preset3<<",grater than 5.00 KM:"<<count.range4<<",%"<<count.preset3<<std::endl;
}
int main(int argc, char* argv[])
{
if( MPI_Init(&argc, &argv) == MPI_SUCCESS )
{
// Get the number of processes and the rank of this process
int procRank,numProcs;
MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
MPI_Comm_rank(MPI_COMM_WORLD, &procRank);
ProcesData(procRank,numProcs);
// Create a derived type for passing the rec array
MPI_Datatype recType = createRecType();
static countType count;
countType* countBuff = new countType[numProcs];
MPI_Gather(&count, 1, recType, &countBuff, 1, recType,0, MPI_COMM_WORLD);
cout<<"MPI_Gather data rank 0 "<<procRank<<endl;
//MPI_Allgather(&count, 1, recType, &countBuff, 1, recType,MPI_COMM_WORLD);
std::cout<<"from 0 to 1.00 KM:"<<countBuff[0].range1<<",from 1.00 to 2.00 KM:"
<<countBuff[0].range2<<",from 2.00 to 5.00 KM:"<<countBuff[0].range3
<<",grater than 5.00 KM:"<<countBuff[0].range4<<std::endl;
cout<<"MPI_Type_free"<<procRank<<endl;
MPI_Type_free(&recType);
cout<<"delete countBuff"<<endl;
cout<<"MPI_Finalize"<<endl;
MPI_Finalize();
}
return 0;
}
解决方案
void processData(int rank,int numProcs)
{
static countType count;
MPI_Datatype recType = createRecType();
//read file and populate the vectors
ifstream foodbankFile("foodbanks.dat");
ifstream residenceFile("residences.dat");
// populate datavector
std::vector<Foodbank> foodbankData((std::istream_iterator<Foodbank>(foodbankFile)),
std::istream_iterator<Foodbank>());
Residence res;
int numLines = 0;
while(!residenceFile.eof())
{
residenceFile >> res.x >>res.y;
if ( numLines % numProcs == rank)
{
analysis_range(getShortestDistances(res,foodbankData),count);
}
++numLines;
}
countType* countBuff = new countType[numProcs];
MPI_Gather(&count, 1, recType, countBuff, 1, recType,0, MPI_COMM_WORLD);
if(rank == 0)
{
static countType countArggResult;
for (int p = 0; p < numProcs; ++p)
{
// out put result
}
}
//free virables
delete [] countBuff;
MPI_Type_free(&recType);
}
这篇关于我收集缓冲区是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文