- Main Page
- Classes
- Files

- File List

# OptFrame/Parallel/MapReduce++/MapMP/mapper.hpp

    00001 #ifndef MAPPER_HPP
    00002 #define MAPPER_HPP
    00003 #include <iterator>
    00004
    00006 template<class KeyA, class A, class KeyB, class B, class C>
    00007 class MapMP_Mapper : public Mapper<KeyA,A,KeyB,B,C>
    00008 {
    00009 public:
    00011         MapMP_Mapper(MapReduce<KeyA,A,KeyB,B,C> * _mapReduce):mapReduce(_mapReduce){};
    00013 #ifndef MRI_USE_MULTIMAP
    00014         virtual vector< pair<KeyB,B> > run( vector< pair<KeyA,A> > & as )
    00015         {
    00016                 vector< pair<KeyB,B> > bs;
    00017
    00018                 #pragma omp parallel for
    00019                 for (int i = 0 ; i < as.size() ; i++)
    00020                 {
    00021                         vector< pair<KeyB,B> > bss = map( as[i] );
    00022                         #pragma omp critical
    00023                         for (int j = 0 ; j < bss.size() ; j++) bs.push_back( bss[j] );
    00024                 }
    00025
    00026                 return bs;
    00027         };
    00028 #else
    00029         virtual multimap<KeyB,B> run( vector< pair<KeyA,A> > & as )
    00030         {
    00031                 multimap<KeyB,B> bs;
    00032
    00033                 #pragma omp parallel for
    00034                 for (int i = 0 ; i < as.size() ; i++)
    00035                 {
    00036                         vector< pair<KeyB,B> > bss = map( as[i] );
    00037                         #pragma omp critical
    00038                         for (int j = 0 ; j < bss.size() ; j++) bs.insert( bss[j] );
    00039                 }
    00040
    00041                 return bs;
    00042         };
    00043 #endif
    00044
    00045         virtual vector< pair<KeyB,B> > map( pair<KeyA,A> ) = 0 ;
    00046 protected:
    00047         MapReduce<KeyA,A,KeyB,B,C> * mapReduce;
    00048 };
    00049
    00051 class MapMP_StrMapper : public MapMP_Mapper<string,string,string,string,string>
    00052 {
    00053 public:
    00055         MapMP_StrMapper(MapReduce<string,string,string,string,string> * _mapReduce)
    00056                 :MapMP_Mapper<string,string,string,string,string>(_mapReduce) {};
    00057 };
    00058
    00059 #endif /* MAPPER_HPP */

All Classes Functions