Lab 9 (5 points)
CS550, Operating Systems
File Systems and Scheduling

Name: _____________________________________________

To submit this assignment, you may copy and paste parts of the assignment into a text editor such as nano, vi, notepad, MS Word, OpenOffice Writer, etc.  Zip any code and scripts showing the output of your solutions, and submit the zip file to the dropbox for lab 7.  Be sure to include a text document including any written/typed/graphed results.  The purpose of this lesson is to learn to about scheduling, file systems, and MPI-IO in the C programming language.

1. Write a C program (single-threaded) that uses file IO to write a large number of ASCII characters to a file.  Use C functions to time the write speed and record it in MB/s.  This program should be similar to the program from problem 2.  Be sure to look at that program first.  Within this program, you must write the following sizes of strings to a file: 1KB, 10KB, 100KB, 1MB, and 10MB, you must determine the write speed for each of these, and you must graph your results showing write speed vs. size of the data elements written (string size). Try this using both ASCII and byte level write commands (e.g. using fputc or fprintf and fwrite). You can find information on fwrite at the following site:

2. Unzip the MPI-IO example from the examples page on LittleFe2.  The command to do so follows below:

        unzip MPI_IO.zip

If you are using a BCCD virtual machine, you may need to download zip and unzip with the following command:

        sudo apt-get install zip unzip

Then run:

        unzip MPI_IO.zip

First, try to run the existing file on LittleFe.   All the unzipped files should be in a directory called MPI_IO.  There is a .c file included within the zip file called MPIparallelwrite.c.  Browse the file using nano or another text editor.  Next, compile the file using the following command:

    mpicc MPIparallelwrite.c -O3 -o MPIparallelwrite.exe

Run this Producer-Consumer project on LittleFe with the following command:

    mpirun -np 12 -machinefile ~/machines-openmpi MPIparallelwrite.exe testfile.txt 50000

Record the output from this file.  Note that the file saved will be of approximately 50MB in size because 50000 1KB strings will be written to the file.

3. Run the program above several times as described below.  Be aware that you will have to delete the test file before each run as your account on LittleFe2 is limited to 500MB.

Make the following modifications to the program, running the program and record the results after you make each modification:

a) Change the size of the string written to 10KB and the number of strings written to 5000.
b) Change the size of the string written to 100KB and the number of strings written to 500.
c) Change the size of the string written to 1MB and the number of strings written to 50.

Graph the write speed vs. the size of the of data elements written.

4. Repeat problem 3, using the Stampede supercomputer instead of LittleFe.  Use the same number of strings on Stampede, and it is recommended that you try the program using 16 CPU cores (i.e. 1 node).  You may place your output (write speed vs. size of data elements written) on the same graph as used in problem 3.  Be sure to submit your batch script for this problem.  Note that you should not run your program directly on the login node of Stampede.  You MUST submit your job to the batch queue.

5. Write a multi-threaded C program to compute the number of words in a program (string tokens separated by spaces).

This program must provide as output the run time of the whole program in seconds, starting immediately before all threads are created and stopping immediately after all threads are joined.  You must use time.h to time this program and the clock() function to compute starting and stopping times.

Run the program 3 times.  On the first run, use the default scheduling policy for threads (SCHED_OTHER).  Record the run time of this program.  For the second run, change the scheduling policy to Round Robin (SCHED_RR) and record the run time of this program.  For the third run, change the scheduling policy to first-in-first-out (SCHED_FIFO), and record the run time of this program.

Explain the results in 3 to 4 sentences, and submit your programs and your results.

6. Write a program that will run x instances of a worker thread where x is provided as input. Your program must use a semaphore to allow exactly one thread to run at a time (i.e. FIFO Scheduling). You may choose your own worker thread for this problem.

7. Modify the program above to use Round Robin scheduling. Use a timer to force a thread to give up the semaphore after a fixed amount of time (for example, 1 millisecond). Hint: this can be accomplished with a loop and the clock. Your implementation of timing does not have to be perfect for this problem.