Ai Dreams Forum

Member's Experiments & Projects => AI Programming => Topic started by: Kaeldric on February 04, 2018, 02:12:48 pm

Title: Fastest C or C++ math library
Post by: Kaeldric on February 04, 2018, 02:12:48 pm
Does anyone know the fastest C or C++ math library?  :-\
I'm writing a software based upon a lot of matrix calculations.

Thank you.  :)
Title: Re: Fastest C or C++ math library
Post by: keghn on February 04, 2018, 03:28:42 pm
 There both about the same. But there are software libraries that are highly optimized for fast computing. Like openBAS. 

https://www.chpc.utah.edu/documentation/software/mathlibraries.php#fftw 

http://arma.sourceforge.net/ 

https://en.wikipedia.org/wiki/OpenBLAS 

https://github.com/BelaPlatform/Bela/wiki/Fast-math-functions 





Title: Re: Fastest C or C++ math library
Post by: 8pla.net on February 06, 2018, 01:05:40 am
May I suggest inline Assembly Language is the fastest for mathematics in C language?
Title: Re: Fastest C or C++ math library
Post by: Kaeldric on February 10, 2018, 03:19:29 pm
Thank you.
I tried BLAS and it seemed very fats to me. :)

May I suggest inline Assembly Language is the fastest for mathematics in C language?

Inline assembly code should be fine, but I don't have much experience. Are you sure it will be worth?
Title: Re: Fastest C or C++ math library
Post by: infurl on February 10, 2018, 11:01:51 pm
Inline assembly code should be fine, but I don't have much experience. Are you sure it will be worth?

I have decades of experience writing highly optimized code in assembly language and quite frankly nowadays, it is not worth it. C compilers (and numeric libraries) are so good that any tiny advantage that you might gain writing in assembler will be lost amongst the vast amount of time wasted just trying to write and debug it. The only time I would still consider using assembler is for an 8 bit microcontroller with very limited memory but that's probably not what you are using if speed is the most important factor.
Title: Re: Fastest C or C++ math library
Post by: 8pla.net on February 13, 2018, 12:42:28 am
Friends,

The question was fastest (not worthiest) I thought.
But to me, inline asm makes C code look worthier.
( Though, infurl gave good advice to Kaeldric. )
Title: Re: Fastest C or C++ math library
Post by: korrelan on February 14, 2018, 05:08:02 pm
If you’re using loads of trig functions, the usual generic method to increase speed is to pre-calculate as much as you can into lookup tables/ arrays.

Most compliers (Python, C++, Fortran, Java, etc) are obviously optimized for one dimensional arrays because multiplications aren’t required to calculate the array element address.

Code: [Select]
‘// define arrays
Dim ASIn(360) as Single
Dim ACos(360) as Single

‘// pre-calculate arrays
Cs=360
de=(2* PI)/Cs
For d=1 to Cs
  ASin(d)=Sin(d*de)
  ACos(d)=Cos(d*de)
Next

‘// plot circle or rotate vector
For d=1 to Cs
  X=100+20*Asin(d)
  Y=100+20*ACos(d)
  PlotPoint x,y
Next

 :)