Skip Navigation | ANU Home | Search ANU | Search FEIT | Feedback
The Australian National University
Faculty of Engineering and Information Technology (FEIT)
Department of Computer Science
Printer Friendly Version of this Document
High Performance Scientific Computing COMP2310
COMP2310 Introduction to Ada: Online Tutorial Week 1

Introduction to Ada: Online Tutorial for Week 1 (and 2)

You need to complete this tutorial during weeks 1 and 2 and in your own time. There is no formal labs timetabled in these weeks, or tutors to assist you. If you have questions you will need to see me (Alistair Rendell). Formal labs will begin in week 3. At that point you will be seriously disadvantaged if you have not looked that this tutorial (or have Ada experience from elsewhere).

The first part of COMP2310 and the first assignment will make use Ada. We use Ada as it provides good support for concurrent programming through the availability of a number of constructs, such as protected objects and rendezous, in a form that is relatively easy to use. Before using the concurrent aspects of Ada, however, you need to become familiar with some basic Ada! The aim of this web page is to point you in the direction of an online tutorial that will help you to achieve that knowledge.

There is a variety of Ada material available online. I think the Lovelace site prepared by David Wheeler is particularly useful, but if you find other useful resources I encourage you to post them on the COMP2310 Discussion board.

Using Ada on the student system

Although the Lovelace tutorial provides snippets of code and indicates that these can be compiled using "WebAda", this does not appear to work. So you will need to compile and run the code snippets on the student system, or elswhere. In the labs and for the assignment we will be using the GNU Ada Compiler, known as GNAT. You can run this on the student system (any of the machines in the student lab or from outside the ANU by ssh to partch.anu.edu.au) or download a copy and install it on your own machine. (Note, if you install your own version you must do final testing of your assignment using the version of gnat on the student system).

The gnat compiler expects to find Ada programs in files that have either a suffix of .ads (denoting Ada specifications) or of .adb (denoting Ada body). These files bear a similar relationship to the .h and .c files in a C program.

The first example from the Loverlace tutorial is

-- Print a simple message to demonstrate a trivial Ada program.
with Ada.Text_IO;
procedure Hello is
begin
 Ada.Text_IO.Put_Line("Hello, world!");
end Hello;
copy this program into a file called "hello.adb" on the student system and then compile it by typing "gnatmake hello" in the same directory. Then run the code by typing "./hello". Here are the details of what I did on partch:
partch:~/comp2310/2007> pwd
/students/u9507815/comp2310/2007
partch:~/comp2310/2007> cat hello.adb
-- Print a simple message to demonstrate a trivial Ada program.
with Ada.Text_IO;
procedure Hello is
begin
 Ada.Text_IO.Put_Line("Hello, world!");
end Hello;
partch:~/comp2310/2007> gnatmake hello
gcc-4.1 -c hello.adb
gnatbind -x hello.ali
gnatlink hello.ali
partch:~/comp2310/2007> ./hello
Hello, world!
Note that to compile the code we type gnatmake, dependencies usually associated with a makefile are automatically handled via gnatmake. (You should not attempt to compile and link without using gnatmake!)

I think all the other examples can be built in a similar fashion using only one file named something.adb. If you come across any problems, let me (Alistair) know.

The Lovelace Tutorials

The master outline of the lovelace tutorials is given here. Before the first lab in week 3 you should aim to complete lessons 1-10. I would suggest the following. Another useful web site is Ada95: A guide for C and C++ programmers