On Fri, Jun 26, 2009 at 6:25 PM, Ralph Castain<r...@open-mpi.org> wrote:
> Not sure I understand the problem. Your server will have the ability to recv

this is what i wanted. feel free to add to the FAQ. In the TODO list
is still remove the step of copying of the URI from one machine to
another, but that can be done later. This works only from version 1.3
and up. Regards

[root@niko code]# cat server.c
#include <stdio.h>
#include <mpi.h>

int main(int argc,char *argv[]){
int size;
    char port_name[MPI_MAX_PORT_NAME],data[256],message[5]="pong\0";
    MPI_Comm client; MPI_Status status;

    MPI_Init(&argc,&argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    if (size != 1) {printf("only one process is accepted\n"); return(1);}
    MPI_Open_port(MPI_INFO_NULL, port_name);
    printf("server: listening on port %s\n",port_name);
    MPI_Publish_name("myserver", MPI_INFO_NULL, port_name);
    MPI_Comm_accept( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD,&client );
    MPI_Recv( data,256,MPI_CHAR,MPI_ANY_SOURCE, MPI_ANY_TAG, client, &status );
    printf("server: %s\n",data);
    MPI_Send(message,5,MPI_CHAR,0,2,client);
    MPI_Comm_disconnect( &client );
    MPI_Finalize();
}
[root@niko code]# cat client.c
#include <stdio.h>
#include "mpi.h"
int main( int argc, char **argv )
{
    MPI_Comm server; MPI_Status status;
    char port_name[MPI_MAX_PORT_NAME],data[256],message[5]="ping\0";

    MPI_Init( &argc, &argv );

    MPI_Lookup_name("myserver", MPI_INFO_NULL, port_name);
    MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_SELF,
                      &server);
    MPI_Send( message, 5, MPI_CHAR, 0, 1, server );
    MPI_Recv( data,256,MPI_CHAR,MPI_ANY_SOURCE, MPI_ANY_TAG, server, &status );
    printf("client: %s\n",data);
    MPI_Comm_disconnect( &server );
    MPI_Finalize();
}
[root@niko code]# mpicc -I/usr/include/openmpi/1.2.4-gcc/
-L/usr/lib64/openmpi/1.2.4-gcc -lmpi -o server server.c
[root@niko code]# mpicc -I/usr/include/openmpi/1.2.4-gcc/
-L/usr/lib64/openmpi/1.2.4-gcc -lmpi -o client client.c
[root@niko code]# scp client root@192.168.1.63:/root
client                                                            100%
9645     9.4KB/s   00:00
[root@niko code]# ompi-server -r ompi-server.uri
[root@niko code]# cat ompi-server.uri
258080768.0;tcp://192.168.1.64:48683
[root@niko code]# mpirun -np 1 -ompi-server $(cat ompi-server.uri) ./server &
[1] 24079
[root@niko code]# server: listening on port
257949696.0;tcp://192.168.1.64:58284+257949697.0;tcp://192.168.1.64:59326:300

[root@niko code]# ssh -l root 192.168.1.63
Last login: Sat Jun 27 23:17:24 Local time zone must be set--see zic
manual page 2009 from n64 on ssh
master ~ # mpirun -np 1 -ompi-server
'258080768.0;tcp://192.168.1.64:48683' ./client
server: ping
            client: pong
master ~ #

Reply via email to