Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

3.7 Compilation Time

The next questions we need to answer are, "How long will a compile take?" and "How long will a compile take on a parallel computer?" The first question is easy to answer. We simply sum the compile time for all the vertices in the graph. Just for fun, we do this computation using the std::accumulate function. To use this function we need iterators that, when dereferenced, yield the compile cost for the vertex. The vertex iterators of the graph do not provide this capability. When dereferenced, they yield vertex descriptors. Instead, we use the graph_property_iter_range class (see §16.8) to generate the appropriate iterators.

graph property_iter_range<file_dep_graph2, 
vertex_compile_cost_t>::iterator ci, ci_end; 
tie(ci, ci_end) = get_property_iter_range(g, vertex_compile_cost); 
std::cout << "total (sequential) compile time: " 
          << std::accumulate(ci, ci_end, 0.0) << std::endl;

The output of the code sequence is

total (sequential) compile time: 21.3 

Now suppose we have a parallel super computer with hundreds of processors. If there are build targets that do not depend on each other, then they can be compiled at the same time on different processors. How long will the compile take now? To answer this, we need to determine the critical path through the file dependency graph. Or, to put it another way, we need to find the longest path through the graph.

The black lines in Figure 3.3 show the file dependency of libfoobar.a. Suppose that we have already determined when bar.o and foo.o will finish compiling. Then the compile time for libfoobar.a will be the longer of the times for bar.o and foo.o plus the cost for linking them together to form the library file.

Now that we know how to compute the "distance" for each vertex, in what order should we go through the vertices? Certainly if there is an edge (u; v) in the graph, then we better compute the distance for u before v because computing the distance to v requires the distance to u. This should sound familiar. We need to consider the vertices in topological order.

Figure 3.3 Compile time contributions to libfoobar.a.

  • + Share This
  • 🔖 Save To Your Account