aboutsummaryrefslogtreecommitdiffstats
path: root/P2
diff options
context:
space:
mode:
authorMatthew Strapp <strap012@umn.edu>2020-10-28 18:10:23 -0500
committerGitHub Enterprise <noreply-github@umn.edu>2020-10-28 18:10:23 -0500
commitaa59190c9e0fc28cd8413784413fd143754e3acc (patch)
tree1f8f4754c8ec161342cefe18350f2f017772a0c3 /P2
parentProject now runs and does not hang forever (diff)
parent? (diff)
downloadcsci4061-aa59190c9e0fc28cd8413784413fd143754e3acc.tar
csci4061-aa59190c9e0fc28cd8413784413fd143754e3acc.tar.gz
csci4061-aa59190c9e0fc28cd8413784413fd143754e3acc.tar.bz2
csci4061-aa59190c9e0fc28cd8413784413fd143754e3acc.tar.lz
csci4061-aa59190c9e0fc28cd8413784413fd143754e3acc.tar.xz
csci4061-aa59190c9e0fc28cd8413784413fd143754e3acc.tar.zst
csci4061-aa59190c9e0fc28cd8413784413fd143754e3acc.zip
Merge pull request #13 from STRAP012/FixAlltheProblems
Fix all the problems
Diffstat (limited to '')
-rw-r--r--P2/include/utils.h2
-rw-r--r--P2/lib/utils.c27
-rw-r--r--P2/src/mapreduce.c1
3 files changed, 20 insertions, 10 deletions
diff --git a/P2/include/utils.h b/P2/include/utils.h
index 050a0e3..6fa4fa8 100644
--- a/P2/include/utils.h
+++ b/P2/include/utils.h
@@ -23,7 +23,9 @@ struct msgBuffer {
};
//Open Queue as a function because writing this once is probably better than four times.
//Hopefully it works properly.
+
int openQueue();
+void closeQueue();
// mapper side
int validChar(char c);
diff --git a/P2/lib/utils.c b/P2/lib/utils.c
index f485b11..82f7a70 100644
--- a/P2/lib/utils.c
+++ b/P2/lib/utils.c
@@ -2,13 +2,20 @@
int openQueue() {
int id = msgget(ftok("4061 Project 2 SS", 'S'), 0666 | IPC_CREAT);
- if (id < 0)
- {
+ if (id < 0) {
perror("Cannot open queue.\n");
return -1;
- };
+ }
return id;
}
+void closeQueue() {
+ int msgid = msgget(ftok("4061 Project 2 SS", 'S'), 0666);
+ if (msgid < 0) {
+ perror("Cannot open queue. It may already exist.\n");
+ exit(-1);
+ }
+ msgctl(msgid, IPC_RMID, NULL);
+}
char *getChunkData(int mapperID) {
printf("GETTING CHUNK DATA\n");
@@ -19,8 +26,8 @@ char *getChunkData(int mapperID) {
msgrcv(mid, &message, sizeof(message.msgText), mapperID, 0);
/*IMPLEMENT END AND ACK SOON*/
if (strncmp("END", message.msgText, 3)) {
- struct msgBuffer ACK = {mapperID, "ACK"};
- msgsnd(mid, &ACK, MSGSIZE, 0);
+ // struct msgBuffer ACK = {mapperID, "ACK"};
+ // msgsnd(mid, &ACK, MSGSIZE, 0);
return NULL;
}
char* value = message.msgText;
@@ -39,13 +46,13 @@ void sendChunkData(char *inputFile, int nMappers) {
// construct chunks of 1024 bytes
memset(message.msgText, '\0', MSGSIZE);
while(read(fd, message.msgText, chunkSize) != 0) {
- printf("%s\n", message.msgText);
+ // printf("%s\n", message.msgText);
/* 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
message.msgType = map++;
- //THIS IS DEBUG, NOT ACTUALLY FUNCTIONAL
+ //THIS IS DEBUG, NOT ACTUALLY FUNCTIONAL (like at all)
msgsnd(msgid, &message, map, 0);
if (map > nMappers)
map = 1;
@@ -56,7 +63,7 @@ void sendChunkData(char *inputFile, int nMappers) {
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);
+ // msgrcv(msgid, &message, MSGSIZE, i, 0);
}
}
@@ -81,8 +88,8 @@ int getInterData(char *Qkey, int reducerID) {
Qkey = message.msgText;
if (strncmp("END", message.msgText, 3))
{
- struct msgBuffer ACK = {reducerID, "ACK"};
- msgsnd(id, &ACK, MSGSIZE, 0);
+ // struct msgBuffer ACK = {reducerID, "ACK"};
+ // msgsnd(id, &ACK, MSGSIZE, 0);
return 0;
} else {
return 1;
diff --git a/P2/src/mapreduce.c b/P2/src/mapreduce.c
index 962a9ca..290c1c5 100644
--- a/P2/src/mapreduce.c
+++ b/P2/src/mapreduce.c
@@ -77,5 +77,6 @@ int main(int argc, char *argv[]) {
// wait for all children to complete execution
while (wait(&status) > 0);
+ closeQueue();
return 0;
} \ No newline at end of file