NewMadeleine

Documentation

« back to PM2 home.
nm_flypack.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2015-2026 (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
20#include <nm_core_interface.h>
21
22#define FLYPACK_CHUNK_SIZE 16
23
25{
26 void*buf;
28};
29
30static void flypack_traversal(const void*_content, struct nm_data_op_s*p_op) __attribute__((unused));
31
32static const struct nm_data_ops_s flypack_ops =
33 {
35 };
37
38
40{
41 static nm_len_t chunk_size = 0;
42 if(chunk_size == 0)
43 {
44 const char*s_chunk_size = getenv("FLYPACK_CHUNK_SIZE");
45 if(s_chunk_size != NULL)
46 {
47 chunk_size = atoi(s_chunk_size);
48 }
49 else
50 {
51 chunk_size = FLYPACK_CHUNK_SIZE;
52 }
53 fprintf(stderr, "# nmad: flypack chunk size = %d\n", (int)chunk_size);
54 }
55 return chunk_size;
56}
57
58static void flypack_traversal(const void*_content, struct nm_data_op_s*p_op)
59{
60 const struct flypack_data_s*content = _content;
61 const nm_len_t chunk_size = flypack_chunk_size();
62 if(content->len >= chunk_size)
63 {
64 const nm_len_t chunk_count = content->len / chunk_size;
65 NM_DATA_OP_APPLY_LOOP(i, chunk_count, content->buf + 2 * chunk_size * i, chunk_size, p_op);
66 if(chunk_count * chunk_size < content->len)
67 {
68 const nm_len_t remainder = content->len - chunk_count * chunk_size;
69 nm_data_op_apply(content->buf + 2 * chunk_size * chunk_count, remainder, p_op);
70 }
71 }
72 else
73 {
74 nm_data_op_apply(content->buf, content->len, p_op);
75 }
76}
77
78static inline void flypack_import(char*p_flypack_buffer, const char*p_buf, nm_len_t len)
79{
80 const nm_len_t chunk_size = flypack_chunk_size();
81 const nm_len_t nchunks = len / chunk_size;
82 int i;
83 for(i = 0; i < nchunks; i++)
84 {
85 memcpy(&p_flypack_buffer[i * 2 * chunk_size], &p_buf[i * chunk_size], chunk_size);
86 }
87 if(nchunks * chunk_size < len)
88 {
89 memcpy(&p_flypack_buffer[nchunks * 2 * chunk_size], &p_buf[nchunks * chunk_size], len - nchunks * chunk_size);
90 }
91}
92
93static inline void flypack_export(const char*p_flypack_buffer, char*p_buf, nm_len_t len)
94{
95 const nm_len_t chunk_size = flypack_chunk_size();
96 const nm_len_t nchunks = len / chunk_size;
97 int i;
98 for(i = 0; i < nchunks; i++)
99 {
100 memcpy(&p_buf[i * chunk_size], &p_flypack_buffer[i * 2 * chunk_size], chunk_size);
101 }
102 if(nchunks * chunk_size < len)
103 {
104 memcpy(&p_buf[nchunks * chunk_size], &p_flypack_buffer[nchunks * 2 * chunk_size], len - nchunks * chunk_size);
105 }
106}
struct nm_core_event_s __attribute__
Definition nm_data.h:530
#define NM_DATA_TYPE(ENAME, CONTENT_TYPE, OPS)
macro to generate typed functions to init/access data fields.
Definition nm_data.h:222
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:1051
#define NM_DATA_OP_APPLY_LOOP
selector to switch easily between implementations
Definition nm_data.h:504
static void flypack_import(char *p_flypack_buffer, const char *p_buf, nm_len_t len)
Definition nm_flypack.h:78
static void flypack_traversal(const void *_content, struct nm_data_op_s *p_op) __attribute__((unused))
Definition nm_flypack.h:58
static nm_len_t flypack_chunk_size(void)
Definition nm_flypack.h:39
#define FLYPACK_CHUNK_SIZE
Definition nm_flypack.h:22
static const struct nm_data_ops_s flypack_ops
Definition nm_flypack.h:32
static void flypack_export(const char *p_flypack_buffer, char *p_buf, nm_len_t len)
Definition nm_flypack.h:93
uint16_t len
chunk len
Definition nm_headers.h:0
struct nm_mpi_operator_s * p_op
uint64_t nm_len_t
data length used by nmad
Definition nm_types.h:68
nm_len_t len
Definition nm_flypack.h:27
set of operations available on data type.
Definition nm_data.h:188
nm_data_traversal_t p_traversal
operation to apply a given function to all chunks of data (required)
Definition nm_data.h:189