Appendix A. Building the MTS Demo Programs¶
A.1 Introduction¶
MTS includes a multithreaded, user-tunable MTS and system allocator performance test demo program. The makefile included with MTS creates two executables, one (demoF) linked against MTS and one (demoM) linked against the system allocator. These executables provide a realistic performance comparison of MTS and the system’s native malloc for multithreaded applications. They perform an intensive series of allocations and frees in each of a user-specifiable number of threads.
A.2 Building the Demo Executables¶
The procedure for building the demo executables is:
- Set up your environment to use the C compiler.
- Navigate to the directory that contains the MTS makefile and libraries.
- Build the demo executables. For Windows platforms, use the command line below:
prompt> nmake
For UNIX or Linux, use the command line below:
prompt> make
NOTE: This makefile may define several macros used in the demo
program, such as -DMTS_OPTIMIZED=1
, -DMTS_MT
, and so on. There
is no need to define these macros for other programs.
This creates the following files:
- demoF : Malloc test using MTS.
- demoM : Malloc test using standard system allocator.
- To remove the executables, invoke make or nmake for the clean target. For Windows, use the command shown below:
prompt> nmake clean
For UNIX or Linux, use the command shown below:
prompt> make clean
Calling Conventions The calling conventions for the demo programs are:
demoF [number-of-threads [number of heaps]]
demoM [number-of-threads]
The first command line argument is a number specifying the number of concurrent threads to run. Each thread performs the same sequence of calls to malloc and free, as determined by the parameters explained below. The default number of threads is 1. For executables linked to MTS, the second parameter is a number specifying the number of heaps to use. By default, the number of heaps is the same as the number of threads.
NOTE: On Windows, the demoF program ignores the number of heaps
specified on the command line. The demoF program reports an incorrect
number of heaps when the MTS_INIT_THREAD_HEAPS
environment variable
is larger than the number of heaps specified.
Each thread performs 10,000,000 malloc
and free
operations that
use between 11 megabytes and 15 megabytes of space. The malloc/free
operations are divided into very large (>10000 bytes), large (>1000 bytes),
medium (>100 bytes) and small (<100 bytes) sizes. The allocations are
performed in runs of 250 small sizes, 50 medium sizes, 10 large sizes and
individual allocations of sizes larger than 10,000 bytes. This, in our experience,
approximates the distribution of size allocations in a typical program.
These distributions are controlled by the k_max
variable in the demo code.
Before using the library in your application, ensure that the time demoF 1
takes to run is similar to the time that demoF 2
takes to run on your target
multiprocessor system (at least 2 CPUs).
On UNIX or Linux, compare the output of the command lines shown below:
prompt> time demoF 1
prompt> time demoF 2
On Windows, compare the output of the commands line shown below:
prompt> demoF 1
prompt> demoF 2
Since MTS allows memory allocation in different threads to overlap, the threads should run in parallel on a multiprocessor system. Therefore, the elapsed time should be similar for one thread and for two threads. If the demo program runs substantially longer for two threads, please contact your Support Representative (see the section 1.5 Technical Support.)