Мой сборный буфер пуст?

У меня проблемы со сбором данных из всех процессов для обработки главного «корня». Я могу отправить данные MPI_Bcast, но на MPI_Gather У меня все проблемы в моем countBuff. Я отлаживаю свои выходные данные, и это то, что у меня есть.

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:: 123the codevoid 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;
}

0

Решение

Сначала я неправильно прочитал ваш пост. Сожалею.

Посмотрите на этот код:

        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_Gather отправляет &count, Но внимательно прочитайте код. Какова стоимость count что будет отправлено?

Либо вы неправильно поняли Bcast и Gather — они не связаны между собой. Не за что! — или вы ошибочно предположили, что «count» из ProcessData волшебным образом переходит в «count» из main. Они не будут. Это разные переменные. В таком случае просто return количество от ProcessData.

Проверьте примеры на http://mpitutorial.com/mpi-scatter-gather-and-allgather/ они очень похожи на то, что вы пытаетесь сделать.

РЕДАКТИРОВАТЬ:

хм .. на самом деле, после прочтения вашего кода в 4-й раз, я не понимаю, что и куда вы хотите отправить. Подумайте: хотите ли вы отправить «подсчет» всем работникам или вы хотите ПРОЧИТАТЬ подсчет всех работников? Если вам нужен типичный случай, когда некоторые работники читают некоторые части входного файла, то каждый вычисляет что-то, а затем результаты «собираются» — см. Ссылку выше. В противном случае вам придется уточнить, потому что мое воображение закончилось.

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);
}
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector