aboutsummaryrefslogtreecommitdiffstats
path: root/P1
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-10-04 12:39:26 -0500
committerMatt Strapp <strap012@umn.edu>2020-10-04 12:39:26 -0500
commit7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675 (patch)
tree32a61959b7a3c0853a2bdccc4f890d8dff890e11 /P1
parentFix mapper, finally (diff)
downloadcsci4061-7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675.tar
csci4061-7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675.tar.gz
csci4061-7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675.tar.bz2
csci4061-7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675.tar.lz
csci4061-7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675.tar.xz
csci4061-7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675.tar.zst
csci4061-7f6118c98e5c7ab7fc9bdbd8e6af981c24cbe675.zip
Finally fixes #4
Diffstat (limited to 'P1')
-rw-r--r--P1/src/mapreduce.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/P1/src/mapreduce.c b/P1/src/mapreduce.c
index ed44e9e..9efccf7 100644
--- a/P1/src/mapreduce.c
+++ b/P1/src/mapreduce.c
@@ -34,7 +34,6 @@ int main(int argc, char *argv[]) {
char numMap[10];
sprintf(numMap, "%d", i);
execl("./mapper", "./mapper", &numMap, NULL);
- exit(0);
}
}
@@ -47,29 +46,29 @@ int main(int argc, char *argv[]) {
// ###### 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 = 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);
- // }
- // }
+ 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 = 1; i <= nReducers; i++) {
- // //Maybe this works too?
- // wait(NULL);
- // }
+ for (int i = 0; i <= nReducers; i++) {
+ //Maybe this works too?
+ wait(NULL);
+ }
return 0;
} \ No newline at end of file