TinyURL widget - shorten your URL's for free!

Enter a long URL to make tiny:

Sunday, December 18, 2016

How to mention someone in Blogger Blogspot posting.

To mention someone in a post or comment:
  1. Type +[person's name] or @[person's name]. (You can also type their email address instead of their name.)
  2. As you type, an autocomplete list of people will appear.
  3. Select the person you want to mention.
My addendum:

You can also copy a twitter handle from Twitter.com and that includes the hyperlink to Twitter in your post.

Friday, December 16, 2016

OpenMPI working nameserver publish / lookup example

This blog post entails a simple client / server example using OpenMPI, the opmi-server, and simple commands to publish a named server, lookup the server using a client, then connect and transceive data between the server and client.

If you need a refresher on OpenMPI first then this is a good start


The Gist is located here. 


I got this working on:

 uname -a
Linux hellion 3.19.0-77-generic #85-Ubuntu SMP Fri Dec 2 03:43:54 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

mpicc --version
gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This post assumes you've got the OpenMPI installed completely and working properly.


This builds on pseudo-examples left here and mainly here: http://www.mcs.anl.gov/research/projects/mpi/mpi-standard/mpi-report-2.0/node106.htm#Node108

You compile the client and server:

The client is here

https://gist.github.com/DaemonDave/21fea476847d94326ec6c9664c15fb87#file-name-client-c 


/*!
*
* OpenMPI nameserver example
*
* client that looks up name from nameserver then connects to that server
*
* */
#include "mpi.h"
#include "stdio.h"
#include "string.h"
#define MAX_DATA 50
/*!
\brief How to execute mpi name server
mpirun -np 1 ompi-server --no-daemonize -r + &
*
* Success looks like this :
*
"server available at 3653042176.0;tcp://192.168.10.191:52434+3653042177.0;tcp://192.168.10.191:48880:300"
*/
int main( int argc, char **argv )
{
MPI_Comm server;
double buf[MAX_DATA];
char port_name[MPI_MAX_PORT_NAME];
int tag = 0;
int done = 0;
int n;
double * p;
buf[0] = 25.5;
buf[1] = 26.5;
buf[2] = 27.5;
n = 2;
MPI_Init( &argc, &argv );
//strcpy(port_name, argv[1] );/* assume server's name is cmd-line arg */
fprintf(stderr, "looking up server ... \n");
// second command line parameter is the name of server to lookup
MPI_Lookup_name( "ocean", MPI_INFO_NULL, port_name);
// connect to name and place data into server
MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &server );
// aim p at first double entry
p = buf;
while (!done)
{
tag = 2; /* Action to perform */
MPI_Send( (void *) p, 1, MPI_DOUBLE, 0, tag, server );
/* etc */
n--;
p++;
if ( n < 0) done = 1;
}
MPI_Send( buf, 0, MPI_DOUBLE, 0, 1, server );
MPI_Comm_disconnect( &server );
MPI_Finalize();
return 0;
}
/* client side lookup request
MPI_Lookup_name("ocean", MPI_INFO_NULL, port_name);
MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_SELF,
&intercomm);
*/
view raw name-client.c hosted with ❤ by GitHub
/*!
*
* OpenMPI nameserver example
*
* server that publishes name to nameserver then awaits client connections
*
* */
#include "mpi.h"
#include "stdio.h"
#include "string.h"
#define MAX_DATA 50
/*!
\brief How to execute mpi name server
mpirun -np 1 ompi-server --no-daemonize -r + &
*
* Success looks like this :
*
"server available at 3653042176.0;tcp://192.168.10.191:52434+3653042177.0;tcp://192.168.10.191:48880:300"
*/
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_Info info;
double * p;
MPI_Init( &argc, &argv );
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size != 1) error( "Server too big");
MPI_Open_port(MPI_INFO_NULL, port_name);
printf("server available at %s\n",port_name);
MPI_Info_create(&info);
MPI_Info_set(info, "ompi_global_scope", "true");
// publish to name server with global scope info
MPI_Publish_name("ocean", info, port_name);
while (1)
{
// accept clients
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_Unpublish_name("ocean", MPI_INFO_NULL, port_name);
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 */
p = (double *) buf;
fprintf(stderr, " we got a client's data: %f\n", *p);
break;
default:
/* Unexpected message type */
// radical original version aborted everything...
;//MPI_Abort( MPI_COMM_WORLD, 1 );
}
}
}
}
/*
MPI_Open_port(MPI_INFO_NULL, port_name);
MPI_Publish_name("ocean", MPI_INFO_NULL, port_name);
MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm);
// do something with intercomm
MPI_Unpublish_name("ocean", MPI_INFO_NULL, port_name);
*/
view raw name-server.c hosted with ❤ by GitHub


 mpicc -o client name-client.c
 The server is here

https://gist.github.com/DaemonDave/21fea476847d94326ec6c9664c15fb87#file-name-server-c

mpicc -o server  name-server.c


You run the ompi-server first, to establish the name server. But to do this you run mpirun with ompi-server and not just run it.

*!
 \brief How to execute mpi name server
 mpirun -np 1  ompi-server --no-daemonize -r + &
 *
 * Success looks like this :
 *
    "server available at 3653042176.0;tcp://192.168.10.191:52434+3653042177.0;tcp://192.168.10.191:48880:300"

*/


Once the ompi-server is running, you can refer to it by file, but you can also refer to it by it's pid if it's local. To get things running with the minimum of overlapping errors, I start with simple local setups.

You find the pid of the ompi-server:

ps -ef | grep ompi     

1634  1458  0 Dec15 ?        00:03:41 compiz  dave     

16050  1954  0 10:26 pts/18   00:00:00 mpirun -n 1 ompi-server --no-daemonize -r + dave    

16051 16050  0 10:26 pts/18   00:00:00 ompi-server --no-daemonize -r + dave

You run the server like this:
mpirun -np 1  --ompi-server pid:16050  ./server
It looks successful like this:
server available at 3500802048.0;tcp://192.168.10.191:50129+3500802049.0;tcp://192.168.10.191:53693:300

Now you mpirun the client and it looks like this:
  mpirun -np 1 --ompi-server pid:14341 ./client
looking up  server ...
The server  responds like this:

 we got a client's data: 25.500000
 we got a client's data: 26.500000
 we got a client's data: 27.500000
^Cmpirun: killing job...

You can mpirun the client and server from a config file as well instead of informing of the ompi-server location by PID like this:

 mpirun -np 1 --ompi-server file:./nameserver.cfg ./server
server available at 2886402048.0;tcp://192.168.10.191:51344+2886402049.0;tcp://192.168.10.191:54857:300