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

View file

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

View file

@ -44,7 +44,7 @@ int main(int argc, char** argv)
const int ALL = MpiNode::comm().size();
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.requiredNodesNumber = ALL;
tests.push_back( tIntervalStatic );
@ -77,26 +77,26 @@ int main(int argc, char** argv)
tests.push_back( tVectorStatic );
Test tIntervalDynamic;
tIntervalDynamic.assign = new StaticAssignmentAlgorithm( 1, MpiNode::comm().size()-1, v.size() );
tIntervalDynamic.description = "Correct static assignment with interval.";
tIntervalDynamic.assign = new StaticAssignmentAlgorithm( 1, eo::REST_OF_THE_WORLD, v.size() );
tIntervalDynamic.description = "Dynamic assignment with interval.";
tIntervalDynamic.requiredNodesNumber = ALL;
tests.push_back( tIntervalDynamic );
Test tUniqueDynamic;
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;
tests.push_back( tUniqueDynamic );
Test tVectorDynamic;
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;
tests.push_back( tVectorDynamic );
Test tWorldDynamic;
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;
tests.push_back( tWorldDynamic );