This source file includes following definitions.
- main
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
4 #include "mpi.h"
5
6 #define MAX_DATA 100
7
8 int main( int argc, char **argv )
9 {
10 MPI_Comm client;
11 MPI_Status status;
12 char port_name[MPI_MAX_PORT_NAME];
13 double buf[MAX_DATA];
14 int size, again;
15
16 MPI_Init( &argc, &argv );
17 MPI_Comm_size(MPI_COMM_WORLD, &size);
18 if (size != 1) {
19 fprintf(stderr, "Server too big - need only 1 rank\n");
20 exit(1);
21 }
22 MPI_Open_port(MPI_INFO_NULL, port_name);
23 printf("server available at %s\n",port_name);
24
25 while (1)
26 {
27 MPI_Comm_accept( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client );
28 again = 1;
29
30 while (again)
31 {
32 fprintf(stderr, "Server loop %d\n", again);
33 MPI_Recv( buf, MAX_DATA, MPI_DOUBLE, MPI_ANY_SOURCE,
34 MPI_ANY_TAG, client, &status );
35
36 switch (status.MPI_TAG)
37 {
38 case 0:
39 fprintf(stderr, "Server recvd terminate cmd\n");
40 MPI_Comm_disconnect( &client );
41 MPI_Close_port(port_name);
42 MPI_Finalize();
43 return 0;
44 case 2:
45 fprintf( stderr, "Do something ...\n" );
46 break;
47 default:
48
49 MPI_Abort( MPI_COMM_WORLD, 1 );
50 }
51 ++again;
52 }
53 }
54 }
55