I want to perform a simple client/server application doing the client search (using the MPI_Lookup_name function) for the server published name.
My programs are:
server.c
#include<mpi.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
MPI_Comm cliente;
MPI_Status status;
char portname[MPI_MAX_PORT_NAME];
int size, rank, msg;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Open_port(MPI_INFO_NULL, portname);
MPI_Publish_name("ocean", MPI_INFO_NULL, portname);
MPI_Comm_accept(portname, MPI_INFO_NULL, 0, MPI_COMM_SELF, &cliente);
printf("client connected\n");
MPI_Recv(&msg, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, cliente, &status);
printf("msg: %d\n", msg);
MPI_Comm_free(&cliente);
MPI_Close_port(portname);
MPI_Finalize();
return 0;
}
client.c
#include<mpi.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int size, rank;
int main(int argc, char *argv[])
{
MPI_Comm servidor;
int msg, tag, dest;
char portname[MPI_MAX_PORT_NAME];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Lookup_name("ocean", MPI_INFO_NULL, portname);
MPI_Comm_connect(portname, MPI_INFO_NULL, 0, MPI_COMM_WORLD,&servidor);
msg = 42; tag = 0; dest = 0;
MPI_Send(&msg, 1, MPI_INT, dest, tag, servidor);
MPI_Comm_disconnect(&servidor);
MPI_Finalize();
return 0;
}
and the makefile
EXECS=server client
MPICC?=mpicc
all: ${EXECS}
server: server.c
${MPICC} -o server -g server.c
client: client.c
${MPICC} -o client -g client.c
if I do:
mpirun -np 1 ./server
the server waits and then I do
mpirun -np 1 ./client
and I have:
*** An error occurred in MPI_Lookup_name
*** on communicator MPI_COMM_WORLD
*** MPI_ERR_NAME: invalid name argument
*** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
I took this example from http://www.mcs.anl.gov/research/projects/mpi/mpi-standard/mpi-report-2.0/node106.htm . The questions are: what I am doing wrong ? Server and client can be execute separately as I did ?