FreeNOS
Public Member Functions | Private Member Functions | Private Attributes
MpiPrime Class Reference

Calculate prime numbers in parallel. More...

#include <MpiPrime.h>

Inheritance diagram for MpiPrime:
SievePrime POSIXApplication Application

Public Member Functions

 MpiPrime (int argc, char **argv)
 Constructor. More...
 
virtual ~MpiPrime ()
 Destructor. More...
 
virtual Result initialize ()
 Initialize the application. More...
 
virtual Result exec ()
 Execute the application. More...
 
- Public Member Functions inherited from SievePrime
 SievePrime (int argc, char **argv)
 Constructor. More...
 
virtual ~SievePrime ()
 Destructor. More...
 
- Public Member Functions inherited from POSIXApplication
 POSIXApplication (int argc, char **argv)
 Class constructor. More...
 
virtual ~POSIXApplication ()
 Class destructor. More...
 
- Public Member Functions inherited from Application
 Application (int argc, char **argv)
 Class constructor. More...
 
virtual ~Application ()
 Class destructor. More...
 
virtual int run ()
 Run the application. More...
 

Private Member Functions

Result searchParallel (int k, int n, u8 *rootMap, u8 *map)
 Calculate prime numbers in parallel. More...
 
Result collect (int n, u8 *rootMap, u8 *map)
 Collect prime number results. More...
 

Private Attributes

int m_mpiInitResult
 Result of MPI initialization. More...
 
int m_id
 MPI core identifier (rank) of the current process. More...
 
Size m_cores
 Total number of cores. More...
 
Size m_numbersPerCore
 Prime numbers calculated per core. More...
 
Size m_numberStart
 Prime numbers array range start for this core. More...
 
Size m_numberEnd
 Prime numbers array range end for this core. More...
 

Additional Inherited Members

- Public Types inherited from Application
enum  Result {
  Success, NotFound, IOError, InvalidArgument,
  ShowUsage, TimedOut, OutOfMemory
}
 Result codes. More...
 
- Protected Member Functions inherited from SievePrime
Result reportResult (const int n, const u8 *map, Size &resultsWritten, const Size offsetNumber=0) const
 Report the calculated results. More...
 
Result searchSequential (const int n, u8 *map) const
 Perform sequential search for prime numbers. More...
 
- Protected Member Functions inherited from POSIXApplication
virtual Result output (const char *string) const
 Print text to output. More...
 
int runProgram (const char *path, const char **argv)
 Runs an external program. More...
 
- Protected Member Functions inherited from Application
virtual Result output (String &string) const
 Print string to output. More...
 
ArgumentParserparser ()
 Get program arguments parser. More...
 
const ArgumentParserparser () const
 Get constant program arguments parser. More...
 
const ArgumentContainerarguments () const
 Get program arguments. More...
 
void setVersion (const String &version)
 Set program version. More...
 
- Protected Attributes inherited from Application
int m_argc
 Input argument count. More...
 
char ** m_argv
 Input argument values. More...
 

Detailed Description

Calculate prime numbers in parallel.

Definition at line 32 of file MpiPrime.h.

Constructor & Destructor Documentation

◆ MpiPrime()

MpiPrime::MpiPrime ( int  argc,
char **  argv 
)

Constructor.

Parameters
argcArgument count
argvArgument values

Definition at line 30 of file MpiPrime.cpp.

References Application::parser(), and ArgumentParser::setDescription().

◆ ~MpiPrime()

MpiPrime::~MpiPrime ( )
virtual

Destructor.

Definition at line 38 of file MpiPrime.cpp.

References DEBUG.

Member Function Documentation

◆ collect()

MpiPrime::Result MpiPrime::collect ( int  n,
u8 rootMap,
u8 map 
)
private

Collect prime number results.

Parameters
nUpper limit to search for primes
rootMapPointer to the root primes array
mapPointer to results array
Returns
Result code

Definition at line 213 of file MpiPrime.cpp.

References m_cores, m_id, m_numbersPerCore, MPI_COMM_WORLD, MPI_Recv(), MPI_Send(), MPI_UNSIGNED_CHAR, SievePrime::reportResult(), sqrt(), Application::Success, and write().

Referenced by searchParallel().

◆ exec()

MpiPrime::Result MpiPrime::exec ( )
virtual

◆ initialize()

MpiPrime::Result MpiPrime::initialize ( )
virtual

Initialize the application.

Returns
Result code

Reimplemented from Application.

Definition at line 43 of file MpiPrime.cpp.

References ERROR, Application::IOError, m_cores, m_id, m_mpiInitResult, MPI_Comm_rank(), MPI_Comm_size(), MPI_COMM_WORLD, MPI_SUCCESS, and Application::Success.

◆ searchParallel()

MpiPrime::Result MpiPrime::searchParallel ( int  k,
int  n,
u8 rootMap,
u8 map 
)
private

Calculate prime numbers in parallel.

Parameters
kStart number to search for primes
nUpper limit to search for primes
rootMapPointer to the root primes array
mapPointer to results array
Returns
Result code

Definition at line 146 of file MpiPrime.cpp.

References collect(), m_id, m_numberEnd, m_numberStart, SystemClock::now(), SystemClock::printDiff(), printf(), SievePrime::searchSequential(), sqrt(), and Application::Success.

Referenced by exec().

Field Documentation

◆ m_cores

Size MpiPrime::m_cores
private

Total number of cores.

Definition at line 99 of file MpiPrime.h.

Referenced by collect(), exec(), and initialize().

◆ m_id

int MpiPrime::m_id
private

MPI core identifier (rank) of the current process.

Definition at line 96 of file MpiPrime.h.

Referenced by collect(), exec(), initialize(), and searchParallel().

◆ m_mpiInitResult

int MpiPrime::m_mpiInitResult
private

Result of MPI initialization.

Definition at line 93 of file MpiPrime.h.

Referenced by initialize().

◆ m_numberEnd

Size MpiPrime::m_numberEnd
private

Prime numbers array range end for this core.

Definition at line 108 of file MpiPrime.h.

Referenced by exec(), and searchParallel().

◆ m_numbersPerCore

Size MpiPrime::m_numbersPerCore
private

Prime numbers calculated per core.

Definition at line 102 of file MpiPrime.h.

Referenced by collect(), and exec().

◆ m_numberStart

Size MpiPrime::m_numberStart
private

Prime numbers array range start for this core.

Definition at line 105 of file MpiPrime.h.

Referenced by exec(), and searchParallel().


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