Category Archives: programming

?: beyond the ternary operator (PHP surprise)

Here is a famous ternary operator in C: condition ? A : B It can also be conveniently chained: condition1 ? A : condition2 ? B : condition3 ? C : D The evaluation of the conditions are in turns: condition1, condition2, … Continue reading

Posted in programming | Leave a comment

Populate and serialize text options (Java and C++)

I find it convenient to have a unified text options, similar to those ini/rc files, with serializer/de-serializer for both Java and C++ and here is it. Sample text file: testmode=3 block_repeat=100 # floating point scaling_factor=0.9 # arrays c=1.0, -2.0, 1.0 … Continue reading

Posted in programming | 2 Comments

Lapack Java SGBTRF and SGBTRS

A sample code in Java, as a memo of the correct indexing (row/col): import org.netlib.lapack.Sgbtrf; import org.netlib.lapack.Sgbtrs; /* Purpose: We want to use the LAPACK routines SGBTRF and SGBTRS to solve a banded linear system of the form A*x=b. Our … Continue reading

Posted in programming | Leave a comment

Overloading open() and fopen()

One can overload fopen() and open() for debugging purpose, the example below traces each file opening operation: #include #include static FILE * (*next_fopen)(const char *path, const char *mode); FILE * fopen(const char *path, const char *mode) { char *msg; if … Continue reading

Posted in programming | Leave a comment

debug MPI programs with many slaves

Although ddt is handy, in some cases one might want to do it the old fashioned way (e.g., debugging many nodes that exceeds the license limit, or, you do not have ddt). Instead opening 30 terminals and attach gdb to the … Continue reading

Posted in programming | Leave a comment

fgsl: single precision float version of gsl

Many of GSL (GNU Scientific Library)’s routines are implemented in double only.  When one needs the additional speed and storage advantage, there wasn’t a quick way to go to float.  Here is a quick hack: cd gsl-1.15,  edit configure.ac, change … Continue reading

Posted in programming | Tagged , , | 1 Comment

gcc build error: undefined _Unwind_Ptr

I have tried on build both gcc-4.6.2 and gcc-4.6.1 and failed.  Here is the error: In file included from ../../.././libgcc/../gcc/unwind-dw2.c:35:0: ../../.././libgcc/../gcc/unwind-pe.h:101:1: error: unknown type name ‘_Unwind_Ptr’ Solution: rename the first unwind.h to another name and there should be another unwind.h … Continue reading

Posted in Info Tech, programming | 1 Comment

Passing class member function as argument

Here is one example: Declaration: class CDifferentialFFT : public CDifferential {   …   double benchmark(void (CDifferential::*) (float*, float*, int), float* p, float* pz);   … } Implementation: double CDifferentialFFT::benchmark(void (CDifferential::*func) (float*, float*, int), float* p, float* pz) {   … … Continue reading

Posted in programming | Tagged , | Leave a comment

calloc for C++?

It’s recommended to use: double * data = new double[mysize]; in C++ rather than the C-way: double * data = (double *)malloc(sizeof(double)*mysize); How about the one corresponds to calloc( ) ? Short memo here: double * data = new double[mysize](); … Continue reading

Posted in programming | Tagged | Leave a comment