| 3-1 |
Compiling with the make utility. Getting from the original C-program to the final file ready to be downloaded onto the transputer takes too many commands for most users to find acceptable. Fortunately, the make utility (distributed with LS C) is ideal for keeping track of this kind of file processing. The listing below shows a skeleton make-file that can be easily tailored to maintain single- to multiple-file programs. It will automatically preprocess, compile, assemble, and link the files making up the program. Most programs on the distribution diskette have make files associated with them. The make file always carries the same name as the main program, but with a .mak extension.
# =======================================================================
# Skeleton make file for Logical Systems C programs.
# D. Thiebaut
#
# To be used with Logical Systems' MAKE utility
#
# To use, fill in first five lines after header with the information
# requested shown in the example below.
#
# ======================================================================
# FILENAME = queenslb
# FILE_NAMES = $(FILENAME) balance heap search
# C_FILES = $(FILENAME).c balance.c heap.c search.c
# LINK_FILES = $(FILENAME).trl $(FILENAME).lnk balance.trl \
# heap.trl search.trl
# HEADERS = balance.h heap.h search.h
# =======================================================================
# = MACROS ==============================================================
FILENAME = [Enter here name of main program (no .c extension)]
FILE_NAMES = $(FILENAME) [name (no extension) of other .c files needed]
C_FILES = $(FILENAME).c [same as above, but with a .c extension]
LINK_FILES = $(FILENAME).trl $(FILENAME).lnk [same, with a .trl ext]
HEADERS = [any header files used to generate main program]
# = FLAGS USED BY PREPROCESSOR, COMPILER, AND LINKER ====================
PP_FLAGS = -v
TCX_FLAGS = -p85 -v
TASM_FLAGS = -t -v
# = DEPENDENCIES ========================================================
$(FILENAME).tld: $(LINK_FILES)
$(FILENAME).trl: $(FILENAME).tal
$(FILENAME).tal: $(FILENAME).pp
# = ADD OTHER DEPENDENCIES HERE IF NECESSARY ============================
# example:
# balance.pp: balance.c balance.h
$(FILENAME).pp: $(FILENAME).c $(HEADERS)
$(FILENAME).lnk: $(FILENAME).mak
ECHO FLAG > $(FILENAME).lnk
ECHO LIST $(FILENAME).map >> $(FILENAME).lnk
ECHO INPUT $(FILE_NAMES) >> $(FILENAME).lnk
ECHO ENTRY _vcmain >> $(FILENAME).lnk
ECHO LIB t8lib >> $(FILENAME).lnk
ECHO LOAD 0x80002000 >> $(FILENAME).lnk
ECHO STACK 0x80001F00 >> $(FILENAME).lnk
# = IMPLIED RULES =======================================================
.c.pp:
pp $< $(PP_FLAGS)
.pp.tal:
tcx $< $(TCX_FLAGS)
.tal.trl:
ttasm $< $(TASM_FLAGS)
.trl.tld:
tlnk $(FILENAME).lnk
The stdio.h library provided by LS C contains all the ASCII input/output functions. In particular you will find that you have access to your favorite functions, fopen, fclose, fscanf, fprintf, fgets, etc. Write a program for one transputer that opens a file containing 1000 random integers, sorts them, and stores the result back to the file. Use the sorting algorithm of your choice. Use the skeleton make file to compile your program. Verify that your program also runs on the host. (Hints: since your program will not be using any "parallel" constructs yet, and if you use ANSI-compatible functions, it should run exactly the same way on the host machine as it does on the transputer. Hence you may want to develop it on the host first!) . |
| 3-2 |
As soon as the program of exercise 3-1 is written and working well, it
becomes tempting to compare the speed of execution of the transputer versus
that of the host machine. To time the execution time of a program for the transputer, follow the example below.
#include <stdio.h>
#include <time.h>
main()
{
int StartTime, EndTime, i, j=0;
StartTime = Time();
/*--- do some computation here ---*/]
for (i=0; i<10000; i++)
j += i;
EndTime = Time();
printf("Elapsed time = %f seconds\n",
(EndTime-StartTime)*0.000064);
}
The function Time() (note the uppercase T) returns the current value of the Timer register (see previous chapter), which, for low priority tasks such as main, beats at one tick every 64 s. Time the execution time of your program on the transputer, and time it as well on your host machine. What is the rating of your Root transputer compared to your host processor? . |
| 3-3 |
What improvements can be gained by turning ON the "compress" option of
the compiler and assembler? Select a large size C program, and evaluate the
reduction in load time and in disk storage gained by the use of this option. . |
Writing parallel programs is slightly more complicated than writing programs for serial machines. The complexity of the preprocessing, compiling, assembling and linking can very easily been handled by the tcc and make utilities. Tcc will handle straighforward single- and multiple-file projects, while make be able to manage larger projects where several modules and their header files constitute the whole program.
One added area of complexity that we do not have with serial machines is the presence of the network of transputers, the exact layout of which we must know in order to map our program to it. This knowledge can be acquired by a direct inspection of the physical connections, or by running utility flood programs such as the check utility bundled by Computer Systems Architects in the Educational Kit. This program floods the networks and creates a map of the physical layout, which it then displays on the screen.
The chck2nif program in the util directory of the distribution disk can be used to transform the output of check to a nif file format.
In the next chapter we start developing more interesting programs by incorporating message passing primitives in our programs. This will introduce us to examples of true parallelism of code running on different transputers and solving a common problem.