473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

BLAS vs CBLAS in C++

hello --

i'm working on a C++ code that uses dgemm in a simple way, but i want
ports of my code to different machines to be easy.

further, i want to make compiling of my code easy for new users -- i
don't want them to compile more libraries than absolutely necessary
(compiling ATLAS or GotoBLAS is necessary).

i already have my code working with both BLAS and CBLAS interfaces,
but I have some questions.
1) can i expect cblas to be available on pretty much any machine i
want to use? because ATLAS packages CBLAS, it didn't occur to me that
CBLAS might be standard until now.

2) to use blas, I had to switch from using new [] to malloc, and
delete [] to free. why? once allocated, i didn't realize there was a
difference.
is it not possible to use new [] allocated arrays with fortran
libraries?

3) once your code can is programmed to use either, is linking directly
to BLAS preferable in any way to using CBLAS?

thanks!

amos.

Sep 3 '07 #1
6 11413
On 2007-09-04 01:12, ni*******@gmail.com wrote:
hello --

i'm working on a C++ code that uses dgemm in a simple way, but i want
ports of my code to different machines to be easy.

further, i want to make compiling of my code easy for new users -- i
don't want them to compile more libraries than absolutely necessary
(compiling ATLAS or GotoBLAS is necessary).

i already have my code working with both BLAS and CBLAS interfaces,
but I have some questions.
You might also be interested in uBlas from Boost, which would remove the
dependency on external libraries (do not know how the compare
performance wise). There is also Lapack++ which provide both BLAS and
LAPACK, once again, I make no guarantees of performance.
1) can i expect cblas to be available on pretty much any machine i
want to use? because ATLAS packages CBLAS, it didn't occur to me that
CBLAS might be standard until now.
I don't have it on any of my computers, however you might be able to
assume that those computers where your program will run will have it, or
perhaps you cannot.
2) to use blas, I had to switch from using new [] to malloc, and
delete [] to free. why? once allocated, i didn't realize there was a
difference.
is it not possible to use new [] allocated arrays with fortran
libraries?
There should not be any problem as long as BLAS does not try to free or
reallocate memory (memory allocated with new[] must be freed with
delete[], using free() will not work). Are you sure it does not work?
3) once your code can is programmed to use either, is linking directly
to BLAS preferable in any way to using CBLAS?
I seem to recall that CBLAS is BLAS converted to C, and I seem to recall
that there are certain features (or lack thereof) in Fortran that allows
for better optimisations in Fortran than C. So it probably depends on
how good your Fortran compiler is compared to your C compiler.

--
Erik Wikström
Sep 4 '07 #2
On Tue, 04 Sep 2007 11:15:59 +0000, Erik Wikström wrote:
On 2007-09-04 01:12, ni*******@gmail.com wrote:
>hello --

i'm working on a C++ code that uses dgemm in a simple way, but i want
ports of my code to different machines to be easy.
[...]
>3) once your code can is programmed to use either, is linking directly
to BLAS preferable in any way to using CBLAS?

I seem to recall that CBLAS is BLAS converted to C,
I think, rather, it's just a set of C wrappers for the (Fortran) BLAS
functions, so you should not see any performance difference at all.

[...]

--
Lionel B
Sep 4 '07 #3
i would expect that for large enough matrices, there would be no
performance difference between BLAS and CBLAS since the overhead of
calling libraries would be amortized.

however, if CBLAS is not available and my code relies on it, then a
user might be stuck having to compile it. and that is more work than i
want them to have to do.

basically, i put in the effort to program direct BLAS links, and I'm
trying to find excuses to convince myself that i didn't waste my
effort! :-)

amos.
On Sep 4, 5:25 am, Lionel B <m...@privacy.netwrote:
On Tue, 04 Sep 2007 11:15:59 +0000, Erik Wikström wrote:
On 2007-09-04 01:12, nitroa...@gmail.com wrote:
hello --
i'm working on a C++ code that uses dgemm in a simple way, but i want
ports of my code to different machines to be easy.

[...]
3) once your code can is programmed to use either, is linking directly
to BLAS preferable in any way to using CBLAS?
I seem to recall that CBLAS is BLAS converted to C,

I think, rather, it's just a set of C wrappers for the (Fortran) BLAS
functions, so you should not see any performance difference at all.

[...]

--
Lionel B

Sep 4 '07 #4
>
There should not be any problem as long as BLAS does not try to free or
reallocate memory (memory allocated with new[] must be freed with
delete[], using free() will not work). Are you sure it does not work?
I've gone back to investigate this issue, and the problem has
disappeared. I can use either memory allocation/deallocation method
with no problem.

Sep 4 '07 #5
Hi,
i'm working on a C++ code that uses dgemm in a simple way, but i want
ports of my code to different machines to be easy.

further, i want to make compiling of my code easy for new users -- i
don't want them to compile more libraries than absolutely necessary
(compiling ATLAS or GotoBLAS is necessary).
I am currently also using BLAS and LAPACK in a c++ code, and I generally
want the same features like you. Being easily portable, disregarding of
the BLAS LAPACK library the person uses (original netlib BLAS and
LAPACK, GotoBLAS, Intel MKL, AMD CML, ...)

If you take a look at most of these libraries, they all contain the
FORTRAN versions with/without a c wrapper. CLAPACK and CBLAS on the
other hand, are fully f2c versions of the original FORTRAN code and need
F2Clibs to work.

This means that if you take a look at the symbols whit for example the
gnutool nm or objdump, you will notice that all the same symbols
(representing the functions) are there. For BLAS this means srotg_,
drotg_ scopy_, dcopy_, ... (notice the underscore at the end).

For this reason, I strongly suggest to use these symbols to call the
functions, and this according the rules of engagement when it comes to
calling FORTRAN from C(++). This makes sure that you don't have to
implement any different BLAS wrappers like there exist several and are
also included in the Intel and AMD versions.
2) to use BLAS, I had to switch from using new [] to malloc, and
delete [] to free. why? once allocated, i didn't realize there was a
difference.
is it not possible to use new [] allocated arrays with FORTRAN
libraries?
I had the same problem when I used the CBLAS version, and this is mainly
because you can not mix new, delete with malloc, free. When linking
CBLAS you also need to link the libF77.a and libI77.a from the F2CLIBS.
If you check out this code, you see they make use of the free and
malloc command there, and hence all new and delete operations will
conflict with this. You see this clearly with valgrind.
3) once your code can is programmed to use either, is linking directly
to BLAS preferable in any way to using CBLAS?
Hence as I stated above, I suggest linking to FORTRAN versions and not
C-wrapped or F2C versions of BLAS (i.e. CBLAS). A FORTRAN version is
more frequent available then a C converted version.

I hope this helped.

Regards
Klaas
Sep 5 '07 #6
yes, your discussion answered my questions.

i won't delete my CBLAS calls, but they'll be commented out.

thanks!
amos.

Sep 6 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: drife | last post by:
Hello, I need to calculate the eigenvectors and eigenvalues for a 3600 X 3600 covariance matrix. The LinearAlgebra package in Python is incredibly slow to perform the above calculations...
1
by: Edward C. Jones | last post by:
I have a PC with Debian sid installed. I install all my Python stuff in /usr/local. I just installed numarray 1.3.1. Blaslite and lapacklite were compiled. Did the installation process search for...
5
by: querypk | last post by:
Did anyone try to install Scipy package on python2.4 linux version. I see only python2.3 version of scipy released. When I try to install I get an dependency warning saying scipy cannot find...
5
by: NM | last post by:
Hi all I am trying to link C++ and Fortran.I am not very familiar with Fortran. I have been successful in linking C++ and fortran using g++ and ifc for simple program. So adding _ to at the end of...
1
by: pervinder | last post by:
Hi, I am building a c++ executable which uses fortan math libs. blas, lapack etc. But when i build this on HP-UX, i get below linker errors while it build without anyissues on Sun and Linux...
13
by: Havatcha | last post by:
Does anyone know of a decent (free/easy to use) C++ library for manipulating matrices and caculating eigenvalues, eigenvectors and so on? I intend to add some Principal Component Analysis...
0
by: Darren L. Weber | last post by:
The following is a first attempt to almost create a shell script for installation of ATLAS and LAPACK. It does not work right now and it is specific to a particular platform. It is posted here to...
1
by: Ken Dere | last post by:
I am trying to install numpy-0.9.8 prior to installing scipy (0.4.9) on a machine running Suse 10.0 with Python 2.4 I am able to get numpy installed to the point when I import it I can do the...
2
by: aberte | last post by:
Hi, i'm learning how to use lapack library (in particular, Intel MKL). I wish to know how I have to format the my inputs. I'm calling lapack functions from c++ (zhetri, zhemm, zgemm, zhseqr,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.