FreeNOS
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
MpiTarget Class Reference

Implements a Message Passing Interface (MPI) for communication between local cores. More...

#include <MpiTarget.h>

Inheritance diagram for MpiTarget:
MpiBackend AbstractFactory< MpiBackend >

Public Member Functions

 MpiTarget ()
 Constructor. More...
 
virtual Result initialize (int *argc, char ***argv)
 Initialize the backend. More...
 
virtual Result terminate ()
 Terminate the backend. More...
 
virtual Result getCommRank (MPI_Comm comm, int *rank)
 Retrieve communication rank (core id) More...
 
virtual Result getCommSize (MPI_Comm comm, int *size)
 Retrieve communication size (total cores) More...
 
virtual Result send (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
 Synchronous send data. More...
 
virtual Result receive (void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
 Synchronous receive data. More...
 

Private Member Functions

Result initializeMaster (int *argc, char ***argv)
 Initialize the master. More...
 
Result initializeSlave (int *argc, char ***argv)
 Initialize a slave. More...
 
Result createReadChannel (const Size coreId, const Address memoryBase)
 Create a new MPI channel for reading. More...
 
Result createWriteChannel (const Size coreId, const Address memoryBase)
 Create a new MPI channel for writing. More...
 
Address getMemoryBaseRead (const Size coreId) const
 Get memory address for MPI read communication. More...
 
Address getMemoryBaseWrite (const Size coreId) const
 Get memory address for MPI write communication. More...
 

Private Attributes

Size m_coreId
 Core identifier is a unique number on each core. More...
 
Size m_coreCount
 Total number of cores. More...
 
Memory::Range m_memChannelBase
 Memory base address for local MPI communication. More...
 
Index< MemoryChannel, MaximumChannelsm_readChannels
 Stores all channels for receiving data from other cores. More...
 
Index< MemoryChannel, MaximumChannelsm_writeChannels
 Stores all channels for sending data to other cores. More...
 

Static Private Attributes

static const Size MaximumChannels = 128u
 Maximum number of communication channels. More...
 

Additional Inherited Members

- Public Types inherited from MpiBackend
typedef int Result
 Result code. More...
 
- Static Public Member Functions inherited from AbstractFactory< MpiBackend >
static MpiBackendcreate ()
 Abstract function to create an instance of T. More...
 

Detailed Description

Implements a Message Passing Interface (MPI) for communication between local cores.

Todo:
Currently only supports communication between the master and slaves. Direct communication between slave cores is not implemented.

Definition at line 40 of file MpiTarget.h.

Constructor & Destructor Documentation

◆ MpiTarget()

MpiTarget::MpiTarget ( )

Constructor.

Definition at line 37 of file MpiTarget.cpp.

References m_memChannelBase, and MemoryBlock::set().

Member Function Documentation

◆ createReadChannel()

MpiTarget::Result MpiTarget::createReadChannel ( const Size  coreId,
const Address  memoryBase 
)
private

Create a new MPI channel for reading.

Parameters
coreIdSource coreId for reading
memoryBasePhysical memory base address
Returns
Result code

Definition at line 345 of file MpiTarget.cpp.

References Channel::Consumer, coreId, DEBUG, ERROR, Index< T, N >::insertAt(), m_coreId, m_readChannels, MPI_ERR_NO_MEM, MPI_SUCCESS, PAGESIZE, and MemoryChannel::setPhysical().

Referenced by initializeMaster(), and initializeSlave().

◆ createWriteChannel()

MpiTarget::Result MpiTarget::createWriteChannel ( const Size  coreId,
const Address  memoryBase 
)
private

Create a new MPI channel for writing.

Parameters
coreIdDestination coreId for writing
memoryBasePhysical memory base address
Returns
Result code

Definition at line 367 of file MpiTarget.cpp.

References coreId, DEBUG, ERROR, Index< T, N >::insertAt(), m_coreId, m_writeChannels, MPI_ERR_NO_MEM, MPI_SUCCESS, PAGESIZE, Channel::Producer, and MemoryChannel::setPhysical().

Referenced by initializeMaster(), and initializeSlave().

◆ getCommRank()

MpiTarget::Result MpiTarget::getCommRank ( MPI_Comm  comm,
int *  rank 
)
virtual

Retrieve communication rank (core id)

Parameters
commCommunication reference
rankOutput the communication rank number
Returns
Result code

Implements MpiBackend.

Definition at line 64 of file MpiTarget.cpp.

References m_coreId, and MPI_SUCCESS.

◆ getCommSize()

MpiTarget::Result MpiTarget::getCommSize ( MPI_Comm  comm,
int *  size 
)
virtual

Retrieve communication size (total cores)

Parameters
commCommunication reference
sizeOutput the communication size
Returns
Result code

Implements MpiBackend.

Definition at line 71 of file MpiTarget.cpp.

References m_coreCount, and MPI_SUCCESS.

◆ getMemoryBaseRead()

Address MpiTarget::getMemoryBaseRead ( const Size  coreId) const
private

Get memory address for MPI read communication.

Parameters
coreIdCore identifier
Returns
Physical memory base address

Definition at line 389 of file MpiTarget.cpp.

References assert, coreId, m_coreCount, m_coreId, m_memChannelBase, PAGESIZE, and Memory::Range::phys.

Referenced by initializeMaster(), and initializeSlave().

◆ getMemoryBaseWrite()

Address MpiTarget::getMemoryBaseWrite ( const Size  coreId) const
private

Get memory address for MPI write communication.

Parameters
coreIdCore identifier
Returns
Physical memory base address

Definition at line 405 of file MpiTarget.cpp.

References assert, coreId, m_coreCount, m_coreId, m_memChannelBase, PAGESIZE, and Memory::Range::phys.

Referenced by initializeMaster(), and initializeSlave().

◆ initialize()

MpiTarget::Result MpiTarget::initialize ( int *  argc,
char ***  argv 
)
virtual

Initialize the backend.

Parameters
argcArgument count pointer
argvArgument values array pointer
Returns
Result code

Implements MpiBackend.

Definition at line 44 of file MpiTarget.cpp.

References MemoryBlock::compare(), initializeMaster(), initializeSlave(), and MPI_SUCCESS.

◆ initializeMaster()

MpiTarget::Result MpiTarget::initializeMaster ( int *  argc,
char ***  argv 
)
private

◆ initializeSlave()

MpiTarget::Result MpiTarget::initializeSlave ( int *  argc,
char ***  argv 
)
private

Initialize a slave.

Parameters
argcArgument count pointer
argvArgument values array pointer
Returns
Result code

Definition at line 299 of file MpiTarget.cpp.

References assert, createReadChannel(), createWriteChannel(), Number::Dec, ERROR, getMemoryBaseRead(), getMemoryBaseWrite(), Number::Hex, m_coreCount, m_coreId, m_memChannelBase, MaximumChannels, MPI_ERR_ARG, MPI_SUCCESS, Memory::Range::phys, and String::toLong().

Referenced by initialize().

◆ receive()

MpiTarget::Result MpiTarget::receive ( void *  buf,
int  count,
MPI_Datatype  datatype,
int  source,
int  tag,
MPI_Comm  comm,
MPI_Status status 
)
virtual

Synchronous receive data.

Parameters
bufOutput data buffer
countNumber of data items
datatypeType of data
sourceSource to receive data from (core id)
tagOptional data identifier to receive
commCommunication reference
statusOutput the MPI status
Returns
Result code

Implements MpiBackend.

Definition at line 118 of file MpiTarget.cpp.

References Index< T, N >::get(), MPIMessage::integer, m_readChannels, MPI_ERR_RANK, MPI_ERR_UNSUPPORTED_DATAREP, MPI_INT, MPI_SUCCESS, MPI_UNSIGNED_CHAR, ProcessCtl(), MemoryChannel::read(), Schedule, SELF, Channel::Success, and MPIMessage::uchar.

◆ send()

MpiTarget::Result MpiTarget::send ( const void *  buf,
int  count,
MPI_Datatype  datatype,
int  dest,
int  tag,
MPI_Comm  comm 
)
virtual

Synchronous send data.

Parameters
bufInput data buffer
countNumber of data items
datatypeType of data
destDestination to send to (core id)
tagOptional data identifier to send
commCommunication reference
Returns
Result code

Implements MpiBackend.

Definition at line 78 of file MpiTarget.cpp.

References Index< T, N >::get(), MPIMessage::integer, m_writeChannels, MPI_ERR_RANK, MPI_ERR_UNSUPPORTED_DATAREP, MPI_INT, MPI_SUCCESS, MPI_UNSIGNED_CHAR, ProcessCtl(), Schedule, SELF, Channel::Success, MPIMessage::uchar, and MemoryChannel::write().

◆ terminate()

MpiTarget::Result MpiTarget::terminate ( )
virtual

Terminate the backend.

Returns
Result code

Implements MpiBackend.

Definition at line 59 of file MpiTarget.cpp.

References MPI_SUCCESS.

Field Documentation

◆ m_coreCount

Size MpiTarget::m_coreCount
private

Total number of cores.

Definition at line 204 of file MpiTarget.h.

Referenced by getCommSize(), getMemoryBaseRead(), getMemoryBaseWrite(), initializeMaster(), and initializeSlave().

◆ m_coreId

Size MpiTarget::m_coreId
private

Core identifier is a unique number on each core.

Definition at line 201 of file MpiTarget.h.

Referenced by createReadChannel(), createWriteChannel(), getCommRank(), getMemoryBaseRead(), getMemoryBaseWrite(), initializeMaster(), and initializeSlave().

◆ m_memChannelBase

Memory::Range MpiTarget::m_memChannelBase
private

Memory base address for local MPI communication.

Definition at line 207 of file MpiTarget.h.

Referenced by getMemoryBaseRead(), getMemoryBaseWrite(), initializeMaster(), initializeSlave(), and MpiTarget().

◆ m_readChannels

Index<MemoryChannel, MaximumChannels> MpiTarget::m_readChannels
private

Stores all channels for receiving data from other cores.

Definition at line 210 of file MpiTarget.h.

Referenced by createReadChannel(), and receive().

◆ m_writeChannels

Index<MemoryChannel, MaximumChannels> MpiTarget::m_writeChannels
private

Stores all channels for sending data to other cores.

Definition at line 213 of file MpiTarget.h.

Referenced by createWriteChannel(), and send().

◆ MaximumChannels

const Size MpiTarget::MaximumChannels = 128u
staticprivate

Maximum number of communication channels.

Definition at line 45 of file MpiTarget.h.

Referenced by initializeSlave().


The documentation for this class was generated from the following files: