Debian Codegraph @

src/event_router.cc

raw
1 /*
2 * This file is part of MUSIC.
3 * Copyright (C) 2008, 2009, 2022 INCF
4 *
5 * MUSIC 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 3 of the License, or
8 * (at your option) any later version.
9 *
10 * MUSIC is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "music/event.hh"
20 #include "music/event_router.hh"
21
22 #include <algorithm>
23 #include <cassert>
24 #include <cstring>
25
26 namespace MUSIC {
27
28 OutputRoutingData::OutputRoutingData (const IndexInterval &i, FIBO* b) : EventRoutingData(i), buffer_ (b)
29 {
30 }
31
32 void
33 OutputRoutingData::process (double t, int id)
34 {
35 Event* e = static_cast<Event*> (buffer_->insert ());
36 e->t = t;
37 e->id = id;
38 }
39
40 void
41 DirectRouter::processExtra (double t, int id)
42 {
43 unsigned int pos = extra_.size ();
44 extra_.resize (pos + sizeof (Event));
45 Event* e = static_cast<Event*> (static_cast<void*> (&extra_[pos]));
46 e->t = t;
47 e->id = id;
48 }
49
50 void
51 DirectRouter::setOutputBuffer (void* buffer, unsigned int size)
52 {
53 if (size == size_)
54 {
55 // Buffer relocated
56 buffer_ = static_cast<char*> (buffer);
57 return;
58 }
59 #if 0
60 if (size - size_ != extra_.size ())
61 std::cout << "Rank " << mpi_get_rank (MPI_COMM_WORLD)
62 << ": DirectRouter: Had " << extra_.size ()
63 << " extra spike space, size changed from "
64 << size_ << " to " << size << " = " << size - size_
65 << std::endl;
66 #endif
67 assert (size - size_ == extra_.size ());
68 buffer_ = static_cast<char*> (buffer);
69 memcpy (buffer_ + size_, &extra_[0], extra_.size ());
70 extra_.clear ();
71 std::vector<char> (extra_).swap (extra_); // trim
72 size_ = size;
73 }
74
75 }