Hi
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.
James Fang a écrit:
> Hi
>
> Can anyone give me an example of how MPI_INFO may be used to specify
> how where the spawned the processes will be launched on a cluster? I
> am using the codes below, but it doesn't have any effect and it
> doesn't generate any error message, so I don't know if I am doing
> anything wrong or not. Thanks a bunch.
>
> James
>
> int nnodes = 8;
> int *errcodes;
>
> errcodes = (int *) malloc(sizeof(int) * nnodes);
> memset(errcodes, -1, nnodes);
>
> MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
>
> MPI_Info info;
> MPI_Info_create (&info);
> MPI_Info_set (info, "lam_spawn_sched_round_robin", "n2");
> MPI_Comm_spawn(worker_program, MPI_ARGV_NULL, 5, MPI_INFO_NULL, 3,
> MPI_COMM_WORLD, &everyone, errcodes);
>
>------------------------------------------------------------------------
>
>_______________________________________________
>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();
}
|