您的位置:首页 > 其它

Using the Intel® MPI Library in a server/client setup

2013-01-25 09:26 190 查看
http://www.mpi-forum.org/docs/mpi-20-html/node106.htm
http://software.intel.com/zh-cn/articles/using-the-intel-mpi-library-in-a-serverclient-setup
如何用MPI创建server client架构

1) Build 2 applications. Both uses MSMPI and share the same COMM WORLD in the API.

2) Run the 2 application at the same time like below:

job submited /numodes:3 /askednodes:server1,node1,node2 mpiexec -hosts 1 server1 1 win-form-app.exe : -hosts 2 node1 1 node2 1 console-app.exe

where:

- totally 3 nodes are used. each node runs 1 process. If you want to run more than 1 process on certain node. you can do -hosts 2 node1 M -node2 N ...

- server1 will run your win form application; node1 and node2 will run the console application.
http://www.mpi-forum.org/docs/mpi-20-html/node106.htm
Submitted by James Tullos (Intel) on Fri,
07/13/2012 - 08:59

Categories:

=im_field_topic%3A20862]Cluster Computing
Intel®
MPI Library
Intel®
Cluster Studio
Intel®
Cluster Studio XE
=im_field_operating_system%3A20787]Linux*
Microsoft
Windows* (XP, Vista, 7)
=im_field_skill_level%3A20808]Intermediate

Tags:

=im_field_tags%3A17339]server

=im_field_tags%3A19522]MPI

=im_field_tags%3A19916]client

=im_field_tags%3A41531]Intel® MPI Library

=im_field_tags%3A41532]Intel® Cluster Studio XE

Overview

In some instances, it can be advantageous to have an MPI program join a job after it has started. Additional resources can be added to a long job as they become available, or a more traditional server/client program can be created. This can be facilitated with
the MPI_Comm_accept and MPI_Comm_connect functions.

Key Functions

MPI_Open_port - Creates the port that is used for the communications. This port is given a name that is used to reference it later, both by the server and the client. Only the server program calls MPI_Open_port
MPI_Comm_accept - Uses the previously opened port to listen for a connecting MPI program. This is called by the server and will create an intercommunicator once it completes.
MPI_Comm_connect - Connects to another MPI program at the named port. This is called by the client and will create an intercommunicator once it completes.

Notes

The programs must use the same fabric in order to connect, as the port is dependent on the fabric.
The programs must be on the same operating system in order to connect. Different versions/distributions of the same operating systems could work, this has not been tested and is not supported.
The method of getting the port name from the server to the client can vary. In the sample provided, a text file is written containing the port name.

Example

A very simple example is attached to this article. The server opens a port, writes the name of the port to a file, and waits for the client. The client will read the file and attempt to connect to the port. To verify that the two programs are connected, each
sends a pre-defined value to the other. To compile and run the example, download the files and place them in the same folder. Open two terminals and navigate to the folder where the files are located. In the first terminal, use:
[code]1
mpiicpc
 server.cpp -o server
2
mpirun
 -n 1 ./server
[/code]

And in the second terminal:
[code]1
mpiicpc
 client.cpp -o client
2
mpirun
 -n 1 ./client
[/code]

In Windows*, change mpirun to mpiexec. With the code as provided, the server should show:
[code]1
Waiting
 for a client
2
A
 client has connected
3
The
 server sent the value: 25
4
The
 server received the value: 42
[/code]

And the client should show:
[code]1
Attempting
 to connect
2
Connected
 to the server
3
The
 client sent the value: 42
4
The
 client received the value: 25
5.4.6.3. Simple Client-Server Example.

Up: Client/Server Examples Next: Other Functionality Previous: Ocean/Atmosphere - Relies on Name Publishing
This is a simple example; the server accepts only a single connection at a time and serves that connection until the client requests to be disconnected. The server is a single process.

Here is the server. It accepts a single connection and then processes data until it receives a message with tag 1. A message with tag 0 tells the server to exit. 
#include "mpi.h" 
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_Init( &argc, &argv ); 
    MPI_Comm_size(MPI_COMM_WORLD, &size); 
    if (size != 1) error(FATAL, "Server too big"); 
    MPI_Open_port(MPI_INFO_NULL, port_name); 
    printf("server available at %s\n",port_name); 
    while (1) { 
        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_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 */ 
                ... 
                default: 
                        /* Unexpected message type */ 
                        MPI_Abort( MPI_COMM_WORLD, 1 ); 
                } 
            } 
        } 
} 
Here is the client.

#include "mpi.h" 
int main( int argc, char **argv ) 
{ 
    MPI_Comm server; 
    double buf[MAX_DATA]; 
    char port_name[MPI_MAX_PORT_NAME]; 
 
    MPI_Init( &argc, &argv ); 
    strcpy(port_name, argv[1] );/* assume server's name is cmd-line arg */ 
 
    MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD,  
                      &server ); 
 
    while (!done) { 
        tag = 2; /* Action to perform */ 
        MPI_Send( buf, n, MPI_DOUBLE, 0, tag, server ); 
        /* etc */ 
        } 
    MPI_Send( buf, 0, MPI_DOUBLE, 0, 1, server ); 
    MPI_Comm_disconnect( &server ); 
    MPI_Finalize(); 
    return 0; 
}


[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐