Simple Client-Server Example.
This is a simple example; the server 
accepts only a single connection at a time and serves
that connection 
until the client requests to be disconnected. The server is a single 
process.
Here is the server. It accepts a single connection and then 
processes data until it
receives a message with tag 1. A message with 
tag 0 tells the server to exit.

#include "mpi.h"
int main( int argc, 
char **argv )
{
MPI_Comm client;
MPI_Status status;
char port_name
[MPI_MAX_PORT_NAME];
double buf[MAX_DATA];
int size, again;
MPI_Init( 
&argc, &argv );
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size != 1) 
error(FATAL, "Server too big");
MPI_Open_port(MPI_INFO_NULL, 
port_name);
printf("server available at %s\n",port_name);
while (1) {
MPI_Comm_accept( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD,
&client 
);
again = 1;
while (again) {
MPI_Recv( buf, MAX_DATA, MPI_DOUBLE,
MPI_ANY_SOURCE, MPI_ANY_TAG, client, &status );
switch (status.MPI_TAG) 
{
case 0: MPI_Comm_free( &client );
MPI_Close_port(port_name);
MPI_Finalize();
return 0;
case 1: MPI_Comm_disconnect( &client );
again 
= 0;
break;
case 2: /* do something */
...
default:
/* Unexpected 
message type */
MPI_Abort( MPI_COMM_WORLD, 1 );
}
}
}
}
Here is the 
client.
#include "mpi.h"
int main( int argc, char **argv )
{
MPI_Comm 
server;
double buf[MAX_DATA];
char port_name[MPI_MAX_PORT_NAME];
MPI_Init( &argc, &argv );
strcpy(port_name, argv[1] );/* assume 
server's name is cmd-line arg */
MPI_Comm_connect( port_name, 
MPI_INFO_NULL, 0, MPI_COMM_WORLD,
&server );
while (!done) {
tag = 2; 
/* Action to perform */
MPI_Send( buf, n, MPI_DOUBLE, 0, tag, server );
/* etc */
}
MPI_Send( buf, 0, MPI_DOUBLE, 0, 1, server );
MPI_Comm_disconnect( &server );
MPI_Finalize();
return 0;
}

I have the 
same problem also if I don't use the MPI_LOOKUP_NAME but by the 
port_name recovered by the MPI_open_port.

I have seen that the address 
supplied by the system to the server is always the same 0.1.0:2000 , I 
think that thi is very strange.

If I write an example where I use the 
MPI routines that are in the MPI protocol, they have to work!! Is a 
mistake to say that the same program can work and not dependently on 
the implementation.
Because if I wirte a correct MPI application, if 
the implementation work and support all the routines inside the 
application, the program has to work!
Then this example has to work in 
MPICH2 and also in OPEN_MPI. If this doesn't happen this means that 
Open_MPI has some problems...

The software has to be independent from 
the implementation that you use.

bye 

A.A.Isola


Reply via email to