This is how we did to spawn 2 executables server and client I use
the MPI_Info only if a conf file
relative to each executable exist .
see man appschema and man MPI_Comm_spawn
Etienne Gondet.
Josh Hursey a écrit:
> Is it possible to specify exactly which processors/nodes to use when
> launching a program via MPI_Comm_spawn?
>
> I would like to allow the user of my application to control which
> nodes my program will use via a conf file [not necessarily a
> lam-hosts.conf file which could be passed to lamboot]. I read that the
> MPI_Info argument might do just this, but is it implemented in LAM-MPI?
>
> Josh Hursey
> Earlham College Cluster Computing Lab
> http://cluster.earlham.edu/html/
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
>
>
#include "mpi.h"
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
/*
* Start this with "mpiexec -n 1 master" to try without fast
* attachments.
* Use "mpiexec -n 1 -fa <some-name> master" to switch on
* fast attachments.
*
*/
#define TYPE char
#define MPI_TYPE MPI_BYTE
int
main(int argc, char **argv)
{
int myrank, mysize, i, msgsize;
int il_err;
MPI_Status status;
int istop[10], recv_buf[10], irc;
MPI_Comm mg_child1;
MPI_Comm mg_child2;
MPI_Info appsch_info;
char cl_appsch_client[32], cl_appsch_server[32];
FILE *fl_client, *fl_server;
char portname[MPI_MAX_PORT_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &mysize);
fprintf(stdout, "master --\n");
fprintf(stdout, "master -- myrank = %d\n",myrank);
fprintf(stdout, "master -- mysize = %d\n",mysize);
fprintf(stdout, "master -- pid = %ld\n",getpid());
fflush(stdout);
system("echo master `hostname`");
istop[0] = 9999;
/* spawn child processes */
/** ++ If LAM version of MPI we may consider spawning on another node **/
fprintf(stdout, "master -- before spawn client \n");
fflush(stdout);
#ifdef LAM_MPI
strcpy(cl_appsch_client, "appsch_client");
/** +++ Test if file cd_exec_name.where exist **/
if ( (fl_server = fopen(cl_appsch_client, "r")) == (FILE *) NULL)
{
fprintf(stdout, "master -- before spawn client with appsch_client of size null \n");
fflush(stdout);
MPI_Comm_spawn("client", MPI_ARGV_NULL, mysize, MPI_INFO_NULL,
0, MPI_COMM_WORLD, &mg_child2, &il_err);
}
else
{
MPI_Info_create(&appsch_info);
MPI_Info_set(appsch_info,"file","appsch_client");
MPI_Comm_spawn("client", MPI_ARGV_NULL, mysize, appsch_info,
0, MPI_COMM_WORLD, &mg_child2, &il_err);
}
#else
MPI_Comm_spawn("client", MPI_ARGV_NULL, mysize, MPI_INFO_NULL,
0, MPI_COMM_WORLD, &mg_child2, &il_err);
#endif
/** ++ If LAM version of MPI we may consider spawning on another node **/
fprintf(stdout, "master -- before spawn server \n");
fflush(stdout);
#ifdef LAM_MPI
strcpy(cl_appsch_server, "appsch_server");
/** +++ Test if file cd_exec_name.where exist **/
if ( (fl_server = fopen(cl_appsch_server, "r")) == (FILE *) NULL)
{
MPI_Comm_spawn("server", MPI_ARGV_NULL, mysize, MPI_INFO_NULL,
0, MPI_COMM_WORLD, &mg_child1, &il_err);
}
else
{
MPI_Info_create(&appsch_info);
MPI_Info_set(appsch_info,"file","appsch_server");
MPI_Comm_spawn("server", MPI_ARGV_NULL, mysize, appsch_info,
0, MPI_COMM_WORLD, &mg_child1, &il_err);
}
#else
MPI_Comm_spawn("server", MPI_ARGV_NULL, mysize, MPI_INFO_NULL,
0, MPI_COMM_WORLD, &mg_child1, &il_err);
#endif
/* Receive port name from child1 */
irc = MPI_Recv(portname, MPI_MAX_PORT_NAME, MPI_TYPE, 0, 111, mg_child1, &status);
fprintf(stdout, "master -- server available at %s\n", portname);
fflush(stdout);
/* pass port to child2 */
irc = MPI_Send(portname, MPI_MAX_PORT_NAME, MPI_TYPE, 0, 111, mg_child2);
/* Wait for stop message from child2 */
fprintf(stdout, "master -- before receive from child2=client \n");
fflush(stdout);
irc = MPI_Recv(recv_buf, 1, MPI_INT, 0, 999, mg_child2, &status);
/* Send stop message to child 1 */
fprintf(stdout, "master -- before send to child1=server \n");
fflush(stdout);
irc = MPI_Send(istop, 1, MPI_INT, 0, 999, mg_child1);
/* Disconnect and Finalize */
fprintf(stdout, "master -- before disconnect\n");
fflush(stdout);
#if !defined (LAM_MPI)
MPI_Comm_disconnect(&mg_child2);
MPI_Comm_disconnect(&mg_child1);
#endif
fprintf(stdout, "master -- about to die\n");
fflush(stdout);
MPI_Finalize();
}
|