Here is the file servidor.c:
#include
#include
#include
int size, rank, msg;
int main(int argc, char *argv[]){
MPI_Comm cliente;
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, &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();
}
and here is the file cliente.c:
#include
#include
#include
#include
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);
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, &servidor);
msg = 42; tag = 0; dest = 0;
MPI_Send(&msg, 1, MPI_INT, dest, tag, servidor);
MPI_Comm_disconnect(&servidor);
}
MPI_Finalize();
}
I compiled them with:
mpicc servidor.c -o servidor
mpicc cliente.c -o cliente
First I run the server with:
$ mpirun -np 1 servidor
portname: 0.1.0:2000
so I get the portname and use it as parameter for the client:
$ mpirun -np 1 cliente 0.1.0:2000
and get this error:
Trying connect to 0.1.0:2000
[irmaos:13280] [0,1,0] ORTE_ERROR_LOG: Pack data mismatch in file dss/dss_unpack.c at line 171
[irmaos:13280] [0,1,0] ORTE_ERROR_LOG: Pack data mismatch in file dss/dss_unpack.c at line 145
[irmaos:13280] *** An error occurred in MPI_Comm_connect
[irmaos:13280] *** on communicator MPI_COMM_WORLD
[irmaos:13280] *** MPI_ERR_UNKNOWN: unknown error
[irmaos:13280] *** MPI_ERRORS_ARE_FATAL (goodbye)
(where irmaos is mine machine’s name)
I also tried this:
$ mpirun -np 1 cliente 127.0.0.1:2000
Trying connect to 127.0.0.1:2000
But nothing happens.
Anyone knows what I’m doing wrong?
I’m using MPICH version 1.2.7p1. I’m going to try this in another machine to see the results, but I guess it will be the same.
i’ve got error message when i run this command (in /usr/bin) : mpicc -o master masterprocess.c
mpicc: no such file or directory.I need your help, please….
@rerey try using “./mpicc” or “/usr/bin/mpicc”.
Hi, i got a solution.
Server:
mpirun -np 1 ./Server and the result are
portname: tag#0$description#guilhermefabrin$port#41422$ifname#69.28.93.21$
and
mpirun -np 1 ./Client ‘tag#0$description#guilhermefabrin$port#41422$ifname#69.28.93.21$’
Trying connect to tag#0$description#guilhermefabrin$port#41422$ifname#69.28.93.21$
Works after i put portname between ‘, and add ./ before compiled source.
I hope its help. 😉
The Server/Client architecture is depreciated in Open MPI since version 1.7. You have to switch to MPICH or Intel MPI in order for this to work.
See this StackOverflow question: https://stackoverflow.com/q/61191379/10470171