View | Details | Raw Unified | Return to bug 1079
Collapse All | Expand All

(-)a/examples/mpi/wscript (-1 / +1 lines)
 Lines 2-8    Link Here 
2
2
3
def build(bld):
3
def build(bld):
4
    obj = bld.create_ns3_program('simple-distributed',
4
    obj = bld.create_ns3_program('simple-distributed',
5
                                 ['point-to-point', 'internet', 'nix-vector-routing'])
5
                                 ['point-to-point', 'internet', 'nix-vector-routing', 'applications'])
6
    obj.source = 'simple-distributed.cc'
6
    obj.source = 'simple-distributed.cc'
7
7
8
    obj = bld.create_ns3_program('third-distributed',
8
    obj = bld.create_ns3_program('third-distributed',
(-)a/src/mpi/model/mpi-interface.cc (-6 / +5 lines)
 Lines 24-30    Link Here 
24
#include <list>
24
#include <list>
25
25
26
#include "mpi-interface.h"
26
#include "mpi-interface.h"
27
#include "mpi-net-device.h"
27
#include "mpi-receiver.h"
28
28
29
#include "ns3/node.h"
29
#include "ns3/node.h"
30
#include "ns3/node-list.h"
30
#include "ns3/node-list.h"
 Lines 235-258    Link Here 
235
235
236
      // Find the correct node/device to schedule receive event
236
      // Find the correct node/device to schedule receive event
237
      Ptr<Node> pNode = NodeList::GetNode (node);
237
      Ptr<Node> pNode = NodeList::GetNode (node);
238
      Ptr<MpiReceiver> pMpiRec = 0;
238
      uint32_t nDevices = pNode->GetNDevices ();
239
      uint32_t nDevices = pNode->GetNDevices ();
239
      Ptr<MpiNetDevice> pMpiDev;
240
      for (uint32_t i = 0; i < nDevices; ++i)
240
      for (uint32_t i = 0; i < nDevices; ++i)
241
        {
241
        {
242
          Ptr<NetDevice> pThisDev = pNode->GetDevice (i);
242
          Ptr<NetDevice> pThisDev = pNode->GetDevice (i);
243
          if (pThisDev->GetIfIndex () == dev)
243
          if (pThisDev->GetIfIndex () == dev)
244
            {
244
            {
245
              pDev = DynamicCast<MpiNetDevice> (pThisDev);
245
              pMpiRec = pThisDev->GetObject<MpiReceiver> ();
246
              break;
246
              break;
247
            }
247
            }
248
        }
248
        }
249
249
250
      NS_ASSERT (pNode && pDev);
250
      NS_ASSERT (pNode && pMpiRec);
251
251
252
      // Schedule the rx event
252
      // Schedule the rx event
253
      Simulator::ScheduleWithContext (pNode->GetId (), rxTime - Simulator::Now (),
253
      Simulator::ScheduleWithContext (pNode->GetId (), rxTime - Simulator::Now (),
254
                                      &MpiNetDevice::Receive,
254
                                      &MpiReceiver::Receive, pMpiRec, p);
255
                                      pMpiDev, p);
256
255
257
      // Re-queue the next read
256
      // Re-queue the next read
258
      MPI_Irecv (m_pRxBuffers[index], MAX_MPI_MSG_SIZE, MPI_CHAR, MPI_ANY_SOURCE, 0,
257
      MPI_Irecv (m_pRxBuffers[index], MAX_MPI_MSG_SIZE, MPI_CHAR, MPI_ANY_SOURCE, 0,
(-)a/src/mpi/model/mpi-net-device.cc (-33 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: George Riley <riley@ece.gatech.edu>
17
 */
18
19
#include "mpi-net-device.h"
20
21
namespace ns3 {
22
23
MpiNetDevice::~MpiNetDevice ()
24
{
25
}
26
27
void
28
MpiNetDevice::MpiReceive (Ptr<Packet> p)
29
{
30
  DoMpiReceive (p);
31
}
32
33
} // namespace ns3
(-)a/src/mpi/model/mpi-net-device.h (-51 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: George Riley <riley@ece.gatech.edu>
17
 */
18
19
// Provides a mixin interface to allow MPI-compatible NetDevices to inherit
20
21
#ifndef NS3_MPI_NET_DEVICE_H
22
#define NS3_MPI_NET_DEVICE_H
23
24
#include "ns3/packet.h"
25
26
namespace ns3 {
27
28
/**
29
 * Class to mixin to a NetDevice if it supports MPI capability
30
 * 
31
 * Subclass must implement DoMpiReceive to direct it to the device's
32
 * normal Receive() method.
33
 */
34
class MpiNetDevice
35
{
36
public:
37
  virtual ~MpiNetDevice();
38
  /**
39
   * 
40
   * Receive a packet 
41
   *
42
   * \param p Ptr to the received packet.
43
   */
44
  void MpiReceive (Ptr<Packet> p);
45
protected:
46
  virtual void DoMpiReceive (Ptr<Packet> p) = 0;
47
};
48
49
} // namespace ns3
50
51
#endif /* NS3_MPI_NET_DEVICE_H */
(-)e9ca5b2838e7 (+49 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: George Riley <riley@ece.gatech.edu>
17
 */
18
19
#include "mpi-receiver.h"
20
21
namespace ns3 {
22
23
TypeId
24
MpiReceiver::GetTypeId (void)
25
{
26
  static TypeId tid = TypeId ("ns3::MpiReceiver")
27
    .SetParent<Object> ()
28
    .AddConstructor <MpiReceiver> ();
29
  return tid;
30
}
31
32
MpiReceiver::~MpiReceiver ()
33
{
34
}
35
36
void 
37
MpiReceiver::SetReceiveCallback (Callback<void, Ptr<Packet> > callback)
38
{
39
  m_rxCallback = callback;
40
}
41
42
void 
43
MpiReceiver::Receive (Ptr<Packet> p)
44
{
45
  NS_ASSERT (! m_rxCallback.IsNull ());
46
  m_rxCallback (p);
47
}
48
49
} // namespace ns3
(-)e9ca5b2838e7 (+62 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: George Riley <riley@ece.gatech.edu>
17
 */
18
19
// Provides an interface to aggregate to MPI-compatible NetDevices 
20
21
#ifndef NS3_MPI_RECEIVER_H
22
#define NS3_MPI_RECEIVER_H
23
24
#include "ns3/object.h"
25
#include "ns3/packet.h"
26
27
namespace ns3 {
28
29
/**
30
 * Class to aggregate to a NetDevice if it supports MPI capability
31
 * 
32
 * MpiInterface::ReceiveMessages () needs to send packets to a NetDevice
33
 * Receive() method.  Since each NetDevice's Receive() method is specific
34
 * to the derived class, and since we do not know whether such a NetDevice
35
 * is MPI-capable, we aggregate one of these objects to each MPI-capable
36
 * device.  In addition, we must hook up a NetDevice::Receive() method
37
 * to the callback.  So the two steps to enable MPI capability are to
38
 * aggregate this object to a NetDevice, and to set the callback.
39
 */
40
class MpiReceiver : public Object
41
{
42
public:
43
  static TypeId GetTypeId (void);
44
  virtual ~MpiReceiver ();
45
46
  /**
47
   * \brief Direct an incoming packet to the device Receive() method
48
   * \param p Packet to receive
49
   */
50
  void Receive (Ptr<Packet> p);
51
  /**
52
   * \brief Set the receive callback to get packets to net devices
53
   * \param callback the callback itself
54
   */
55
  void SetReceiveCallback (Callback<void, Ptr<Packet> > callback);
56
private:
57
  Callback<void, Ptr<Packet> > m_rxCallback;
58
};
59
60
} // namespace ns3
61
62
#endif /* NS3_MPI_RECEIVER_H */
(-)a/src/mpi/wscript (-2 / +2 lines)
 Lines 34-40    Link Here 
34
    sim.source = [
34
    sim.source = [
35
        'model/distributed-simulator-impl.cc',
35
        'model/distributed-simulator-impl.cc',
36
        'model/mpi-interface.cc',
36
        'model/mpi-interface.cc',
37
        'model/mpi-net-device.cc',
37
        'model/mpi-receiver.cc',
38
        ]
38
        ]
39
39
40
    headers = bld.new_task_gen('ns3header')
40
    headers = bld.new_task_gen('ns3header')
 Lines 42-48    Link Here 
42
    headers.source = [
42
    headers.source = [
43
        'model/distributed-simulator-impl.h',
43
        'model/distributed-simulator-impl.h',
44
        'model/mpi-interface.h',
44
        'model/mpi-interface.h',
45
        'model/mpi-net-device.h',
45
        'model/mpi-receiver.h',
46
        ]
46
        ]
47
47
48
    if env['ENABLE_MPI']:
48
    if env['ENABLE_MPI']:
(-)a/src/point-to-point/helper/point-to-point-helper.cc (+7 lines)
 Lines 29-34    Link Here 
29
#include "ns3/packet.h"
29
#include "ns3/packet.h"
30
#include "ns3/names.h"
30
#include "ns3/names.h"
31
#include "ns3/mpi-interface.h"
31
#include "ns3/mpi-interface.h"
32
#include "ns3/mpi-receiver.h"
32
33
33
#include "ns3/trace-helper.h"
34
#include "ns3/trace-helper.h"
34
#include "point-to-point-helper.h"
35
#include "point-to-point-helper.h"
 Lines 257-262    Link Here 
257
  else
258
  else
258
    {
259
    {
259
      channel = m_remoteChannelFactory.Create<PointToPointRemoteChannel> ();
260
      channel = m_remoteChannelFactory.Create<PointToPointRemoteChannel> ();
261
      Ptr<MpiReceiver> mpiRecA = CreateObject<MpiReceiver> ();
262
      Ptr<MpiReceiver> mpiRecB = CreateObject<MpiReceiver> ();
263
      mpiRecA->SetReceiveCallback (MakeCallback (&PointToPointNetDevice::Receive, devA));
264
      mpiRecB->SetReceiveCallback (MakeCallback (&PointToPointNetDevice::Receive, devB));
265
      devA->AggregateObject (mpiRecA);
266
      devB->AggregateObject (mpiRecB);
260
    }
267
    }
261
    
268
    
262
  devA->Attach (channel);
269
  devA->Attach (channel);
(-)a/src/point-to-point/model/point-to-point-net-device.h (-2 / +1 lines)
 Lines 30-36    Link Here 
30
#include "ns3/data-rate.h"
30
#include "ns3/data-rate.h"
31
#include "ns3/ptr.h"
31
#include "ns3/ptr.h"
32
#include "ns3/mac48-address.h"
32
#include "ns3/mac48-address.h"
33
#include "ns3/mpi-net-device.h"
34
33
35
namespace ns3 {
34
namespace ns3 {
36
35
 Lines 50-56    Link Here 
50
 * include a queue, data rate, and interframe transmission gap (the 
49
 * include a queue, data rate, and interframe transmission gap (the 
51
 * propagation delay is set in the PointToPointChannel).
50
 * propagation delay is set in the PointToPointChannel).
52
 */
51
 */
53
class PointToPointNetDevice : public NetDevice, public MpiNetDevice 
52
class PointToPointNetDevice : public NetDevice
54
{
53
{
55
public:
54
public:
56
  static TypeId GetTypeId (void);
55
  static TypeId GetTypeId (void);

Return to bug 1079