One of the most common complaints about SystemC is that it takes too long to compile. I tend to agree that it does take longer to compile compared to C or Verilog. The primary reason is that SystemC is a somewhat complex set of libraries built on top of C++ and is compiled with g++. Almost every programming language has pros and cons, and compile time happens to be a con of SystemC.
The next most common complaint after general SystemC compile time is that the utility commonly used to compile SystemC Virtual Platform models, ncsc_run, doesn't implement parallel compile like make -j does. The GNU make -j option stands for jobs and specifies how many jobs to run in parallel. The best number is generally equal to the number or processors in your machine. If you have only 1 CPU this option doesn't help you, but since most machines have at least 2 CPUs compilation can be run in parallel. If the -j is not followed by a number then make will not limit the number of jobs that can be run simultaneously.
I did a little digging and found out that ncsc_run actually does implement parallel compile and it's pretty easy to do, it's just not obvious how to do it. As a result I decided a quick explanation will go a long way toward helping others implement parallel SystemC compilation.
Inspection of ncsc_run -help revealed some options for distributed compilation, but they look like they are for a farm of machines and the only solution mentioned is LSF (Load Sharing Facility from Platform Computing). LSF support is good, but I'm looking for parallel compile on a single machine with multiple processors (like my laptop). In the Virtual System Platform (VSP) User Guide there is also a section after the distributed compilation system about using -CATCXX to concatenate multiple source files together to save compile time. Again, a good idea, but not what I'm looking for.
In the end I found the solution is to use an environment variable called NCSC_MAKE. To enable parallel compilation set it like this (for csh):
% setenv NCSC_MAKE "make -j"
The VSP User Guide doesn't say much about this environment variable, but it is mentioned. The only description is that the variable specifies which make utility to run, but no mention of parallel compile or make -j.
The bad news is that setting the environment variable NCSC_MAKE doesn't actually work; no parallel compile is executed when ncsc_run is invoked. All hope is not lost, it turns out that the key to enable parallel compile is to use the -format off switch. This switch disables the pretty printing by ncsc_run and displays the raw output of all of the compilation steps. Normally this is a good thing to do if you are really stuck on a compilation issue and can't see what is going on. In this case I don't really know why it triggers the NCSC_MAKE environment variable to work as expected, but it does.
In conclusion, it is possible to do parallel compilation of SystemC with ncsc_run using a combination of the NCSC_MAKE environment variable and the "-format off" switch.
Let's try an example.
Go to a scratch area, and from your release tree take a copy of one of the examples. I don't know what this example does, but it doesn't matter for this experiment.
% cp -r `ncroot`/tools/systemc/examples/precompiled_headers .
Now edit the file run_ncsc_run to put a $* at the end of the second ncsc_run invocation so we can pass extra options to it to experiment with parallel compile.
First, run the regular way, I told ncsc_run to stop after elaboration since we only care about compile right now:
% time ./run_ncsc_run -O3 -stop elab
Now set the environment variable:
% setenv NCSC_MAKE "make -j"
and run with -format off to see the parallel compile:
% time ./run_ncsc_run -O3 -stop elab -format off
I ran on a 12 processor server and the compilation was done in a fraction of the time it took using serial compile. Of course, your results will vary depending on your machine and how many SystemC files and the size of the files you pass to ncsc_run.
Hopefully you learned something about ncsc_run and can now setup a better compilation environment on your Virtual Platform modeling projects.
I'm sure the same is possible with irun for those of you doing mixed language simulation (or just using irun for fun). Maybe somebody can try with irun and post the instructions.