Opened 4 years ago

#783 new enhancement

Performance tuning for 1D calculations

Reported by: pkienzle Owned by:
Priority: minor Milestone: sasmodels WishList
Component: sasmodels Keywords:
Cc: Work Package: SasView Bug Fixing


Many of the 1D calculations involve nested integrals over a fixed set of theta and phi values, with trig functions to turn these values into something useful for the kernel.

For example, the cylinder kernel, 2 trig operations, a multiply and an add can be replaced by two table lookups by converting:

    const double zm = M_PI_4;
    const double zb = M_PI_4; 

    double total = 0.0;
    for (int i=0; i<76 ;i++) {
        const double alpha = Gauss76Z[i]*zm + zb;
        double sn, cn; // slots to hold sincos function output
        // alpha(theta,phi) the projection of the cylinder on the detector plane
        SINCOS(alpha, sn, cn);
        total += Gauss76Wt[i] * square(fq(q, sn, cn, radius, length)) * sn;
    return total*zm;


    double total = 0.0;
    for (int i=0; i<76 ;i++) {
        total += Gauss76Wt_times_sin_alpha[i] * square(fq(q, sin_alpha[i], cos_alpha[i], radius, length));
    return total*M_PI_4;

To see if this might be worthwhile, I substituted Gauss76Z for the sin and Gauss76Wt for cos, and observed a 64% speedup. It had the wrong answer of course, but it does show that this approach could be worthwhile.

Change History (0)

Note: See TracTickets for help on using tickets.