REST_OF_THE_WORLD constant in assignmentAlgorithm.

This commit is contained in:
Benjamin Bouvier 2012-06-22 17:40:00 +02:00
commit ac13550faa
3 changed files with 24 additions and 7 deletions

View file

@ -3,6 +3,12 @@
# include <vector> # include <vector>
# include "MpiNode.h" # include "MpiNode.h"
namespace eo
{
const int REST_OF_THE_WORLD = -1;
}
struct AssignmentAlgorithm struct AssignmentAlgorithm
{ {
virtual int get( ) = 0; virtual int get( ) = 0;
@ -35,6 +41,11 @@ struct DynamicAssignmentAlgorithm : public AssignmentAlgorithm
DynamicAssignmentAlgorithm( int first, int last ) DynamicAssignmentAlgorithm( int first, int last )
{ {
if( last == eo::REST_OF_THE_WORLD )
{
last = MpiNode::comm().size() - 1;
}
for( int i = first; i <= last; ++i) for( int i = first; i <= last; ++i)
{ {
availableWrk.push_back( i ); availableWrk.push_back( i );
@ -82,6 +93,12 @@ struct StaticAssignmentAlgorithm : public AssignmentAlgorithm
StaticAssignmentAlgorithm( int first, int last, int runs ) StaticAssignmentAlgorithm( int first, int last, int runs )
{ {
std::vector<int> workers; std::vector<int> workers;
if( last == eo::REST_OF_THE_WORLD )
{
last = MpiNode::comm().size() - 1;
}
for(int i = first; i <= last; ++i) for(int i = first; i <= last; ++i)
{ {
workers.push_back( i ); workers.push_back( i );

View file

@ -24,7 +24,7 @@ struct plusOne : public eoUF< int&, void >
void subtask( vector<int>& v ) void subtask( vector<int>& v )
{ {
DynamicAssignmentAlgorithm algo( 2, MpiNode::comm().size()-1 ); DynamicAssignmentAlgorithm algo( 2, eo::REST_OF_THE_WORLD );
plusOne plusOneInstance; plusOne plusOneInstance;
ParallelApply<int> job( plusOneInstance, v, algo, 1 ); ParallelApply<int> job( plusOneInstance, v, algo, 1 );
job.run(); job.run();

View file

@ -44,7 +44,7 @@ int main(int argc, char** argv)
const int ALL = MpiNode::comm().size(); const int ALL = MpiNode::comm().size();
Test tIntervalStatic; Test tIntervalStatic;
tIntervalStatic.assign = new StaticAssignmentAlgorithm( 1, MpiNode::comm().size()-1, v.size() ); tIntervalStatic.assign = new StaticAssignmentAlgorithm( 1, eo::REST_OF_THE_WORLD, v.size() );
tIntervalStatic.description = "Correct static assignment with interval."; tIntervalStatic.description = "Correct static assignment with interval.";
tIntervalStatic.requiredNodesNumber = ALL; tIntervalStatic.requiredNodesNumber = ALL;
tests.push_back( tIntervalStatic ); tests.push_back( tIntervalStatic );
@ -77,26 +77,26 @@ int main(int argc, char** argv)
tests.push_back( tVectorStatic ); tests.push_back( tVectorStatic );
Test tIntervalDynamic; Test tIntervalDynamic;
tIntervalDynamic.assign = new StaticAssignmentAlgorithm( 1, MpiNode::comm().size()-1, v.size() ); tIntervalDynamic.assign = new StaticAssignmentAlgorithm( 1, eo::REST_OF_THE_WORLD, v.size() );
tIntervalDynamic.description = "Correct static assignment with interval."; tIntervalDynamic.description = "Dynamic assignment with interval.";
tIntervalDynamic.requiredNodesNumber = ALL; tIntervalDynamic.requiredNodesNumber = ALL;
tests.push_back( tIntervalDynamic ); tests.push_back( tIntervalDynamic );
Test tUniqueDynamic; Test tUniqueDynamic;
tUniqueDynamic.assign = new StaticAssignmentAlgorithm( 1, v.size() ); tUniqueDynamic.assign = new StaticAssignmentAlgorithm( 1, v.size() );
tUniqueDynamic.description = "Correct static assignment with unique worker."; tUniqueDynamic.description = "Dynamic assignment with unique worker.";
tUniqueDynamic.requiredNodesNumber = 2; tUniqueDynamic.requiredNodesNumber = 2;
tests.push_back( tUniqueDynamic ); tests.push_back( tUniqueDynamic );
Test tVectorDynamic; Test tVectorDynamic;
tVectorDynamic.assign = new StaticAssignmentAlgorithm( workers, v.size() ); tVectorDynamic.assign = new StaticAssignmentAlgorithm( workers, v.size() );
tVectorDynamic.description = "Correct static assignment with precise workers specified."; tVectorDynamic.description = "Dynamic assignment with precise workers specified.";
tVectorDynamic.requiredNodesNumber = tVectorStatic.requiredNodesNumber; tVectorDynamic.requiredNodesNumber = tVectorStatic.requiredNodesNumber;
tests.push_back( tVectorDynamic ); tests.push_back( tVectorDynamic );
Test tWorldDynamic; Test tWorldDynamic;
tWorldDynamic.assign = new StaticAssignmentAlgorithm( v.size() ); tWorldDynamic.assign = new StaticAssignmentAlgorithm( v.size() );
tWorldDynamic.description = "Correct static assignment with whole world as workers."; tWorldDynamic.description = "Dynamic assignment with whole world as workers.";
tWorldDynamic.requiredNodesNumber = ALL; tWorldDynamic.requiredNodesNumber = ALL;
tests.push_back( tWorldDynamic ); tests.push_back( tWorldDynamic );