#ifdef MPI_YES
#include <mpi.h>
#else
#include <mpi_dummy.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include "msg_mpi_two.h"
using namespace CSLIB_NS;
MsgMPITwo::MsgMPITwo(int csflag, const void *ptr, MPI_Comm cworld) :
MsgMPIOne(csflag, ptr, cworld)
{
char *filename = (char *) ptr;
init(filename);
}
MsgMPITwo::~MsgMPITwo()
{
MPI_Comm_free(&bothcomm);
MPI_Close_port(port);
}
void MsgMPITwo::init(char *filename)
{
if (client) {
if (me == 0) {
FILE *fp = NULL;
while (!fp) {
fp = fopen(filename,"r");
if (!fp) sleep(1);
}
fgets(port,MPI_MAX_PORT_NAME,fp);
fclose(fp);
}
MPI_Bcast(port,MPI_MAX_PORT_NAME,MPI_CHAR,0,world);
MPI_Comm_connect(port,MPI_INFO_NULL,0,world,&bothcomm);
if (me == 0) unlink(filename);
} else if (server) {
MPI_Open_port(MPI_INFO_NULL,port);
if (me == 0) {
FILE *fp = fopen(filename,"w");
fprintf(fp,"%s",port);
fclose(fp);
}
MPI_Comm_accept(port,MPI_INFO_NULL,0,world,&bothcomm);
}
otherroot = 0;
}