1

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 ?

gagiuntoli
  • 475
  • 5
  • 13
  • Where do you spawn server and client applications? Take a look at [this example](https://stackoverflow.com/documentation/mpi/9416/process-creation-and-management/29185/establishing-connection-between-two-independent-applications#t=201705281234290208947). – Shibli May 28 '17 at 12:41
  • Hi Shibli ! no, I was not spawning processes. Do you know if this is the only way to apply this port connections ? Thank you for this nice example ! – gagiuntoli May 28 '17 at 20:57
  • No this is not the only way but perhaps one of the simplest. You can simply do `mpirun` but you need to do additional stuff. Look at [this answer](https://stackoverflow.com/a/15008715/1128551). – Shibli May 28 '17 at 23:20
  • Oh look at that !! that does not seems to be funny... I am performing a code coupling with a friend and we are looking for different alternatives. I think that splitting the communicator and making inter-communicators seems to be more solid. what do you think about ? – gagiuntoli May 29 '17 at 07:28
  • It helps if you specify the MPI implementation as name publishing and lookup are implementation-specific. – Hristo Iliev May 30 '17 at 11:39

0 Answers0