First taste of building cilk program on Arch Linux

I bump into cilk that is much like OpenMP this week, and give it a try on Arch Linux:

(1) Follow the Quick start to build Tapir-Meta:

$ git clone --recursive https://github.com/wsmoses/Tapir-Meta.git
$ cd Tapir-Meta/
$ ./build.sh release
$ source ./setup-env.sh

Please note gcc is the default compiler on Arch Linux, and there is a compile error of using gcc. So I switch to clang:

$ CC=clang CXX=claang++ ./build.sh release

The setup-env.sh is simple, just make Tapir/LLVM compilers as the default ones:

$ which clang
/home/xiaonan/Tapir-Meta/tapir/build/bin/clang
$ which clang++
/home/xiaonan/Tapir-Meta/tapir/build/bin/clang++

(2) Build libcilkrts (please refer this issue: “/usr/bin/ld: cannot find -lcilkrts” error).

(3) Write a simple program:

$ cat test.c
#include <unistd.h>
#include <cilk/cilk.h>

int main(void)
{
        cilk_spawn sleep(100);
        cilk_spawn sleep(100);
        cilk_spawn sleep(100);

        cilk_sync;
        return 0;
}

Build it:

$ clang -L/home/xiaonan/cilkrts/build/install/lib -fcilkplus test.c
$ ldd a.out
    linux-vdso.so.1 (0x00007ffdccd32000)
    libcilkrts.so.5 => /home/xiaonan/cilkrts/build/install/lib/libcilkrts.so.5 (0x00007f1fe4d60000)
    libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f1fe4b48000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007f1fe478c000)
    libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f1fe4588000)
    libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f1fe436a000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f1fe3fe1000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007f1fe3c4c000)
    /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f1fe4f7e000)

From ldd output, we can see it links the ibcilkrts library. Execute the program:

$ ./a.out &
[1] 25530
[xiaonan@tesla-p100 ~]$ ps -T 25530 | wc -l
105

We can see a.out spawns many threads.

Fix “==> ERROR: options array contains unknown option ‘!upx'” on ArchLinux

You may bump into following error when installing packages from AUR:

$ makepkg -si
==> ERROR: options array contains unknown option '!upx'

One workaround is open the PKGBUILD file, and spot the line which contains options:

......
options=('staticlibs' 'libtool' '!upx')
......

Remove the !upx, then you can build it now.

Reference:
dropbox: unrecognized !upx in the options array.

 

Fix “error while loading shared libraries: libalpm.so.10” on ArchLinux

Today, when I tried to use yaourt to install some software, the following error happened:

......
package-query: error while loading shared libraries: libalpm.so.10: cannot open shared object file: No such file or directory

The root cause is the libalpm in system is already libalpm.so.11:

$ ls -lt /usr/lib/libalpm.so*
lrwxrwxrwx 1 root root     17 Jun  1 00:32 /usr/lib/libalpm.so -> libalpm.so.11.0.0
lrwxrwxrwx 1 root root     17 Jun  1 00:32 /usr/lib/libalpm.so.11 -> libalpm.so.11.0.0
-rwxr-xr-x 1 root root 223616 Jun  1 00:32 /usr/lib/libalpm.so.11.0.0

But the package-query is still searching libalpm.so.10:

$ ldd /usr/bin/package-query
        linux-vdso.so.1 (0x00007fffb1d8d000)
        libcurl.so.4 => /usr/lib/libcurl.so.4 (0x00007f4baee32000)
        libyajl.so.2 => /usr/lib/libyajl.so.2 (0x00007f4baec28000)
        libalpm.so.10 => not found
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f4bae86c000)
        libnghttp2.so.14 => /usr/lib/libnghttp2.so.14 (0x00007f4bae647000)
......

The solution is removing yaourt and package-query, and re-intall them:

$ sudo pacman -Rn yaourt package-query
$ sudo pacman -S fakeroot
$ git clone https://aur.archlinux.org/package-query.git
$ cd package-query
$ makepkg -si
$ git clone https://aur.archlinux.org/yaourt.git
$ cd yaourt
$ makepkg -si

That’s it!

Linking error of _ntl_gbigint_body in using NTL

I use NTL on ArchLinux, and there is a struct _ntl_gbigint_body which is actually not defined (refer this post):

/*
 * This way of defining the bigint handle type is a bit non-standard,
 * but better for debugging.
 */

struct _ntl_gbigint_body;
typedef _ntl_gbigint_body *_ntl_gbigint;  

You should pay attention to functions who depend on this struct, such as:

void _ntl_gcopy(_ntl_gbigint a, _ntl_gbigint *bb)   

Because for old NTL library, the function prototype generated by compiler is _ntl_gcopy(void*, void**):

$ readelf -sW libntl.so | c++filt | grep ntl_gcopy
2511: 000000000012b750   184 FUNC    GLOBAL DEFAULT   12 _ntl_gcopy(void*, void**)

While for new one it is _ntl_gcopy(_ntl_gbigint_body*, _ntl_gbigint_body**):

$ readelf -sW libntl.so | c++filt | grep ntl_gcopy
615: 0000000000148500   202 FUNC    GLOBAL DEFAULT   11 _ntl_gcopy(_ntl_gbigint_body*, _ntl_gbigint_body**)

So if you meet linking error as following:

undefined reference to `_ntl_gcopy(void*, void**)'

It should be NTL header files and library mismatch. The header files are old, while library is new.

Set up Haskell development environment on Arch Linux

Follow this post, install stack first:

# pacman -S stack
resolving dependencies...
looking for conflicting packages...
......

At the end of installation, it prompts following words:

You need to either 1) install latest stable ghc package from [extra] or 2) install ncurses5compat-libs from AUR for the prebuilt binaries installed by stack to work.

So install ghc further:

# pacman -S ghc
resolving dependencies...
looking for conflicting packages...

Now that the environment is ready, you should modify your own ~/.stack/config.yaml file:

# This file contains default non-project-specific settings for 'stack', used
# in all projects.  For more information about stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/

# The following parameters are used by "stack new" to automatically fill fields
# in the cabal config. We recommend uncommenting them and filling them out if
# you intend to use 'stack new'.
# See https://docs.haskellstack.org/en/stable/yaml_configuration/#templates
templates:
  params:
#    author-name:
#    author-email:
#    copyright:
#    github-username:

For example, add name, email etc.

Then follow this link to create a simple program:

# stack new hello
# cd hello
# stack setup
# stack build
# stack exec hello-exe

You will see “someFunc” is outputted.

BTW, you can also use ghc compiler directly. E.g., write a “Hello world” program (Reference is here):

# cat hello.hs
main :: IO ()
main = putStrLn "Hello World!"
# ghc -dynamic hello.hs
# ./hello
Hello World!

That’s all!