Search code examples
cmetis

METIS: different results on different OS


This C program calls METIS to partition a mesh.

Edit: New version of the C program taking into account comments of WeatherVane and PaulOgilvie.

On my GNU/Linux I get the results:

objval: 14
epart: 0 0 0 0 0 1 2 2 1 0 0 1 2 2 1 2 2 1 
npart: 0 0 0 2 0 0 1 1 2 2 2 1 2 2 1 1 
8

while on my OSX I get:

objval: 17
epart: 0 1 1 0 1 0 2 2 0 1 1 1 2 2 1 2 2 0 
npart: 0 1 1 1 0 1 0 1 2 2 2 0 2 2 0 0 
8

What causes the results to be different?

How to fix it, I mean, always get the same results whatever the OS/architecture/compiler is?

Note: idx_t is int64_t, which is long on my GNU/Linux, but long long on my OSX.

My GNU/Linux

$ cat /etc/issue
Ubuntu 12.04.4 LTS \n \l

$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ uname -s -r -v -p -i -o
Linux 3.5.0-45-generic #68~precise1-Ubuntu SMP Wed Dec 4 16:18:46 UTC 2013 x86_64 x86_64 GNU/Linux

My OSX

$ sw_vers 

ProductName:    Mac OS X
ProductVersion: 10.9.5
BuildVersion:   13F34

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

$ uname -m -p -r -s -v
Darwin 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64 i386

METIS installation

METIS version is 5.1.0

I have installed METIS with miniconda.

The packages are here (files linux-64/metis-5.1.0-0.tar.bz2 and osx-64/metis-5.1.0-2.tar.bz2).

These packages have been built with this recipe.


Solution

  • METIS make use of pseudo-random numbers.

    The pseudo-random numbers are generated by GKlib functions. (GKlib is embedded inside METIS tarbarlls).

    By default, GKlib uses the rand function from the C standard library, which may generates different number on different platforms. (see: Consistent pseudo-random numbers across platforms).

    But GKlib can also be compiled with the flag -DUSE_GKRAND. Instead of using the rand function, it uses its own, which always give the same random numbers of different plateforms.

    Compiling with -DUSE_GKRAND the C code in the function give the same results on my GNU/Linux and on my OSX:

    objval: 18
    epart: 0 0 0 2 1 1 2 2 1 0 0 1 0 1 1 2 2 1 
    npart: 0 0 0 0 2 0 1 1 2 1 2 1 2 2 1 1 
    8
    

    I've used this conda recipe to build METIS.