星期三 十二月 03, 2008

/* On Solaris Platform */
#pragma init (fct[,fct])
#pragma fini (fct[,fct])

/* On Linux Platform */
void __attribute__ ((__constructor__)) fct (void){...}
void __attribute__ ((__destructor__))  fct (void){...} 

As I tested, Gcc 4.4.x on Ubuntu only supports the later form. While on Solaris, either SunStudio or Gcc (only 3.4.3 is available currently) supports both of them.

While there is a little different between SunStudio and Gcc, in case we declared two functions (let's say f1, f2) with attribute __constructor__, the call sequence would be f1 then f2 with SunStudio, but f2 then f1 with Gcc. However, the call sequence for 'destructors' is just the same -- f1 then f2.

星期一 十一月 03, 2008

1. Set the CBE environment (/opt/jdsbld/bin/env.sh), and export CC=$CXX, so that /usr/lib/python2.4/pycc would eventually use the C++ compiler in SunStudio.

2. Download the source code from http://matplotlib.sourceforge.net,  then apply the following patch,
--- setupext.py	2008-08-04 02:15:22.000000000 +0800
+++ setupext.py	2008-11-03 17:08:41.387138200 +0800
@@ -218,6 +218,8 @@ def get_win32_compiler():
 win32_compiler = get_win32_compiler()
 if sys.platform == 'win32' and win32_compiler == 'msvc':
     std_libs = []
+elif sys.platform == 'sunos5':
+    std_libs = ['Crun', 'Cstd']
 else:
     std_libs = ['stdc++', 'm']
 
@@ -298,6 +300,7 @@ def check_for_freetype():
         for d in basedirs:
             module.include_dirs.append(os.path.join(d, 'freetype2'))
 
+    module.include_dirs.append('/usr/include')
     print_status("freetype2", get_pkgconfig_version('freetype2'))
     if not find_include_file(module.include_dirs, 'ft2build.h'):
         print_message(
--- src/_backend_gdk.c	2008-08-04 02:14:18.000000000 +0800
+++ src/_backend_gdk.c	2008-11-03 17:31:32.896210699 +0800
@@ -62,6 +62,7 @@ static PyMethodDef _backend_gdk_function
     { NULL, NULL, 0 }
 };
 
+extern "C"
 DL_EXPORT(void)
 init_backend_gdk(void)
 {
3. Then build and install,
$ python setup.py build
$ pfexec python setup.py install
Note: this version of matplotlib requires numpy-1.1 or higher version, you need build and install a newer one since solaris only has 1.0.4.

星期五 十月 31, 2008

I finally got some clues about how to build scipy with SunStudio and Sun Performance library from this discussion thread. And here are the steps I sumerized:

1. Download the source tar file of scipy, SciPy 0.6.0 tarball, and extract it to anywhere. Apply the following changes to /usr/lib/python2.4/vendor-packages/numpy/distutils/fcompiler/sun.py, since f77compat library is not available on x86/x64 platform,
--- sun.py.orig	2008-10-31 18:30:17.519425733 +0800
+++ sun.py	2008-10-31 18:30:23.842495794 +0800
@@ -38,7 +38,7 @@
         return ['-xtarget=generic']
     def get_libraries(self):
         opt = []
-        opt.extend(['fsu','sunmath','mvec','f77compat'])
+        opt.extend(['fsu','sunmath','mvec'])
         return opt
 
 if __name__ == '__main__':
and apply the following patch,

--- scipy/sparse/sparsetools/sparsetools.h    2007-09-22 15:55:25.000000000 +0800
+++ scipy/sparse/sparsetools/sparsetools.h    2008-10-31 17:54:47.317379521 +0800
@@ -22,6 +22,7 @@

 #include <vector>
 #include <algorithm>
+#include <functional>


 /*


2. Set CBE environment (/opt/jdsbld/bin/env.sh), and the following environment variables,
$ export LDFLAGS="-lCrun -lCstd"
$ export LAPACK=/opt/SUNWspro/lib/libsunmath.so
$ export BLAS=/opt/SUNWspro/lib/libsunperf.so
3. Then build, install, and test
$ python setup.py build
$ pfexec setup.py install
$ cd ~ # don't run the test under the source directory
$ python
>>> import scipy
>>> scipy.test()
Though, you would see several errors, most of the tests passed.

星期一 五月 26, 2008

//extern "C" void foo (void*);
extern void foo (void*);

template <typename T, void(*cb)(T*)> class Test {};
typedef Test<void, foo> TestVoid;


SunStudio C++ compiler will fail if I try to use the 1st prototype, and reports:

line 5: Error: Template parameter cb requires an expression of type void(*)(void*).
1 Error(s) detected.

No idea why this happens... 

星期三 八月 01, 2007

If your program has a lot of std::set<T> or std::map<T> object instances, while mostly have small sizes (e.g., 1..5), you'd better change them to Vector or other unassociated container types if you built your code with Cstd in SunStudio.

The genpyt utility in sunpinyin/slm module, takes over 800M virtual memory, and about 4~500M is allocated for the unused __rb_tree_node buffer. If your machine has less memory than 1GB, the paging in/out (to/from swap) will make the program (and your system) running very slowly.

E.g., for the following example,

std::set<TNode*> nodeset;
nodeset.insert (new TNode());

During the std::set<TNode*>::insert(TNode*), the underlying __rb_tree structure would allocate 32 __rb_tree_node (whose size is 20 bytes), in total 640 bytes. While you just want it to hold a 4/8 bytes pointer. If your program has a lot of such small Set objects, the "wasted" memory is quite large.

I tested g++, and SunStudio with stlport4, they do not has such problem (or feature ;)).

This blog copyright 2009 by yongsun