WORKING ON THE LAB MACHINES In PHY4020/5020 - Computational Physics, we will be doing our work in the linux operating system. We will be compiling code using gcc and we'll be using gnuplot to visualize data. Much of your work can be done on the lab computers, but we are setting up a Linux server which it will be possible for you to log into remotely, and do work there. Later on in this document we discuss how this will be carried out. To begin, however, let us get acquainted with the Linux system and how to carry out simple commands. FILE CREATION AND MANIPULATION ============================== If you choose to do your work locally on the lab machines, please do all of your work in the CompPhys directory. The following brief tutorial assumes that you're sitting at a lab machine doing all of your work on the machine. To work in Linux, it may be necessary to either turn the machine on or reboot the machine. Either way, you will be presented with a screen which says: "Booting into Windows XP in XX seconds". At this point, hit the return key, and then use the arrow keys to select Fedora Linux. Hit return, and the computer will boot into Linux. Once you are in Linux, double click on the terminal icon (the one that looks like a computer terminal). A window will appear that contains a prompt. At this prompt, type cd CompPhys to change the working directory to CompPhys. You should do all of your work in the CompPhys directory. To create a new file, you can use the editor emacs, which is both simple and powerful. For instance, if you want to create the file trial.dat, enter the following at the prompt: emacs trial.dat & The "&" symbol at the end means the operation is put into "background", and it is possible to continue using the terminal at the same time as you edit the file. This command will bring up a new window, the emacs window, in which you can write statements. Try it out. Type in a line, then use the delete key to delete some characters. You can outline part of a line by dragging the mouse across it, and then cut it and paste it elsewhere in the document using the options under edit. Finally, to save it, click on "File" and "Save (current buffer)". Now exit from emacs. (File -> Exit Emacs). Lets learn some other Linux commands to create and manipulate files: To view files from the terminal command line, type ls or, alternatively ls -l This will list all of the files in your folder. Note it also lists the 'permissions' and 'time stamp' which could be helpful in sorting through different versions of your code. To create a directory, type mkdir name where "name" is the name of the directory. For example, mkdir ex72 creates a subdirectory which is a daughter to the parent CompPhys directory. You can do work relating solely to exercise 7.2 in that directory without garbling up the CompPhys directory. To make a subdirectory your "working" directory, simply type, for example, cd ex72 and to change back to CompPhys, type cd .. which brings you back up 1 level. To copy a file, type cp source destination where "source" and "destination" are the filenames and path description. For example, cp current.c old.c makes a copy of current.c, called old.c, on the working directory. cp current.c ex72 copies current.c to the subdirectory ex72 (it retains the same name). cp current.c ex72/old.c copies current.c to the subdirectory ex72 with the name old.c To move a file, type mv course destination This does the same thing as cp but it erases the source. So to change the nane of some file, just type mv oldname newname Here's another example, mv here.c ../there.c This moves here.c from the working directory up 1 level and renames it there.c Let's say you are currently working in the CompPhys directory and you want to move something from the ex71 subdirectory to the ex72 subdirectory...you don't want to rename it. Type, mv ex71/something.c ex72 To delete a file, type rm name where "name" is the name of the file you want to delete. Be careful, linux doesn't place it in a "trash" bin for possible recovery. To simply view a file without editing it (for example, if you want to peek at an output file), type more name where "name" is the name of the file you want to view. CONNECTING WITH A SERVER ======================== We do not yet have the permanent server for this class, but we have set up an account on a temporary server for you to practice on. You can connect to this server using the following command: ssh -l comphys stellar.phys.appstate.edu for the password, use "einstein", all lower case. You should now be on the server, and you can use "ls" to see what files are on that computer. Please do not delete or rename any of these files, as this account is being used by all the students in this class! You will notice that a file called hello.c and this set of directions, README.1st, are on that server. Now, logout by typing "exit" at the prompt. We are now going to use "sftp" to transfer some files from the server to your local computer. Type at the prompt at your local computer: sftp comphys@stellar.phys.appstate.edu again, enter the password when it asks you to do so. Transfer the two files mentioned above with the commands: get hello.c get README.1st then exit with "exit". These two files should now be on your local machine. The file hello.c is a simple program. We will now learn how to compile and execute this program. COMPILATION AND EXECUTION ========================= To compile your code, Type: gcc -o exename name.c -lm (for instance, gcc -o hello hello.c -lm) where "name.c" is your source code and "exename" is the name of the executable code that will be produced on a successful compile/link. Normally, your code will not compile without error the first time - gcc will produce an error with a line number and a description for each error. If you get a warning, the code will still compile but it may crash during execution. The -lm tells the compiler to include the math libraries (more in class). To execute your code, simply type ./exename (for instance ./hello) To kill hung executables, hit CONTROL-C. Alternatively, you can use the 'kill' command but ask for help. To get instructions on the use of any linux command, type man command FURTHER INFORMATION ON SERVERS AND HOW THIS CLASS WILL WORK =========================================================== CLASS SYSTEM OVERVIEW ===================== In PHY4020/5020 - Computational Physics, we will be doing our work in the linux operating system. We will be compiling code using gcc and we'll be using gnuplot to visualize data. You have the option of installing linux on your computer, using a system with linux already installed, and/or logging into our server which is running linux. Since you will need to submit your homework assignments on the server, we highly recommend that you simply access our server for all of your work. If you're already running linux, this means you'll just have to ssh/sftp into the server, or you can open a remote X-window if you choose to run gnuplot (or any other graphics service program, like gimp). However, most of you are running Windows, so you will need to run a windows native ssh program and an sftp program. SSH "ssh" (secure shell) is a network protocol typically used to log into a remote machine and execute commands. In Windows, you can download a free ssh client, called "putty", at: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Putty runs independent of the Windows registry so once you download it, say to your desktop, you just double-click it and it will run (there is no install required). A typical ssh session would involve logging into the server (you provide the server name in the putty screen) to get a command line. You can then do anything you need to do, such as edit (using, for example, vm), compile using gcc, or copy (cp) or move (mv) for homework submission. To run ssh from a linux command line, type ssh servername.domain.name.edu -l userid (the '-l' (el) is not required). You will be prompted for your password. SFTP "ftp" (file transfer protocol) is a commonly used protocol for exchanging files over any network that supports the TCP/IP protocol - "sftp" is the "secure ftp" (ftp running through ssh) version of ftp (note: ftp is not enabled on our server but sftp is enabled). If you're running Windows, there is a free sftp client called WinSCP, available for free download at: http://winscp.net/eng/download.php (select WinSCP 4.0.3 installation package). This will actually run an install program in Windows. This sftp version is nice in that it is driven by a graphical user interface that allows you to point-click-and-drag files from your machine to and from the server easily. You will use this primarily to transfer your files to and from the server and other machines. All of your operations, such as homework submission, compiliing, and executing code will be done in an ssh session, not sftp. To run sftp from a linux command line, type sftp userid@servername.domain.name.edu -i (the '-i' is optional - it just makes things easier during your session). XMING SSH programs (see above) will enable you to connect to the Linux server from a Windows machine, but will not enable you to run graphics programs such as gnuplot. To do this, and have the graphics appear on the Windows screen, you need to use what is called an Xserver. Xming is an Xserver for Windows. It can be downloaded from http://sourceforge.net/projects/xming you will need to download two setup files, Xming and Xming-fonts and install them on your Windows computer. During the install, check the option to install icons for both Xming and Xlaunch on your desktop. Also, during the install of Xming, ask the installer to install Putty. Before you attempt to run Xming, reboot your computer. Once your computer reboots, you should see two icons on your desktop for Xming and XLaunch. Double click on XLaunch, and select "Multiple Windows". Click Next, and then select "start a program". The program "xterm" is default, and this is what you want. Also click under "Run Remote" "Using Putty", and then enter the name of the server, your username on that server and your password. Click next twice, and then Finish, and then an xterm should appear on your desktop. From this, you can enter any Linux command, as well as run graphics programs such as gnuplot. If you want a second xterm window, simply type xterm & in the first, and hit return.