This repository has been archived on 2026-03-28. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
eodev/eo/src/eoParallelApply.h
2012-06-18 14:20:06 +02:00

49 lines
1.2 KiB
C++

# ifndef __EO_PARALLEL_APPLY_H__
# define __EO_PARALLEL_APPLY_H__
# include "eompi.h"
# include <eoFunctor.h>
# include <vector>
template< typename EOT >
class ParallelApply : public MpiJob< EOT >
{
public:
ParallelApply( eoUF<EOT&, void> & _proc, std::vector<EOT>& _pop ) :
MpiJob<EOT>( _pop ),
func( _proc )
{
// empty
}
virtual void sendTask( int wrkRank, int index )
{
MpiJob<EOT>::comm.send( wrkRank, 1, MpiJob<EOT>::data[ index ] );
}
virtual void handleResponse( int wrkRank, int index )
{
MpiJob<EOT>::comm.recv( wrkRank, 1, MpiJob<EOT>::data[ index ] );
}
virtual void processTask( )
{
EOT ind;
cout << "Receiving individual." << endl;
MpiJob<EOT>::comm.recv( 0, 1, ind );
cout << "Applying function." << endl;
func( ind );
cout << "Sending result." << endl;
MpiJob<EOT>::comm.send( 0, 1, ind );
cout << "Leaving processTask" << endl;
}
protected:
eoUF<EOT&, void>& func;
};
# endif // __EO_PARALLEL_APPLY_H__