PyFR 0.8.0: Openmp backend compilation failure

Hi All,

I am trying to run PyFR0.8.0 using openmp backend, but the following error occurred. I am not sure if the error happened due to Python or gcc or even Blas library. I am running PyFR on Mac OS X 10.10.3 and using Python 3.4.3, gcc 4.9.2 and atlas for Blas library.

Any help would be very appreciated.

Regards,
Watchapon

PS. I have no problem with -bcuda option.

pyfr run -p -bopenmp couette_flow_2d.pyfrm couette_flow_2d.ini

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/util.py", line 32, in __call__
KeyError: (<function OpenMPKernelProvider._build_kernel at 0x103de8730>, b'(X\x08\x00\x00\x00par_gemmq\x00X\x96\n\x00\x00\n\n#include <omp.h>\n#include <stdlib.h>\n#include <tgmath.h>\n\n#define PYFR_ALIGN_BYTES 32\n#define PYFR_NOINLINE __attribute__ ((noinline))\n\n#define min(a, b) ((a) < (b) ? (a) : (b))\n#define max(a, b) ((a) > (b) ? (a) : (b))\n\n// Typedefs\ntypedef double fpdtype_t;\n\n// OpenMP static loop scheduling functions\n\nstatic inline int\ngcd(int a, int b)\n{\n return (a == 0) ? b : gcd(b % a, a);\n}\n\nstatic inline void\nloop_sched_1d(int n, int align, int *b, int *e)\n{\n int tid = omp_get_thread_num();\n int nth = omp_get_num_threads();\n\n // Round up n to be a multiple of nth\n int rn = n + nth - 1 - (n - 1) % nth;\n\n // Nominal tile size\n int sz = rn / nth;\n\n // Handle alignment\n sz += align - 1 - (sz - 1) % align;\n\n // Assign the starting and ending index\n *b = sz * tid;\n *e = min(*b + sz, n);\n\n // Clamp\n if (*b >= n)\n *b = *e = 0;\n}\n\nstatic inline void\nloop_sched_2d(int nrow, int ncol, int colalign,\n int *rowb, int *rowe, int *colb, int *cole)\n{\n int tid = omp_get_thread_num();\n int nth = omp_get_num_threads();\n\n // Distribute threads\n int nrowth = gcd(nrow, nth);\n int ncolth = nth / nrowth;\n\n // Row and column indices for our thread\n int rowix = tid / ncolth;\n int colix = tid % ncolth;\n\n // Round up ncol to be a multiple of ncolth\n int rncol = ncol + ncolth - 1 - (ncol - 1) % ncolth;\n\n // Nominal tile size\n int ntilerow = nrow / nrowth;\n int ntilecol = rncol / ncolth;\n\n // Handle column alignment\n ntilecol += colalign - 1 - (ntilecol - 1) % colalign;\n\n // Assign the starting and ending row to each thread\n *rowb = ntilerow * rowix;\n *rowe = *rowb + ntilerow;\n\n // Assign the starting and ending column to each thread\n *colb = ntilecol * colix;\n *cole = min(*colb + ntilecol, ncol);\n\n // Clamp\n if (*colb >= ncol)\n *colb = *cole = 0;\n}\n\n\n\n\n// CBLAS GEMM constants\n#define ROW_MAJOR 101\n#define NO_TRANS 111\n\n// CBLAS GEMM prototype\ntypedef void (*cblas_gemm_t)(int, int, int,\n int, int, int,\n fpdtype_t, const fpdtype_t *, int,\n const fpdtype_t *, int,\n fpdtype_t, fpdtype_t *, int);\n\nvoid\npar_gemm(cblas_gemm_t gemm, int M, int N, int K,\n fpdtype_t alpha, const fpdtype_t *A, int lda,\n const fpdtype_t *B, int ldb,\n fpdtype_t beta, fpdtype_t *C, int ldc)\n{\n #pragma omp parallel\n {\n int begin, end;\n loop_sched_1d(N, PYFR_ALIGN_BYTES / sizeof(fpdtype_t), &begin, &end);\n\n gemm(ROW_MAJOR, NO_TRANS, NO_TRANS, M, end - begin, K,\n alpha, A, lda, B + begin, ldb, beta, C + begin, ldc);\n }\n}\n\nq\x01]q\x02(cnumpy\nint64\nq\x03cnumpy\nint32\nq\x04h\x04h\x04cnumpy\nfloat64\nq\x05h\x03h\x04h\x03h\x04h\x05h\x03h\x04etq\x06.', b'}q\x00.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/bin/pyfr", line 9, in <module>
load_entry_point('pyfr==0.8.0', 'console_scripts', 'pyfr')()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpmath/ctx_mp.py", line 1301, in g
return f(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/scripts/main.py", line 126, in main
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/scripts/main.py", line 247, in process_run
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/scripts/main.py", line 231, in _process_common
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/solvers/__init__.py", line 14, in get_solver
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/integrators/__init__.py", line 29, in get_integrator
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/integrators/controllers.py", line 14, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/integrators/steppers.py", line 9, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/integrators/writers.py", line 15, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/integrators/base.py", line 47, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/solvers/base/system.py", line 59, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/solvers/base/system.py", line 158, in _gen_kernels
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/solvers/baseadvecdiff/elements.py", line 32, in <lambda>
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/backends/base/backend.py", line 173, in kernel
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/backends/openmp/cblas.py", line 94, in mul
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/util.py", line 34, in __call__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/backends/openmp/provider.py", line 13, in _build_kernel
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/backends/openmp/compiler.py", line 57, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/backends/openmp/compiler.py", line 29, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyfr-0.8.0-py3.4.egg/pyfr/backends/openmp/compiler.py", line 83, in _build
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pytools/prefork.py", line 197, in call_capture_output
return forker[0].call_capture_output(cmdline, cwd, error_on_nonzero)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pytools/prefork.py", line 156, in call_capture_output
error_on_nonzero)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pytools/prefork.py", line 139, in _remote_invoke
raise result
pytools.prefork.ExecError: error invoking 'gcc -shared -std=c99 -Ofast -march=native -fopenmp -fPIC -o libtmp.dylib tmp.c': status 1 invoking 'gcc -shared -std=c99 -Ofast -march=native -fopenmp -fPIC -o libtmp.dylib tmp.c': b"/var/folders/76/46f9zhnd61n02thypjmrzt180000gn/T//cc5s9iBT.s:54:no such instruction: `vmovsd 32(%rbx), %xmm1'\n/var/folders/76/46f9zhnd61n02thypjmrzt180000gn/T//cc5s9iBT.s:55:no such instruction: `vmovsd 8(%rbx), %xmm0'\n/var/folders/76/46f9zhnd61n02thypjmrzt180000gn/T//cc5s9iBT.s:111:no such instruction: `vmovsd %xmm0, 8(%rsp)'\n/var/folders/76/46f9zhnd61n02thypjmrzt180000gn/T//cc5s9iBT.s:113:no such instruction: `vmovsd %xmm1, 32(%rsp)'\n"

Hi Watchapon,

I am trying to run PyFR0.8.0 using openmp backend, but the following
error occurred. I am not sure if the error happened due to Python or gcc
or even Blas library. I am running PyFR on Mac OS X 10.10.3 and using
Python 3.4.3, gcc 4.9.2 and atlas for Blas library.

The issue is somewhat suble and can be reproduced as follows:

calcium:~ freddie$ cat test.c
#include <stdio.h>

int main()
{
    printf("%f\n", 3.14);
    return 0;
};

calcium:~ freddie$ gcc-mp-4.9 -march=native test.c
cc7YTUIB.s:13:no such instruction: `vmovd %rax, %xmm0'

where we see that it is an issue with the distribution of GCC being
unable to handle AVX instructions correctly.

The workaround is to remove the "-march=native" flag from
pyfr/backends/openmp/compiler.py file.

However, this is fundamentally a compiler problem: compilers should not
be emitting instructions which they are uanble to assemble.

Regards, Freddie.

Hi Freddie,

Thank you very much indeed for your answer.

It does solve the problem.

Regards,
Watchapon

Hi Watchapon,

I just wanted to provide an additional workaround for OS X users. There is an active clang-omp compiler that is available outside of the Apple provided clang compiler. I believe work on clang-omp is being spearheaded by a couple of developers at Intel. You can grab clang-omp from https://clang-omp.github.io/ or if you have the homebrew package manager installed, you can install it simply via brew install clang-omp. Then under [backend-openmp] set cc = clang-omp.

Best Regards,

Zach Davis