OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Format.cpp
Go to the documentation of this file.
1//
2// Class Format
3// Format class to allow serializing message objects into plain buffers
4// to send directly with mpi calls or similar means
5//
6// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
19#include "Message/Format.h"
20
22{
23 items = msg->size();
24 size = 0;
25
26 format_array.resize(2*items);
27 for (unsigned int i=0; i<items; ++i)
28 {
29 Message::MsgItem &msgitem = msg->item(i);
30 format_array[2*i+0] = msgitem.numElems();
31 format_array[2*i+1] = msgitem.numBytes();
32 size += format_array[2*i+1];
33 }
34}
35
37{
38 std::cout << "size: " << size << std::endl;
39 for (unsigned int i=0; i<items; ++i)
40 {
41 std::cout << "entry " << i << ": " << format_array[2*i+0]
42 << " elements " << format_array[2*i+1] << " bytes\n";
43 }
44}
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
Format(Message *)
Definition: Format.cpp:21
unsigned int size
Definition: Format.h:49
unsigned int items
Definition: Format.h:49
void print()
Definition: Format.cpp:36
std::vector< unsigned int > format_array
Definition: Format.h:50
size_t size() const
Definition: Message.h:292
MsgItem & item(size_t n)
Definition: Message.h:308
unsigned int numBytes() const
Definition: Message.h:218
unsigned int numElems() const
Definition: Message.h:222