Next 20: Running Fortran Up 19: Running C Prev Compiling C Contents


Specialized

§ 16.C: Programming Courtesy


When running programs on a shared computer, or on a cluster of computers, it is important to be aware of how your program consumes resources. As your program consumes more and more resources, you affect other users more and more. If you are working with large arrays which occupy a large fraction of the computer's RAM, or if your program takes more than a few minutes to run, you probably are affecting other users.

In the Physics Department, the machines goophy, daphy, and hermes each has more than 32 Meg of RAM. But be aware, the highest priority for the departmental cluster is class use. If you need to run a large research program on the cluster, you should give it low priority and have it run between 10 pm and 8 am. If you run a large job on the cluster during class time, the system administrators have been instructed to kill them.

To run your program at a lower priority, use the nice command. To use it, enter nice -15 followed by the command you want niceed. For example, to be nice when you run the program a.out

Even though your job may have a lower priority, it may still interefere with other people's work. For example, if it is occuping too a large fraction of central memory for other jobs to fit it, your job must first be written to disk before the others can proceed. And because disk-writing is a slow process, this slows everone down. Likewise, if your job is doing a lot of I/O, this may keep others users from doing I/O or may clog up the entire network.

To keep from losing control of your terminal window while running a long program, you should run it in background. To do this, enter a & after your command:

You can now do other things in the same window without stopping your program.

Depending on the Unix shell you are using, you may have job control from your keyboard. This means that if you decide you want control back of a command you placed in background (or of any other command you happen to be running), you can enter ^Z (ctrl-Z) to stop it. Then enter fg to place it in foreground, or bg to place it in background.

If you start a program without nice, you can lower its priority with renice. To renice a command, you need its job number. To get the job number use the ps (process status) command. If you try
> ps ,

you might get something like

The far right column lists the commands running under this session. The -tcsh line is the shell you are interacting with through your terminal. Sometimes, the ps command itself is shown. Once you have found the command you want to renice, look in the leftmost column for the process identification number (PID). In this example, a.out has PID 13805. So, to renice a.out, enter

If you should decide you are tired of having some job run, feel free to go ahead and kill it. If the job is running in the foreground , in which case the window in which you entered it is locked up while the job runs, you can enter the ^c (ctrl-c) command to stop it.

If it is running in the background, you can use the kill command (which also uses the job number)

A kill may not always work on the first try. You should use a ps after a little bit to check that the command is no longer executing. If the command is still running ,re-enter your kill command.

It's a good idea to be aware of how much time and memory your program uses. Then you can estimate what will happen as you increase your program's scope.This is particularly true if your program contains multidimensional arrays, since there is a geometric increase in computational intensity with size. For example, if you double the dimension of a 3-D array, your memory use and run time increases by a factor of about eight.

Remember, if you prefer not to have other users interfere with your work on a shared computer system, then get the message across by being courteous to others.


Next 20: Running Fortran Up 19: Running C Prev Compiling C Contents


Comments and questions to CP-unix@physics.orst.edu.