Song of the Whale
Parallel Processing Using APL2

by Per Gjerløv, Technical University of Denmark, Lyngby, Denmark
(gjerlov@ibm.net), and Izabela Meisel,
University of Mining and Metallurgy, Krakow, Poland (Izabella_Owsiak@doctorq.com)

Abstract

APL2 has often been used in a credit course at the Technical University of Denmark. The objective of the course exercise has been to analyse the vocalisations of Sperm Whales. In January 1996 the course was run again, this time using the IBM SP/2 supercomputer to solve the problem, and in this course an additional objective was to utilize the possibilities of this powerful parallel computer.

During the three weeks of the course the students learned the APL language, solved a non-trivial problem, used a very powerful computer for the solution and wrote excellent and detailed reports.

The whale

The course is based on sound recordings from sperm whales (Physeter macrocephalus or Physeter catodon). The sperm whales are the largest of the toothed whales, they can be up to 15m in length and can weigh more than 30 tons. A whale typically swims at the surface for about 10 minutes, and then starts a dive, often to depths of more than 1000m, and with a duration of up to an hour. During the dive the whale feeds. There is no light from the surface at these depths, and the whale emits sounds which presumably are used for echolocation of the prey.

Like the other toothed whales the sperm whales are predators, feeding on squids or deep-sea fish, which are swallowed whole.

One typical sound from a sperm whale is a short click of several milliseconds duration. Analysis of these sounds is an important tool in ongoing research on the behaviour of sperm whales.

The ship

The “Song of the Whale” is a research vessel, its operation is supported by IFAW, the International Foundation for Animal Welfare. The ship is equipped with sound recording equipment, which can record the sounds from towed hydrophones and store the sounds on tape recorders. Typically whales are observed when diving, and photos of the tail fins are used for identifications of individual whales. On a cruise on the “Song of the Whale” at the Azores in 1991 the author (PG) collected several recordings of the sounds from sperm whales, and one of these recordings is used as data for the course.

The computer

Over the years the course has been run using a variety of computers. For some years the workhorse has been the IBM 3090 at the Technical University. The machine had a Vector Facility, that worked very well with the APL2 system. After the decommission of the IBM 3090 the course has been run using several rather small pc’s. For the latest course we have been using the IBM SP/2 computer at the UNI*C, the common computing center for the Danish Universities.

The IBM SP/2 computer contains several RISC/6000 workstations in a common cabinet. The workstations are connected by an internal high-speed switch, and by a standard TCP/IP network. The configuration can be varied within very wide limits, a configuration with one computer is possible, and the SP/2 can be built with as many as 256 workstations. Each workstation runs under the control of the AIX system.

The SP/2 computer at the UNI*C has 40 workstations, or nodes, each with a memory of 256 Mb, except one which has a 1 Gb memory. The total hard disk capacity is several hundred Gb. The SP/2 is connected to the Internet, normally it is addressed by a generic name.

Solving this problem cannot in any way tax the capabilities of the SP/2. After all, in an earlier course we used rather small pc’s. However, we wanted to show the possibilities of programming a parallel solution using APL2.

The APL

The programming language used for this course was IBM’s APL2. For the purpose of the course it has some major advantages. First the language is identical across several platforms. We have been using the IBM 3090 under control of VM, the pc’s under DOS, and for the present course testing and development has been done on an OS/2 system. The course has been run under AIX, IBM’s version of UNIX, and porting of programs has always been painless. We use the possibility to use user-defined functions as in the outer matrix product. For the exercise it is necessary to have access to a complex Fourier transform program, and complex numbers, and the FFT program is integrated in these APL2 systems. The GRAPHPAK program, included with APL2, is very useful for plotting of the data.

The data

For the course one recording is selected, where the sounds of one diving whale are heard very distinctly. The whale is diving almost vertically, and at the start of the recording the whale is probably not more than 100 – 200m under the boat. In addition to the sounds of this whale the recording contains sounds from a small number of other whales, presumably swimming at hunting depth. The recording is slightly atypical, as it only contains short clicks — other recordings can contain sounds of longer duration.

Before the start of the class this recording is digitised using a standard pc sound card. Several cards have been used with good results, for this course the digitising was done using a Sound Blaster 16 ASP. For the class we use one minute of the recording. As the sound is sampled with a frequency of 44100 Hertz, and each sample is stored as a 16-bit number, the one-minute recording becomes a file of a size of about 5 Mb.

The digitising is done using the standard OS/2 multimedia program. The result is a file in the RIFF WAVE format. It has a header describing the file — duration, sample frequency etc. followed directly by the digitised sounds, as pc format numbers.

The first task is to transform this file to a more manageable format. As mentioned above this recording contains only one type of sounds from the whales, single clicks, separated by periods containing only background noise — mainly wave and engine noise. It is changed into a matrix, where each line contains e.g. 256 sample points of one click, corresponding to a duration of just under 6 ms. The transformation is done by an APL program. The file is scanned to find the first value numerically larger than a given threshold. The values from 30 sample points before this value for a total of 256 sample points is stored as a line in the sound matrix, and at the same time the index of the first sample point is stored in a corresponding vector, to give the starting time for the click. Each time a click is found and stored, the first part of the data vector, including the stored click, is discarded, and the search continues in the remaining vector.

The file is read in records of a size of 32768 bytes. Each record is read, transformed to APL integers and analysed. When the analysis of one record is finished, the remaining part of the record is catenated with the next record, and the process is repeated. Apart from experiments to find a reasonable threshold value this reduction of the original data is a one-time operation, and it is run in a reasonably short time. For the purpose of the course, the reduction is completed in advance, using APL2 for OS/2. The resulting datafile is entered in the SP/2, and the students are given an APL2 function, which will read the datafile and generate the click matrix into the students’ workspace.

The clicks

The following figure shows the first click from the diving whale. The figure shows the amplitude of the click as a function of time. Fig1 (graph)

The total duration of this click is about 5 ms. The click contains a high-intensity, high-frequency part of very short duration, about 0.5 ms, a lower-intensity, lower-frequency part of about 3 ms duration, and a reflection, or echo, of the first part. The echo is believed to be generated inside the head of the whale, and the interval (called the Interpulse Interval, or IPI) between the first part and the echo is probably correlated to the size of the head of the whale, and may therefore be correlated to the size of the whale. There may be following echoes, they are not shown because the click is cut off after 256 sample points.

During the dives the whales very often click at intervals of 0.5 to 1 second.

The clicks were recorded as stereo recordings, the two hydrophones were separated by 3m.

The clicks of one whale may be characterized by:

The exercise

The students normally start the exercise by plotting several clicks, using the graphical routines in 2 GRAPHPAK. It is easy to locate the first clicks from the diving whale (in this context called the primary whale), as these clicks have a relatively high amplitude. For this whale the first clicks look almost identical when plotted together, and echoes of these clicks, most probably from the sea surface are also found. It is rather easy to distinguish the first 5 – 10 clicks by this method.

Next, for the first 20 – 30 clicks the frequency transforms are found by using the FFT routine from 1 MATHFNS. For each of the transforms only the magnitude is used — the phase is disregarded. The first clicks of the primary whale can be discriminated in this way, just as they could from their waveforms. The following figure shows the frequency spectrum for the previously shown click. This click has peaks around 1500 Hz and 5000 Hz. Fig2 (graph)

When the first clicks are found for one whale, a vector of the intervals between clicks can be calculated. The time interval between clicks is another criterion for locating the clicks of one whale, but the time interval may change during the dive, e.g. when the whale is closing on a prey.

The clicks and their surface echoes have the same frequency spectrum. The phase of the echoes is reversed relative to the original sounds, and they occur a short time after the clicks, so they are rather easy to eliminate. Because of the methods for finding the clicks, consecutive clicks from one whale in the data matrix may appear as shifted along the time axis relative to each other, so a function may be constructed to shift a click along the time axis to facilitate the comparison.

The amplitude and frequency representations of each click may be compared with those of all other clicks using a simple test function and an outer product. By experiments a threshold value can be found, and sets of clicks belonging to one whale can be determined.

By these methods a set of APL functions, a toolkit, can be constructed, and by using these tools it is possible to locate clicks belonging to 3 – 5 whales in the sound sample. When clicks (and echoes) belonging to one whale are found, it is useful to remove these clicks from the original data, to make the continued search easier.

The time interval between a click from the primary whale and the surface echo of the click may be used to judge the depth of the hydrophone, this analysis is often done by the students.

By observing the diminishing amplitude of the clicks of the primary whale it may also be possible to estimate the depth as a function of time, and the diving speed.

Using the SP/2 Computer

The task outlined here is of course much too small to justify using the SP/2, but it can be used to explore some of its capabilities. The methods can easily be tested using a single computer running APL2 under OS/2 or under AIX. Several APL2 sessions can be started in a single computer, and when the communication between sessions has been tested, it is almost trivial to move the functions to several nodes of the SP/2. The communication between sessions is done by the standard shared variable mechanism of APL2. For one computer this is straightforward, and exactly the same functions can be used for several computers. The process numbers are translated to a description of other computers by a Shared Variable profile describing the other processes by IP addresses and usernames.

One process is a master process, and offers one or more variables to a number of other processes, slave processes. The processes may be named e.g. 2001, 2002, ..., and a share then has the form:

2001 ŒSVO 'A2001 A'

This is easily extended to a general function describing sharing with a number of processes. By using a surrogate name as here, each of the slave processors may use identical functions to accept the offer and process the necessary function.

The Fourier transform is done by the APL2 statement:

FT„FFT¨›[2]M

where M is the matrix of click amplitudes, in the matrix each row represents the amplitude function of one click. The first attempt to build a parallel program was to replace the EACH operator with an operator distributing the load on N nodes.

We did not succeed in this general approach, and also for the course we had only access to a few of the SP/2 nodes. We split the matrix M in three parts of almost equal size, and then sent these smaller matrices to three nodes for evaluation. The resulting frequency transforms are then collected in one vector for further processing. Comparisons between two vectors may be done by the following function:

[0]   Z„X TEST Y
[1]    X„X÷+/X
[2]    Y„Y÷+/Y
[3]    Z„(+/(X-Y)*2)*0.5

If the two vectors are identical, the result will be zero, and a large difference is shown by a large number. If FT is the vector of vectors to be compared, the comparison can be done by the outer product:

C„FT °.TEST FT

The matrix C will contain values, where small values show similarities, and large values differences. A cut-off value can be determined empirically.

Calculation of the comparison matrix, C, is rather time consuming. However, it is symmetrical, and the main diagonal is not interesting. One student therefore replaced the above computation with computation only of the upper triangular matrix, and distributed this calculation between the slave processors.

Further possibilities for utilizing parallel programming

We would like to do more work on the user-defined EACH operator. This seems otherwise to be a promising way for easy exploration of the parallel possibilities.

For all methods it will be useful to program a form of automatic load balancing. If part of a job happens to be submitted to a very busy node, the whole job will be delayed.

Especially, for APL2, it is worth trying a form of object oriented programming, where a subtask is submitted to a slave as a structured matrix containing both the data, and the program to work on the data. This is feasible in APL2, where the programs (functions) generally are of a very limited size. APL2 seems to have an advantage in this area over other programming languages.

During the course the session managers both for the master computer and the slaves were shown as windows on the access workstation. A more professional setup may be to run the session managers for all nodes on the master computer, or even on the workstation used for access to the SP/2. These session managers may be run as unattended background tasks, but their windows will be available for debugging purposes.

For the size of problem in this course the performance using standard APL2 is quite sufficient. If a time analysis shows a bottleneck, one solution may be to replace a critical part of the code by a program written e.g. in C, or maybe a routine from a program package as the ESSL for SP/2. ESSL can be called from an APL2 function. This is well documented in the ESSL manual.

Finally it is worth noting that the SP/2 is very similar to a group of powerful, independent workstations. The methods outlined here can be tried also on a single computer with several processes (APL2 sessions), or on a group of interconnected separate workstations running under control of OS/2 or AIX.

The SP/2 is a very powerful server computer. Its configuration can be varied within very wide limits. A smaller configuration can be useful in a small company, and a large configuration can serve the need for a large corporation or university. It is possible to utilize parallel computing for very heavy tasks, but it is also possible to use a single processor of the SP/2 as a server. As the machine has load balancing facilities, it is possible to automatically schedule a task to the machine with the lightest load at that time.

The student reports

The present course, as similar previous courses, was run as a three-week credit course at the Technical University of Denmark. It has been shown again that by using APL2, the students can learn the language (and its notation) very quickly. The formal APL education was only five lectures, using an effective, on-line teaching technique. On the first day of the course, the students get a diskette with TRYAPL2, and they are encouraged to install this program on their own computers and to practise using APL2 already before day two, and also later in the course. The students can within the three weeks use the APL2 system to solve a reasonably advanced problem. The questions in the exercise are on purpose only vaguely described, and the data is real life data with all the associated complications. The students are encouraged to use the “APL machine” as a “tool for thought”, for experiments, and for developing a toolkit for the solution of the problem, rather than developing one large program to give the answer automatically.

The students are requested to deliver a written report, and these reports have often been of outstanding quality. This was also the case in this year’s course. This time the class had only three students. One major reason is that the SP/2 is normally not open for educational projects, and the number of students was therefore strictly restricted. Another reason was that the course was taught in English (sort of) — this may have scared a number of potential attendees. The three students delivered very complete reports, one of the reports was written in English, as a courtesy to the teacher, and for their work all three students got an A grading (13 in the Danish scale).

The problems

We encountered several practical problems during the course.

We made a quick test of APL2 on the SP/2 system in September 1995, using an old program package, and concluded that the project was feasible. IBM granted free use of APL2 for the class, and according to agreement they delivered a fresh program package in November.

Unfortunately we did not check the content of the package at that time, and when we checked on the installation early in January, we learned that the new program had not been installed “as it was identical to the already installed program”. A customer is supposed to know that an IBM program as delivered is obsolete, and the customer has to order an update immediately on delivery of the original package — the UNI*C staff did not know that, and unfortunately the installation was not checked in November. The local IBM engineers denied that an update existed, and only after heavy-handed assistance from the APL2 group at IBM in Santa Teresa did they admit that an update could be delivered.

The net result was that we did not have the correct product installed until the fourth day of the three-week course. The original program was used in the meantime, but it was faulty, and we did not know what changes to expect when we got the updated program.

A student course at the Technical University is normally scheduled on a large group of HP workstations. The computing center never solved the APL keyboard problems with these workstations, and instead the course was scheduled on a group of IBM RISC/6000 workstations. On these workstations almost all keys on the keyboard worked as intended, but for a few characters the “keying” had to be done by “drag and drop” from the atomic vector. The installation instructions for APL2/6000 can be improved in the area of keyboard and font support.

On the Saturday at the end of the first week of the course a major fire broke out in the room adjacent to the RISC/6000 workstations, the room burned out completely, and the window panes broke. The fire was caused by an experiment running wild. Fortunately the fire door between the rooms held. The room with the workstations was closed for the remaining part of the Saturday and the following Sunday for a much needed cleaning of a layer of soot on all computers and all furniture, so one day and a half was lost. The server in the group of workstations was much damaged by the acid smoke from the fire, but it was decided to attempt to keep it running for the remaining days of the course. It worked, and it was only taken down for cleaning just after the end of the course period.

On the morning of the last Monday of the course period the computing center decided to change the operating system to AIX version 4. The installation failed, and the SP/2 was unaccesible for two days and nights close to the end of the course period.

Each node of the SP/2 has three or four different IP addresses, giving access to the different nets. We only succeeded in establishing communication via the standard net address, and never found out how to use the high-speed switch. It is not clear for us whether this is caused by a problem with the TCP/IP interface in APL2, or by lack of knowledge of the teachers.

Conclusion

It has again been demonstrated that APL2 is an outstanding teaching tool. The students master it very quickly, and can solve an advanced problem in a very short time.

APL2 is an excellent language for such a course. The students get an effective grounding in problem solving, and with this exercise they also get a lot of practice using the Fourier Transform in the complex domain. This is very helpful in understanding the Fourier Transform itself.

The APL2 system is a powerful tool for developing and executing programs in a high-performance, parallel environment. When a new technique emerges, it can be exploited using a standard APL2 system.

Acknowledgements

We would like to thank Jonathan Gordon, Oxford University and IFAW, for encouragement, and permission to use the data from the “Song of the Whale” surveys, and also for his review of this report. We are grateful for the grant from the Danish Data Association which made it possible for Izabela Meisel to assist in the teaching. We also thank Ove Skovgaard, Department of Mathematics at the Technical University of Denmark, for arranging the course. Thanks to the staff at UNI*C, the Danish computing center for research and education, for access to the SP/2, and for help in installing APL2 on the SP/2, and solving numerous small problems in the setup. We also want to thank IBM Denmark for permission to use the APL2/6000 for the class, and the APL2 team in Santa Teresa for quick and competent support before and during the course period. Without all this help the course would not have been possible.

References

For information on the SP/2, see the World Wide Web at: /http://www.sp2.uni-c.dk.

John C. Goold & Sarah E. Jones: Time and frequency domain characteristics of sperm whale clicks. J. Acoust. Soc. Am. 96 (3), September 1995

Russell Leaper, Oliver Chappell & Jonathan Gordon: The Development of Practical Techniques for Surveying Sperm Whale Populations Acoustically. Rep. Int. Whal Commn 42, 1992

Jonathan Gordon: Evaluation of a method for determining the length of sperm whales (Physeter catodon) from their vocalisations. J. Zool. Lond. (1991)