compile for very long expression

Hi All,

I am working on a project for modeling robotic dynamics. It requires to compile very very long c++ expressions produced by a symbolic tool. One of the long expressions is 28 million characters long. I am using current Linux Ubuntu and g++, (gcc 4.8.4). My make file tries to compile it with

g++ -c -Wall -g -o ConstraintMatrixdSpdx11.o ConstraintMatrixdSpdx11.cpp

The g++ has been running for a few hours with 99% CPU and 50% of memory load. I wonder the g++ has limitations on how long the expression can be? My symbolic tool can't simply the expression further. What other things I can try to compile and run my code?

Thanks in advance.

Everett
Geez, that poor GCC.
What sort of operations are in these expressions? Any function calls, or only unary and binary operators?
In the latter case, you could probably make it easier for the parser by reducing your expression to RPN form and generating your code like this:
1
2
3
4
5
std::stack<T> stack;
stack.push(42);
stack.push(37);
sum(stack);
//etc. 
It can be made faster if you can calculate the stack size in advance.
Yes, I am doing something extreme. :-) The calculation is just combinations of binary operations without function call. Here is a typical portion:

#include <math.h>
#include <iostream>
#include "ConstraintMatrix.h"

using namespace std;

// compute dSpdx1[9][3]
void ConstraintMatrix::ComputedSpdx1()
{
double W = WheelBase;
double dxf = xf, dxf2 = xf2, dxf3 = xf3;

dSpdx1[3][1] = cp2m2 * cp1m2 * (cp22 * cp12 * cosx13 * cosx75 * sinx8 *
(cosx1 / cp1 - sinx1 * cp1m2 * cp1m1 * (-2.0 * cosx1 * cosx72 * sinx1 + 2.0 * si
nx1 * cosx1) / 2.0) * Rr * dxf2 * rcr + cp22 * cp1 * cosx13 * cosx8 * sinx7 * si
nlmd * (cosx1 / cp1 - sinx1 * cp1m2 * cp1m1 * (-2.0 * cosx1 * cosx72 * sinx1 + 2
.0 * sinx1 * cosx1) / 2.0) * Rr2 * dxf2 + (cosx1 / cp1 - sinx1 * cp1m2 * cp1m1 *
(-2.0 * cosx1 * cosx72 * sinx1 + 2.0 * sinx1 * cosx1) / 2.0) * cp12 * cp22 * co
sx72 * sinlmd * sinx8 * cosx3c * Rf * Rr3 + sinx7 * (cosx1 / cp1 - sinx1 * cp1m2
* cp1m1 * (-2.0 * cosx1 * cosx72 * sinx1 + 2.0 * sinx1 * cosx1) / 2.0) * cp13 *
cp2 * cosx13 * cosx8 * Rf2 * dxf * rcr + cp13 * cp22 * (cosx1 / cp1 - sinx1 * c
p1m2 * cp1m1 * (-2.0 * cosx1 * cosx72 * sinx1 + 2.0 * sinx1 * cosx1) / 2.0) * co
slmd2 * cosx8 * cosx7 * sinx7 * dxf3 * rcr + cp12 * cp22 * (cosx1 / cp1 - sinx1
* cp1m2 * cp1m1 * (-2.0 * cosx1 * cosx72 * sinx1 + 2.0 * sinx1 * cosx1) / 2.0) *
......

Even though it is still running, I think the compilation died after 3 hours since It is using only 4% of CPU while using 80% of memory on my laptop computer. Any suggestions are welcome.

Best regards,

Everett
Try making the variables volatile qualified with external linkage.
Generated code would be slow, but it does not give the compiler any leeway.
Topic archived. No new replies allowed.