Skip to content

SRW and OpenMP

Maksim Rakitin edited this page Feb 7, 2017 · 9 revisions

SRW and OpenMP

Sergey Yakubov implemented OpenMP support for SRW on Linux - https://github.com/SergeyYakubov/SRW/tree/openmp. I did minor updates to make it work on Windows as well. Here is the full list of changes - https://github.com/SergeyYakubov/SRW/compare/openmp...mrakitin:openmp_sergey?expand=1. Related ticket - https://github.com/mrakitin/SRW/issues/26.

Linux

On Linux it compiled great without any additional changes of the code. Recent gcc compilers support OpenMP on Linux by default.

Sizes of the compiled files:

Without OpenMP:

-rw-rw----  1 vagrant vagrant 2134008 Feb  2 21:29 srwlpy.so

With OpenMP:

-rwxrwx---  1 vagrant vagrant 2194650 Feb  7 14:46 srwlpy.so*

Note: compilation with the commented OpenMP-related flags in the following files

CFLAGS+=-fopenmp -Wno-write-strings
    extra_link_args=['-fopenmp'],
    extra_compile_args=['-Wno-sign-compare','-Wno-parentheses','-fopenmp','-Wno-write-strings'],

leads to an error:

Traceback (most recent call last):
  File "SRWLIB_Example14_short.py", line 9, in <module>
    from srwlib import *
  File "/home/vagrant/src/mrakitin/SRW/env/work/srw_python/srwlib.py", line 6, in <module>
    import srwlpy as srwl
ImportError: /home/vagrant/src/mrakitin/SRW/env/work/srw_python/srwlpy.so: undefined symbol: omp_get_thread_num

MS Windows

For Windows the code didn't compile since a Linux-specific function gettimeofday() for timing was used. I implemented a cross-platform solution based on http://www.cplusplus.com/reference/ctime/clock/. Visual Studio solution files were updated to support OpenMP (/openmp flag) - https://msdn.microsoft.com/en-us/library/fw509c3b.aspx: VS_openmp_config

Mac OS

Instructions from Rob Nagler:

sudo port install gcc49
sudo port install openmpi-gcc49
sudo port select --set gcc mp-gcc49
sudo port install fftw-single
mkdir -p ~/src/mrakitin
cd ~/src/mrakitin
git clone https://github.com/mrakitin/SRW
cd SRW
git checkout openmp_sergey
perl -pi -e 's/-lfftw/-lsfftw/; s/\bcc\b/gcc/; s/\bc\+\+/g++/' cpp/gcc/Makefile
perl -pi -e "s/'fftw'/'sfftw'/; /library_dirs/ && s{(?=\\])}{, '/opt/local/lib'}" cpp/py/setup.py
make CC=gcc CXX=c++ nofftw
cd env/work/srw_python/
python SRWLIB_Example14_short.py
Clone this wiki locally