C ++ Open-MPI: пользовательский тип структуры. Не удается отправить через Ssend.

Поэтому я работаю над проектом с использованием MPI и пытаюсь создать свою собственную структуру. Проблема, с которой я сталкиваюсь, заключается в том, что она, кажется, не работает правильно, потому что я никогда ничего не получаю внутри работника, и поэтому у меня перерыв. Я попробовал со стандартным MPI_INT, и он работал отлично. Однако, когда я попытался реализовать свой собственный тип, он не понравился … Вот мой код:

#include <iostream>
#include <mpi.h>
#include "main.hpp"
int main(int argc, char *argv[]){
//initialize MPI
MPI_Init(&argc, &argv);

message_to_worker message;
//declare my new type
MPI_Datatype MessageType;

//declare the types the the structure will have
MPI_Datatype type[1] = { MPI_INT };
//the number of results for each type(int[50] will be 50 etc..)
int blocklen[1] = {1};

//this will store the displacement for each var in the structure
MPI_Aint disp[1] = {0};
MPI_Aint var1, var2;

//number of vars
int count = 1;

//define the type
MPI_Type_struct(count, blocklen, disp, type, &MessageType);
MPI_Type_commit(&MessageType);

std::cout << "The displacement is " << disp[0] << std::endl;

int rank;
int world_size;

//give me my current rank(node 1 reiceves 1 , node 2 etc... )
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);

int counter = 1;
message.N = 5;

//IF MASTER
if (rank == 0) {
int result;

//send messages to the workers
while(counter<world_size){
//send 1 message of type MessageType using my own structure(first parameter)
result = MPI_Ssend(&message, 1, MessageType, counter, 123, MPI_COMM_WORLD);

//make sure the mssage was sent correctly
if (result == MPI_SUCCESS){
std::cout << "I am master and the world size is : " << world_size << std::endl;
std::cout << " I send a message to mky worker thread " << std::endl;
}else{
std::cout << "There was a problem with the sending for worker " << counter << std::endl;
}
counter++;
}
}
//IF WORKER
else if (rank > 0) {
//the worker will wait until it receives a message
int result = MPI_Recv(&message, 1, MessageType, 0, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);

//make sure the message was RECEIVED correctly
if (result == MPI_SUCCESS){
std::cout << "Worker - Rank: " << rank <<" OK! and the value received through the message is " << message.N << std::endl;
}
}

//shutdown MPI
MPI_Finalize();
return 0;

}

0

Решение

Мой параметр тега (3 параметра от последнего) отличался для отправителя и получателя. Мастер использовал тег 123, а рабочий искал тег 0. Они оба должны быть синхронизированы, поскольку им нужно установить канал связи. Вот исправление (обратите внимание, как изменился 5-й параметр, тег).

До:

MPI_Ssend(&message, 1, MessageType, counter, 123, MPI_COMM_WORLD);

MPI_Recv(&message, 1, MessageType, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

После

MPI_Ssend(&message, 1, MessageType, counter, 123, MPI_COMM_WORLD);

MPI_Recv(&message, 1, MessageType, 0, 123, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
0

Другие решения


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