Debugging OpenMP fortran code

As the code becomes parallel, the complexity increases. One of the common problem in parallel code is data race. To debug this problem, I encounter that Intel’s Thread Checker to be a good software. You can download from the Intel’s website for evaluation. I found about this when I read this article

When I run tcheck_cl, I realized that some parts has a data race. So I need to eliminate this. I couldn’t make it private since it will give segmentation fault (refer to this bug). So I simply add the !$omp critical to the section that has the data race. And it solves the problem.

Anyway, Intel’s Thread Checker really helped to identify which section of the code has the problem.

Advertisements

VTK error reading ascii data! when writing using Fortran

I write a fortran code and save the data in VTK legacy format with structured points. However, for certain data somehow Paraview and Mayavi are unable to read the VTK file. It gives a “Generic Warning”, and says that
Error reading ascii data!

After days of debugging, it turns out that the cause is my precision, I used double precision for my data, and there are some data with 3 digit for the exponents, and I write to the file using ES format. This turns out cannot be read by Paraview and Mayavi. So when I changed the format to F which is just a floating point with decimal points (no exponents), then paraview and mayavi2 can read my data. But this is of course is not a good format to store. And after looking for more detail in Fortran languange, I can set my digit in the exponent to only 2. This is the format in fortran

ESw.dEe

where “e” is the digit for the exponent.

The other thing is that In VTK, I set the data type as “float”, I need to change this to “double”.

How to embed fonts when using pdflatex and gnuplot

IEEE require that PDF documents are created with embedded fonts. To do this, run

$ updmap --setoption pdftexDownloadBase14 true

And then run pdflatex again. To check whether it is embedded, run pdffonts on to the newly created pdf. You will see something like this.

$ pdffonts draft_isic2009_1.pdf
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
OONIXM+NimbusRomNo9L-Regu            Type 1            yes yes no       6  0
LREKMX+NimbusRomNo9L-MediItal        Type 1            yes yes no       7  0
GPJANF+NimbusRomNo9L-Medi            Type 1            yes yes no       8  0
SOCFYY+CMMI10                        Type 1            yes yes no       9  0
XUABDJ+CMR10                         Type 1            yes yes no      18  0
[none]                               Type 3            yes no  no      19  0
[none]                               Type 3            yes no  no      20  0
NYFSWW+CMR7                          Type 1            yes yes no      21  0
[none]                               Type 3            yes no  no      22  0
Symbol                               Type 1            no  no  no      25  0
MJDZZV+Arial                         TrueType          yes yes no      26  0
NEOHJY+Arial                         TrueType          yes yes no      33  0
RGPVWY+CMMI7                         Type 1            yes yes no      42  0
QFGUOO+Arial                         TrueType          yes yes no      45  0
WHIAUZ+NimbusRomNo9L-ReguItal        Type 1            yes yes no      54  0
Symbol                               Type 1            no  no  no      57  0
KLCILH+Arial                         TrueType          yes yes no      58  0
SHWEVG+Arial                         TrueType          yes yes no      65  0
PWUUWC+Arial                         TrueType          yes yes no      71  0

Now you notice that Symbol font is not embedded. It turns out to be from the figures that I have. I created my figures using Gnuplot, and it gives the eps file. The eps file is then converted to pdf using epstopdf command. If you type pdffonts to this figures, you will notice that the symbol font is not embedded. To ensure that the symbol font is embedded, edit the following file:

/usr/share/ghostscript/8.61/lib/gs_pdfwr.ps

And comment the lines as shown below:

/.standardfonts [
% /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique
% /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique
% /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic
% /Symbol /ZapfDingbats
] readonly def

After this, run epstopdf again, and check using pdffonts. I ran my pdflatex to my tex file again, and check to find that all fonts have been embedded:

$ pdffonts draft_isic2009_1.pdf
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
OONIXM+NimbusRomNo9L-Regu            Type 1            yes yes no       6  0
LREKMX+NimbusRomNo9L-MediItal        Type 1            yes yes no       7  0
GPJANF+NimbusRomNo9L-Medi            Type 1            yes yes no       8  0
SOCFYY+CMMI10                        Type 1            yes yes no       9  0
XUABDJ+CMR10                         Type 1            yes yes no      18  0
[none]                               Type 3            yes no  no      19  0
[none]                               Type 3            yes no  no      20  0
NYFSWW+CMR7                          Type 1            yes yes no      21  0
[none]                               Type 3            yes no  no      22  0
CNBJKM+Symbol                        Type 1C           yes yes no      25  0
MJDZZV+Arial                         TrueType          yes yes no      26  0
NEOHJY+Arial                         TrueType          yes yes no      35  0
RGPVWY+CMMI7                         Type 1            yes yes no      44  0
QFGUOO+Arial                         TrueType          yes yes no      47  0
WHIAUZ+NimbusRomNo9L-ReguItal        Type 1            yes yes no      56  0
CNBJKM+Symbol                        Type 1C           yes yes no      59  0
KLCILH+Arial                         TrueType          yes yes no      60  0
SHWEVG+Arial                         TrueType          yes yes no      69  0
PWUUWC+Arial                         TrueType          yes yes no      75  0

Installing Octave 3.2.3 in Kubuntu Hardy

Octave has released a major version 3.2 and now the latest bug fix release is 3.2.3. I decided to install it. What I did was to download the tarball from http://www.octave.org and then unzip it. After that, I run the configure:

./configure --prefix=$HOME/Programs/Octave-3.2.3

where the prefix defines the location where to install the new version of octave. I got some warning on the graphics library since Octave 3.2 uses a different graphics library.

configure: WARNING: qrupdate not found. The QR & Cholesky updating functions will be slow.
configure: WARNING: GraphicsMagick++ config script not found. Assuming GraphicsMagic++ library and header files are missing, so imread will not be fully functional
configure: WARNING: "FTGL headers not found. Native renderer will not have on-screen text"
configure: WARNING: "FLTK config script not found. Native graphics will be disabled."
configure: WARNING:
configure: WARNING: I didn't find the necessary libraries to compile native
configure: WARNING: graphics. It isn't necessary to have native graphics
configure: WARNING: but you will have to use gnuplot or you won't be able
configure: WARNING: to use any of Octave's plotting commands
configure: WARNING:

To solve this problem, I run Adept package manager and install the following:

libgraphicsmagick++1-dev
ftgl-dev
libfltk1.1-dev

And I also download qrupdate library from this page. Hardy does not provide this package, but it can be found in Karmic. To install this, edit the Makeconf file according to your system. In my case I just edit the PREFIX part to where I want to install it. After that type "make lib" for creating static library, and "make solib" for dynamic library. To install, type "make install". For more info, you can type "make help"

To make sure Octave can find the qrupdate library, you might have to add LDFLAGS into the ./configure command:

./configure --prefix=$HOME/Programs/Octave-3.2.3 LDFLAGS='-L/home/kurniawano/local/lib'

After everything seems ok, type "make" and "make install"

Debugger for Fortran in Linux

I have been trying to search for a good debugger for Fortran code in Linux. But it is very hard to find. I know that GDB is supposed to be able to do it. But when I debug Fortran 95 code compiled using GFortran, I simply don’t know how to display the dynamic size array. I tried to google, and found that other people also find the same issue with GDB and fortran:
comp.lang.fortran

this is what I get when I tried to print an array which was allocatable, and allocated afterward:

(gdb) p myarray
{ 0x80614c8, -1, 537, ({ 1, 1, 6})}

and when I get the type:

(gdb) pt myarray
type = Type array_descriptor1
PTR TO -> ( void ) :: data
int4 :: offset
int4 :: dtype
Type descriptor_dimension
int4 :: stride
int4 :: lbound
int4 :: ubound
End Type descriptor_dimension (0:0) :: dim
End Type array_descriptor1

so for me, the best solution currently is to use Intel compiler and debugger in Linux. The debugger is called “idb”. You can download freely from intel website.

So what I did was that I recompiled my code using “ifort” which is the intel fortran compiler, and use the “idb” to debug. To run it type:

$ /opt/intel/Compiler/11.1/038/bin/ia32/idb

the location will depend on where you install the compiler and the debugger.

To start debug, click “File->Load executable”, and choose the executable which has been compiled using Ifort. To view the source as well, click “View->Source Files”.

You can set a break point, etc, in the code, and to view an array simply type:

(idb) p myarray

or you can also access the element

(idb) p myarray(3)

Below is the snapshot of the debugger. I used Kubuntu 8.04.

idb