Compiling C++ code with MPI for parallel processing

#include "mpi.h"
int main(int argc,char** argv)

then compile with

to run it, use
mpirun -np 4 ./a.out
for using 4 copies in 4 processors.


Atlas spectral response simulation does not converge

I am simulating a photodetector using Atlas from Silvaco. The simulation uses Luminous module to calculate the photocurrent for a range of optical wavelength. Somehow the simulation cannot converge for higher wavelengths.

It turns out due to the Schrodinger-Poisson calculation. I added in SCHRO in models statement since I wanted to calculate the conduction band as well.
models bgn srh auger conmob fldmob print schro
But this causes the simulation cannot converge when calculating higher optical wavelengths. After I remove the SCHRO parameter from model, the simulation converge

C++ code using acos for complex number in IT++

I am currently trying out IT++ and so far it was great. It is as easy as Octave but written for C++ programming. One thing that I had trouble was that in my code I need to compute
complex acos(complex a)
However, it gives me error

for the function acos. It turns out acos for complex number was not in the C++ 98 specification, it will only be on the C++ 0x specification. So I turn to Boost library.

To modify IT++, this is what I do:
1. go to “itpp-4.0.6/itpp/base/math” folder, and modify the file “trig_hyp.h”

2. Add this line:
#include <boost/math/complex/acos.hpp>

Of course you need to have Boost library.

3. Find the line for “acos” in trig_hyp.h file, and add these lines:
//! Inverse cosine function vector
inline cvec acos(const cvec &x) { return apply_function<std::complex >(boost::math::acos, x); }
//! Inverse cosine function matrix
inline cmat acos(const cmat &x) { return apply_function<std::complex >(boost::math::acos, x); }
//! Inverse cosine function scalar
inline std::complex acos(const std::complex &x) { return boost::math::acos( x); }

4. Go back to the root directory for IT++ and do a ./configure again
./configure --prefix=$(HOME)/local F77=gfortran CPPFLAGS=-I
where we have included the root folder of our Boost libraries.

5. Type “make”, “make check”, and “make install”

6. Now, in your code, you also need to include your Boost folder in your Makefile.

That’s all, now we have acos in IT++

check memory leak in a program or code

We can use “valgrind”, simply compile your code with -g option, and then run
valgrind --leak-check=full ./program > output.log
if you run “top” then you will see a process called “memcheck”.

this is a kind of output you will get:
==1651== Memcheck, a memory error detector.
==1651== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==1651== Using LibVEX rev 1804, a library for dynamic binary translation.
==1651== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==1651== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation framework.
==1651== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==1651== For more details, rerun with: -v
==1651== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 33 from 1)
==1651== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1651== malloc/free: 567 allocs, 567 frees, 147,342,292 bytes allocated.
==1651== For counts of detected errors, rerun with: -v
==1651== All heap blocks were freed -- no leaks are possible.

Installing IT++ in Linux

I am currently trying to use IT++ in Kubuntu 8.04. Download the source from
unzip the archive, and cd into the directory. Then do as usual: ./configure, make, make check, make install. But when I did a make check, 2 tests failed. It is documented in the FAQ #1. So I need to run configure as

./configure –prefix=$HOME/local F77=gfortran

this is to use gfortran instead of g77 (which was detected during configure). After this, the make and make check run perfectly.

To link your code you can use pkg-config as follows:
g++ `pkg-config --cflags itpp` -o ex1 ex1.cpp `pkg-config --libs itpp`
where ex1.cpp is your code.
However, in order to pkg-config to find the necessary information, you need to set PKG_CONFIG_PATH to the folder where it contains the .pc files. You can find this file in the folder where you extract the source code.

export PKG_CONFIG_PATH=$(HOME)/Download/NumericalComputation/itpp-4.0.6

Enable wireless connection in Kubuntu Intrepid 8.10

After I upgraded to Kubuntu Intrepid, knetwork-manager can detect wireless, and it’s activated, but it can never connect to the network.

After browsing through, I decided to try WICD, to install in Kubuntu, follow the instruction given in this page.

After installation, quit knetwork-manager, and run from konsole “wicd-client&”, this will run the tray application. click the tray icon to see the wireless networks, and click “connect”. It works perfectly fine for me.

Installing g77 in Ubuntu/Kubuntu Intrepid 8.10

One of the biggest annoyance in updgrading to Kubuntu Intrepid is that g77 is no longer in repository. So I need to install g77 from source. To do that:
tar xvzf gcc-3.4.6.tar.gz

then cd to that directory, and run configure with this options:
./configure --enable-languages=c,f77 --disable-checking --prefix=$HOME/local
make CC=/usr/bin/gcc
make install

more info in this post.

UPDATE: I am having some compilation eror, so I still don’t have g77 yet.