ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 12 Feb 2011 19:40:25 -0600How to use GOTOBLAS (instead of ATLAS)?https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/> GotoBLAS2 has been released by the
> Texas Advanced Computing Center as
> open source software under the BSD
> license. This product is no longer
> under active development by TACC, but
> it is being made available to the
> community to use, study, and extend.
> GotoBLAS2 uses new algorithms and
> memory techniques for optimal
> performance of the BLAS routines. The
> changes in this final version target
> new architecture features in
> microprocessors and interprocessor
> communication techniques; also, NUMA
> controls enhance multi-threaded
> execution of BLAS routines on node.
[http://www.tacc.utexas.edu/tacc-projects/gotoblas2/](http://)
Compiling the package is not to difficult, a static and a dynamic library are created: *libgoto2_core2p-r1.13.a* and *libgoto2_core2p-r1.13.so*
How is it possible to use those in Sage, what steps are needed?
[link to thread on sage-devel](http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=GOTOBLAS#2a6fcb3dcfee46bd[])
Edit: The question was meant how to use Gotoblas instead of atlas as the default optimized blas library of sage.
Tue, 08 Feb 2011 19:37:04 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/Comment by niles for <blockquote>
<p>GotoBLAS2 has been released by the
Texas Advanced Computing Center as
open source software under the BSD
license. This product is no longer
under active development by TACC, but
it is being made available to the
community to use, study, and extend.
GotoBLAS2 uses new algorithms and
memory techniques for optimal
performance of the BLAS routines. The
changes in this final version target
new architecture features in
microprocessors and interprocessor
communication techniques; also, NUMA
controls enhance multi-threaded
execution of BLAS routines on node.</p>
</blockquote>
<p><a href="http://">http://www.tacc.utexas.edu/tacc-projects/gotoblas2/</a></p>
<p>Compiling the package is not to difficult, a static and a dynamic library are created: <em>libgoto2_core2p-r1.13.a</em> and <em>libgoto2_core2p-r1.13.so</em> </p>
<p>How is it possible to use those in Sage, what steps are needed?</p>
<p><a href="http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=GOTOBLAS#2a6fcb3dcfee46bd[]">link to thread on sage-devel</a></p>
<p>Edit: The question was meant how to use Gotoblas instead of atlas as the default optimized blas library of sage.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22155#post-id-22155Sorry, I was afraid that might be what you meant. I think you should open a trac ticket for this!Wed, 09 Feb 2011 10:40:15 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22155#post-id-22155Answer by cswiercz for <blockquote>
<p>GotoBLAS2 has been released by the
Texas Advanced Computing Center as
open source software under the BSD
license. This product is no longer
under active development by TACC, but
it is being made available to the
community to use, study, and extend.
GotoBLAS2 uses new algorithms and
memory techniques for optimal
performance of the BLAS routines. The
changes in this final version target
new architecture features in
microprocessors and interprocessor
communication techniques; also, NUMA
controls enhance multi-threaded
execution of BLAS routines on node.</p>
</blockquote>
<p><a href="http://">http://www.tacc.utexas.edu/tacc-projects/gotoblas2/</a></p>
<p>Compiling the package is not to difficult, a static and a dynamic library are created: <em>libgoto2_core2p-r1.13.a</em> and <em>libgoto2_core2p-r1.13.so</em> </p>
<p>How is it possible to use those in Sage, what steps are needed?</p>
<p><a href="http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=GOTOBLAS#2a6fcb3dcfee46bd[]">link to thread on sage-devel</a></p>
<p>Edit: The question was meant how to use Gotoblas instead of atlas as the default optimized blas library of sage.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12088#post-id-12088From what I understand, the question is "how do I completely replace BLAS with GOTOBLAS"? The first place to start would be to take a look at `$SAGE_ROOT/devel/sage/module_list.py.` This is sort of a master file describing how Sage's various Cython code links with the various libraries included with Sage. For example, dense general matrices use BLAS to handle multiplication whereas integer matrices uses Flint. (Or something like that.)
Near the top of the file `module_list.py` is a section called "BLAS setup". You can add a line like
...
elif os.path.exists('%s/lib/libgotoblas.so'%os.environ['SAGE_LOCAL']):
BLAS='gotoblas'
BLAS2='atlas'
elif ...
replacing "gotoblas" with whatever the library is actually named. (I took an educated guess. :) ) There's a note at the top of this section about possibly having to modify sage/misc/cython.py as well. It looks like you'd have to add something similar there in the function `cblas()` such that it returns the name of the library.
Finally, you should probably rebuild Sage with the `-a` flag a la
$ sage -ba
Anyway, the end result should be that all of Sage's Cython-based objects (like matrices) will use GOTOBLAS for the appropriate computations instead of BLAS. I haven't tried this myself but it looks like this is the way to go. I'm just curious if there's a less "invasive" way to do it. (Like your suggestion of symblinking to libcblas.so or whatever the standard "BLAS" library is called.)Thu, 10 Feb 2011 02:51:30 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12088#post-id-12088Comment by Emil Widmann for <p>From what I understand, the question is "how do I completely replace BLAS with GOTOBLAS"? The first place to start would be to take a look at <code>$SAGE_ROOT/devel/sage/module_list.py.</code> This is sort of a master file describing how Sage's various Cython code links with the various libraries included with Sage. For example, dense general matrices use BLAS to handle multiplication whereas integer matrices uses Flint. (Or something like that.)</p>
<p>Near the top of the file <code>module_list.py</code> is a section called "BLAS setup". You can add a line like</p>
<pre><code>...
elif os.path.exists('%s/lib/libgotoblas.so'%os.environ['SAGE_LOCAL']):
BLAS='gotoblas'
BLAS2='atlas'
elif ...
</code></pre>
<p>replacing "gotoblas" with whatever the library is actually named. (I took an educated guess. :) ) There's a note at the top of this section about possibly having to modify sage/misc/cython.py as well. It looks like you'd have to add something similar there in the function <code>cblas()</code> such that it returns the name of the library.</p>
<p>Finally, you should probably rebuild Sage with the <code>-a</code> flag a la</p>
<pre><code>$ sage -ba
</code></pre>
<p>Anyway, the end result should be that all of Sage's Cython-based objects (like matrices) will use GOTOBLAS for the appropriate computations instead of BLAS. I haven't tried this myself but it looks like this is the way to go. I'm just curious if there's a less "invasive" way to do it. (Like your suggestion of symblinking to libcblas.so or whatever the standard "BLAS" library is called.)</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22144#post-id-22144Oh, thank you,that sounds interesting!Thu, 10 Feb 2011 03:46:55 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22144#post-id-22144Comment by niles for <p>From what I understand, the question is "how do I completely replace BLAS with GOTOBLAS"? The first place to start would be to take a look at <code>$SAGE_ROOT/devel/sage/module_list.py.</code> This is sort of a master file describing how Sage's various Cython code links with the various libraries included with Sage. For example, dense general matrices use BLAS to handle multiplication whereas integer matrices uses Flint. (Or something like that.)</p>
<p>Near the top of the file <code>module_list.py</code> is a section called "BLAS setup". You can add a line like</p>
<pre><code>...
elif os.path.exists('%s/lib/libgotoblas.so'%os.environ['SAGE_LOCAL']):
BLAS='gotoblas'
BLAS2='atlas'
elif ...
</code></pre>
<p>replacing "gotoblas" with whatever the library is actually named. (I took an educated guess. :) ) There's a note at the top of this section about possibly having to modify sage/misc/cython.py as well. It looks like you'd have to add something similar there in the function <code>cblas()</code> such that it returns the name of the library.</p>
<p>Finally, you should probably rebuild Sage with the <code>-a</code> flag a la</p>
<pre><code>$ sage -ba
</code></pre>
<p>Anyway, the end result should be that all of Sage's Cython-based objects (like matrices) will use GOTOBLAS for the appropriate computations instead of BLAS. I haven't tried this myself but it looks like this is the way to go. I'm just curious if there's a less "invasive" way to do it. (Like your suggestion of symblinking to libcblas.so or whatever the standard "BLAS" library is called.)</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22143#post-id-22143indeed -- a big +1 :)Thu, 10 Feb 2011 05:32:50 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22143#post-id-22143Answer by fbissey for <blockquote>
<p>GotoBLAS2 has been released by the
Texas Advanced Computing Center as
open source software under the BSD
license. This product is no longer
under active development by TACC, but
it is being made available to the
community to use, study, and extend.
GotoBLAS2 uses new algorithms and
memory techniques for optimal
performance of the BLAS routines. The
changes in this final version target
new architecture features in
microprocessors and interprocessor
communication techniques; also, NUMA
controls enhance multi-threaded
execution of BLAS routines on node.</p>
</blockquote>
<p><a href="http://">http://www.tacc.utexas.edu/tacc-projects/gotoblas2/</a></p>
<p>Compiling the package is not to difficult, a static and a dynamic library are created: <em>libgoto2_core2p-r1.13.a</em> and <em>libgoto2_core2p-r1.13.so</em> </p>
<p>How is it possible to use those in Sage, what steps are needed?</p>
<p><a href="http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=GOTOBLAS#2a6fcb3dcfee46bd[]">link to thread on sage-devel</a></p>
<p>Edit: The question was meant how to use Gotoblas instead of atlas as the default optimized blas library of sage.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12083#post-id-12083A major problem that I already mentioned on sage-devel is that ATLAS produces 2 libraries: libf77blas for fortran and libcblas for C. GOTOBlas is only producing
libf77blas. lapack is perfectly happy with libf77blas as it is a fortran library. However most of the packages in sage and sage itself require libcblas.
So to use GOTOBlas instead of atlas you need to produce an extra layer that will
translate fortran to C, or recode a substantial portion of sage to use libf77blas. Whichever way you want to go, that's a big amount of work.Thu, 10 Feb 2011 21:01:51 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12083#post-id-12083Comment by Emil Widmann for <p>A major problem that I already mentioned on sage-devel is that ATLAS produces 2 libraries: libf77blas for fortran and libcblas for C. GOTOBlas is only producing
libf77blas. lapack is perfectly happy with libf77blas as it is a fortran library. However most of the packages in sage and sage itself require libcblas.</p>
<p>So to use GOTOBlas instead of atlas you need to produce an extra layer that will
translate fortran to C, or recode a substantial portion of sage to use libf77blas. Whichever way you want to go, that's a big amount of work.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22141#post-id-22141You think a "wrapper" libcblas which links to the functions in libfblas would do? Or does this make no sense because of overhead - speed loss?Thu, 10 Feb 2011 21:55:44 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22141#post-id-22141Comment by fbissey for <p>A major problem that I already mentioned on sage-devel is that ATLAS produces 2 libraries: libf77blas for fortran and libcblas for C. GOTOBlas is only producing
libf77blas. lapack is perfectly happy with libf77blas as it is a fortran library. However most of the packages in sage and sage itself require libcblas.</p>
<p>So to use GOTOBlas instead of atlas you need to produce an extra layer that will
translate fortran to C, or recode a substantial portion of sage to use libf77blas. Whichever way you want to go, that's a big amount of work.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22130#post-id-22130lapack is fine with libf77blas because they are both fortran libraries. The real hurdle is getting libcblas. I am not sure how to create a wrapper from libf77blas. Function name mapping is easy. The big problem is that C and fortran store matrix differently so you would have to reorganize your arrays before passing them to libf77blas. That's a job and a half.Fri, 11 Feb 2011 21:48:04 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22130#post-id-22130Comment by Emil Widmann for <p>A major problem that I already mentioned on sage-devel is that ATLAS produces 2 libraries: libf77blas for fortran and libcblas for C. GOTOBlas is only producing
libf77blas. lapack is perfectly happy with libf77blas as it is a fortran library. However most of the packages in sage and sage itself require libcblas.</p>
<p>So to use GOTOBlas instead of atlas you need to produce an extra layer that will
translate fortran to C, or recode a substantial portion of sage to use libf77blas. Whichever way you want to go, that's a big amount of work.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22140#post-id-22140My main problem was a failing atlas build, and this was solved by using the new atlas spkg from Volker Braun. However I leave some links I found during my research - maybe they are useful if someone finds this thread in the future: http://shimingyoung.blogspot.com/2010/01/gotoblas-and-lapackwrapper.html XXX http://itf.fys.kuleuven.be/~rob/computer/lapack_wrapper/index.html XXX http://seehuhn.de/pages/linear Thanks all for the answers. I hope it is OK if I leave it without solution for now.Thu, 10 Feb 2011 22:04:56 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22140#post-id-22140Comment by Emil Widmann for <p>A major problem that I already mentioned on sage-devel is that ATLAS produces 2 libraries: libf77blas for fortran and libcblas for C. GOTOBlas is only producing
libf77blas. lapack is perfectly happy with libf77blas as it is a fortran library. However most of the packages in sage and sage itself require libcblas.</p>
<p>So to use GOTOBlas instead of atlas you need to produce an extra layer that will
translate fortran to C, or recode a substantial portion of sage to use libf77blas. Whichever way you want to go, that's a big amount of work.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22125#post-id-22125For the record: There is a code example of wrapper function, including the conversion of matrix data from fortran to c format here http://seehuhn.de/pages/matrixfn.Sat, 12 Feb 2011 19:40:25 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22125#post-id-22125Answer by cswiercz for <blockquote>
<p>GotoBLAS2 has been released by the
Texas Advanced Computing Center as
open source software under the BSD
license. This product is no longer
under active development by TACC, but
it is being made available to the
community to use, study, and extend.
GotoBLAS2 uses new algorithms and
memory techniques for optimal
performance of the BLAS routines. The
changes in this final version target
new architecture features in
microprocessors and interprocessor
communication techniques; also, NUMA
controls enhance multi-threaded
execution of BLAS routines on node.</p>
</blockquote>
<p><a href="http://">http://www.tacc.utexas.edu/tacc-projects/gotoblas2/</a></p>
<p>Compiling the package is not to difficult, a static and a dynamic library are created: <em>libgoto2_core2p-r1.13.a</em> and <em>libgoto2_core2p-r1.13.so</em> </p>
<p>How is it possible to use those in Sage, what steps are needed?</p>
<p><a href="http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=GOTOBLAS#2a6fcb3dcfee46bd[]">link to thread on sage-devel</a></p>
<p>Edit: The question was meant how to use Gotoblas instead of atlas as the default optimized blas library of sage.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12082#post-id-12082You can use C libraries from Sage via Cython. Cython is a Python-like language that makes it easy to write Python programs that manipulate pure C data types allowing for faster computations and the like. In you're unfamiliar with Cython you should take a look at [these tutorials](http://www.cython.org/#documentation) for more information.
I'm not familiar with ATLAS or GOTOBLAS but I can provide an example of how to link to some BLAS routines. Suppose I wanted to add two vectors using [BLAS](http://www.gnu.org/software/gsl/manual/html_node/BLAS-Support.html), which is included with Sage. To do $y \leftarrow \alpha x + y$ where $x$ and $y$ are double vectors and $\alpha$ is a double scalar, I start by `extern`-ing the appropriate function, `cblas_daxpy()` into my Cython code. (i.e. `#import`-ing) In the Sage notebook, I begin a cell with the following:
%cython
cdef extern from "gsl/gsl_cblas.h":
void cblas_daxpy (int N, double alpha, double *x, int incX, double *y, int incY)
Then, to perform this addition I add the following (to the same cell)
cdef double x[3]
cdef double y[3]
cdef double alpha = -1
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0
y[0] = 1.0; y[1] = 2.0; y[2] = 3.0
print "x =",x[0],x[1],x[2]
print "y =",y[0],y[1],y[2]
print "a =",alpha
cblas_daxpy(3,alpha,x,1,y,1)
print "alpha x + y =",y[0],y[1],y[2]
The output is
x = 1.0 1.0 1.0
y = 1.0 2.0 3.0
a = -1.0
alpha x + y = 0.0 1.0 2.0
You might need to compile GOTOBLAS in the Sage shell (type "`sage -sh`") in the terminal but it might also work if you have a system-wide install.
I hope this is a decent enough introduction to using C libraries in Sage. You can fine more information at the Cython website and documentation at [http://www.cython.org]()Wed, 09 Feb 2011 09:47:19 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12082#post-id-12082Comment by Emil Widmann for <p>You can use C libraries from Sage via Cython. Cython is a Python-like language that makes it easy to write Python programs that manipulate pure C data types allowing for faster computations and the like. In you're unfamiliar with Cython you should take a look at <a href="http://www.cython.org/#documentation">these tutorials</a> for more information.</p>
<p>I'm not familiar with ATLAS or GOTOBLAS but I can provide an example of how to link to some BLAS routines. Suppose I wanted to add two vectors using <a href="http://www.gnu.org/software/gsl/manual/html_node/BLAS-Support.html">BLAS</a>, which is included with Sage. To do $y \leftarrow \alpha x + y$ where $x$ and $y$ are double vectors and $\alpha$ is a double scalar, I start by <code>extern</code>-ing the appropriate function, <code>cblas_daxpy()</code> into my Cython code. (i.e. <code>#import</code>-ing) In the Sage notebook, I begin a cell with the following:</p>
<pre><code>%cython
cdef extern from "gsl/gsl_cblas.h":
void cblas_daxpy (int N, double alpha, double *x, int incX, double *y, int incY)
</code></pre>
<p>Then, to perform this addition I add the following (to the same cell)</p>
<pre><code>cdef double x[3]
cdef double y[3]
cdef double alpha = -1
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0
y[0] = 1.0; y[1] = 2.0; y[2] = 3.0
print "x =",x[0],x[1],x[2]
print "y =",y[0],y[1],y[2]
print "a =",alpha
cblas_daxpy(3,alpha,x,1,y,1)
print "alpha x + y =",y[0],y[1],y[2]
</code></pre>
<p>The output is</p>
<pre><code>x = 1.0 1.0 1.0
y = 1.0 2.0 3.0
a = -1.0
alpha x + y = 0.0 1.0 2.0
</code></pre>
<p>You might need to compile GOTOBLAS in the Sage shell (type "<code>sage -sh</code>") in the terminal but it might also work if you have a system-wide install.</p>
<p>I hope this is a decent enough introduction to using C libraries in Sage. You can fine more information at the Cython website and documentation at <a href="">http://www.cython.org</a></p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22157#post-id-22157- double comment -Wed, 09 Feb 2011 10:03:46 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22157#post-id-22157Comment by Emil Widmann for <p>You can use C libraries from Sage via Cython. Cython is a Python-like language that makes it easy to write Python programs that manipulate pure C data types allowing for faster computations and the like. In you're unfamiliar with Cython you should take a look at <a href="http://www.cython.org/#documentation">these tutorials</a> for more information.</p>
<p>I'm not familiar with ATLAS or GOTOBLAS but I can provide an example of how to link to some BLAS routines. Suppose I wanted to add two vectors using <a href="http://www.gnu.org/software/gsl/manual/html_node/BLAS-Support.html">BLAS</a>, which is included with Sage. To do $y \leftarrow \alpha x + y$ where $x$ and $y$ are double vectors and $\alpha$ is a double scalar, I start by <code>extern</code>-ing the appropriate function, <code>cblas_daxpy()</code> into my Cython code. (i.e. <code>#import</code>-ing) In the Sage notebook, I begin a cell with the following:</p>
<pre><code>%cython
cdef extern from "gsl/gsl_cblas.h":
void cblas_daxpy (int N, double alpha, double *x, int incX, double *y, int incY)
</code></pre>
<p>Then, to perform this addition I add the following (to the same cell)</p>
<pre><code>cdef double x[3]
cdef double y[3]
cdef double alpha = -1
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0
y[0] = 1.0; y[1] = 2.0; y[2] = 3.0
print "x =",x[0],x[1],x[2]
print "y =",y[0],y[1],y[2]
print "a =",alpha
cblas_daxpy(3,alpha,x,1,y,1)
print "alpha x + y =",y[0],y[1],y[2]
</code></pre>
<p>The output is</p>
<pre><code>x = 1.0 1.0 1.0
y = 1.0 2.0 3.0
a = -1.0
alpha x + y = 0.0 1.0 2.0
</code></pre>
<p>You might need to compile GOTOBLAS in the Sage shell (type "<code>sage -sh</code>") in the terminal but it might also work if you have a system-wide install.</p>
<p>I hope this is a decent enough introduction to using C libraries in Sage. You can fine more information at the Cython website and documentation at <a href="">http://www.cython.org</a></p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22150#post-id-22150I have always understood that GotoBlas uses the same funtion interfaces as BLAS. So the libraries are basically exchangeable somehow without major changes in the code.Wed, 09 Feb 2011 18:21:03 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22150#post-id-22150Comment by cswiercz for <p>You can use C libraries from Sage via Cython. Cython is a Python-like language that makes it easy to write Python programs that manipulate pure C data types allowing for faster computations and the like. In you're unfamiliar with Cython you should take a look at <a href="http://www.cython.org/#documentation">these tutorials</a> for more information.</p>
<p>I'm not familiar with ATLAS or GOTOBLAS but I can provide an example of how to link to some BLAS routines. Suppose I wanted to add two vectors using <a href="http://www.gnu.org/software/gsl/manual/html_node/BLAS-Support.html">BLAS</a>, which is included with Sage. To do $y \leftarrow \alpha x + y$ where $x$ and $y$ are double vectors and $\alpha$ is a double scalar, I start by <code>extern</code>-ing the appropriate function, <code>cblas_daxpy()</code> into my Cython code. (i.e. <code>#import</code>-ing) In the Sage notebook, I begin a cell with the following:</p>
<pre><code>%cython
cdef extern from "gsl/gsl_cblas.h":
void cblas_daxpy (int N, double alpha, double *x, int incX, double *y, int incY)
</code></pre>
<p>Then, to perform this addition I add the following (to the same cell)</p>
<pre><code>cdef double x[3]
cdef double y[3]
cdef double alpha = -1
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0
y[0] = 1.0; y[1] = 2.0; y[2] = 3.0
print "x =",x[0],x[1],x[2]
print "y =",y[0],y[1],y[2]
print "a =",alpha
cblas_daxpy(3,alpha,x,1,y,1)
print "alpha x + y =",y[0],y[1],y[2]
</code></pre>
<p>The output is</p>
<pre><code>x = 1.0 1.0 1.0
y = 1.0 2.0 3.0
a = -1.0
alpha x + y = 0.0 1.0 2.0
</code></pre>
<p>You might need to compile GOTOBLAS in the Sage shell (type "<code>sage -sh</code>") in the terminal but it might also work if you have a system-wide install.</p>
<p>I hope this is a decent enough introduction to using C libraries in Sage. You can fine more information at the Cython website and documentation at <a href="">http://www.cython.org</a></p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22146#post-id-22146In that case, I think the first place to start would be to take a look at $SAGE_ROOT/devel/sage/module_list.py. This is sort of a master file describing how Sage's various Cython code links with the various libraries included with Sage. Near the top of the file is a section called "BLAS setup". You can add a line like elif os.path.exists(...) where "..." is the path to the GOTOBLAS library then set BLAS='gotoblas' or whatever the library is actually named. (There's a note about possibly having to modify sage/misc/cython.py as well.) Anyway, the end result should be that all of Sage's Cython-based objects (like matrices) will use BLAS for the appropriate computations.Thu, 10 Feb 2011 02:41:42 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22146#post-id-22146Comment by cswiercz for <p>You can use C libraries from Sage via Cython. Cython is a Python-like language that makes it easy to write Python programs that manipulate pure C data types allowing for faster computations and the like. In you're unfamiliar with Cython you should take a look at <a href="http://www.cython.org/#documentation">these tutorials</a> for more information.</p>
<p>I'm not familiar with ATLAS or GOTOBLAS but I can provide an example of how to link to some BLAS routines. Suppose I wanted to add two vectors using <a href="http://www.gnu.org/software/gsl/manual/html_node/BLAS-Support.html">BLAS</a>, which is included with Sage. To do $y \leftarrow \alpha x + y$ where $x$ and $y$ are double vectors and $\alpha$ is a double scalar, I start by <code>extern</code>-ing the appropriate function, <code>cblas_daxpy()</code> into my Cython code. (i.e. <code>#import</code>-ing) In the Sage notebook, I begin a cell with the following:</p>
<pre><code>%cython
cdef extern from "gsl/gsl_cblas.h":
void cblas_daxpy (int N, double alpha, double *x, int incX, double *y, int incY)
</code></pre>
<p>Then, to perform this addition I add the following (to the same cell)</p>
<pre><code>cdef double x[3]
cdef double y[3]
cdef double alpha = -1
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0
y[0] = 1.0; y[1] = 2.0; y[2] = 3.0
print "x =",x[0],x[1],x[2]
print "y =",y[0],y[1],y[2]
print "a =",alpha
cblas_daxpy(3,alpha,x,1,y,1)
print "alpha x + y =",y[0],y[1],y[2]
</code></pre>
<p>The output is</p>
<pre><code>x = 1.0 1.0 1.0
y = 1.0 2.0 3.0
a = -1.0
alpha x + y = 0.0 1.0 2.0
</code></pre>
<p>You might need to compile GOTOBLAS in the Sage shell (type "<code>sage -sh</code>") in the terminal but it might also work if you have a system-wide install.</p>
<p>I hope this is a decent enough introduction to using C libraries in Sage. You can fine more information at the Cython website and documentation at <a href="">http://www.cython.org</a></p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22152#post-id-22152To fully replace ATLAS with GOTOBLAS would be quite an undertaking in modifying Sage's matrix, vector, etc. objects or, as you suggested, symlinking and "translating" function headers and the like. However, instead of replacing you can allow the matrix object the option of using GOTOBLAS instead of ATLAS by adding some sort of algorithm='gotoblas' attribute. Again, a big undertaking but entirely possible. These objects should interface with ATLAS in a way similar to that described in my post above.Wed, 09 Feb 2011 11:20:58 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22152#post-id-22152Comment by cswiercz for <p>You can use C libraries from Sage via Cython. Cython is a Python-like language that makes it easy to write Python programs that manipulate pure C data types allowing for faster computations and the like. In you're unfamiliar with Cython you should take a look at <a href="http://www.cython.org/#documentation">these tutorials</a> for more information.</p>
<p>I'm not familiar with ATLAS or GOTOBLAS but I can provide an example of how to link to some BLAS routines. Suppose I wanted to add two vectors using <a href="http://www.gnu.org/software/gsl/manual/html_node/BLAS-Support.html">BLAS</a>, which is included with Sage. To do $y \leftarrow \alpha x + y$ where $x$ and $y$ are double vectors and $\alpha$ is a double scalar, I start by <code>extern</code>-ing the appropriate function, <code>cblas_daxpy()</code> into my Cython code. (i.e. <code>#import</code>-ing) In the Sage notebook, I begin a cell with the following:</p>
<pre><code>%cython
cdef extern from "gsl/gsl_cblas.h":
void cblas_daxpy (int N, double alpha, double *x, int incX, double *y, int incY)
</code></pre>
<p>Then, to perform this addition I add the following (to the same cell)</p>
<pre><code>cdef double x[3]
cdef double y[3]
cdef double alpha = -1
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0
y[0] = 1.0; y[1] = 2.0; y[2] = 3.0
print "x =",x[0],x[1],x[2]
print "y =",y[0],y[1],y[2]
print "a =",alpha
cblas_daxpy(3,alpha,x,1,y,1)
print "alpha x + y =",y[0],y[1],y[2]
</code></pre>
<p>The output is</p>
<pre><code>x = 1.0 1.0 1.0
y = 1.0 2.0 3.0
a = -1.0
alpha x + y = 0.0 1.0 2.0
</code></pre>
<p>You might need to compile GOTOBLAS in the Sage shell (type "<code>sage -sh</code>") in the terminal but it might also work if you have a system-wide install.</p>
<p>I hope this is a decent enough introduction to using C libraries in Sage. You can fine more information at the Cython website and documentation at <a href="">http://www.cython.org</a></p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22145#post-id-22145I think I'll rewrite my above comment as an answer since it most directly addresses your question.Thu, 10 Feb 2011 02:43:54 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22145#post-id-22145Comment by Emil Widmann for <p>You can use C libraries from Sage via Cython. Cython is a Python-like language that makes it easy to write Python programs that manipulate pure C data types allowing for faster computations and the like. In you're unfamiliar with Cython you should take a look at <a href="http://www.cython.org/#documentation">these tutorials</a> for more information.</p>
<p>I'm not familiar with ATLAS or GOTOBLAS but I can provide an example of how to link to some BLAS routines. Suppose I wanted to add two vectors using <a href="http://www.gnu.org/software/gsl/manual/html_node/BLAS-Support.html">BLAS</a>, which is included with Sage. To do $y \leftarrow \alpha x + y$ where $x$ and $y$ are double vectors and $\alpha$ is a double scalar, I start by <code>extern</code>-ing the appropriate function, <code>cblas_daxpy()</code> into my Cython code. (i.e. <code>#import</code>-ing) In the Sage notebook, I begin a cell with the following:</p>
<pre><code>%cython
cdef extern from "gsl/gsl_cblas.h":
void cblas_daxpy (int N, double alpha, double *x, int incX, double *y, int incY)
</code></pre>
<p>Then, to perform this addition I add the following (to the same cell)</p>
<pre><code>cdef double x[3]
cdef double y[3]
cdef double alpha = -1
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0
y[0] = 1.0; y[1] = 2.0; y[2] = 3.0
print "x =",x[0],x[1],x[2]
print "y =",y[0],y[1],y[2]
print "a =",alpha
cblas_daxpy(3,alpha,x,1,y,1)
print "alpha x + y =",y[0],y[1],y[2]
</code></pre>
<p>The output is</p>
<pre><code>x = 1.0 1.0 1.0
y = 1.0 2.0 3.0
a = -1.0
alpha x + y = 0.0 1.0 2.0
</code></pre>
<p>You might need to compile GOTOBLAS in the Sage shell (type "<code>sage -sh</code>") in the terminal but it might also work if you have a system-wide install.</p>
<p>I hope this is a decent enough introduction to using C libraries in Sage. You can fine more information at the Cython website and documentation at <a href="">http://www.cython.org</a></p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22158#post-id-22158Hi,
thank you - I think this is a good answer howto use the library from inside sage in general. Hum, I am not sure if I saw the header file of GotoBlas, I have to look for that. However my question was meant like: Is it possible to substitute the current Atlas with GotoBlas, so that sage uses it as default for calculations. This might involve some symlinks, some hacks in the Gotoblas code, changes in the sage build scripts etc ... So I give an upvote, but leave the question unanswered for now.Wed, 09 Feb 2011 10:03:46 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22158#post-id-22158Answer by niles for <blockquote>
<p>GotoBLAS2 has been released by the
Texas Advanced Computing Center as
open source software under the BSD
license. This product is no longer
under active development by TACC, but
it is being made available to the
community to use, study, and extend.
GotoBLAS2 uses new algorithms and
memory techniques for optimal
performance of the BLAS routines. The
changes in this final version target
new architecture features in
microprocessors and interprocessor
communication techniques; also, NUMA
controls enhance multi-threaded
execution of BLAS routines on node.</p>
</blockquote>
<p><a href="http://">http://www.tacc.utexas.edu/tacc-projects/gotoblas2/</a></p>
<p>Compiling the package is not to difficult, a static and a dynamic library are created: <em>libgoto2_core2p-r1.13.a</em> and <em>libgoto2_core2p-r1.13.so</em> </p>
<p>How is it possible to use those in Sage, what steps are needed?</p>
<p><a href="http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=GOTOBLAS#2a6fcb3dcfee46bd[]">link to thread on sage-devel</a></p>
<p>Edit: The question was meant how to use Gotoblas instead of atlas as the default optimized blas library of sage.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12081#post-id-12081I think this is a great question, although it should probably include a reference to the [sage-devel thread](http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=gotoblas#2a6fcb3dcfee46bd).
Of course (as you know) there isn't really much information there, except some concerns that it is no longer actively maintained, and therefore might not be a worthwhile pursuit for Sage. Also there seems to be some concern that there would be trouble communicating between the C code in Sage and the Fortran code in GotoBLAS. Maybe someone proposed a resolution for that, but I can't tell :(
In any case, thanks for asking; maybe someone who knows better will notice the question here . . .
---
UPDATE:
Oh, maybe I do have an idea: The answer to this question is probably the same as the answer to "How do I use a compiled C library in Python?". For that, the answer must begin with Cython. In particular, here is the Cython documentation page for [Using C libraries][1]. Strangely, however, the examples on that page don't seem to ever explain what to do if you already have the `.a` or `.so` files. Maybe you can figure that out, or already know -- I think `distutils` has something to do with this. Anyway, there is a [related question on Stack Overflow][2] which does seem to address this . . . maybe between these two there's enough to get you going?
p.s. I really don't understand C, libraries, Cython, or distutils, I've just read *about* them a lot . . . my apologies if this is all totally obvious and unhelpful, or wrong.
[1]: http://docs.cython.org/src/tutorial/clibraries.html
[2]: http://stackoverflow.com/questions/3046305/simple-wrapping-of-c-code-with-cython)Wed, 09 Feb 2011 01:34:01 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?answer=12081#post-id-12081Comment by Emil Widmann for <p>I think this is a great question, although it should probably include a reference to the <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/6c3f4c8e8ed228e/2a6fcb3dcfee46bd?lnk=gst&q=gotoblas#2a6fcb3dcfee46bd">sage-devel thread</a>.</p>
<p>Of course (as you know) there isn't really much information there, except some concerns that it is no longer actively maintained, and therefore might not be a worthwhile pursuit for Sage. Also there seems to be some concern that there would be trouble communicating between the C code in Sage and the Fortran code in GotoBLAS. Maybe someone proposed a resolution for that, but I can't tell :(</p>
<p>In any case, thanks for asking; maybe someone who knows better will notice the question here . . .</p>
<hr/>
<p>UPDATE:</p>
<p>Oh, maybe I do have an idea: The answer to this question is probably the same as the answer to "How do I use a compiled C library in Python?". For that, the answer must begin with Cython. In particular, here is the Cython documentation page for <a href="http://docs.cython.org/src/tutorial/clibraries.html">Using C libraries</a>. Strangely, however, the examples on that page don't seem to ever explain what to do if you already have the <code>.a</code> or <code>.so</code> files. Maybe you can figure that out, or already know -- I think <code>distutils</code> has something to do with this. Anyway, there is a <a href="http://stackoverflow.com/questions/3046305/simple-wrapping-of-c-code-with-cython)">related question on Stack Overflow</a> which does seem to address this . . . maybe between these two there's enough to get you going?</p>
<p>p.s. I really don't understand C, libraries, Cython, or distutils, I've just read <em>about</em> them a lot . . . my apologies if this is all totally obvious and unhelpful, or wrong.</p>
https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22159#post-id-22159Hi Niles,
good idea to put it in a wider framework, i.e. how to use compiled C library generally. Wed, 09 Feb 2011 09:59:18 -0600https://ask.sagemath.org/question/7932/how-to-use-gotoblas-instead-of-atlas/?comment=22159#post-id-22159