Sorting Network Search
Backtracking for Small Sorting Networks
Functions
Main.cpp File Reference

Main. More...

#include <iostream>
#include <fstream>
#include <stdexcept>
#include "Nearsort2.h"
#include "ThreadManager.h"
#include "Task.h"
#include "Timer.h"
#include "TernaryGrayCode.h"

Go to the source code of this file.

Functions

size_t getn (const std::string &strBanner)
 Get size_t from input. More...
 
bool CheckParams (const size_t n, const size_t d)
 Check that depth is reasonable for width. More...
 
void ReadParams (size_t &n, size_t &d)
 Read parameters for search. More...
 
void ReadParams (bool &bNearsort2, const size_t d)
 Read optimization settings. More...
 
void SaveSummary (const std::string s)
 Save summary string. More...
 
void Search (CThreadManager *p, const size_t nDepth, const bool bNearsort2)
 Multi-threaded search. More...
 
int main ()
 Main. More...
 

Detailed Description

Prompt the user for width (number of inputs) and depth, then spawn a multi-threaded backtracking search for sorting networks of the given width and depth. The user is also prompted to choose whether the new search hauristic nearsort2 is to the used.

Definition in file Main.cpp.

Function Documentation

◆ CheckParams()

bool CheckParams ( const size_t  n,
const size_t  d 
)

Check that depth is reasonable for width, that is, either equal to or one less than the smallest known depth. An error message is printed to stdout if it is not. This function assumes that \(n \leq 12\).

Parameters
nWidth.
dDepth.
Returns
true if depth is reasonable for width, defaults to false if width is too large..

Definition at line 71 of file Main.cpp.

◆ getn()

size_t getn ( const std::string &  strBanner)

Print a banner and read a value of type size_t.

Parameters
strBannerBanner to print before reading.
Returns
size_t value from input.

Definition at line 53 of file Main.cpp.

◆ main()

int main ( )

Get the sorting network width and depth from the user. Conduct the search and process the results.

Returns
0 (What could possibly go wrong?)

Definition at line 209 of file Main.cpp.

◆ ReadParams() [1/2]

void ReadParams ( bool &  bNearsort2,
const size_t  d 
)

Read the optimization settings.

Parameters
bNearsort2[out] true to use nearsort2 heuristic (if appropriate).
d[out] Depth.

Definition at line 135 of file Main.cpp.

◆ ReadParams() [2/2]

void ReadParams ( size_t &  n,
size_t &  d 
)

Read the sorting network width and depth.

Parameters
n[out] Width.
d[out] Depth.

Definition at line 106 of file Main.cpp.

◆ SaveSummary()

void SaveSummary ( const std::string  s)

Append a summary string to the log file log.txt and print it to the console.

Parameters
sSummary string.

Definition at line 150 of file Main.cpp.

◆ Search()

void Search ( CThreadManager p,
const size_t  nDepth,
const bool  bNearsort2 
)

Conduct multi-threaded sorting network search. First search for all level 2 candidates, then pass each one as a task to the thread manager. Get the thread manager to spawn the search threads, wait until they terminate, then process the results.

Parameters
pPointer to thread manager.
nDepthSorting network depth.
bNearsort2true to use nearsort2 heuristic (if appropriate).

Definition at line 170 of file Main.cpp.