Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disappointing performance in Ubuntu for computational workload

Tags:

c

macos

ubuntu

exp

I've found rather poor performance running some computational code under Ubuntu on a brand new headless workstation machine I'm using for scientific computation. I noticed a difference in speed running some slightly complex code on Ubuntu versus on my old Mac laptop which I use for development. However, I've managed to distill it down to an incredibly simple example which still exhibits less than stelar improvements over my old machine:

#include <stdio.h>
#include <math.h>

int main() {
        double res = 0.0;
        for(int i=1; i<200000000; i++) {
                res += exp((double) 100.0/i);
        }
        printf("%lf", res);
        return(0);
}

Now the Mac is a nearly 5 year old 2.4GHz Core 2 Duo MacBook Pro running OS X 10.5 which runs this code in about 6.8 secs. However, on a brand new 3.4GHz Core i7 Dell running Ubuntu 11.10 it takes about 6.1 secs! Can someone enlighten me as to what is going on here, because it is absurd that a nearly 5 year old laptop is within 10% of a brand new desktop workstation? It is even more absurd because I can see the Core i7 turbo-boosting to nearly 4GHz with monitoring tools!

Mac compiled with:

gcc -o test test.c -std=gnu99 -arch x86_64 -O2

Ubuntu compiled with:

gcc -o test test.c -std=gnu99 -m64 -O2 -lm

Thanks,

Louis

like image 548
L Aslett Avatar asked Feb 23 '12 17:02

L Aslett


3 Answers

it is absurd that a nearly 5 year old laptop is within 10% of a brand new desktop workstation

Bear in mind that you are benchmarking one specific function (exp). We don't really know if the two implementations of the exp() function that you're benchmarking are identical (it is not inconceivable that one is better optimized than the the other).

If you were to benchmark a different function, the results could be quite different (perhaps more in line with your expectations; or not).

If exp() is really the bottleneck of your actual application, one possibility is to look into using a fast approximation. Here is a paper that offers one such approximation: A Fast, Compact Approximation of the Exponential Function.

like image 194
NPE Avatar answered Nov 16 '22 01:11

NPE


As others noted, you're simply benchmarking one math library implementation of exp( ) against another. If you need high-quality math libraries on Linux, I would suggest looking at Intel's compiler tools (which come with an excellent set of libraries); they are also available for OS X and Windows.

like image 39
Stephen Canon Avatar answered Nov 16 '22 02:11

Stephen Canon


Try turning on the -ffast-math option. This might give you a much less pedantically correct implementation of exp(). The question then is whether you want the potentially wrong answer that can produce.

like image 31
Phil Miller Avatar answered Nov 16 '22 01:11

Phil Miller