Exercise Hello-World

Objective: Create a working programming environment and make a Hello-World program.
  1. Get yourself an account on IFA computer system. You probably have one if you have an email account on phys.au.dk;
  2. Boot your POSIX system e.g. from the Ubuntu CD;
  3. Prepare the directory for the exercises:
    1. Open a terminal window (in Gnome: Applications→Accessories→Terminal) and login into lifa.phys.au.dk. If your login name is fedorov (it is not), do
      
      ssh -X fedorov@lifa.phys.au.dk
      
      where -X option is needed if you plan to use X-windows programs. After typing your password do
      
      mkdir ~/public_html
      mkdir ~/public_html/numeric
              
      where ~/ is an abbreviation for you home directory. Now the URL http://www.phys.au.dk/~fedorov points to your ~/public_html/ directory, while http://www.phys.au.dk/~fedorov/numeric points to your"~/public_html/numeric" directory which should then be the place for your solutions to the exercises.
      1. If you are outside IFA's firewall you need to have a pair of your personal RSA keys. If you don't have the keys, you can create them with the commands:
        
        cd
        cd .ssh
        ssh-keygen -t rsa
                
        It will ask you for a passphrase which you have to make up and remember. If wverything goes right a private key, called "id_rsa", and a public key, called "id_rsa.pub" are generated in your .ssh directory. The private key has to be kept in the .ssh directory of the computer you want to login from. The public key has to be trasferred to lifa and added to the file ".ssh/authorized_keys" on lifa:
        
        cat id_rsa.pub >> authorized_keys
                
        After the public key had been added to authorized keys on lifa, all computers with the corresponding private key can ssh into lifa as
        
        ssh -X your_user_name@lifa.phys.au.dk
                
        It will ask you for the pasphrase of the public key. You can transfer the public key (which is one long line of characters) to lifa by e.g.
        1. send the key to youself by email as an attachment;
        2. get a bootable Linux CD (you can borrow one from me) and boot one of the computers in 1525-319 from this CD;
        3. open a terminal (Applications→Accessories→Terminal) and ssh -X to lifa using your NFIT password (remember the -X option: you will need it to run Firefox on lifa).
        4. run firefox & on lifa, get your attachment and add it to your .ssh/authorized_keys on lifa;
        then connecting to lifa from inside the firewall, e.g. through a cable connection at the institute, reading your email from lifa an and adding the key to your ".ssh/authorized_keys".
      2. Remember to do
        
        chmod -R go+xr ~/public_html
        
        to allow everybody to see your files in this directory. You might need to issue this command again after you have created some new files.
    2. Pick your favourite programming language for the exercises. The only restriction is that there should be a debian package for it (i'll be surprised if there isn't). For example, Javascript -- is an easy to learn modern language built in every browser (though not really used for scientific programming); C -- it's probably the most ubiquitous language in existence, it is very fast and powerful and and there is GNU Scientific Library written in C.
    3. Look also at these benchmarks of computer programs written in different languages.
    4. Pick your favourite editor to edit your programs. If you don't have one, try the following editors available on lifa and molveno: nano (very simple), jed (more advanced), gedit (simple graphical interface, you probably want this one), emacs (popular with computer programmers), vi (good old stuff from 1976, still going strong), kate (KDE advanced text editor)...
    5. Create a Hello-World program in your favourite programming language with your favourite editor and build it using make utility. In C:
      • mkdir ~/public_html/numeric/hello
      • cd ~/public_html/numeric/hello
      • create a file hello.c with the content
        
        #include <stdio.h>
        int main() {
        	printf("Hello, world\n");
        	return 0;
        }
        
      • create a file makefile with the content
        
        hello.txt: hello       # hello.txt is the default target
        	./hello > hello.txt # run hello and redirect stdout into hello.txt
        	cat hello.txt       # send the content of hello.txt to stdout
        
        hello: hello.o
        	cc hello.o -o hello
        
        clean:
        	rm -f hello hello.o hello.txt
        	
        Note that the indented lines start with a tab-character, not with spaces.
      • Now run the make utility
         make 
        you should see the message on your screen if everything goes right (it never does the first time, of course...).
      • You can find other hello-world examples here. Note that some compilers are only installed on molveno, not lifa.
    6. Go to the Wiki page of Numerical methods at AULA and add your name with the link to your exercises to the Homeworks page.