Dana Vrajitoru
B424 Parallel and Distributed Programming

B424/B524 Homework 7

Due date: Thursday, October 22, 2020.

In this homework we'll implement a (relatively simple) text encryption algorithm based on the model of pool of tasks.

Pool of Tasks Sum

Download the following files containing a frame for implementing the pool of tasks model:
pool_tasks.h
pool_tasks.cc
main.cc
Makefile

This program is based on the ideas present in pseudo-code in the PowerPoint Slides. You can use the simplest outline without a queue of tasks or workers.

Ex. 1 Encryption Program

Write a program implementing a text encryption algorithm as a pool of tasks. The program will input a sequence of characters (simple text) from the console and will output an encrypted version of it.

The master will input the text and will send one word at a time to the workers, until the user enters Ctrl-D. The master will receive results from the workers and will output the encrypted words to the file output.txt. This is to avoid mixing up the input and output of the program on the terminal. You can assume that no individual word will be longer than 50 characters.

You can use the redirection of the input from a text file, with a command such as

mpirun -np 4 tpool < file.txt

Encryption process: the encryption function will get one word at a time, defined as separated by spaces. You can use the function isspace from the header <cctype> to test if something is a space, and isalpha to test for alphabetical letters. You can leave non-alphabetical characters unchanged. The function must first reverse the word, and then replace each letter with one obtained by adding 1 to it in a circular way, in the style of Cesar's code. Thus, 'a' becomes 'b', 's' becomes 't', and so on. Note that by adding 1 to 'z', you must obtain 'a', and the same for the uppercase letters. The sentence "The cat in the hat" would become "fiU ubd oj fiu ubi".

Output: the encrypted text must be output to the file such that the words appear encrypted in the order in which they were input, such that the text can eventually be decrypted to obtain the original text back.

Sending messages: For this problem, the master needs to send a word to a worker, and receive another word in return. Because we need to know the length of the data in send and receive messages, we can send a full string of 50 characters through every time, even if the word itself is smaller.

Another tricky point about this homework is that the master needs to receive messages from the workers in any order, or rather, in the order in which they are done. For this, we can use a receive with any source, such as shown in the code. The source can be found afterward in status.MPI_SOURCE.

At the beginning, the workers need to send an empty result to the master. For that, you can use an empty string. You cannot use a constant "" in an MPI_Send, you need to send a variable containing an array of characters anyway, even if it's empty. To make an empty string in an array, assign '\0' to the first element of the array.

At the end, the master also needs to send an empty task to the workers, to let them know that the tasks are finished. You can also send an empty string for that purpose. You will need to check the length of the string you receive. You can use the function strlen for that, from the header <cstring>.

Performance

Measure the performance in terms of speedup of the algorithm by timing the execution on the same text first using 2 processes, then 4 or 8 of them. Measure this on the cs01, cs02, and cs03 computers, and on Carbonate (carbonate.uits.iu.edu). Add the results in a text file or as a submission comment.

Homework Submission

Upload: to Canvas, Assignments, Homework 7, all the files that you modify, add, create (including the Makefile if you've changed it), and the performance measurements.