I use std::inner_product() to do the vector multiplication when performing matrix multiplication. This involves calling std::inner_product() within 2 nested loops (one across all rows, one across all columns). Unfortunately, g++-4.1.2 will not, it seems, inline the call even at -O5. If I provide my own version with an inline hint, it improves the speed of my matrix multiplication by ~15%, which is not to be sniffed at. I suppose my questions would be: (a) erm, do you need proof? (b) should the compiler do the inlining regardless (ie, it's a compiler issue), or should the declaration of std::inner_product give a hint with the inline keyword (and perhaps also other functions)? Simon.
Note, in GCC any -Ox, x > 3 is identical to -O3. Anyway, I think we can safely add inline to std::accumulate and std::inner_product.
Subject: Bug 33293 Author: paolo Date: Mon Sep 3 17:48:31 2007 New Revision: 128053 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128053 Log: 2007-09-03 Paolo Carlini <pcarlini@suse.de> PR libstdc++/33293 * include/bits/stl_numeric.h (accumulate, inner_product): Add inline function-specifier. Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/stl_numeric.h
Fixed for 4.3.0.
Many thanks for the quick response. Any chance it could make it into 4.2.2?
The patch itself is trivial but in our experience changing the inlining patterns can have far reaching and unpredictable fall-outs. Thus, better not touching the release branches, sorry.
OK, thanks.