#include "mapreduce.h" int main(int argc, char *argv[]) { if(argc < 4) { printf("Less number of arguments.\n"); printf("./mapreduce #mappers #reducers inputFile\n"); exit(0); } // ###### DO NOT REMOVE ###### int nMappers = strtol(argv[1], NULL, 10); int nReducers = strtol(argv[2], NULL, 10); char *inputFile = argv[3]; // ###### DO NOT REMOVE ###### bookeepingCode(); // ###### DO NOT REMOVE ###### pid_t pid = fork(); if(pid == 0){ //send chunks of data to the mappers in RR fashion sendChunkData(inputFile, nMappers); exit(0); } sleep(1); pid_t mapperPid; for (int i = 1; i <= nMappers; i++) { mapperPid = fork(); if (mapperPid == 0) { //TODO: exec here char numMap[10]; sprintf(numMap, "%d", i); execl("./mapper", "./mapper", &numMap, NULL); } } for (int i = 0; i <= nMappers; i++) { //Hopefully this works wait(NULL); } // ###### DO NOT REMOVE ###### // shuffle sends the word.txt files generated by mapper // to reducer based on a hash function pid = fork(); if(pid == 0){ shuffle(nMappers, nReducers); exit(0); } sleep(1); pid_t reducerPid; for (int i = 1; i <= nReducers; i++) { reducerPid = fork(); if (reducerPid == 0) { char numRed[10]; sprintf(numRed, "%d", i); execl("./reducer", "./reducer", &numRed, NULL); } } for (int i = 0; i <= nReducers; i++) { //Maybe this works too? wait(NULL); } return 0; }