Add client/server test
This commit was SVN r28332.
Этот коммит содержится в:
родитель
d0e34adacb
Коммит
d6ac721e22
@ -1,4 +1,4 @@
|
||||
PROGS = mpi_no_op mpi_barrier hello hello_nodename abort multi_abort simple_spawn concurrent_spawn spawn_multiple mpi_spin delayed_abort loop_spawn loop_child bad_exit pubsub hello_barrier segv accept connect hello_output hello_show_help crisscross read_write ziatest slave reduce-hang ziaprobe ziatest bcast_loop parallel_w8 parallel_w64 parallel_r8 parallel_r64 sio sendrecv_blaster early_abort debugger singleton_client_server intercomm_create spawn_tree init-exit77 mpi_info info_spawn
|
||||
PROGS = mpi_no_op mpi_barrier hello hello_nodename abort multi_abort simple_spawn concurrent_spawn spawn_multiple mpi_spin delayed_abort loop_spawn loop_child bad_exit pubsub hello_barrier segv accept connect hello_output hello_show_help crisscross read_write ziatest slave reduce-hang ziaprobe ziatest bcast_loop parallel_w8 parallel_w64 parallel_r8 parallel_r64 sio sendrecv_blaster early_abort debugger singleton_client_server intercomm_create spawn_tree init-exit77 mpi_info info_spawn server client
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
|
37
orte/test/mpi/client.c
Обычный файл
37
orte/test/mpi/client.c
Обычный файл
@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mpi.h"
|
||||
|
||||
#define MAX_DATA 100
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
MPI_Comm server;
|
||||
double buf[MAX_DATA];
|
||||
char port_name[MPI_MAX_PORT_NAME];
|
||||
int done = 0, tag, n, CNT=0;
|
||||
|
||||
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 );
|
||||
|
||||
n = MAX_DATA;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
tag = 2; /* Action to perform */
|
||||
if ( CNT == 5 ) { tag = 0; done = 1; }
|
||||
fprintf(stderr, "Client sending message %d\n", CNT);
|
||||
MPI_Send( buf, n, MPI_DOUBLE, 0, tag, server );
|
||||
CNT++;
|
||||
/* etc */
|
||||
}
|
||||
|
||||
MPI_Comm_disconnect( &server );
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
55
orte/test/mpi/server.c
Обычный файл
55
orte/test/mpi/server.c
Обычный файл
@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "mpi.h"
|
||||
|
||||
#define MAX_DATA 100
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "Server too big - need only 1 rank\n");
|
||||
exit(1);
|
||||
}
|
||||
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)
|
||||
{
|
||||
fprintf(stderr, "Server loop %d\n", again);
|
||||
MPI_Recv( buf, MAX_DATA, MPI_DOUBLE, MPI_ANY_SOURCE,
|
||||
MPI_ANY_TAG, client, &status );
|
||||
|
||||
switch (status.MPI_TAG)
|
||||
{
|
||||
case 0:
|
||||
fprintf(stderr, "Server recvd terminate cmd\n");
|
||||
MPI_Comm_disconnect( &client );
|
||||
MPI_Close_port(port_name);
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
case 2: /* do something */
|
||||
fprintf( stderr, "Do something ...\n" );
|
||||
break;
|
||||
default:
|
||||
/* Unexpected message type */
|
||||
MPI_Abort( MPI_COMM_WORLD, 1 );
|
||||
}
|
||||
++again;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user