NewMadeleine

Documentation

nm_examples_helper.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2006-2024 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#include <nm_public.h>
19#include <nm_coll_interface.h>
20
21
22/* ********************************************************* */
23
24static int is_server = -1;
25static nm_session_t p_session = NULL;
26static nm_gate_t p_gate = NULL;
27static nm_comm_t p_comm = NULL;
28
29static const nm_tag_t data_tag = 0x01;
30static const nm_tag_t sync_tag = 0x02;
31
33 {
37 };
38
39static void nm_examples_init_topo(int*argc, char*argv[], enum nm_example_topo_e topo)
40{
41 int rank, size, peer;
42 nm_launcher_init(argc, argv);
43 nm_session_open(&p_session, "nm_example");
46 switch(topo)
47 {
49 is_server = (rank == 0);
50 peer = (rank + 1) % size;
51 break;
53 if(size % 2 != 0)
54 {
55 fprintf(stderr, "%s: FATAL- needs an even number of nodes.\n", argv[0]);
56 abort();
57 }
58 is_server = ((rank % 2) == 0);
59 peer = is_server ? (rank + 1) : (rank - 1);
60 break;
62 is_server = (rank == 0);
63 peer = 0;
64 break;
65 default:
66 abort();
67 break;
68 }
70 p_comm = nm_comm_world("nm_example");
71}
72
73/* barrier accross all nodes */
74static inline void nm_examples_barrier(nm_tag_t tag)
75{
77}
78
79static inline void nm_examples_init(int*argc, char*argv[])
80{
82}
83
84static inline void nm_examples_exit(void)
85{
86 nm_examples_barrier(0xFFFF);
87 if(p_comm)
91}
92
93
94/* ********************************************************* */
95
96/* ** helpers for size iterators */
97
98static inline nm_len_t _next(nm_len_t len, double multiplier, nm_len_t increment)
99{
100 nm_len_t next = len * multiplier + increment;
101 if(next <= len)
102 next++;
103 return next;
104}
105
106static void fill_buffer(char*buffer, nm_len_t len) __attribute__((unused));
107static void clear_buffer(char*buffer, nm_len_t len) __attribute__((unused));
108static void control_buffer(const char*buffer, nm_len_t len) __attribute__((unused));
109
110
111static inline char buffer_content(nm_len_t offset)
112{
113 return 'a' + (offset % 26);
114}
115
116static void fill_buffer(char*buffer, nm_len_t len)
117{
118 nm_len_t i = 0;
119 for(i = 0; i < len; i++)
120 {
121 buffer[i] = buffer_content(i);
122 }
123}
124
125static void clear_buffer(char*buffer, nm_len_t len)
126{
127 memset(buffer, 0, len);
128}
129
130static void control_buffer(const char*buffer, nm_len_t len)
131{
132 nm_len_t i = 0;
133 for(i = 0; i < len; i++)
134 {
135 const char expected = buffer_content(i);
136 if(buffer[i] != expected)
137 {
138 fprintf(stderr, "Bad data at byte %d: expected 0x%x (%c), received 0x%x (%c)\n",
139 (int)i, expected, expected, buffer[i], buffer[i]);
140 abort();
141 }
142 }
143}
144
145static inline void compute(unsigned usec)
146{
147 if(usec > 0)
148 {
149 puk_tick_t t1, t2;
150 PUK_GET_TICK(t1);
151 do
152 {
153 PUK_GET_TICK(t2);
154 }
155 while(PUK_TIMING_DELAY(t1,t2) < usec);
156 }
157}
158
159#define check_rc(RC) \
160 if((RC) != NM_ESUCCESS) \
161 { \
162 fprintf(stderr, "Error %d (%s) in %s line %d\n", \
163 (RC), nm_strerror(RC), __FILE__, __LINE__); \
164 abort(); \
165 }
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
struct nm_core_event_s __attribute__
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.
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_comm_t p_comm
static int is_server
static char buffer_content(nm_len_t offset)
nm_example_topo_e
@ NM_EXAMPLES_TOPO_STAR
@ NM_EXAMPLES_TOPO_PAIRS
@ NM_EXAMPLES_TOPO_RING
static void control_buffer(const char *buffer, nm_len_t len) __attribute__((unused))
static void fill_buffer(char *buffer, nm_len_t len) __attribute__((unused))
static void nm_examples_barrier(nm_tag_t tag)
static void clear_buffer(char *buffer, nm_len_t len) __attribute__((unused))
static void nm_examples_init(int *argc, char *argv[])
static const nm_tag_t sync_tag
static nm_session_t p_session
static void nm_examples_exit(void)
static void nm_examples_init_topo(int *argc, char *argv[], enum nm_example_topo_e topo)
static nm_gate_t p_gate
static nm_len_t _next(nm_len_t len, double multiplier, nm_len_t increment)
static void compute(unsigned usec)
static const nm_tag_t data_tag
uint16_t len
chunk len
Definition: nm_headers.h:0
nm_len_t size
size of the onsided data (not incuding target-side completion)
This is the common public header for NewMad.
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
Connection to another process.
Definition: nm_gate.h:100