Most commented posts
- Start to Fortran — 1 comment
- Phonons: shake those atoms — 3 comments
Oct 06 2016
Yesterday was the tUL Life Sciences Research Day 2016. A conference event build around finding collaboration possibilities between the University of Hasselt in Belgium and the University of Maastricht (The Netherlands)…after all tUL is the “transnational University Limburg” which brings two universities together that are only separated some 26 km, but you have to cross a national border.
Although Life sciences itself is not my personal niche, I went to look for opportunities, as nano-particles which are used for drug delivery often consist of metals or oxides. These materials on the other hand are my niche. I used my current work on MOFs as a means to show what is possible from the ab-initio point of view, and presented this as a poster.

Poster presented at the tUL Life Sciences Research Day, depicting my work on the unfunctionalized and the functionalized MIL-47(V) MOF.
Permanent link to this article: https://dannyvanpoucke.be/tul-life-sciences-research-day-2016/
Sep 25 2016
| Authors: | S. A. Rounaghi, H. Eshghi, S. Scudino, A. Vyalikh, D. E. P. Vanpoucke, W. Gruner, S. Oswald, A. R. Kiani Rashid, M. Samadi Khoshkhoo, U. Scheler and J. Eckert |
| Journal: | Scientific Reports 6, 33375 (2016) |
| doi: | 10.1038/srep33375 |
| IF(2016): | 4.259 |
| export: | bibtex |
| pdf: | <Sci.Rep.> (open access) |
Hexagonal Aluminium nitride (h-AlN) is an important wide-bandgap semiconductor material which is conventionally fabricated by high temperature carbothermal reduction of alumina under toxic ammonia atmosphere. Here we report a simple, low cost and potentially scalable mechanochemical procedure for the green synthesis of nanostructured h-AlN from a powder mixture of Aluminium and melamine precursors. A combination of experimental and theoretical techniques has been employed to provide comprehensive mechanistic insights on the reactivity of melamine, solid state metalorganic interactions and the structural transformation of Al to h-AlN under non-equilibrium ball milling conditions. The results reveal that melamine is adsorbed through the amine groups on the Aluminium surface due to the long-range van der Waals forces. The high energy provided by milling leads to the deammoniation of melamine at the initial stages followed by the polymerization and formation of a carbon nitride network, by the decomposition of the amine groups and, finally, by the subsequent diffusion of nitrogen into the Aluminium structure to form h-AlN
Permanent link to this article: https://dannyvanpoucke.be/paper2016_scirepalnitride-en/
Permanent link to this article: https://dannyvanpoucke.be/col-mofcofzeo-day2-en/
Permanent link to this article: https://dannyvanpoucke.be/col-mofcofzeo-day1-en/
Aug 31 2016

Visit to Stockholm. The knight at the Medeltidsmuseet (top left), brown bear in Skansen (top right), visiting the Royal palace (bottom left) and local entertainment in the old city center (bottom right).
Summertime is a time of rest for most people. For our little academic family, last summer was a bit of a roller coaster; alternating holidays with hard work which had been postponed too much. The last vestige of my start of a new chapter (moving the remaining stuff from the apartment to our house) was finally bested. Now the conference roller coaster has started with Sylvia’s plenary lecture on conceptual spaces in Stockholm.
As neither of us ever visited Sweden before, we decided to turn it into a semi-family-holiday as well. Our 4-year-old son enjoyed his first ever plane flight (he wasn’t really convinced something impressive was going on). And while Sylvia was of to the conference, the two of us went to explore Stockholm: Finding the knight in the Medeltidsmuseet (at the left in the back of this beautiful museum 🙂 ) and searching for the king and queen at their palace (they weren’t there 🙁 ). Or visiting one of the oldest open-air musea; Skansen (similar to Bokrijk in Belgium) where we saw old professions at work (making cheese for example) and native Scandinavian farm and wild animals (from peacocks to brown bears).
Next weekend starts the next episode of the conference roller-coaster with me hosting a 2-day colloquium on porous frameworks together with Bartek Szyja and Ionut Tranca at the CMD-26 conference in Groningen. We have a nicely packed colloquium with about 20 presentations (8 invited and 12 contributed) covering the whole realm of porous materials from zeolites to COFs and MOFs. The program of the colloquium can be downloaded below:
Permanent link to this article: https://dannyvanpoucke.be/holiday-conference-rollercoaster-en/
Jul 14 2016
The first PC we got at our home was a Pentium II. My dad got it, because I was going to university, and I would be able to do something “useful” with it. (Yup, I survived my entire high school career searching stuff in the library and the home encyclopedia. Even more, Google didn’t even exist before we got our computer, as the company was only founded in 1998 🙂 ). The machine was advertised as state of the art with a clock rate of a whooping 233 MHz! During the decade that followed, the evolution of the clock rates kept going at a steady pace, until it saturated at about 3-4 GHz(15 times faster than the 233 MHz) around 2005. Since then, the clock rate has not increased a bit. If anything, the average clock rate has even decreased to the range 2-3 GHz. As power-consumption grows quadratically with with the clock rate, this means that (1) there is much more heat produced, that needs to be transported away from your CPU (otherwise it get’s destroyed), (2) reducing the clock rate by a factor 2, allows you to power 4 CPU’s at half the clock rate, effectively doubling your calculation power. (There are even more tricks involved in modern CPU’s which crack up performance such that the clock rate isn’t a real measure for performance any longer, and sales people need to learn more new buzzword to sell your computer/laptop 👿 )
Where in 2005 you bought a single CPU with a high clock rate, you now get a machine with multiple cores. Most machines you can get these days have a minimum of 2 cores, with quad-core machines becoming more and more common. But, there is always a but, even though you now have access to multiple times the processing power of 2005, this does not mean that your own code will be able to use it. Unfortunately there is no simple compiler switch which makes your code parallel (like the -m64 switch which makes your code 64-bit), you have to do this yourself (the free lunch is over). Two commonly used frameworks for this task are OpenMP and MPI. The former mainly focuses on shared memory configurations (laptops, desktops, single nodes in a cluster), while the latter focuses of large distributed memory setups (multi-node clusters) and is thus well-suited for creating codes that need to run on hundreds or even thousands of CPU’s. The two frameworks differ significantly in their complexity, fortunately for us, OpenMP is both the easier one, and the one most suited for a modern multi-core computer. The OpenMP framework consists of pragma’s (or directives) which can be added in an existing code as comment lines, and tell a compiler knowledgeable of OpenMP how to parallelize the code. (It is interesting to note that MPI and OpenMP are inteded for parallel programming in either C, C++ or fortran … a hint that what the important programming languages are.)
As most modern fortran compilers also are well aware of openMP (you can check which version of openMP is supported here), you generally will not need to install a new compiler to write parallel fortran code. You only need to add a single compiler flag: -fopenmp (gcc/gfortran), -openmp (intel compiler), or -mp (Portland Group). In Code::Blocks you will find this option under Settings > Compiler > Compiler Settings tab > Compiler Flags tab (If the option isn’t present try adding it to “other compiler options” and hope your compiler recognizes one of the flags).
Secondly, you need to link in the OpenMP library. In Code::Blocks go to Settings > Compiler > Linker Settings tab > Link Libraries: add. Where you add the libgomp.dll.a library (generally found in the folder of your compiler…in case of 64 bit compilers, make sure you get the 64 bit version)
Finally, you may want to get access to OpenMP functions inside your code. This can be achieved by a use statement: use omp_lib.
OpenMP contains several functions which allow you to query and set several environment variables (check out these cheat-sheets for OpenMP v3.0 and v4.0).
[codesyntax lang=”fortran” lines=”fancy” container=”div” strict=”yes” title=”Simple OpenMP functions” blockstate=”expanded” highlight_lines=”10,13″]
subroutine OpenMPTest1()
use omp_lib;
write(*,*) "Running OpenMP Test 1: Environment variables"
write(*,*) "Number of threads :",omp_get_num_threads()
write(*,*) "Number of CPU's available:",omp_get_num_procs()
call omp_set_num_threads(8) ! set the number of threads to 8
write(*,*) "#Threads outside the parallel section:",omp_get_num_threads()
!below we start a parallel section
!$OMP PARALLEL
write(*,*) "Number of threads in a parallel section :",omp_get_num_threads()
write(*,*) "Currently in thread with ID = ",omp_get_thread_num()
!$OMP END PARALLEL
end subroutine OpenMPTest1
[/codesyntax]
Notice in the example code above that outside the parallel section indicated with the directives $OMP PARALLEL and $OMP END PARALLEL, the program only sees a single thread, while inside the parallel section 8 threads will run (independent of the number of cores available).
The OpenMP frameworks consists of an set of directives which can be used to manage the parallelization of your code (cheat-sheets for OpenMP v3.0 and v4.0). I will not describe them in detail as there exists several very well written and full tutorials on the subject, we’ll just have a look at a quick and easy parallelization of a big for-loop. As said, OpenMP makes use of directives (or Pragma’s) which are placed as comments inside the code. As such they will not interfere with your code when it is compiled as a serial code (i.e. without the -fopenmp compiler flag). The directives are preceded by what is called a sentinel ( $OMP ). In the above example code, we already saw a first directive: PARALLEL. Only inside blocks delimited by this directive, can your code be parallel.
[codesyntax lang=”fortran” lines=”fancy” container=”div” title=”OpenMP second test” highlight_lines=”18,21,29,31″]
subroutine OMPTest2()
use omp_lib;
integer :: IDT, NT,nrx,nry,nrz
doubleprecision, allocatable :: A(:,:,:)
doubleprecision :: RD(1:1000)
doubleprecision :: startT, TTime, stt
call random_seed()
call random_number(RD(1:1000))
IDT=500 ! we will make a 500x500x500 matrix
allocate(A(1:IDT,1:IDT,1:IDT))
write(*,'(A)') "Number of preferred threads:"
read(*,*) NT
call omp_set_num_threads(NT)
startT=omp_get_wtime()
!$OMP PARALLEL PRIVATE(stt)
stt=omp_get_wtime()
!$OMP DO
do nrz=1,IDT
do nry=1,IDT
do nrx=1,IDT
A(nrx,nry,nrz)=RD(modulo(nrx+nry+nrz,1000)+1)
end do
end do
end do
!$OMP END DO
write(*,*) "time=",(omp_get_wtime()-stt)/omp_get_wtick()," ticks for thread ",omp_get_thread_num()
!$OMP END PARALLEL
TTime=(omp_get_wtime()-startT)/omp_get_wtick()
write(*,*)" CPU-resources:",Ttime," ticks."
deallocate(A)
end subroutine RunTest2
[/codesyntax]
The program above fills up a large 3D array with random values taken from a predetermined list. The user is asked to set the number of threads (lines 14-16), and the function omp_get_wtime() is used to obtain the number of seconds since epoch, while the function omp_get_wtick() gives the number of seconds between ticks. These functions can be used to get some timing data for each thread, but also for the entire program. For each thread, the starting time is stored in the variable stt. To protect this variable of being overwritten by each separate thread, this variable is declared as private to the thread (line 18: PRIVATE(stt) ). As a result, each thread will have it’s own private copy of the stt variable.
The DO directive on line 21, tells the compiler that the following loop needs to be parallelized. Putting the !$OMP DO pragma around the outer do-loop has the advantage that it minimizes the overhead produced by the parallelization (i.e. resources required to make local copies of variables, calculating the distribution of the workload over the different threads at the start of the loop, and combining the results at the end of the loop).
As you can see, parallelizing a loop is rather simple. It takes only 4 additional comment lines (!$OMP PARALLEL , !$OMP DO, !$OMP END DO and !$OMP END PARALLEL) and some time figuring out which variables should be private for each thread, i.e. which are the variables that get updated during each cycle of a loop. Loop counters you can even ignore as these are by default considered private. In addition, the number of threads is set on another line giving us 5 new lines of code in total. It is of course possible to go much further, but this is the basis of what you generally need.
Unfortunately, the presented example is not that computationally demanding, so it will be hard to see the full effect of the parallelization. Simply increasing the array size will not resolve this as you will quickly run out of memory. Only with more complex operations in the loop will you clearly see the parallelization. An example of a more complex piece of code is given below (it is part of the phonon-subroutine in HIVE):
[codesyntax lang=”fortran” lines=”fancy” container=”div” title=”Parallel example: Phonon spectra” highlight_lines=”4,5,6,7,11,12,13,15,42,43,44,45,47″]
!setup work space for lapack
N = this%DimDynMat
LWORK = 2*N - 1
call omp_set_num_threads(this%nthreads)
chunk=(this%nkz)/(this%nthreads*5)
chunk=max(chunk,1)
!$OMP PARALLEL PRIVATE(WORK, RWORK, DM, W, RPart,IO)
allocate(DM(N,N))
allocate( WORK(2*LWORK), RWORK(3*N-2), W(N) )
!the write statement only needs to be done by a single thread, and the other threads do not need to wait for it
!$OMP SINGLE
write(uni,'(A,I0,A)') " Loop over all ",this%nkpt," q-points."
!$OMP END SINGLE NOWAIT
!we have to loop over all q-points
!$OMP DO SCHEDULE(DYNAMIC,chunk)
do nrz=1,this%nkz
do nry=1,this%nky
do nrx=1,this%nkx
if (this%kpointListBZ1(nrx,nry,nrz)) then
!do nrk=1,this%nkpt
WORK = 0.0_R_double
RWORK = 0.0_R_double
DM(1:this%DimDynMat,1:this%DimDynMat)=this%dynmatFIpart(1:this%DimDynMat,1:this%DimDynMat) ! make a local copy
do nri=1,this%poscar%nrions
do nrj=1,this%poscar%nrions
Rpart=cmplx(0.0_R_double,0.0_R_double)
do ns=this%vilst(1,nri,nrj),this%vilst(2,nri,nrj)
Rpart=Rpart + exp(i*(dot_product(this%rvlst(1:3,ns),this%kpointList(:,nrx,nry,nrz))))
end do
Rpart=Rpart/this%mult(nri,nrj)
DM(((nri-1)*3)+1:((nri-1)*3)+3,((nrj-1)*3)+1:((nrj-1)*3)+3) = &
& DM(((nri-1)*3)+1:((nri-1)*3)+3,((nrj-1)*3)+1:((nrj-1)*3)+3)*Rpart
end do
end do
call MatrixHermitianize(DM,IOS=IO)
call ZHEEV( 'V', 'U', N, DM, N, W, WORK, LWORK, RWORK, IO )
this%FullPhonFreqList(:,nrx,nry,nrz)=sign(sqrt(abs(W)),W)*fac
end if
end do
end do
end do
!$OMP END DO
!$OMP SINGLE
write(uni,'(A)') " Freeing lapack workspace."
!$OMP END SINGLE NOWAIT
deallocate( WORK, RWORK,DM,W )
!$OP END PARALLEL
[/codesyntax]
In the above code, a set of equations is solved using the LAPACK eigenvalue solver ZHEEV to obtain the energies of the phonon-modes in each point of the Brillouin zone. As the calculation of the eigenvalue spectrum for each point is independent of all other points, this is extremely well-suited for parallelization, so we can add !$OMP PARALLEL and !$OMP END PARALLEL on lines 7 and 47. Inside this parallel section there are several variables which are recycled for every grid point, so we will make them PRIVATE (cf. line 7, most of them are work-arrays for the ZHEEV subroutine).
Lines 12 and 44 both contain a write-statement. Without further action, each thread will perform this write action, and we’ll end up with multiple copies of the same line (Although this will not break your code it will look very sloppy to any user of the code). To circumvent this problem we make use of the !$OMP SINGLE directive. This directive makes sure only 1 thread (the first to arrive) will perform the write action. Unfortunately, the SINGLE block will create an implicit barrier at which all other threads will wait. To prevent this from happening, the NOWAIT clause is added at the end of the block. In this specific case, the NOWAIT clause will have only very limited impact due to the location of the write-statements. But this need not always to be the case.
On line 15 the !$OMP DO pragma indicates a loop will follow that should be parallelized. Again we choose for the outer loop, as to reduce the overhead due to the parallelization procedure. We also tell the compiler how the work should be distributed using the SCHEDULE(TYPE,CHUNK) clause. There are three types of scheduling:
From this real life example, it is again clear that OpenMP parallelization in fortran can be very simple.
On my loyal sidekick (with hyper-threaded quad-core core i7) I was able to get following speedups for the phonon-code (the run was limited to performing only a phonon-DOS calculation):

Speedup of the entire phonon-subroutine due to parallelization of the main-phonon-DOS loop.
The above graph shows the speed-up results for the two different modes for calculating the phonon-DOS. The reduced mode (DM red), uses a spectrum reduced to that of a unit-cell, but needs a much denser sampling of the Brillouin zone (second approach), and is shown by the black line. The serial calculation in this specific case only took 96 seconds, and the maximum speedup obtained was about x1.84. The red and green curves give the speedup of the calculation mode which makes use of the super-cell spectrum (DM nored, i.e. much larger matrix to solve), and shows for increasing grid sizes a maximum speedup of x2.74 (serial time: 45 seconds) and x3.43 (serial time 395 seconds) respectively. The reason none of the setups reaches a speedup of 4 (or more) is twofold:
In case of the DM nored calculations, the parallelized loop clearly takes the biggest part of the calculation-time, while for the DM red calculation, also the section generating the q-point grid takes a large fraction of the calculation time limiting the effect of parallelization. An improvement here would be to also parallelize the subroutine generating the grid, but that will be for future work. For now, the expensive DM nored calculations show an acceptable speedup.
Permanent link to this article: https://dannyvanpoucke.be/fortran-openmp1-en/
Permanent link to this article: https://dannyvanpoucke.be/ihev-tec-en/
Permanent link to this article: https://dannyvanpoucke.be/folding-phonons/
Jun 19 2016
Current day computers generally have 64-bit processors, and most even have 64-bit operating systems. On such systems, 32-bit programs will run fine, but 64-bit programs can make more efficient use of the underlying system. When we installed a fortran compiler and the code::blocks IDE, the default fortran compiler generated 32-bit programs. This generally is not an issue, unless you need a large amount of memory, for example to store a temporary array with 4003 double precision coordinates (as I did for a project I’m currently working on). You may first start to look for ways of increasing the stack-size of your program, but you will soon discover that the problem is more profound: a 32-bit program cannot access address spacing beyond 4Gb. (In practice, generally you will not even reach 4Gb before running into problems.) This is because the memory address of your data is stored as a 32-bit value (232 = 4 294 967 296 = 4Gb) so the only way out of this predicament is a “larger address” aka 64-bit. So you need to install a new compiler capable of providing 64-bit programs.
Permanent link to this article: https://dannyvanpoucke.be/install-fortran64bit-en/
May 29 2016
Over the past few weeks I have bumped into several issues each tracing back to numerical accuracy. Although I have been programming for almost two decades I never had to worry much about this, making these events seem as-if the universe is trying to tell me something.
Now, let me try to give a proper start to this story; Computational (materials) research is generally perceived as a subset of theoretical (materials) research, and it is true that such a case can be made. It is, however, also true that such thinking can trap us (i.e. the average computational physicist/chemist/mathematician/… programming his/her own code) with numerical accuracy problems. While theoretical equations use exact values for numbers, a computer program is limited by the numerical precision of the variables (e.g. single, double or quadruple precision for real numbers) used in the program. This means that actual numbers with a larger precision are truncated or rounded to the precision of the variable (e.g. 1/3 becomes 0.3333333 instead of 0.333… with an infinite series of 3’s). Most of the time, this is sufficient, and nothing strange will happen. Even more, most of the time, the additional digits would only increase the computational cost while not improving the results in a significant fashion.
To understand the importance, or the lack thereof, of additional significant digits, let us first have a look at the precision of and the circumference and surface area of a disc. We will be looking at a rather large disc, one with a radius equal to the distance between the sun, and the nearest star, Alpha Centauri, which is 39 900 000 000 000 km away. The circumference of this disc is given by
(or
km ). As a single precision variable
will have about 7-8 significant digits. This means the calculated circumference will have an accuracy of about 1 000 000 km (or a few times the distance between the earth and the moon). Using a double precision
variable, which has a precision of 16 decimal digits, the circumference will be accurately calculated to within a few meters. At quadrupal precision, the
variable would have 34 significant decimal digits, and we would even be able to calculate the surface of the disc (
or
m² ) to within 1 m². Even the surface of a disc the size of our milky way could be calculated with an accuracy of a few hundred square km (or ± the size of Belgium ).
Knowing this, our mind is quickly put at easy regarding possible issues regarding numerical accuracy. However, once in a while we run into one exceptional case (or three, in my case).

Temperature profile in the insulating layer of a cylindrical wire.
While looking into the theory behind finite elements, I had some fun implementing a simple program which calculated the temperature distribution due to heat transport in an insulating layer. The finite element approach performed rather nicely, leading to good approximate results, already for a few dozen elements. However, I wanted to push the implementation a bit (the limit of infinite elements should give the exact solution). Since the set of equations was solved by a LAPACK subroutine, using 10 000 elements instead of 10 barely impacted the required time (writing the results took most of 2-3 seconds anyway). The results on the other hand were quite funny as you can see in the picture. The initial implementation, with single precision variables, breaks down even worse already at 1000 elements. Apparently the elements had become too small leading to too small variations of the properties in the stiffness-matrix, resulting in the LAPACK subroutine returning nonsense.
So it turns out that you can have too many elements in a finite elements method.

Optimized volume in Equation of State fit, as function of the range of the fitting data, and step size between data-points. green diamonds, blue triangles and black discs: 1% , 0.5% and 0.25% volume steps respectively.
Recently, I started working at the Wide Band Gap Materials group at the University of Hasselt. So in addition to MOFs I am also working on diamond based materials. While setting up a series of reference calculations, using scripts which already suited me well during my work on MOFs, I was trying to figure out for which volume range, and step size I would get a sufficient convergence in my Equation-of-States Fitting procedure. For the MOFs this is a computationally rather expensive (and tedious) exercise, which, fortunately, gives clear results. For the 2-atom diamond unit cell the calculations are ridiculously fast (in comparison), but the results were confusing. As you can see in the picture, the values I obtained from the different fits seem to oscillate. Checking my E(V) data showed nothing out of the ordinary. All energies and volumes were clearly distinguishable, with the energies given with a precision of 0.001 meV, and the volumes with a precision of 0.01 Å3. However, as you can see in the figure, the volume-oscillations are of the order of 0.001 Å3, ten times smaller than our input precision. Calculating the volumes based on the lattice parameters to get a precision of 10-6 Å3 for the input volumes stabilizes the convergence behavior of the fits (open symbols in the figure). This problem was not present with the MOFs since these have a unit cell volume which is one hundred times larger, so a precision of 0.01 Å3 makes the relative error on the volumes one hundred times smaller than was the case for diamond.
In essence, I was trying to get more accurate output than the input I provided, which will never give sensible results (even if they actually look sensible).
The last one is a bit embarrassing as it lead to a bug in the HIVE-toolbox, which is fixed in the mean time.
One of the HIVE-toolbox users informed me that the dosgrabber routine had crashed because it could not find the Fermi-level in the output of a VASP calculation. Although VASP itself gives a value for the Fermi-level, I do not use it in the above sub-program, since this value tend to be incorrect for spin-polarized systems with different minority and majority spins. However, in an attempt to be smart (and efficient) I ended up in trouble. The basic idea behind my Fermi-level search is just running through the entire Density of States-spectrum until you have counted for all the electrons in the system. Because the VASP estimate for the Fermi-level is not that far of, you do not need to run through the entire list of several thousand entries, but you could just take a subset-centered around the estimated Fermi-level and check in that subset, speeding this up by a factor of 10 to 100. Unfortunately I calculated the energy step size between density of states entries as the difference between the first two entries, which are given to with an accuracy of 0.001 eV. I guess you already have a feeling what will be the problem. When the index of the estimated Fermi-level is 1000, the error will be of the order of 1 eV, which is much larger than the range I took into account. Fortunately, the problem is easily solved by calculating the energy step size as the difference between the first and last index, and divide by the number of steps, making the error in the particular case more than a thousand times smaller.
So, trying to be smart, you always need to make sure you really are being smart, and remember that small number can become very big when there are a lot of them.
Permanent link to this article: https://dannyvanpoucke.be/one-more-digit-of-importance-en/