-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
Matheus C. Santos edited this page Jan 17, 2015
·
1 revision
Faster works on distributed datasets called FDDs. These datasets are (or will be) fault tolerant data storages responsible to store data and handle distributed functions. Those functions can be predefined or customized by the user. Next we provide a example of a simple program that uses Faster libraries;
1. Initialize a context and start workers:
fastContext fc();2. Register your custom functions:
fc.registerFunction((void*) &map1);
fc.registerFunction((void*) &reduce1);3. Start workers:
fc.startWorkers();Every program must have at least one worker
WARNING: in MPI mode, the code before this call is executed by all processes and the code after is NOT.
4. Create a FDD dataset. In this case we will use a int array already in memory:
fdd <int> data(fc, data, [NUMBER_OF_ITEMS]);5. Apply your functions to your data and get the result:
int result = data.map<int>(&map1)->reduce(&reduce1);A full example would be:
#include <iostream>
#include "libfaster.h"
#define NUMITEMS 100*1000
using namespace std;
int map1(int & input){
return input * 2;
}
int reduce1(int &a, int &b){
return a + b;
}
int main(int argc, char ** argv){
cout << "Init FastLib" << '\n';
fastContext fc("local");
fc.registerFunction((void*) &map1);
fc.registerFunction((void*) &reduce1);
fc.startWorkers();
cout << "Generate Data" << '\n';
int rawdata[NUMITEMS];
for ( int i = 0; i < NUMITEMS; ++i )
rawdata[i] = 1;
cout << "Import Data" << '\n';
fdd <int> data(fc, rawdata, NUMITEMS);
cout << "Process Data" << '\n';
int result = data.map<int>(&map1)->reduce(&reduce1);
cout << "DONE!" << '\n';
std::cout << result << "\n";
return 0;
}