From 92bd4eec1b1d1d5731d88481c004289020702b53 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 21 Jun 2012 17:22:28 +0200 Subject: [PATCH] Adding tests for multiple roles and updating parallel apply. --- eo/test/mpi/multipleRoles.cpp | 91 +++++++++++++++++++++++++++++++++++ eo/test/mpi/parallelApply.cpp | 6 +-- 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 eo/test/mpi/multipleRoles.cpp diff --git a/eo/test/mpi/multipleRoles.cpp b/eo/test/mpi/multipleRoles.cpp new file mode 100644 index 00000000..bd91245b --- /dev/null +++ b/eo/test/mpi/multipleRoles.cpp @@ -0,0 +1,91 @@ +# include +# include + +# include + +# include + +# include +using namespace std; + +// Role map +// 0 : general master +// 1 : worker of general job, master of subjob +// 2 and more : workers of subjob + +struct plusOne : public eoUF< int&, void > +{ + void operator() ( int & x ) + { + cout << "Subjob is being applied." << endl; + ++x; + } +}; + +void subtask( vector& v ) +{ + DynamicAssignmentAlgorithm algo( 2, MpiNode::comm().size()-1 ); + plusOne plusOneInstance; + ParallelApply job( plusOneInstance, v, algo, 1 ); + Role node( job ); + node.run(); +} + +struct transmit : public eoUF< vector&, void > +{ + void operator() ( vector& v ) + { + cout << "Into the master subjob..." << endl; + subtask( v ); + } +}; + +int main(int argc, char** argv) +{ + MpiNode::init( argc, argv ); + vector v; + + v.push_back(1); + v.push_back(3); + v.push_back(3); + v.push_back(7); + v.push_back(42); + + transmit transmitInstance; + + vector< vector > metaV; + metaV.push_back( v ); + + switch( MpiNode::comm().rank() ) + { + case 0: + case 1: + { + // only one node is assigned to subjob mastering + DynamicAssignmentAlgorithm algo( 1, 1 ); + ParallelApply< vector > job( transmitInstance, metaV, algo, 0 ); + Role< vector > node( job ); + node.run(); + if( node.master() ) + { + v = metaV[0]; + cout << "Results : " << endl; + for(int i = 0; i < v.size(); ++i) + { + cout << v[i] << ' '; + } + cout << endl; + } + } + break; + + default: + { + // all the other nodes are sub workers + subtask( v ); + } + break; + } + + return 0; +} diff --git a/eo/test/mpi/parallelApply.cpp b/eo/test/mpi/parallelApply.cpp index ab559815..82686bf7 100644 --- a/eo/test/mpi/parallelApply.cpp +++ b/eo/test/mpi/parallelApply.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) { cout << "Appel à init... " << endl; MpiNode::init( argc, argv ); - DynamicAssignmentAlgorithm algo( 1, MpiNode::comm().size() ); + DynamicAssignmentAlgorithm algo( 1, MpiNode::comm().size()-1 ); cout << "Création des données... " << endl; vector v; @@ -32,8 +32,8 @@ int main(int argc, char** argv) plusOne plusOneInstance; cout << "Création du job..." << endl; - ParallelApply job( plusOneInstance, v, algo ); - Role node( job, MpiNode::comm().rank() == 0 ); + ParallelApply job( plusOneInstance, v, algo, 0 ); + Role node( job ); node.run(); if( node.master() )