aboutsummaryrefslogtreecommitdiffstats
path: root/P2/lib
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-10-29 10:34:28 -0500
committerMatt Strapp <strap012@umn.edu>2020-10-29 10:34:28 -0500
commit999ca7aeafebe0737f8276cbe9d3dd1da5395165 (patch)
treec3d5f9499c8e36e91343f84c1c550abf6b0d281a /P2/lib
parentMake two different queues (diff)
downloadcsci4061-999ca7aeafebe0737f8276cbe9d3dd1da5395165.tar
csci4061-999ca7aeafebe0737f8276cbe9d3dd1da5395165.tar.gz
csci4061-999ca7aeafebe0737f8276cbe9d3dd1da5395165.tar.bz2
csci4061-999ca7aeafebe0737f8276cbe9d3dd1da5395165.tar.lz
csci4061-999ca7aeafebe0737f8276cbe9d3dd1da5395165.tar.xz
csci4061-999ca7aeafebe0737f8276cbe9d3dd1da5395165.tar.zst
csci4061-999ca7aeafebe0737f8276cbe9d3dd1da5395165.zip
Add a helper function
Diffstat (limited to 'P2/lib')
-rw-r--r--P2/lib/utils.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/P2/lib/utils.c b/P2/lib/utils.c
index a565717..960ab18 100644
--- a/P2/lib/utils.c
+++ b/P2/lib/utils.c
@@ -7,10 +7,17 @@ int closeQueue(int id) {
return msgctl(id, IPC_RMID, NULL);
}
+struct msgBuffer makeMessage() {
+ struct msgBuffer temp;
+ memset(temp.msgText, '\0', MSGSIZE);
+ temp.msgType = 0;
+ return temp;
+}
+
char *getChunkData(int mapperID) {
printf("GETTING CHUNK DATA\n");
//Message
- struct msgBuffer message;
+ struct msgBuffer message = makeMessage();
//Queue ID
int mid = openQueue("map");
msgrcv(mid, &message, sizeof(message.msgText), mapperID, 0);
@@ -24,14 +31,12 @@ char *getChunkData(int mapperID) {
// sends chunks of size 1024 to the mappers in RR fashion
void sendChunkData(char *inputFile, int nMappers) {
printf("SENDING CHUNK DATA\n");
- struct msgBuffer message;
+ struct msgBuffer message = makeMessage();
// open message queue
int msgid = openQueue("map");
int map = 1;
- // message.msgText = 1;
int fd = open(inputFile, O_RDONLY);
// construct chunks of 1024 bytes
- memset(message.msgText, '\0', MSGSIZE);
while(read(fd, message.msgText, chunkSize) != 0) {
// printf("%s\n", message.msgText);
/* Go to the end of the chunk, check if final character
@@ -76,7 +81,7 @@ int hashFunction(char* Qkey, int reducers){
}
int getInterData(char *Qkey, int reducerID) {
- struct msgBuffer message;
+ struct msgBuffer message= makeMessage();
//make sure it work.
int id = openQueue("reduce");
msgrcv(id, &message, chunkSize, reducerID, 0);
@@ -91,7 +96,7 @@ int getInterData(char *Qkey, int reducerID) {
}
void shuffle(int nMappers, int nReducers) {
- struct msgBuffer message;
+ struct msgBuffer message = makeMessage();
//Once again, MAKE SURE THIS WORKS PROPERLY!
int id = openQueue("reduce");
for (int i = 1; i <= nMappers; i++) {