5 #define NUMITEMS (100*1000) 12 pair<int,int> map1(
const int & key,
int & input){
13 pair<int,int> result (key, 2*input);
20 pair<int,int> reduce1(
const int & keyA,
int &a,
const int & keyB,
int &b){
21 pair<int,int> result ((keyA + keyB), (a+b));
27 void printHistogram(
const std::unordered_map<K, size_t> & hist ){
28 for(
auto it = hist.begin(); it != hist.end(); it++){
29 cout << it->first <<
"\t";
32 for(
auto it = hist.begin(); it != hist.end(); it++){
33 cout << it->second <<
"\t";
38 int main(
int argc,
char ** argv){
40 cout <<
"Init FastLib" <<
'\n';
50 cout <<
"Generate Data" <<
'\n';
51 int rawdata[NUMITEMS];
52 int rawKeys[NUMITEMS];
54 for (
int i = 0; i < NUMITEMS; ++i ){
55 rawKeys[i] = 1 + rand() % 10;
56 rawdata[i] = 1 + rand() % 100;
59 cout <<
"Import Data" <<
'\n';
62 cout <<
"Key Histogram\n";
63 printHistogram(data.countByKey());
65 cout <<
"Process Data" <<
'\n';
66 pair<int,int> result = data.map<int,
int>(&map1)->reduce(&reduce1);
68 cout <<
"DONE!" <<
'\n';
70 std::cout <<
"Result: " << result.first/NUMITEMS <<
", " << result.second/NUMITEMS <<
"\n";
void startWorkers()
Start worker machines computation.
void registerFunction(void *funcP)
Register a user custom function in the context.
bool isDriver()
Checks for the driver process.