The Original CHomP Software
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
chomp::multiwork::mwSubCoordinator< dim, coord > Class Template Reference

This class defines a coordinator for the multi-work subdivision framework. More...

#include <mwsubdiv.h>

Inheritance diagram for chomp::multiwork::mwSubCoordinator< dim, coord >:
chomp::multiwork::mwCoordinator chomp::multiwork::mwTask

Public Member Functions

 mwSubCoordinator ()
 The constructor of an uninitialized coordinator. More...
 
 mwSubCoordinator (const char *filename, int _inilevel, int _maxlevel, bool _flushfile, const double *_paramLeft, const double *_paramRight)
 The complete constructor of a coordinator object. More...
 
 ~mwSubCoordinator ()
 The destructor. More...
 
- Public Member Functions inherited from chomp::multiwork::mwCoordinator
 mwCoordinator ()
 The default constructor. More...
 
virtual ~mwCoordinator ()
 The virtual destructor. More...
 
void KeepWorkers (bool keep=true)
 Makes workers keep running after the coordinator's completion. More...
 
int SaveWorkers (const char *filename)
 Saves addresses of workers to the given file in the form of address:port. More...
 
void Init (mwData &data)
 Defines a portion of initialization data which will be sent to every newly connected worker. More...
 
int Coordinate (mwWorker *w=NULL)
 Run the coordinator until all the work has been completed. More...
 
- Public Member Functions inherited from chomp::multiwork::mwTask
 mwTask ()
 The default constructor. More...
 
virtual ~mwTask ()
 The destructor. More...
 
void Port (int number)
 Sets the port number for the communication or 0 to use none. More...
 
int Port () const
 Returns the current port number. More...
 
void ControlNumber (unsigned int number)
 Sets the control number for identification. More...
 
unsigned int ControlNumber () const
 Returns the currently set identification control number. More...
 
void TimeOut (int seconds)
 Sets the network connection time-out interval in seconds. More...
 
int TimeOut () const
 Returns the currently set network connection time-out interval. More...
 
int LogFile (const char *filename)
 Begins logging detailed communication debug information to the given file. More...
 
void LogFile (const mwTask &other)
 Uses another task's log file to log this task's information. More...
 
void LogClose ()
 Closes the log file and adds a line with the time information unless this log file was borrowed from another task. More...
 
int Add (const char *name, int port=-1)
 Adds an address to the list of computers to connect to at the beginning of working or coordinating. More...
 
int Load (const char *filename)
 Loads computer addresses from the given file. More...
 
int QuitWorkers ()
 Quits all the workers whose addresses were added with the 'Add' and 'Load' functions. More...
 

Private Types

typedef tCubeFix< dim, coord > ppCube
 The maximal feasible subdivision level. More...
 
typedef hashedset< ppCubeppCubes
 The type of a set of cubes in the parameter space. More...
 
typedef tRectangle< coord > ppRect
 The kind of rectangle used to iterate ranges of cubes. More...
 
typedef mwSubDataPack< dim, coord > ppPack
 The type of a sent data pack kept in an internal array. More...
 

Private Member Functions

int Prepare (mwData &data)
 A function for preparing data by a coordinator. More...
 
int Accept (mwData &data)
 A function for accepting results by a coordinator. More...
 
int Reject (mwData &data)
 A function for taking rejected data by a coordinator. More...
 
bool FindMinCube (const typename mwSubCoordinator< dim, coord >::ppCubes tab[], const typename mwSubCoordinator< dim, coord >::ppCubes sent[], int minlevel, int maxlevel, int &level, typename mwSubCoordinator< dim, coord >::ppCube &q)
 Finds a cube at the lowest level (>= min, < max) of the given set of cubes that was not sent, yet. More...
 
int Contained (const typename mwSubCoordinator< dim, coord >::ppCube &q, int level, const typename mwSubCoordinator< dim, coord >::ppCubes tab[], int minlevel) const
 Verifies if the given box is contained in a box at any level greater than or equal to the given minimum in the given family of boxes. More...
 
void NegativeProbe (const ppCube &q, int level)
 A function for acquiring a negative probe. More...
 
void GoodProbe (const ppCube &q, int level)
 A function for acquiring a good probe. More...
 
void FailedBox (const ppCube &q, int level)
 A function for acquiring a box for which the verification failed. More...
 
void SuccessfulBox (const ppCube &q, int level)
 A function for acquiring a successful box. More...
 
int ReadResults (std::istream &in)
 A procedure for reading the previously computed results. More...
 

Static Private Member Functions

static mwSubCoordinator< dim, coord >::ppCube UpLevel (const typename mwSubCoordinator< dim, coord >::ppCube &q)
 Returns a probe with respect to a higher level grid, that is, multiplies all the coordinates by 2. More...
 
static mwSubCoordinator< dim, coord >::ppCube UpLevel (const typename mwSubCoordinator< dim, coord >::ppCube &box, const typename mwSubCoordinator< dim, coord >::ppCube &corner)
 Returns a box with respect to a higher level grid which is contained in the given box and contains the given corner. More...
 
static mwSubCoordinator< dim, coord >::ppCube DownLevel (const typename mwSubCoordinator< dim, coord >::ppCube &q)
 Returns a box with respect to a higher level grid which contains the given box, that is, divides all the coordinates by 2. More...
 

Private Attributes

ppCubes Negative [ppMaxSubdiv]
 The set N: Probes for which the verification of the property was negative. More...
 
ppCubes Good [ppMaxSubdiv]
 The set G: Good probes, that is, probes for which the property was verified successfully. More...
 
ppCubes Test [ppMaxSubdiv]
 The set T: Probes which have to be sent for testing. More...
 
ppCubes CurProbes [ppMaxSubdiv]
 Part of the set C2: Currently processed probes. More...
 
ppCubes Failed [ppMaxSubdiv]
 The set F: Boxes for which the verification failed. More...
 
ppCubes Successful [ppMaxSubdiv]
 The set A: Boxes which are successfully verified to satisfy the given property and thus are contained in the set A. More...
 
ppCubes Waiting [ppMaxSubdiv]
 The set W: Boxes waiting for verification. More...
 
ppCubes CurBoxes [ppMaxSubdiv]
 Part of the set C: Currently processed boxes. More...
 
double paramLeft [dim]
 The left (minimal) vertices of the parameter cube. More...
 
double paramRight [dim]
 The right (maximal) vertices of the parameter cube. More...
 
int inilevel
 The level of subdivisions in the parameter space at which the actual computations begin. More...
 
int maxlevel
 The maximal allowed level of subdivision in the parameter space. More...
 
mwIniProbes< dim, coord > iniProbes
 An iterator of initial probes. More...
 
ppCubes iniProcessed
 A set of previously processed initial probes (used only if continuing the computations). More...
 
std::ofstream f
 A file to append the results to. More...
 
bool flushfile
 Should the results file be flushed after every write? More...
 
int current
 The counter of data packs prepared by a coordinator. More...
 
multitable< ppPacksent
 The data packs sent for processing. More...
 
int sentlen
 The number of data packs sent for processing. More...
 
int countNegative
 The number of processed probes with negative result. More...
 
int countGood
 The number of processed probes which turn out to be good. More...
 
int countFailed
 The number of processed boxes for which the verification failed. More...
 
int countSuccessful
 The number of processed boxes for which the verification was successful. More...
 

Static Private Attributes

static const int ppMaxSubdiv = 8 * sizeof (coord) - 2
 The maximal feasible subdivision level. More...
 
static const int ppMaxDim = ppCube::MaxDim
 The maximal dimension of cubes. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from chomp::multiwork::mwTask
static int SendMessage (int fd, unsigned int ctrl, unsigned int code, const mwData &x)
 Sends a message with data to the given socket. More...
 
static int RecvMessage (int fd, unsigned int &ctrl, unsigned int &code, mwData &x)
 Receives a message with data from the given socket. More...
 
- Protected Attributes inherited from chomp::multiwork::mwTask
std::ofstream * logFile
 The debug log file stream. More...
 
std::vector< std::string > computers
 A list of workers or coordinators to connect to at start-up. More...
 
std::vector< int > ports
 A list of port numbers of workers to connect to at start-up. More...
 

Detailed Description

template<int dim, class coord>
class chomp::multiwork::mwSubCoordinator< dim, coord >

This class defines a coordinator for the multi-work subdivision framework.

Definition at line 554 of file mwsubdiv.h.

Member Typedef Documentation

◆ ppCube

template<int dim, class coord >
typedef tCubeFix<dim,coord> chomp::multiwork::mwSubCoordinator< dim, coord >::ppCube
private

The maximal feasible subdivision level.

The type of a cube of parameters.

Definition at line 563 of file mwsubdiv.h.

◆ ppCubes

template<int dim, class coord >
typedef hashedset<ppCube> chomp::multiwork::mwSubCoordinator< dim, coord >::ppCubes
private

The type of a set of cubes in the parameter space.

Definition at line 569 of file mwsubdiv.h.

◆ ppPack

template<int dim, class coord >
typedef mwSubDataPack<dim,coord> chomp::multiwork::mwSubCoordinator< dim, coord >::ppPack
private

The type of a sent data pack kept in an internal array.

Definition at line 575 of file mwsubdiv.h.

◆ ppRect

template<int dim, class coord >
typedef tRectangle<coord> chomp::multiwork::mwSubCoordinator< dim, coord >::ppRect
private

The kind of rectangle used to iterate ranges of cubes.

Definition at line 572 of file mwsubdiv.h.

Constructor & Destructor Documentation

◆ mwSubCoordinator() [1/2]

template<int dim, class coord >
chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator
inline

The constructor of an uninitialized coordinator.

Definition at line 750 of file mwsubdiv.h.

751{
752 return;
753} /* mwSubCoordinator<dim,coord>::mwSubCoordinator */

◆ mwSubCoordinator() [2/2]

template<int dim, class coord >
chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator ( const char *  filename,
int  _inilevel,
int  _maxlevel,
bool  _flushfile,
const double *  _paramLeft,
const double *  _paramRight 
)

The complete constructor of a coordinator object.

Definition at line 756 of file mwsubdiv.h.

758 :
759 inilevel ((_inilevel < 2) ? 2 : _inilevel),
760 maxlevel ((_maxlevel <= inilevel) ? (inilevel + 1) : _maxlevel),
762 flushfile (_flushfile),
763 current (0), sentlen (0),
764 countNegative (0), countGood (0),
766{
767 // display a warning if no file name is provided
768 if (!filename || !*filename)
769 sout << "WARNING: No results file name given. "
770 "Computation results will not be saved.\n";
771
772 // initialize the subdivision levels
773 if (maxlevel > ppMaxSubdiv)
774 {
775 sout << "WARNING: Max subdivision level decreased from " <<
776 maxlevel << " to " << ppMaxSubdiv << ".\n";
778 if (inilevel >= maxlevel)
779 inilevel = maxlevel - 1;
780 }
781
782 // read the previously computed results of the computations
783 if (filename && *filename)
784 {
785 std::ifstream in (filename);
786 if (!in)
787 sout << "Note: Could not open the results file. "
788 "Any previous results will be ignored.\n";
789 else
790 {
791 this -> ReadResults (in);
792 in. close ();
793 }
794 }
795
796 // open the results file for appending
797 if (filename && *filename)
798 {
799 f. open (filename, std::ios::out | std::ios::app);
800 f << "; Started on " << currenttime ();
801 if (flushfile)
802 f << std::flush;
803 }
804
805 // copy the left and right ends of the intervals
806 for (int i = 0; i < dim; ++ i)
807 {
808 paramLeft [i] = _paramLeft [i];
809 paramRight [i] = _paramRight [i];
810 }
811
812 return;
813} /* mwSubCoordinator<dim,coord>::mwSubCoordinator */
static const int ppMaxSubdiv
The maximal feasible subdivision level.
Definition: mwsubdiv.h:557
bool flushfile
Should the results file be flushed after every write?
Definition: mwsubdiv.h:709
int inilevel
The level of subdivisions in the parameter space at which the actual computations begin.
Definition: mwsubdiv.h:691
mwIniProbes< dim, coord > iniProbes
An iterator of initial probes.
Definition: mwsubdiv.h:697
int countFailed
The number of processed boxes for which the verification failed.
Definition: mwsubdiv.h:734
int countGood
The number of processed probes which turn out to be good.
Definition: mwsubdiv.h:731
std::ofstream f
A file to append the results to.
Definition: mwsubdiv.h:706
double paramRight[dim]
The right (maximal) vertices of the parameter cube.
Definition: mwsubdiv.h:687
int sentlen
The number of data packs sent for processing.
Definition: mwsubdiv.h:723
double paramLeft[dim]
The left (minimal) vertices of the parameter cube.
Definition: mwsubdiv.h:684
int countNegative
The number of processed probes with negative result.
Definition: mwsubdiv.h:728
int current
The counter of data packs prepared by a coordinator.
Definition: mwsubdiv.h:717
int ReadResults(std::istream &in)
A procedure for reading the previously computed results.
Definition: mwsubdiv.h:1378
int maxlevel
The maximal allowed level of subdivision in the parameter space.
Definition: mwsubdiv.h:694
int countSuccessful
The number of processed boxes for which the verification was successful.
Definition: mwsubdiv.h:738
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
const char * currenttime(void)
Retrieves the current time as a pointer to a C-style string.
Definition: textfile.h:454

References chomp::homology::currenttime(), chomp::multiwork::mwSubCoordinator< dim, coord >::f, chomp::multiwork::mwSubCoordinator< dim, coord >::flushfile, chomp::multiwork::mwSubCoordinator< dim, coord >::inilevel, chomp::multiwork::mwSubCoordinator< dim, coord >::maxlevel, chomp::multiwork::mwSubCoordinator< dim, coord >::paramLeft, chomp::multiwork::mwSubCoordinator< dim, coord >::paramRight, chomp::multiwork::mwSubCoordinator< dim, coord >::ppMaxSubdiv, chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults(), and chomp::homology::sout.

◆ ~mwSubCoordinator()

template<int dim, class coord >
chomp::multiwork::mwSubCoordinator< dim, coord >::~mwSubCoordinator
inline

The destructor.

Definition at line 816 of file mwsubdiv.h.

817{
818 f << "; A total of " << (countNegative + countGood) <<
819 " probes and " << (countFailed + countSuccessful) <<
820 " boxes have been processed.\n";
821 f << "; The verification was negative for " << countNegative <<
822 " probes, and " << countGood << " probes were good.\n";
823 f << "; The verification failed for " << countFailed <<
824 " boxes, and was successful for " << countSuccessful <<
825 " boxes.\n";
826 f << "; Finished on " << currenttime ();
827 f << "; ---------------------------------------------------\n";
828 f. close ();
829 return;
830} /* mwSubCoordinator<dim,coord>::~mwSubCoordinator */

References chomp::homology::currenttime().

Member Function Documentation

◆ Accept()

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Accept ( mwData data)
privatevirtual

A function for accepting results by a coordinator.

Reimplemented from chomp::multiwork::mwCoordinator.

Definition at line 1286 of file mwsubdiv.h.

1287{
1288 // decode the data pack number
1289 int n = 0;
1290 data >> n;
1291
1292 // decode the result
1293 int result = 0;
1294 data >> result;
1295
1296 // say what has been received
1297 sout << "* " << n << " " << result << ".\n";
1298
1299 // find this data among the data packs that were sent for processing
1300 int pos = 0;
1301 while ((pos < sentlen) && (sent [pos]. num != n))
1302 ++ pos;
1303 if (pos >= sentlen)
1304 {
1305 sout << "ERROR: Wrong data pack number received "
1306 "from a worker.\n";
1307 return mwError;
1308 }
1309 const ppPack &pack = sent [pos];
1310
1311 // save the data to the output file
1312 f << (pack. full ? "* " : "@ ") << n << " " << result <<
1313 " " << pack. level << " " << pack. q << ".\n";
1314 if (flushfile)
1315 f << std::flush;
1316
1317 // extract the data from the data pack
1318 const ppCube &q = pack. q;
1319 int level = pack. level;
1320 bool full = pack. full;
1321
1322 // remove the cube from appropriate sets and process it
1323 if (full)
1324 {
1325 CurBoxes [level]. remove (q);
1326 Waiting [level]. remove (q);
1327 if (result)
1328 {
1329 ++ countSuccessful;
1330 SuccessfulBox (q, level);
1331 }
1332 else
1333 {
1334 ++ countFailed;
1335 FailedBox (q, level);
1336 }
1337 }
1338 else
1339 {
1340 CurProbes [level]. remove (q);
1341 Test [level]. remove (q);
1342 if (result)
1343 {
1344 ++ countGood;
1345 GoodProbe (q, level);
1346 }
1347 else
1348 {
1349 ++ countNegative;
1350 NegativeProbe (q, level);
1351 }
1352 }
1353
1354 // remove the data pack from the table containing the data packs
1355 -- sentlen;
1356 if (pos != sentlen)
1357 sent [pos] = sent [sentlen];
1358
1359 return mwOk;
1360} /* mwSubCoordinator<dim,coord>::Accept */
void NegativeProbe(const ppCube &q, int level)
A function for acquiring a negative probe.
Definition: mwsubdiv.h:1078
void GoodProbe(const ppCube &q, int level)
A function for acquiring a good probe.
Definition: mwsubdiv.h:1108
void FailedBox(const ppCube &q, int level)
A function for acquiring a box for which the verification failed.
Definition: mwsubdiv.h:1150
tCubeFix< dim, coord > ppCube
The maximal feasible subdivision level.
Definition: mwsubdiv.h:563
ppCubes CurBoxes[ppMaxSubdiv]
Part of the set C: Currently processed boxes.
Definition: mwsubdiv.h:628
ppCubes Test[ppMaxSubdiv]
The set T: Probes which have to be sent for testing.
Definition: mwsubdiv.h:612
void SuccessfulBox(const ppCube &q, int level)
A function for acquiring a successful box.
Definition: mwsubdiv.h:1202
mwSubDataPack< dim, coord > ppPack
The type of a sent data pack kept in an internal array.
Definition: mwsubdiv.h:575
ppCubes Waiting[ppMaxSubdiv]
The set W: Boxes waiting for verification.
Definition: mwsubdiv.h:625
ppCubes CurProbes[ppMaxSubdiv]
Part of the set C2: Currently processed probes.
Definition: mwsubdiv.h:615
multitable< ppPack > sent
The data packs sent for processing.
Definition: mwsubdiv.h:720
@ mwError
A serious error occurred.
Definition: mwconfig.h:162
@ mwOk
Everything is fine.
Definition: mwconfig.h:159

References chomp::multiwork::mwError, chomp::multiwork::mwOk, and chomp::homology::sout.

◆ Contained()

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Contained ( const typename mwSubCoordinator< dim, coord >::ppCube q,
int  level,
const typename mwSubCoordinator< dim, coord >::ppCubes  tab[],
int  minlevel 
) const
private

Verifies if the given box is contained in a box at any level greater than or equal to the given minimum in the given family of boxes.

Returns the level of a box which is found or 0 if none.

Definition at line 1054 of file mwsubdiv.h.

1058{
1059 // verify if the box itself is contained in any set of boxes
1060 if (tab [level]. check (q))
1061 return level;
1062
1063 // subdivide the box and verify at a higher level
1064 if (minlevel < inilevel)
1065 minlevel = inilevel;
1066 ppCube box = q;
1067 while (-- level > minlevel)
1068 {
1069 box = DownLevel (box);
1070 if (tab [level]. check (box))
1071 return level;
1072 }
1073
1074 return 0;
1075} /* mwSubCoordinator::Contained */
static mwSubCoordinator< dim, coord >::ppCube DownLevel(const typename mwSubCoordinator< dim, coord >::ppCube &q)
Returns a box with respect to a higher level grid which contains the given box, that is,...
Definition: mwsubdiv.h:1044

◆ DownLevel()

template<int dim, class coord >
mwSubCoordinator< dim, coord >::ppCube chomp::multiwork::mwSubCoordinator< dim, coord >::DownLevel ( const typename mwSubCoordinator< dim, coord >::ppCube q)
staticprivate

Returns a box with respect to a higher level grid which contains the given box, that is, divides all the coordinates by 2.

Definition at line 1043 of file mwsubdiv.h.

1045{
1046 coord c [dim];
1047 q. coord (c);
1048 for (int i = 0; i < dim; ++ i)
1049 c [i] >>= 1;
1050 return ppCube (c, dim);
1051} /* mwSubCoordinator::DownLevel */

◆ FailedBox()

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::FailedBox ( const ppCube q,
int  level 
)
private

A function for acquiring a box for which the verification failed.

Definition at line 1150 of file mwsubdiv.h.

1151{
1152 // add the box to the list of boxes which failed
1153 Failed [level]. add (q);
1154 sbug << "@ FailedBox [" << level << "]: " << q << "\n";
1155
1156 // if no further subdivisions are to be considered then quit here
1157 if (level + 1 == maxlevel)
1158 return;
1159
1160 // consider all the corners of the box
1161 mwCorners<dim,coord> corners (q);
1162 while (corners. available ())
1163 {
1164 // take the next corner of the box
1165 ppCube c = corners. get ();
1166
1167 // if this is a negative probe then skip it
1168 if (Negative [level]. check (c))
1169 continue;
1170
1171 // if this probe has not yet been checked
1172 // then add it to the list of probes to test
1173 if (!Good [level]. check (c))
1174 {
1175 Test [level]. add (c);
1176 sbug << "+ Test [" << level << "]: " << c << "\n";
1177 continue;
1178 }
1179
1180 // add a twice smaller box located at the given corner
1181 // to the list of boxes which wait for being verified,
1182 // unless the result for this box is already known
1183 ppCube box = UpLevel (q, c);
1184 if (!Successful [level + 1]. check (box) &&
1185 !Failed [level + 1]. check (box))
1186 {
1187 Waiting [level + 1]. add (box);
1188 sbug << "+ Waiting [" << (level + 1) << "]: " <<
1189 box << "\n";
1190 }
1191
1192 // mark the probe as good at the higher subdivision level
1193 ppCube probe = UpLevel (c);
1194 Good [level + 1]. add (probe);
1195 sbug << "+ Good [" << (level + 1) << "]: " << probe << "\n";
1196 }
1197
1198 return;
1199} /* mwSubCoordinator::FailedBox */
static mwSubCoordinator< dim, coord >::ppCube UpLevel(const typename mwSubCoordinator< dim, coord >::ppCube &q)
Returns a probe with respect to a higher level grid, that is, multiplies all the coordinates by 2.
Definition: mwsubdiv.h:1012
ppCubes Failed[ppMaxSubdiv]
The set F: Boxes for which the verification failed.
Definition: mwsubdiv.h:618
ppCubes Negative[ppMaxSubdiv]
The set N: Probes for which the verification of the property was negative.
Definition: mwsubdiv.h:605
ppCubes Good[ppMaxSubdiv]
The set G: Good probes, that is, probes for which the property was verified successfully.
Definition: mwsubdiv.h:609
ppCubes Successful[ppMaxSubdiv]
The set A: Boxes which are successfully verified to satisfy the given property and thus are contained...
Definition: mwsubdiv.h:622
outputstream sbug
An output stream for writing additional debug messages.

References chomp::homology::sbug.

◆ FindMinCube()

template<int dim, class coord >
bool chomp::multiwork::mwSubCoordinator< dim, coord >::FindMinCube ( const typename mwSubCoordinator< dim, coord >::ppCubes  tab[],
const typename mwSubCoordinator< dim, coord >::ppCubes  sent[],
int  minlevel,
int  maxlevel,
int &  level,
typename mwSubCoordinator< dim, coord >::ppCube q 
)
inlineprivate

Finds a cube at the lowest level (>= min, < max) of the given set of cubes that was not sent, yet.

Modifies 'level' and 'q'. Returns true if found, false if not found.

Definition at line 835 of file mwsubdiv.h.

840{
841 for (int l = minlevel; l < maxlevel; ++ l)
842 {
843 const ppCubes &theSet = tab [l];
844 const ppCubes &sentSet = sent [l];
845 int number = theSet. size ();
846 for (int i = number - 1; i >= 0; -- i)
847 {
848 const ppCube &c = theSet [i];
849 if (!sentSet. check (c))
850 {
851 level = l;
852 q = c;
853 return true;
854 }
855 }
856 }
857 return false;
858} /* mwSubCoordinator::FindMinCube */
hashedset< ppCube > ppCubes
The type of a set of cubes in the parameter space.
Definition: mwsubdiv.h:569

◆ GoodProbe()

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::GoodProbe ( const ppCube q,
int  level 
)
private

A function for acquiring a good probe.

Definition at line 1108 of file mwsubdiv.h.

1109{
1110 // if it is already known that this probe is good then skip it
1111 if (Good [level]. check (q))
1112 {
1113 sbug << "@ GoodKnown [" << level << "]: " << q << "\n";
1114 return;
1115 }
1116
1117 // add the probe to the set of good probes at its level
1118 Good [level]. add (q);
1119 sbug << "@ GoodProbe [" << level << "]: " << q << "\n";
1120
1121 // if the next level is beyond the scope then quit here
1122 if (level + 1 == maxlevel)
1123 return;
1124
1125 // transfer the probe to the next level and remember that it is good
1126 ppCube probe = UpLevel (q);
1127 Good [level + 1]. add (probe);
1128 sbug << "+ GoodProbe [" << (level + 1) << "]: " << probe << "\n";
1129
1130 // consider all the boxes which contain this probe
1131 mwBoxes<dim,coord> boxes (probe);
1132 while (boxes. available ())
1133 {
1134 // if the box is not contained in any larger successful box
1135 // then add it to the waiting list
1136 ppCube box = boxes. get ();
1137 if (!Contained (box, level + 1, Successful, 0))
1138 {
1139
1140 Waiting [level + 1]. add (box);
1141 sbug << "+ Waiting [" << (level + 1) << "]: " <<
1142 box << "\n";
1143 }
1144 }
1145
1146 return;
1147} /* mwSubCoordinator::GoodProbe */
int Contained(const typename mwSubCoordinator< dim, coord >::ppCube &q, int level, const typename mwSubCoordinator< dim, coord >::ppCubes tab[], int minlevel) const
Verifies if the given box is contained in a box at any level greater than or equal to the given minim...
Definition: mwsubdiv.h:1055

References chomp::homology::sbug.

◆ NegativeProbe()

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::NegativeProbe ( const ppCube q,
int  level 
)
private

A function for acquiring a negative probe.

Definition at line 1078 of file mwsubdiv.h.

1079{
1080 // add the probe to the set of negative probes
1081 Negative [level]. add (q);
1082 sbug << "@ NegProbe [" << level << "]: " << q << "\n";
1083
1084 // boxes around this probe automatically fail, so remove them
1085 // from the queue and interpret them as failed boxes
1086 mwBoxes<dim,coord> boxes (q);
1087 while (boxes. available ())
1088 {
1089 // take a box which has this probe in its corner
1090 ppCube box = boxes. get ();
1091
1092 // if it is waiting for processing but was not sent yet
1093 // then pretend it has just returned as a failed box
1094 if (Waiting [level]. check (box) &&
1095 !CurBoxes [level]. check (box))
1096 {
1097 sbug << "# FailedBox [" << level << "]: " <<
1098 box << "\n";
1099 Waiting [level]. remove (box);
1100 FailedBox (box, level);
1101 }
1102 }
1103
1104 return;
1105} /* mwSubCoordinator::NegativeProbe */

References chomp::homology::sbug.

◆ Prepare()

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Prepare ( mwData data)
privatevirtual

A function for preparing data by a coordinator.

Reimplemented from chomp::multiwork::mwCoordinator.

Definition at line 861 of file mwsubdiv.h.

862{
863 // prepare a data pack to send
864 ppPack &pack = sent [sentlen];
865
866 // if there is any initial probe that has not yet been processed
867 // then take this probe
868 bool iniProbe = false;
869 while (iniProbes. available ())
870 {
871 pack = ppPack (current, iniProbes. get (), inilevel, false);
872 if (iniProcessed. check (pack. q))
873 {
874 iniProcessed. remove (pack. q);
875 continue;
876 }
877 else
878 {
879 iniProbe = true;
880 break;
881 }
882 }
883
884 // otherwise send a probe or a box which is waiting to be verified
885 if (!iniProbe)
886 {
887 // find a probe for testing at the lowest level available
888 int levelT = 0;
889 ppCube cubeT;
890 bool foundT = this -> FindMinCube (Test, CurProbes,
891 inilevel, maxlevel, levelT, cubeT);
892
893 // find a box that is waiting at the lowest level available
894 int levelW = 0;
895 ppCube cubeW;
896 bool foundW = this -> FindMinCube (Waiting, CurBoxes,
897 inilevel, maxlevel, levelW, cubeW);
898
899 // if no cube for processing can be found, then interrupt
900 if (!foundT && !foundW)
901 return mwNoData;
902
903 // send the probe found if this is the right thing to do
904 if (foundT && (!foundW || (levelT <= levelW)))
905 {
906 pack = ppPack (current, cubeT, levelT, false);
907 CurProbes [levelT]. add (cubeT);
908 }
909 // otherwise send the box found
910 else
911 {
912 pack = ppPack (current, cubeW, levelW, true);
913 CurBoxes [levelW]. add (cubeW);
914 }
915 }
916
917 // prepare the intervals of parameters corresponding to the cube
918 coord c [ppMaxDim];
919 pack. q. coord (c);
920 int fullSize = 1 << pack. level;
921 double left [ppMaxDim];
922 double right [ppMaxDim];
923 for (int i = 0; i < dim; ++ i)
924 {
925 // prepare the probe or the left corner of the box
926 left [i] = mwSubdivPoint (paramLeft [i], paramRight [i],
927 c [i], fullSize);
928
929 // if this is a full box then compute the right corner, too
930 if (pack. full)
931 {
932 // prepare the right corner of the box
933 right [i] = mwSubdivPoint (paramLeft [i],
934 paramRight [i], c [i] + 1, fullSize);
935
936 // if the resolution of the representable numbers
937 // has been reached then set this level to be
938 // the strict upper bound for the subdivision level
939 if (left [i] == right [i])
940 {
941 // leave a note of this situation in the file
942 f << "; The resolution of representable "
943 "numbers exceeded.\n; Decreasing "
944 "max level from " << maxlevel <<
945 " to " << pack. level << ".\n";
946 if (flushfile)
947 f << std::flush;
948
949 // notify the user about this situation
950 sout << "WARNING: The resolution of "
951 "representable numbers exceeded.\n"
952 "Decreasing max level from " <<
953 maxlevel << " to " << pack. level <<
954 ".\n";
955
956 // decrease the max level limit
957 maxlevel = pack. level;
958 return mwNoData;
959 }
960 }
961 }
962
963 // write th information on the prepared cube to the results file
964 f << "+ " << pack. num;
965 for (int i = 0; i < dim; ++ i)
966 {
967 f << (i ? "x[" : " [") << left [i];
968 if (pack. full)
969 f << "," << right [i];
970 f << "]";
971 }
972 f << ".\n";
973 if (flushfile)
974 f << std::flush;
975
976 // send the data pack number
977 data << pack. num;
978
979 // send the subdivision level
980 data << pack. level;
981
982 // send the information on whether this is a full box or a probe
983 data << pack. full;
984
985 // send the intervals (left and right ends where applicable)
986 for (int i = 0; i < dim; ++ i)
987 {
988 data << left [i];
989 if (pack. full)
990 data << right [i];
991 }
992
993 // append the data end marker for extra verification
994 const int dataEndMarker = 13;
995 data << dataEndMarker;
996
997 // show a message on which data pack has been prepared
998 sout << "+ " << pack. num << ".\n";
999
1000 // increase the counters
1001 ++ current;
1002 ++ sentlen;
1003
1004 return mwOk;
1005} /* mwSubCoordinator<dim,coord>::Prepare */
static const int ppMaxDim
The maximal dimension of cubes.
Definition: mwsubdiv.h:566
bool FindMinCube(const typename mwSubCoordinator< dim, coord >::ppCubes tab[], const typename mwSubCoordinator< dim, coord >::ppCubes sent[], int minlevel, int maxlevel, int &level, typename mwSubCoordinator< dim, coord >::ppCube &q)
Finds a cube at the lowest level (>= min, < max) of the given set of cubes that was not sent,...
Definition: mwsubdiv.h:836
ppCubes iniProcessed
A set of previously processed initial probes (used only if continuing the computations).
Definition: mwsubdiv.h:701
double mwSubdivPoint(const double &left, const double &right, coord part, coord full)
Returns a subdivision point corresponding to the given fraction of the provided interval.
Definition: mwsubdiv.h:202
@ mwNoData
There is no data to be sent to workers, for example, because everything has been already sent.
Definition: mwconfig.h:166

References chomp::multiwork::mwNoData, chomp::multiwork::mwOk, chomp::multiwork::mwSubdivPoint(), and chomp::homology::sout.

◆ ReadResults()

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::ReadResults ( std::istream &  in)
private

A procedure for reading the previously computed results.

Definition at line 1378 of file mwsubdiv.h.

1379{
1380 ignorecomments (in);
1381 while (!in. eof ())
1382 {
1383 // read the first char and interprete the line
1384 int ch = in. get ();
1385
1386 // ignore the line if it contains no useful information
1387 if ((ch != '*') && (ch != '@'))
1388 {
1389 ignoreline (in);
1390 ignorecomments (in);
1391 continue;
1392 }
1393
1394 // read the data number if relevant
1395 if ((ch == '*') || (ch == '@'))
1396 {
1397 int n = -1;
1398 in >> n;
1399 if (n < 0)
1400 break;
1401 }
1402
1403 // read the result if any
1404 int result = -1;
1405 if ((ch == '*') || (ch == '@'))
1406 {
1407 in >> result;
1408 if (result < 0)
1409 break;
1410 }
1411
1412 // read the subdivision level of the cube
1413 int level = -1;
1414 in >> level;
1415 if (level < 0)
1416 break;
1417
1418 // read the cube itself
1419 ppCube q;
1420 in >> q;
1421
1422 // make sure that there is the dot which ends the line
1423 if (in. peek () != '.')
1424 break;
1425
1426 // ignore the remaining part of the line
1427 ignoreline (in);
1428 ignorecomments (in);
1429
1430 // process the data as necessary
1431 if (ch == '*')
1432 {
1433 Waiting [level]. remove (q);
1434 if (result)
1435 SuccessfulBox (q, level);
1436 else
1437 FailedBox (q, level);
1438 }
1439 else if (ch == '@')
1440 {
1441 if (level == inilevel)
1442 iniProcessed. add (q);
1443 else
1444 Test [level]. remove (q);
1445 if (result)
1446 GoodProbe (q, level);
1447 else
1448 NegativeProbe (q, level);
1449 }
1450 }
1451
1452 return 0;
1453} /* mwSubCoordinator<dim,coord>::ReadResults */
void ignoreline(std::istream &in)
Ignores the input characters until the end of a line, including this end of the line.
Definition: textfile.h:376
void ignorecomments(std::istream &in)
Ignores white characters (spaces, tabulators, CRs and LFs), as well as comments from the input text f...
Definition: textfile.h:385

References chomp::homology::ignorecomments(), and chomp::homology::ignoreline().

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ Reject()

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::Reject ( mwData data)
privatevirtual

A function for taking rejected data by a coordinator.

Reimplemented from chomp::multiwork::mwCoordinator.

Definition at line 1363 of file mwsubdiv.h.

1364{
1365 // decode the number
1366 int n = 0;
1367 data >> n;
1368
1369 // say that data has been rejected
1370 sout << "!!! Data no. " << n << " rejected.\n";
1371
1372 return mwError;
1373} /* mwSubCoordinator<dim,coord>::Reject */

References chomp::multiwork::mwError, and chomp::homology::sout.

◆ SuccessfulBox()

template<int dim, class coord >
void chomp::multiwork::mwSubCoordinator< dim, coord >::SuccessfulBox ( const ppCube q,
int  level 
)
private

A function for acquiring a successful box.

Definition at line 1202 of file mwsubdiv.h.

1203{
1204 // if the box has already been added then skip it
1205 if (Successful [level]. check (q))
1206 {
1207 sbug << "@ SuccessKnown [" << level << "]: " << q << "\n";
1208 return;
1209 }
1210
1211 // if this box is already contained in a larger successful box
1212 // then ignore it
1213 if (Contained (q, level, Successful, 0))
1214 {
1215 sbug << "@ SuccessSubset [" << level << "]: " << q << "\n";
1216 return;
1217 }
1218
1219 // add the box to the set of successful boxes which form the set A
1220 Successful [level]. add (q);
1221 sbug << "@ SuccessBox [" << level << "]: " << q << "\n";
1222
1223 // consider all the vertices of this box
1224 mwCorners<dim,coord> corners (q);
1225 while (corners. available ())
1226 {
1227 // take the next corner of the box
1228 ppCube c = corners. get ();
1229
1230 // remove the corner probe from a list of probes to test
1231 if (Test [level]. check (c))
1232 {
1233 Test [level]. remove (c);
1234 sbug << "- Test [" << level << "]: " << c << "\n";
1235 }
1236
1237 // remove the corner box from a list of boxes to test
1238 ppCube cornerBox = UpLevel (q, c);
1239 if (Waiting [level + 1]. check (cornerBox))
1240 {
1241 Waiting [level + 1]. remove (cornerBox);
1242 sbug << "- Waiting [" << (level + 1) << "]: " <<
1243 cornerBox << "\n";
1244 // note: there might be some boxes contained in q
1245 // waiting at deeper levels, but determining them
1246 // might be quite inefficient,
1247 // so they are not cleaned in this implementation
1248 // of the algorithm
1249 }
1250
1251 // if the probe is already known to be good then skip it
1252 if (Good [level]. check (c))
1253 continue;
1254
1255 // add the probe to the list of good ones
1256 Good [level]. add (c);
1257 sbug << "+ Good [" << level << "]: " << c << "\n";
1258
1259 // propagate the probe one level deeper and mark it as good
1260 ppCube probe = UpLevel (c);
1261 Good [level + 1]. add (probe);
1262 sbug << "+ Good [" << (level + 1) << "]: " << probe << "\n";
1263
1264 // consider all the boxes which contain this probe
1265 mwBoxes<dim,coord> boxes (probe);
1266 while (boxes. available ())
1267 {
1268 // take the next box
1269 ppCube box = boxes. get ();
1270
1271 // if this box is not contained in any successful
1272 // larger box then add it to the waiting list
1273 if (!Contained (box, level + 1, Successful, 0))
1274 {
1275 Waiting [level + 1]. add (box);
1276 sbug << "+ Waiting [" << (level + 1) <<
1277 "]: " << box << "\n";
1278 }
1279 }
1280 }
1281
1282 return;
1283} /* mwSubCoordinator::SuccessfulBox */

References chomp::homology::sbug.

◆ UpLevel() [1/2]

template<int dim, class coord >
mwSubCoordinator< dim, coord >::ppCube chomp::multiwork::mwSubCoordinator< dim, coord >::UpLevel ( const typename mwSubCoordinator< dim, coord >::ppCube box,
const typename mwSubCoordinator< dim, coord >::ppCube corner 
)
staticprivate

Returns a box with respect to a higher level grid which is contained in the given box and contains the given corner.

Definition at line 1023 of file mwsubdiv.h.

1026{
1027 coord cBox [dim];
1028 box. coord (cBox);
1029 coord cCorner [dim];
1030 corner. coord (cCorner);
1031 for (int i = 0; i < dim; ++ i)
1032 {
1033 if (cBox [i] == cCorner [i])
1034 cBox [i] <<= 1;
1035 else
1036 cBox [i] = (cBox [i] << 1) + 1;
1037 }
1038 return ppCube (cBox, dim);
1039} /* mwSubCoordinator::UpLevel */

◆ UpLevel() [2/2]

template<int dim, class coord >
mwSubCoordinator< dim, coord >::ppCube chomp::multiwork::mwSubCoordinator< dim, coord >::UpLevel ( const typename mwSubCoordinator< dim, coord >::ppCube q)
staticprivate

Returns a probe with respect to a higher level grid, that is, multiplies all the coordinates by 2.

Definition at line 1011 of file mwsubdiv.h.

1013{
1014 coord c [dim];
1015 q. coord (c);
1016 for (int i = 0; i < dim; ++ i)
1017 c [i] <<= 1;
1018 return ppCube (c, dim);
1019} /* mwSubCoordinator::UpLevel */

Member Data Documentation

◆ countFailed

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::countFailed
private

The number of processed boxes for which the verification failed.

Definition at line 734 of file mwsubdiv.h.

◆ countGood

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::countGood
private

The number of processed probes which turn out to be good.

Definition at line 731 of file mwsubdiv.h.

◆ countNegative

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::countNegative
private

The number of processed probes with negative result.

Definition at line 728 of file mwsubdiv.h.

◆ countSuccessful

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::countSuccessful
private

The number of processed boxes for which the verification was successful.

Definition at line 738 of file mwsubdiv.h.

◆ CurBoxes

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::CurBoxes[ppMaxSubdiv]
private

Part of the set C: Currently processed boxes.

Definition at line 628 of file mwsubdiv.h.

◆ CurProbes

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::CurProbes[ppMaxSubdiv]
private

Part of the set C2: Currently processed probes.

Definition at line 615 of file mwsubdiv.h.

◆ current

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::current
private

The counter of data packs prepared by a coordinator.

Definition at line 717 of file mwsubdiv.h.

◆ f

template<int dim, class coord >
std::ofstream chomp::multiwork::mwSubCoordinator< dim, coord >::f
private

A file to append the results to.

Definition at line 706 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ Failed

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Failed[ppMaxSubdiv]
private

The set F: Boxes for which the verification failed.

Definition at line 618 of file mwsubdiv.h.

◆ flushfile

template<int dim, class coord >
bool chomp::multiwork::mwSubCoordinator< dim, coord >::flushfile
private

Should the results file be flushed after every write?

Definition at line 709 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ Good

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Good[ppMaxSubdiv]
private

The set G: Good probes, that is, probes for which the property was verified successfully.

Definition at line 609 of file mwsubdiv.h.

◆ inilevel

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::inilevel
private

The level of subdivisions in the parameter space at which the actual computations begin.

Definition at line 691 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ iniProbes

template<int dim, class coord >
mwIniProbes<dim,coord> chomp::multiwork::mwSubCoordinator< dim, coord >::iniProbes
private

An iterator of initial probes.

Definition at line 697 of file mwsubdiv.h.

◆ iniProcessed

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::iniProcessed
private

A set of previously processed initial probes (used only if continuing the computations).

Definition at line 701 of file mwsubdiv.h.

◆ maxlevel

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::maxlevel
private

The maximal allowed level of subdivision in the parameter space.

Definition at line 694 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ Negative

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Negative[ppMaxSubdiv]
private

The set N: Probes for which the verification of the property was negative.

Definition at line 605 of file mwsubdiv.h.

◆ paramLeft

template<int dim, class coord >
double chomp::multiwork::mwSubCoordinator< dim, coord >::paramLeft[dim]
private

The left (minimal) vertices of the parameter cube.

Definition at line 684 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ paramRight

template<int dim, class coord >
double chomp::multiwork::mwSubCoordinator< dim, coord >::paramRight[dim]
private

The right (maximal) vertices of the parameter cube.

Definition at line 687 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ ppMaxDim

template<int dim, class coord >
const int chomp::multiwork::mwSubCoordinator< dim, coord >::ppMaxDim = ppCube::MaxDim
staticprivate

The maximal dimension of cubes.

Definition at line 566 of file mwsubdiv.h.

◆ ppMaxSubdiv

template<int dim, class coord >
const int chomp::multiwork::mwSubCoordinator< dim, coord >::ppMaxSubdiv = 8 * sizeof (coord) - 2
staticprivate

The maximal feasible subdivision level.

Definition at line 557 of file mwsubdiv.h.

Referenced by chomp::multiwork::mwSubCoordinator< dim, coord >::mwSubCoordinator().

◆ sent

template<int dim, class coord >
multitable<ppPack> chomp::multiwork::mwSubCoordinator< dim, coord >::sent
private

The data packs sent for processing.

Definition at line 720 of file mwsubdiv.h.

◆ sentlen

template<int dim, class coord >
int chomp::multiwork::mwSubCoordinator< dim, coord >::sentlen
private

The number of data packs sent for processing.

Definition at line 723 of file mwsubdiv.h.

◆ Successful

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Successful[ppMaxSubdiv]
private

The set A: Boxes which are successfully verified to satisfy the given property and thus are contained in the set A.

Definition at line 622 of file mwsubdiv.h.

◆ Test

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Test[ppMaxSubdiv]
private

The set T: Probes which have to be sent for testing.

Definition at line 612 of file mwsubdiv.h.

◆ Waiting

template<int dim, class coord >
ppCubes chomp::multiwork::mwSubCoordinator< dim, coord >::Waiting[ppMaxSubdiv]
private

The set W: Boxes waiting for verification.

Definition at line 625 of file mwsubdiv.h.


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