2
아주 기본적인 MPI 코드를 작성하려고했지만 계속 전화를 끊습니다. 작업은 포인터 사용을 숨길 수 있도록 MPI_Send 및 Receive 루틴에 대한 래퍼를 작성하는 것입니다.MPI_Send and Receive - Wrapper
#include "mpi.h"
#include<iostream>
#include<cstdlib>
#define _MAXSIZE_ 10
using namespace std;
/** Goal: Avoid pointers in MPI_Send and MPI_Recieve */
/* Wrapper for regular MPI_Send. */
void Send(int data, int destination, MPI_Comm mpicomm) {
MPI_Send(&data, 1, MPI_INT, destination, 0, mpicomm);
cout << "Data sent successfully" << data << endl;
}
/* Wrapper for regular MPI_Recieve */
int Recieve(MPI_Status stat, MPI_Comm mpicomm, int source_id = 0) {
int data;
MPI_Recv(&data, 1, MPI_INT, source_id, 0, mpicomm, &stat);
cout << "Data Recieved: " << data << endl;
return data;
}
int main(int argc, char ** argv) {
int myid, numprocs;
int arr[10];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
MPI_Status status;
MPI_Comm mpicomm;
/** Trying to send an array of 10 integers without pointer usage */
int data = 3;
int destination = rand() % numprocs; // choose a destination to send other than the master itself
cout << "Destination: " << destination << "\n" << endl;
if(myid == 0) {
if(destination != 0) {
Send(data, destination, mpicomm);
}
}
else if(myid == destination) {
int data = Recieve(status,mpicomm, 0);
cout << "Data Received Successfully" << data << endl;
}
MPI_Finalize();
return 0;
}
P.S.을 :
다음
내가 개발 한 것입니다 나는 내가 지금받는 답장을 추적하고있다. 감사.산 제이
조나단 고맙습니다. 나는 지금 그것을 시험해보고있다. 계속 게시 할 것입니다. 또한 나는 (그 좋은 비유로) 클러스터의 프로세서와 통신하기 위해 그 프로세서의 순위를 지정하고 또한 모든 노드에 공통적 인 커뮤니케이터 핸들을 사용하여 말할 수 있어야한다고 말하고 있습니다. MPI_COMM_WORLD? – svk
맞습니다. MPI 프로그램을 시작할 때, 모든 프로세서는 MPI_COMM_WORLD의 멤버이며, (rank, MPI_COMM_WORLD)를 지정하여 그들과 통신합니다. 또한 모든 프로세스의 하위 세트 만 포함하거나 모든 프로세스를 포함하지만 편의를 위해 어떤 식 으로든 레이블을 다시 지정하는 고유 한 커뮤니케이터를 만들 수 있습니다. 이 경우 동일한 프로세스가 다른 의사 소통 자에서 다른 순위를 가질 수 있습니다. 그래서 당신은 항상 의사 소통자를 지정해야합니다. –
고마워요. 당신은 또한 그러한 세부 사항을 이해할 수있는 좋은 책/자료를 제안 할 수 있습니까? (비록 내가 Michael Allen과 Wilkinson을 가지고있다.) – svk