nm_sr_custom_data.c
/*
* NewMadeleine
* Copyright (C) 2006-2026 (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>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <nm_launcher_interface.h>
#include <nm_sendrecv_interface.h>
struct user_data_s
{
char**array;
int num;
};
static void user_data_traversal(const void*_content, struct nm_data_op_s*p_op) __attribute__((unused));
{
.p_traversal = &user_data_traversal
};
{
const struct user_data_s*content = _content;
int i;
for(i = 0; i < content->num; i++)
{
}
}
int main(int argc, char**argv)
{
/* init ring topology */
nm_launcher_init(&argc, argv);
nm_launcher_get_rank(&rank);
nm_gate_t p_gate_next, p_gate_prev;
/* init array, filled only on rank #0 */
int num = 200;
int len = 100;
char**array = malloc(sizeof(char*) * num);
int i;
for(i = 0; i < num; i++)
{
array[i] = malloc(len);
if(rank == 0)
{
int j;
for(j = 0; j < len - 1; j++)
{
array[i][j] = 'a' + ((i + j) % 26);
}
array[i][len - 1] = '\0';
}
}
/* create data descriptor */
nm_data_user_data_set(&data, (struct user_data_s){ .array = array, .num = num, .len = len });
if(rank == 0)
{
/* first link in the ring */
nm_sr_request_t request;
}
{
/* last link in the ring */
nm_sr_request_t request;
printf("received data on node %d:\n", rank);
for(i = 0; i < num; i++)
{
printf("%s\n", array[i]);
}
}
else
{
/* forward data */
nm_sr_request_t request;
nm_sr_rwait(p_session, &request);
nm_sr_swait(p_session, &request);
}
for(i = 0; i < num; i++)
{
free(array[i]);
}
free(array);
return 0;
}
#define NM_DATA_TYPE(ENAME, CONTENT_TYPE, OPS)
macro to generate typed functions to init/access data fields.
Definition nm_data.h:223
NM_EXTERN_C_BEGIN int nm_session_open(nm_session_t *pp_session, const char *label)
Open a new session, assuming processes are already connected.
static int nm_sr_isend_data(nm_session_t p_session, nm_gate_t p_gate, nm_tag_t tag, struct nm_data_s *p_data, nm_sr_request_t *p_request)
Definition nm_sendrecv_interface.h:326
static int nm_sr_swait(nm_session_t p_session, nm_sr_request_t *p_request)
Wait for the completion of a non blocking send request.
static int nm_sr_rwait(nm_session_t p_session, nm_sr_request_t *p_request)
Wait for the completion of a non blocking receive request.
static int nm_sr_irecv_data(nm_session_t p_session, nm_gate_t p_gate, nm_tag_t tag, struct nm_data_s *p_data, nm_sr_request_t *p_request)
Definition nm_sendrecv_interface.h:398
static void nm_data_op_apply(void *__restrict__ p_ptr, nm_len_t len, struct nm_data_op_s *__restrict__ p_op)
apply op on block (p_ptr, len)
Definition nm_data.h:1070
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.
Definition nm_launcher_interface.h:80
nm_len_t size
size of the onsided data (not incuding target-side completion)
Definition nm_onesided_private.h:1
Definition nm_data.h:162
nm_data_traversal_t p_traversal
operation to apply a given function to all chunks of data (required)
Definition nm_data.h:190
a data descriptor, used to pack/unpack data from app layout to/from contiguous buffers
Definition nm_data.h:200
Definition nm_session_private.h:24