Introduction
In order to parallelize numerical integration in C++, I want to use a client/server approach on my local machine. For this, I am using the message passing interface for C++.
My code
So I first tried a hello world setup, where I will send a message from the client to the server. For this I have two files in the same directory. Here is the code for the Server, server.cpp:
#include<mpi.h>
#include<stdio.h>
#include<stdlib.h>
int size, rank, msg;
int main(int argc, char *argv[]){
MPI_Comm client;
MPI_Status status;
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_Open_port(MPI_INFO_NULL, portname);
printf("portname: %s\n", portname);
MPI_Comm_accept(portname, MPI_INFO_NULL, 0, MPI_COMM_SELF, &client);
printf("client connected\n");
MPI_Recv(&msg, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, client, &status);
printf("msg: %d\n", msg);
MPI_Comm_free(&client);
MPI_Close_port(portname);
MPI_Finalize();
}
Here is the code for the Client, client.cpp:
#include<mpi.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int size, rank;
int main(int argc, char *argv[]){
MPI_Comm server;
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);
if (argc >= 2){
printf("Trying connect to %s\n", argv[1]);
strcpy(portname, argv[1]);
MPI_Comm_connect(portname, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &server);
msg = 42; tag = 0; dest = 0;
MPI_Send(&msg, 1, MPI_INT, dest, tag, server);
MPI_Comm_disconnect(&server);
}
MPI_Finalize();
}
How I tried to run my code
I compiled both client and server using mpiCC -g -Wall -o client.out client.cpp and mpiCC -g -Wall -o server.out server.cpp respectively.
Now I open two different terminals and I use mpirun -np 1 ./server.out in the first terminal to run the server. This gives me the portname so I can use mpirun -np 1 ./client.out <PORTNAME> in the second terminal to run the client. However, I get the following error:
Trying connect to <PORTNAME>
--------------------------------------------------------------------------
The user has called an operation involving MPI_Connect and/or MPI_Accept
that spans multiple invocations of mpirun. This requires the support of
the ompi-server tool, which must be executing somewhere that can be
accessed by all participants.
Please ensure the tool is running, and provide each mpirun with the MCA
parameter "pmix_server_uri" pointing to it.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
Your application has invoked an MPI function that is not supported in
this environment.
MPI function: MPI_Comm_connect
Reason: Underlying runtime environment does not support accept/connect functionality
--------------------------------------------------------------------------
[ubuntu-workstation:00101] *** An error occurred in MPI_Comm_connect
[ubuntu-workstation:00101] *** reported by process [23056836,0]
[ubuntu-workstation:00101] *** on communicator MPI_COMM_WORLD
[ubuntu-workstation:00101] *** MPI_ERR_INTERN: internal error
[ubuntu-workstation:00101] *** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
[ubuntu-workstation:00101] *** and potentially your MPI job)
What I tried
I found this blog post, where a very similar error occurs.
It seems I only have to start this ominous "ompi-server tool", however, being new to MPI, I have no idea where to find this tool and how to start it... So how can I fix the error?
ompi_info:Package: Debian OpenMPI \n Open MPI: 3.1.3mpirun -np 1 ./server : -np 1 ./client.