1
1
This commit was SVN r30743.
Этот коммит содержится в:
Ralph Castain 2014-02-16 20:54:34 +00:00
родитель d42f4be8a4
Коммит a91d358c48
2 изменённых файлов: 83 добавлений и 2 удалений

79
orte/test/mpi/memcached-dummy.c Обычный файл
Просмотреть файл

@ -0,0 +1,79 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <mpi.h>
void do_server(void)
{
#if 0
/* temporary hack, just use pid to identify service */
#define MAX_SERVER_ID_LEN (256)
int server_id = getpid();
char server_id_str[MAX_SERVER_ID_LEN];
snprintf(server_id_str, MAX_SERVER_ID_LEN, "server-%d", server_id);
#endif
char port_name[MPI_MAX_PORT_NAME];
MPI_Comm accept_comm;
int recvbuf = -1;
MPI_Open_port(MPI_INFO_NULL, port_name);
MPI_Publish_name("memcached", MPI_INFO_NULL, port_name);
MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &accept_comm);
printf("accepted an incoming connection\n");
MPI_Recv(&recvbuf, 1, MPI_INT, 0, 0, accept_comm, MPI_STATUS_IGNORE);
printf("received '%d' from peer\n", recvbuf);
MPI_Comm_disconnect(&accept_comm);
MPI_Unpublish_name("memcached", MPI_INFO_NULL, port_name);
MPI_Close_port(port_name);
}
void do_client(void)
{
char port_name[MPI_MAX_PORT_NAME];
MPI_Comm connect_comm;
int sendbuf = -1;
/* wait for server to publish */
sleep(3);
MPI_Lookup_name("memcached", MPI_INFO_NULL, port_name);
fprintf(stderr, "GOT PORT %s", port_name);
MPI_Comm_connect(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &connect_comm);
printf("connected to port name '%s'\n", port_name);
sendbuf = getpid();
MPI_Send(&sendbuf, 1, MPI_INT, 0, 0, connect_comm);
MPI_Comm_disconnect(&connect_comm);
}
int main(int argc, char **argv)
{
int wrank, wsize;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
/* expects to be called with one arg:
* - the literal string "server" or "client"
*
* Extra arguments are ignored.
*/
assert(argc >= 2);
printf("memcached-dummy, MPI_COMM_WORLD process %d/%d, argv[1]=%s\n", wrank, wsize, argv[1]);
if (0 == strcmp(argv[1], "server")) {
do_server();
}
else {
do_client();
}
MPI_Finalize();
return 0;
}

Просмотреть файл

@ -67,20 +67,22 @@ main(int argc, char *argv[]){
/* wait for it to come around */
OBJ_CONSTRUCT(&blob, orte_rml_recv_cb_t);
blob.active = true;
orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, MY_TAG,
ORTE_RML_NON_PERSISTENT,
orte_rml_recv_callback, &blob);
ORTE_WAIT_FOR_COMPLETION(blob.waiting);
ORTE_WAIT_FOR_COMPLETION(blob.active);
OBJ_DESTRUCT(&blob);
opal_output(0, "%s Ring %d completed", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), j);
} else {
/* wait for msg */
OBJ_CONSTRUCT(&blob, orte_rml_recv_cb_t);
blob.active = true;
orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, MY_TAG,
ORTE_RML_NON_PERSISTENT,
orte_rml_recv_callback, &blob);
ORTE_WAIT_FOR_COMPLETION(blob.waiting);
ORTE_WAIT_FOR_COMPLETION(blob.active);
opal_output(0, "%s received message %d from %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), j, ORTE_NAME_PRINT(&blob.name));