FreeNOS
Public Member Functions | Protected Member Functions
SievePrime Class Reference

Compute prime numbers using the Sieve of Eratosthenes algorithm. More...

#include <SievePrime.h>

Inheritance diagram for SievePrime:
POSIXApplication Application MpiPrime

Public Member Functions

 SievePrime (int argc, char **argv)
 Constructor. More...
 
virtual ~SievePrime ()
 Destructor. More...
 
virtual Result exec ()
 Execute the application. 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...
 

Protected Member Functions

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 initialize ()
 Initialize the application. More...
 
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...
 

Additional Inherited Members

- Public Types inherited from Application
enum  Result {
  Success, NotFound, IOError, InvalidArgument,
  ShowUsage, TimedOut, OutOfMemory
}
 Result codes. More...
 
- Protected Attributes inherited from Application
int m_argc
 Input argument count. More...
 
char ** m_argv
 Input argument values. More...
 

Detailed Description

Compute prime numbers using the Sieve of Eratosthenes algorithm.

Definition at line 31 of file SievePrime.h.

Constructor & Destructor Documentation

◆ SievePrime()

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

Constructor.

Parameters
argcArgument count
argvArgument values

Definition at line 27 of file SievePrime.cpp.

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

◆ ~SievePrime()

SievePrime::~SievePrime ( )
virtual

Destructor.

Definition at line 35 of file SievePrime.cpp.

Member Function Documentation

◆ exec()

SievePrime::Result SievePrime::exec ( )
virtual

Execute the application.

Returns
Result code

Implements Application.

Reimplemented in MpiPrime.

Definition at line 39 of file SievePrime.cpp.

References Application::arguments(), atoi(), errno, ERROR, Application::IOError, malloc(), NULL, reportResult(), searchSequential(), sqrt(), strerror(), Application::Success, and write().

◆ reportResult()

SievePrime::Result SievePrime::reportResult ( const int  n,
const u8 map,
Size resultsWritten,
const Size  offsetNumber = 0 
) const
protected

Report the calculated results.

Parameters
nMaximum number to search for prime numbers
mapPointer to array with prime numbers
resultsWrittenNumber of results written to the output
offsetNumberAdd this constant offset value to each result
Returns
Result code

Definition at line 96 of file SievePrime.cpp.

References Application::arguments(), POSIXApplication::output(), Application::Success, and write().

Referenced by MpiPrime::collect(), and exec().

◆ searchSequential()

SievePrime::Result SievePrime::searchSequential ( const int  n,
u8 map 
) const
protected

Perform sequential search for prime numbers.

Parameters
nMaximum number to search for prime numbers
mapPointer to array with prime numbers marked

Definition at line 132 of file SievePrime.cpp.

References Application::Success.

Referenced by exec(), and MpiPrime::searchParallel().


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