aboutsummaryrefslogtreecommitdiffstats
path: root/P2
diff options
context:
space:
mode:
authorMatthew Strapp <strap012@umn.edu>2020-10-24 17:56:47 -0500
committerGitHub Enterprise <noreply-github@umn.edu>2020-10-24 17:56:47 -0500
commit0834595278279fe5e054488249a7301460409710 (patch)
treec91c498dfefa2d6f040654aff92562d591902377 /P2
parentMerge getChunkData() with master (diff)
parentCheck TODO's (diff)
downloadcsci4061-0834595278279fe5e054488249a7301460409710.tar
csci4061-0834595278279fe5e054488249a7301460409710.tar.gz
csci4061-0834595278279fe5e054488249a7301460409710.tar.bz2
csci4061-0834595278279fe5e054488249a7301460409710.tar.lz
csci4061-0834595278279fe5e054488249a7301460409710.tar.xz
csci4061-0834595278279fe5e054488249a7301460409710.tar.zst
csci4061-0834595278279fe5e054488249a7301460409710.zip
Merge sendChunkData() with master
sendChunkData()
Diffstat (limited to 'P2')
-rw-r--r--P2/lib/utils.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/P2/lib/utils.c b/P2/lib/utils.c
index dba63b5..8373a09 100644
--- a/P2/lib/utils.c
+++ b/P2/lib/utils.c
@@ -23,6 +23,34 @@ char *getChunkData(int mapperID) {
// 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);
+ 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, &msgText, mapperID);
+ }
+
+ for (int i = 1; i < mapperID; i++) {
+ msgsnd(msgid, (void*)&END, MSGSIZE, i);
+
+ // TODO! does this need to be in another loop or is blocking good enough?
+ msgrcv(msgid, (void*)&ACK, MSGSIZE, i);
+ }
+
+ msgctl(msgid, IPC_RMID, 0); // close that bih
}
// hash function to divide the list of word.txt files across reducers