Performance Basics

3.4 Implementation
Code implementation refers to those practices and strategies used to translate algorithms and code designs into functioning software. Some important considerations:

  • Arrange data arrays so that they are accessed contiguously in memory (by columns in Fortran, by rows in C). For example, in Fortran, these elements of a 100 x 100 array are in order after each other in memory:
        x(1,1) x(2,1) ... x(100,1) x(1,2) ... x(100,100)
    

  • Clarity and effective annotation makes the code usable and intelligible for other users (and yourself months later). For example, every program ought to be headed by a block of comments giving the name of the developer, the date it was developed, in what context, a history of updates, and the purpose of the program or routine. Comments on data declarations are helpful (trailing ! comments in free-format Fortran or // comments in C++ can be used on individual variable declaration statements). However, be careful not to over-comment your code. Too many comments are a distraction.

  • Make use of version control utilities (CVS, RCS, SCCS, etc.) to control the software development process. What a version control utility does is to store an initial version of your program, and then every time you store an updated version, it saves only the incremental changes. Thus you can "roll back" to any previous version. Other features of these tools are: they prompt you for a comment on every new version you store, so that you can keep a track of your revision history; multiple users can change the same source; multiple "branches" of code versions can be merged.

  • To as great a degree as possible, write machine-independent code. This means avoiding machine level instructions, avoiding vendor compiler extensions, etc.
The topic of code implementation is covered in more detail in the module on Single-Processor Performance Considerations.