NewMadeleine

Documentation

nm_rpc_hello.c
/*
* NewMadeleine
* Copyright (C) 2016-2024 (see AUTHORS file)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include <stdlib.h>
#include <stdio.h>
const char msg[] = "Hello, world!";
const nm_tag_t tag = 0x02;
static void rpc_hello_handler(nm_rpc_token_t p_token)
{
nm_rpc_recv_header(p_token, &rlen, sizeof(rlen));
printf("rpc_hello_handler()- received header: len = %lu\n", rlen);
char*buf = malloc(rlen);
nm_rpc_token_set_ref(p_token, buf);
nm_rpc_irecv_body(p_token, buf, rlen);
}
static void rpc_hello_finalizer(nm_rpc_token_t p_token)
{
char*buf = nm_rpc_token_get_ref(p_token);
printf("received body: %s\n", buf);
free(buf);
}
int main(int argc, char**argv)
{
/* generic nmad init */
nm_launcher_init(&argc, argv);
nm_session_open(&p_session, "nm_rpc_hello");
int size = 0;
if(size != 2)
{
NM_FATAL("This example works only with two processes.\n");
}
int rank = -1;
int peer = (size > 1) ? (1 - rank) : rank;
nm_gate_t p_gate = NULL;
nm_comm_t p_comm = nm_comm_world("nm_rpc_hello");
/* register the RPC service */
&rpc_hello_handler, &rpc_hello_finalizer, NULL);
nm_len_t len = strlen(msg) + 1; /* header */
/* create rpc request */
nm_rpc_req_t p_req = nm_rpc_req_init(p_service, p_gate, tag);
nm_rpc_req_pack_header(p_req, &len, sizeof(len));
nm_rpc_req_pack_body(p_req, msg, len);
/* generic nmad termination */
nm_rpc_unregister(p_service);
return 0;
}
void nm_coll_barrier(nm_comm_t comm, nm_tag_t tag)
void nm_comm_destroy(nm_comm_t p_comm)
destroy a communicator- no synchronization is done
nm_comm_t nm_comm_world(const char *label)
create a new global communicator with given label
int nm_launcher_get_rank(int *rank)
Returns process rank.
int nm_launcher_get_size(int *size)
Returns the number of nodes.
int nm_launcher_exit(void)
Cleans session.
int nm_launcher_get_gate(int dest, nm_gate_t *gate)
Returns the gate for the process dest.
static int nm_launcher_init(int *argc, char **argv)
Initializes nmad.
static void nm_rpc_token_set_ref(nm_rpc_token_t p_token, void *ref)
attach a user reference to a token, to transmit information between rpc handler and finalizer
static void nm_rpc_recv_header(nm_rpc_token_t p_token, void *hptr, nm_len_t hlen)
receive header; to be called from a handler; data is available immediately upon function return
void nm_rpc_req_pack_body(nm_rpc_req_t p_rpc_req, const void *ptr, nm_len_t len)
pack a body chunk into an rpc request; may be called multiple times for multiple body chunks.
nm_rpc_req_t nm_rpc_req_init(nm_rpc_service_t p_service, nm_gate_t p_gate, nm_tag_t tag)
initializes a new rpc send request
static void nm_rpc_req_wait(nm_rpc_req_t p_req)
wait for a send request completion
static void nm_rpc_irecv_body(nm_rpc_token_t p_token, void *ptr, nm_len_t len)
asynchronously posts the recv for the body of a received request; to be called from a handler; there ...
void nm_rpc_req_pack_header(nm_rpc_req_t p_rpc_req, const void *ptr, nm_len_t len)
pack a header chunk into an rpc request; may be called multiple times for multiple header chunks.
void nm_rpc_req_isend(nm_rpc_req_t p_req)
send an rpc request once it is built; non-blocking operation, user must set a notifier or explicitely...
void nm_rpc_unregister(nm_rpc_service_t p_service)
stop listenning from RPC requests on given service
static void * nm_rpc_token_get_ref(nm_rpc_token_t p_token)
get a user reference previously attached to the token
nm_rpc_service_t nm_rpc_register(nm_session_t p_session, nm_tag_t tag, nm_tag_t tag_mask, nm_rpc_handler_t p_handler, nm_rpc_finalizer_t p_finalizer, void *ref)
register a new RPC service, listenning on the given tag/tag_mask.
int nm_session_open(nm_session_t *pp_session, const char *label)
Open a new session, assuming processes are already connected.
int nm_session_close(nm_session_t p_session)
Disconnect and destroy a session.
nm_tag_t tag
the user-supplied tag
static nm_session_t p_session
static nm_gate_t p_gate
uint16_t len
chunk len
Definition: nm_headers.h:0
#define NM_FATAL(format,...)
Definition: nm_log.h:36
nm_mpi_communicator_t * p_comm
communicator used for communication
nm_len_t size
size of the onsided data (not incuding target-side completion)
#define NM_LEN_UNDEFINED
length is undefined
Definition: nm_types.h:73
uint64_t nm_tag_t
user tags, 64 bits, contained in indirect hashtable
Definition: nm_types.h:58
uint64_t nm_len_t
data length used by nmad
Definition: nm_types.h:70
#define NM_TAG_MASK_FULL
tag mask that matches all bits
Definition: nm_types.h:63
Connection to another process.
Definition: nm_gate.h:100
an outgoing rpc request
descriptor for a registered RPC service
an incoming rpc request