[MPICH2-dev] Publish/Lookup

Rajeev Thakur thakur at mcs.anl.gov
Tue May 16 20:31:24 CDT 2006


One problem in your code is that there is no synchronization between the
call to Publish_name on the server and Lookup_name on the client. So the
client may be calling Lookup_name before the name has been published.
 
An example program is in test/mpi/spawn/namepub.c.
 
Rajeev
 


  _____  

From: owner-mpich2-dev at mcs.anl.gov [mailto:owner-mpich2-dev at mcs.anl.gov] On
Behalf Of Denis Lima
Sent: Tuesday, May 16, 2006 3:54 PM
To: robl
Cc: mpich2-dev
Subject: Re: [MPICH2-dev] Publish/Lookup


Hey Rob,
 
I'm running the following code, and the client does not find the service
name "SERVER".
Thanks
Denis
 
//SERVER
#include <mpi.h>
#include <stdio.h>
int main ( int argc, char * argv[] )
{
 MPI_Comm newcomm; 
 char port_name [MPI_MAX_PORT_NAME];
 int test = 0;
 MPI_Status status;
 MPI_Init ( &argc, &argv );
 MPI_Open_port ( MPI_INFO_NULL, port_name ); 
 
 MPI_Publish_name ( "SERVER", MPI_INFO_NULL, port_name ); 
 
 MPI_Comm_accept( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &newcomm );
 MPI_Recv ( &test, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, &status );
 printf ( "%d", test );
 MPI_Unpublish_name ( "SERVER", MPI_INFO_NULL, port_name );
 MPI_Close_port ( port_name );
 
 MPI_Finalize ( );
 return 0;
}

//CLIENT
#include <mpi.h>
#include <stdio.h>
int main ( int argc, char * argv[] )
{
 MPI_Comm newcomm; 
 char port_name [MPI_MAX_PORT_NAME];
 int test = 1234; 
 MPI_Init ( &argc, &argv );
 MPI_Lookup_name ( "SERVER", MPI_INFO_NULL, port_name ); 
 MPI_Comm_connect ( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &newcomm );

 
 MPI_Send ( &test, 1, MPI_INT, 0, 1, MPI_COMM_WORLD );
 MPI_Comm_disconnect ( &newcomm );
 MPI_Close_port ( port_name );
 
 MPI_Finalize ( );
 return 0;
}
 
 
 
 
> On Tue, May 16, 2006 at 04:07:22PM -0300, Denis Lima wrote: 
> > Hello guys, 
> > 
> > I'm not been able to use the Publish_name/LookUp_name functions in 
> > MPICH2. Do you have any sample c code that works? 
> 
> 
> The 'server' has to do something like this: 
> 
> MPI_Comm newcomm; 
> char port_name[MPI_MAX_PORT_NAME]; 
> 
> MPI_Open_port(MPI_INFO_NULL, port_name); 
> MPI_Publish_name("port_name", MPI_INFO_NULL, port_name); 
> MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, comm, &newcomm); 
> 
> 
> And the 'client': 
> 
> MPI_Comm newcomm; 
> char port_name[MPI_MAX_PORT_NAME]; 
> 
> MPI_Lookup_name("port_name", MPI_INFO_NULL, port_name); 
> MPI_Comm_connect(port_name, MPI_INFO_NULL, 0, comm, &newcomm); 
> 
> 
> Naturally, use whatever you like instead of "port_name". Also, i've 
> omitted checking return values. You'll need an MPD ring up and running 
> for this to work. Can you elaborate on what is not working for you? 
> 
> ==rob 
> 
> -- 
> Rob Latham 
> Mathematics and Computer Science Division A215 0178 EA2D B059 8CDF 
> Argonne National Labs, IL USA B29D F333 664A 4280 315B 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mcs.anl.gov/mailman/private/mpich2-dev/attachments/20060516/5d42573b/attachment.htm>


More information about the mpich2-dev mailing list