Homework 2
cs550 Operating Systems
5 points
Due Wednesday, Sept. 24, 2014 at the beginning of class
1. Write a program in C that uses two different
threads to increment and decrement the same static integer one thousand
times each, respectively. You must write a different
function for each thread. Run this program many times (at
least ten). Is the output ever different from run to run?
2. Write a C program using MPI that uses two processes
- one client and one server. This program should send seven
messages from the server and receive seven messages in the
client. Any additional processes that are created should
print a statement indicating that they are inactive.
Additionally, write a SLURM batch script for this program.
3. Read about pipes in section 3.6.3 of your
textbook. Try using some pipes with commands on
Littlefe. For example, try ls -al | less and ps
| grep bash. Using the sample pipe program provided in
the textbook on pages 143-144, modify the program to write an
array of doubles to the pipe in the parent process. The
child process should determine if those doubles are positive or negative and
print appropriate output.
4. Write a program that sends data in a ring of
processes (from process 0 to 1 to 2 . . . to process n-1 and back
to process 0) using C and MPI. Part of the data sent from
one process to the next must include an identifier (such as the
rank) from the sending process.
5. Write a program that uses two threads (in addition to the main thread) to compute the sum of all elements of a double array. The main thread should acquire the data as input and start two worker threads. The worker threads should sum the first and last halves of the array elements. After the worker threads complete their tasks, the main thread should sum the two results and provide the sum as output.