[mpich-discuss] How to make a non-MPI process to become a MPI process of MPI_COMM_WORLD?

haozi yidanyiji at 163.com
Fri Jan 23 20:43:07 CST 2015


Thanks, Bland and Lu.


You are right.
These functions (such as MPI_Comm_accept, MPI_Comm_connect, MPI_Intercomm_merge) can help me to get a new intra-communicator which contains ALL MPI processes.


Now, I have a more complicated example:
    I have a server and a client. 
    After they merge into an intra-communicator by using connect/accept/merge fucntions, another client would plant to join them, too.
    I thought that the code is simular, but the code CAN'T work: Second client CAN'T connect. The new comm CAN'T accept. They all BLOCK.

    As you see, the second client BLOCKs at MPI_Comm_connect, and processes of newcomm BLOCK at MPI_Comm_accept.
    What's Wrong with my code? 


//server
#include "mpi.h"
int main(int argc, char *argv[])
{
MPI_Comm client, client2, newcomm, newcomm2;
MPI_Status status;
char port_name[MPI_MAX_PORT_NAME];
char port_name2[MPI_MAX_PORT_NAME];
int size, again, rank, myrank;


MPI_Init(&argc, &argv);
MPI_Open_port(MPI_INFO_NULL, port_name);//OK


MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD,&client);//OK


MPI_Intercomm_merge(client,11,&newcomm);//OK


    MPI_Barrier(newcomm);//OK


MPI_Open_port(MPI_INFO_NULL, port_name2);// OK


MPI_Comm_accept(port_name2, MPI_INFO_NULL, 0, newcomm,&client2);// BLOCK here, Wath's wrong?


MPI_Intercomm_merge(client2,12,&newcomm2);


    MPI_Barrier(newcomm2);


    MPI_Close_port(port_name);
MPI_Comm_disconnect(&client);
    MPI_Close_port(port_name2);
MPI_Comm_disconnect(&client2);


MPI_Finalize();
return 0;
}


//first client
#include "mpi.h"
int main( int argc, char **argv )
{
MPI_Comm server,newcomm,newcomm2,client2;
char port_name[MPI_MAX_PORT_NAME];
char port_name2[MPI_MAX_PORT_NAME];
int size,rank;


MPI_Init( &argc, &argv );
strcpy( port_name, argv[1] );
MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_SELF,&server );//OK


MPI_Intercomm_merge(server,11,&newcomm);//OK


MPI_Barrier(newcomm);//OK


MPI_Open_port(MPI_INFO_NULL, port_name2);//OK
MPI_Comm_accept(port_name2, MPI_INFO_NULL, 0, newcomm,&client2);// BLOCK here, Wath's wrong?


MPI_Intercomm_merge(client2,12,&newcomm2);


MPI_Barrier(newcomm2);


    MPI_Close_port(port_name2);
MPI_Comm_disconnect(&client2);
MPI_Comm_disconnect( &server );
MPI_Finalize();
return 0;
}


//second client
#include "mpi.h"
int main( int argc, char **argv )
{
MPI_Comm server,newcomm;
char port_name[MPI_MAX_PORT_NAME];
int size,rank;


MPI_Init( &argc, &argv );
strcpy( port_name, argv[1] );//OK
MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_SELF,&server );// BLOCK here, Wath's wrong?
MPI_Comm_size(MPI_COMM_WORLD, &size);


MPI_Intercomm_merge(server,11,&newcomm);


MPI_Barrier(newcomm);
MPI_Comm_disconnect( &server );
MPI_Finalize();
return 0;
}







At 2015-01-23 23:14:06, "Wesley Bland" <wbland at anl.gov> wrote:


The size of MPI_COMM_WORLD will never change. That communicator is set at initialization time and is not ever modified. However, when you finish connect/accept, you get a new communicator which you can merge into an intra-communicator which functions exactly like MPI_COMM_WORLD. Don’t be attached to the variable name MPI_COMM_WORLD. It’s just a variable and you can use a different one with very little extra work.

Thanks,
Wesley



On Thu, Jan 22, 2015 at 6:14 PM, haozi <yidanyiji at 163.com> wrote:

Thanks, Lu.
My simple code is as following.
//server
#include "mpi.h"


int main(int argc, char *argv[])
{
MPI_Comm client;
MPI_Status status;
char port_name[MPI_MAX_PORT_NAME];
int size, again;


MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Open_port(MPI_INFO_NULL, port_name);
printf("server port_name is %s\n\n", port_name);
MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD,&client);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("At server, comm_size=%d @ MPI_COMM_WORLD=%x, Client_World=%x\n",size,MPI_COMM_WORLD, client);
MPI_Comm_size(client, &size);
printf("At server, client_size=%d @ MPI_COMM_WORLD=%x, Client_World=%x\n",size,MPI_COMM_WORLD, client);


MPI_Comm_disconnect(&client);
MPI_Finalize();
return 0;
}


//client
#include "mpi.h"


int main( int argc, char **argv )
{
MPI_Comm server;
char port_name[MPI_MAX_PORT_NAME];
int size;


MPI_Init( &argc, &argv );
strcpy( port_name, argv[1] );
printf("server port name:%s\n",port_name);
MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD,&server );
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("At client, comm_size=%d @ MPI_COMM_WORLD=%x, Server_World=%x\n",size,MPI_COMM_WORLD,server);
MPI_Comm_size(server, &size);
printf("At client, server_size=%d @ MPI_COMM_WORLD=%x, Server_World=%x\n",size,MPI_COMM_WORLD,server);


MPI_Comm_disconnect( &server );
MPI_Finalize();
return 0;
}


The run command is as following.
mpiexec -n 1 ./server
mpiexec -n 1 ./client


BUT, the SIZE is 1, NOT 2.


My question is as before: How does the size of MPI_COMM_WORLD change to 2 ?



At 2015-01-23 00:30:43, "Huiwei Lu" <huiweilu at mcs.anl.gov> wrote:

You may take a look at MPI_Comm_accept and MPI_Comm_connect, which will connect a new client process to a server process. See Chap. 10 of MPI 3.0 standard (www.mpi-forum.org/docs/mpi-3.0/mpi30-report.pdf) for a detail example.


--
Huiwei Lu
Postdoc Appointee
Mathematics and Computer Science Division
Argonne National Laboratory
http://www.mcs.anl.gov/~huiweilu/


On Thu, Jan 22, 2015 at 9:41 AM, haozi <yidanyiji at 163.com> wrote:

Hi, guys.


This web page (http://wiki.mpich.org/mpich/index.php/PMI_v2_Design_Thoughts) says:
              Singleton init. This is the process by which a program that was not started with mpiexec can become an MPI process and make use of all MPI features, including MPI_Comm_spawn, needs to be designed and documented, with particular attention to the disposition of standard I/O. Not all process managers will want to or even be able to create a new mpiexec process, so this needs to be negotiated. Similarly, the dispostion of stdio needs to be negotiated between the singleton process and the process manager. To address these issues, a new singleton init protocol has been implemented and tested with the gforker process manager.


I am very interested in this function.
Can this function solve the following question:
              At beginning, the MPI job uses the mpiexec commond to start three MPI processes. That is to say, there are three MPI processes in MPI_COMM_WORLD. At some time, the job find itself to need another MPI process to cooperate the three MPI processes. So the question is: Could PMI help an non-MPI process to become a MPI process of the current MPI_COMM_WORLD? That is to say, Could the non-MPI process use the PMI function to become a member process of the current MPI job which would have FOUR MPI processes in MPI_COMM_WORLD?


Is there some method to solve question?
Is anybody have some example?


Thandks!!!



_______________________________________________
discuss mailing list     discuss at mpich.org
To manage subscription options or unsubscribe:
https://lists.mpich.org/mailman/listinfo/discuss






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpich.org/pipermail/discuss/attachments/20150124/62110323/attachment.html>
-------------- next part --------------
_______________________________________________
discuss mailing list     discuss at mpich.org
To manage subscription options or unsubscribe:
https://lists.mpich.org/mailman/listinfo/discuss


More information about the discuss mailing list