FreeNOS
|
Calculate prime numbers in parallel. More...
#include <MpiPrime.h>
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... | |
ArgumentParser & | parser () |
Get program arguments parser. More... | |
const ArgumentParser & | parser () const |
Get constant program arguments parser. More... | |
const ArgumentContainer & | arguments () 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... | |
Calculate prime numbers in parallel.
Definition at line 32 of file MpiPrime.h.
MpiPrime::MpiPrime | ( | int | argc, |
char ** | argv | ||
) |
Constructor.
Definition at line 30 of file MpiPrime.cpp.
References Application::parser(), and ArgumentParser::setDescription().
|
virtual |
|
private |
Collect prime number results.
n | Upper limit to search for primes |
rootMap | Pointer to the root primes array |
map | Pointer to results array |
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().
|
virtual |
Execute the application.
Reimplemented from SievePrime.
Definition at line 68 of file MpiPrime.cpp.
References Application::arguments(), atoi(), errno, ERROR, free(), Application::IOError, m_cores, m_id, m_numberEnd, m_numbersPerCore, m_numberStart, malloc(), MPI_Finalize(), SystemClock::now(), NULL, POSIXApplication::output(), SystemClock::printDiff(), printf(), searchParallel(), sqrt(), strerror(), and Application::Success.
|
virtual |
Initialize the application.
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.
|
private |
Calculate prime numbers in parallel.
k | Start number to search for primes |
n | Upper limit to search for primes |
rootMap | Pointer to the root primes array |
map | Pointer to results array |
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().
|
private |
Total number of cores.
Definition at line 99 of file MpiPrime.h.
Referenced by collect(), exec(), and initialize().
|
private |
MPI core identifier (rank) of the current process.
Definition at line 96 of file MpiPrime.h.
Referenced by collect(), exec(), initialize(), and searchParallel().
|
private |
|
private |
Prime numbers array range end for this core.
Definition at line 108 of file MpiPrime.h.
Referenced by exec(), and searchParallel().
|
private |
Prime numbers calculated per core.
Definition at line 102 of file MpiPrime.h.
|
private |
Prime numbers array range start for this core.
Definition at line 105 of file MpiPrime.h.
Referenced by exec(), and searchParallel().