next up previous index
Next: Diffusion Up: Bank Queue Previous: The Logs

Exercises

1
Insert MPI_Wtime calls  in the client portion of the code in order to measure time spent on computation and time spent on communication. Make each client write the totals on its log file before calling  MPI_Finalize.
2
The program discussed in this section opens the log files in the directory whose name is hardwired into the code, /N/B/gustav/tmp. Rewrite this part of the program to
1.
obtain the value of HOME from the user's environment by calling function  getenv(3);
2.
check if directory tmp exists in HOME by calling function  stat(2);
Hint
If the directory you're testing for does not exist function stat(2) will return -1 signifying an error. You will then have to inspect the value of errno(3), and in particular you should check if errno=ENOENT, which would mean that there is no file or directory that can be accessed by this path name.
Hint
If stat(2) does not return an error, this means that the file does exist, but you still have to check if the file is a directory and if you will be able to write on it. On a successful return stat(2) will fill a structure of type stat that corresponds to the file name given to stat(2) as the first argument. The st_mode field of this structure can be used to test if the file in question is a directory by calling a macro  S_ISDIR, which is defined on /usr/include/sys/stat.h. For example,
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
...
char *file_name;
struct stat buf;
...
if (stat(file_name, &buf) == 0) {
   if (S_ISDIR(buf.st_mode)) {
      /* The file in question is a directory. */
      ...
   } else {
      /* The file in question is not a directory. */
      ...
   }
} else {
   /* The file in question probably does not exist or it cannot
      be queried. Check errno. */
   ...
}
3.
Create this directory if it does not exist by calling function  mkdir(2).
These actions should be carried out by the master process only, whereas other processes should wait on a barrier  call, MPI_Barrier, until the master process has completed its task.


next up previous index
Next: Diffusion Up: Bank Queue Previous: The Logs
Zdzislaw Meglicki
2004-04-29