aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-10-26 08:45:04 -0500
committerMatt Strapp <strap012@umn.edu>2020-10-26 08:45:04 -0500
commitd6e2c01a085d9eebd529fa59fff654663b39e31a (patch)
tree8998ef207083d0a9ef21965b0bbb093243edf743
parentAdd new template (diff)
downloadcsci4061-d6e2c01a085d9eebd529fa59fff654663b39e31a.tar
csci4061-d6e2c01a085d9eebd529fa59fff654663b39e31a.tar.gz
csci4061-d6e2c01a085d9eebd529fa59fff654663b39e31a.tar.bz2
csci4061-d6e2c01a085d9eebd529fa59fff654663b39e31a.tar.lz
csci4061-d6e2c01a085d9eebd529fa59fff654663b39e31a.tar.xz
csci4061-d6e2c01a085d9eebd529fa59fff654663b39e31a.tar.zst
csci4061-d6e2c01a085d9eebd529fa59fff654663b39e31a.zip
Revert "Add new template"
This reverts commit cd43f361676b151a90607fdeb76724b694288ef9.
Diffstat (limited to '')
-rw-r--r--P2/include/utils.h2
-rw-r--r--P2/lib/utils.c54
-rw-r--r--P2/solutionexe/Makefile57
-rw-r--r--P2/solutionexe/mapperbin39000 -> 26444 bytes
-rw-r--r--P2/solutionexe/mapreducebin32800 -> 24940 bytes
-rw-r--r--P2/solutionexe/reducerbin33968 -> 25676 bytes
-rw-r--r--P2/solutionexe/test/T1/F1.txt2
7 files changed, 107 insertions, 8 deletions
diff --git a/P2/include/utils.h b/P2/include/utils.h
index 2c91cdf..e3f5d43 100644
--- a/P2/include/utils.h
+++ b/P2/include/utils.h
@@ -23,6 +23,7 @@ struct msgBuffer {
};
// mapper side
+
int validChar(char c);
char *getWord(char *chunk, int *i);
char *getChunkData(int mapperID);
@@ -30,6 +31,7 @@ void sendChunkData(char *inputFile, int nMappers);
// reducer side
+
int hashFunction(char* key, int reducers);
int getInterData(char *key, int reducerID);
void shuffle(int nMappers, int nReducers);
diff --git a/P2/lib/utils.c b/P2/lib/utils.c
index 17b3104..603a699 100644
--- a/P2/lib/utils.c
+++ b/P2/lib/utils.c
@@ -1,10 +1,62 @@
#include "utils.h"
+//Receive from send and return the chonk
char *getChunkData(int mapperID) {
+ //Message
+ struct msgBuffer message;
+ //Queue ID, not sure what it actually does
+ int mid;
+ //Queue Key
+ key_t key = 10;
+ mid = msgget(key, 0666 | IPC_CREAT);
+ if (mid < 0) {
+ perror("Cannot open queue.\n");
+ return NULL;
+ }
+ msgrcv(mid, &message, MSGSIZE, mapperID, 0);
+ if (strcmp("END", message.msgText)) {
+ struct msgBuffer ACK = {mapperID, "ACK"};
+ msgsnd(mid, &ACK, MSGSIZE, 0);
+ }
+ // msgctl(mid, IPC_RMID, 0);
+ return message.msgText;
}
// sends chunks of size 1024 to the mappers in RR fashion
void sendChunkData(char *inputFile, int nMappers) {
+ struct msgBuffer message;
+ key_t key = 10;
+ int msgid;
+
+ // open message queue
+ msgid = msgget(key, 0666 | IPC_CREAT);
+ if (msgid < 0) {
+ perror("Cannot open queue.\n");
+ exit(-1);
+ }
+ // message.msgText = 1;
+ FILE *fptr = fopen(inputFile, "r");
+
+ // construct chunks of 1024 bytes
+ while(fgets(&message, chunkSize, fptr) != EOF) {
+
+ /* Go to the end of the chunk, check if final character
+ is a space if character is a space, do nothing
+ else cut off before that word and put back file */
+ // TODO! help
+
+ msgsnd(msgid, &message, mapperID);
+ }
+
+ for (long i = 1; i < nMappers; i++) {
+ struct msgBuffer END = {i, "END"};
+ msgsnd(msgid, &END, MSGSIZE, 0);
+
+ // TODO! does this need to be in another loop or is blocking good enough?
+ msgrcv(msgid, &message, MSGSIZE, i, 0);
+ }
+
+ // msgctl(msgid, IPC_RMID, 0); // close that bih
}
// hash function to divide the list of word.txt files across reducers
@@ -27,7 +79,7 @@ void shuffle(int nMappers, int nReducers) {
// check if the character is valid for a word
int validChar(char c){
- return (tolower(c) >= 'a' && tolower(c) <='z') ||
+ return ((tolower(c) >= 'a') && tolower(c <='z')) ||
(c >= '0' && c <= '9');
}
diff --git a/P2/solutionexe/Makefile b/P2/solutionexe/Makefile
index 4a969ac..231a15e 100644
--- a/P2/solutionexe/Makefile
+++ b/P2/solutionexe/Makefile
@@ -1,10 +1,57 @@
-.PHONY: run
+CC=gcc
+CFLAGS=-g
-run:
- chmod +x mapreduce
- chmod +x mapper
- chmod +x reducer
+SRCDIR=src
+INCLDIR=include
+LIBDIR=lib
+
+mapreduce: $(SRCDIR)/mapreduce.c $(LIBDIR)/utils.o mapper reducer
+ $(CC) $(CFLAGS) -I$(INCLDIR) $(LIBDIR)/utils.o $(SRCDIR)/mapreduce.c -o mapreduce
+
+mapper: $(SRCDIR)/mapper.c $(LIBDIR)/utils.o
+ $(CC) $(CFLAGS) -I$(INCLDIR) $(LIBDIR)/utils.o $(SRCDIR)/mapper.c -o mapper
+
+reducer: $(SRCDIR)/reducer.c $(LIBDIR)/utils.o
+ $(CC) $(CFLAGS) -I$(INCLDIR) $(LIBDIR)/utils.o $(SRCDIR)/reducer.c -o reducer
+
+$(LIBDIR)/utils.o: $(LIBDIR)/utils.c
+ $(CC) $(CFLAGS) -I$(INCLDIR) -c $(LIBDIR)/utils.c -o $(LIBDIR)/utils.o
+
+.PHONY: run clean t1 t2 t3
+
+#500KB
+t1:
+# make -i clean
+# make
./mapreduce 5 2 test/T1/F1.txt
+#44KB
+t2:
+# make -i clean
+# make
+ ./mapreduce 5 2 test/T2/F2.txt
+
+#0KB
+t3:
+# make -i clean
+# make
+ ./mapreduce 5 2 test/T3/F3.txt
+
+# m >= r
+
+# m=1 r=1 (min case)
+t4:
+# make -i clean
+# make
+ ./mapreduce 1 1 test/T1/F1.txt
+
+# m=32 r=26 (max case)
+t5:
+# make -i clean
+# make
+ ./mapreduce 32 26 test/T1/F1.txt
+
+
clean:
+ rm lib/utils.o mapreduce mapper reducer
rm -rf output \ No newline at end of file
diff --git a/P2/solutionexe/mapper b/P2/solutionexe/mapper
index 56be08c..15abd74 100644
--- a/P2/solutionexe/mapper
+++ b/P2/solutionexe/mapper
Binary files differ
diff --git a/P2/solutionexe/mapreduce b/P2/solutionexe/mapreduce
index 3932e81..28be9a0 100644
--- a/P2/solutionexe/mapreduce
+++ b/P2/solutionexe/mapreduce
Binary files differ
diff --git a/P2/solutionexe/reducer b/P2/solutionexe/reducer
index c801c99..6d6ccd8 100644
--- a/P2/solutionexe/reducer
+++ b/P2/solutionexe/reducer
Binary files differ
diff --git a/P2/solutionexe/test/T1/F1.txt b/P2/solutionexe/test/T1/F1.txt
deleted file mode 100644
index 8ab70be..0000000
--- a/P2/solutionexe/test/T1/F1.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-
-To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have todayTo give you an estimation of the difference in the original and what we have todayTo give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have today. To give you an estimation of the difference in the original and what we have todayTo give you an estimation of the difference in the original and what we have today. \ No newline at end of file