Closed zvezdochiot closed 2 years ago
You must use the same name as the default OpenMP library from the compiler:
Clang: make LIBMINIOMP=libomp.a
GCC: make LIBMINIOMP=libgomp.a
@ilyakurdyukov say:
make LIBMINIOMP=libgomp.a
:+1:
This was needed for a build under Windows via MSYS2/Mingw64, where the libgomp library is heavy and pulls other libraries like pthreads along with it, and did not work with older versions of Windows.
Hi @zvezdochiot, sorry, but I don't know how to help you - can you give me some intructions?
I cloned https://github.com/ilyakurdyukov/libminiomp and ran make
unsucessful
make: *** No rule to make target `main.o', needed by `main'. Stop.
Hi @JanJastrow .
Copy miniomp.c
to jpeg-quantsmooth/
and:
make LIBMINIOMP=libgomp.a
or
make LIBMINIOMP=libomp.a
See https://github.com/ilyakurdyukov/jpeg-quantsmooth/issues/22#issuecomment-1007948138 , https://github.com/ilyakurdyukov/jpeg-quantsmooth/issues/22#issue-1096878940
make JPEGSRC=jpeg-9e LIBMINIOMP=libomp.a
cc -DOVERFLOW_CHECKS=0 -O2 -Wall -Wextra -c -o miniomp.o miniomp.c -ffunction-sections -fdata-sections
miniomp.c:448:1: error: aliases are not supported on darwin
M1(GOMP_parallel_loop_dynamic, GOMP_parallel_loop_guided)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:449:1: error: aliases are not supported on darwin
M1(GOMP_parallel_loop_dynamic, GOMP_parallel_loop_nonmonotonic_dynamic)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:450:1: error: aliases are not supported on darwin
M1(GOMP_parallel_loop_dynamic, GOMP_parallel_loop_nonmonotonic_guided)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:451:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_start, GOMP_loop_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:452:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_next, GOMP_loop_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:453:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_start, GOMP_loop_nonmonotonic_dynamic_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:454:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_next, GOMP_loop_nonmonotonic_dynamic_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:455:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_start, GOMP_loop_nonmonotonic_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:456:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_next, GOMP_loop_nonmonotonic_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:457:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_start, GOMP_loop_ull_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:458:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_next, GOMP_loop_ull_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:459:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_start, GOMP_loop_ull_nonmonotonic_dynamic_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:460:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_next, GOMP_loop_ull_nonmonotonic_dynamic_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:461:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_start, GOMP_loop_ull_nonmonotonic_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:462:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_next, GOMP_loop_ull_nonmonotonic_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
15 errors generated.
make: *** [miniomp.o] Error 1
make JPEGSRC=jpeg-9e LIBMINIOMP=libgomp.a
cc -DOVERFLOW_CHECKS=0 -O2 -Wall -Wextra -c -o miniomp.o miniomp.c -ffunction-sections -fdata-sections
miniomp.c:448:1: error: aliases are not supported on darwin
M1(GOMP_parallel_loop_dynamic, GOMP_parallel_loop_guided)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:449:1: error: aliases are not supported on darwin
M1(GOMP_parallel_loop_dynamic, GOMP_parallel_loop_nonmonotonic_dynamic)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:450:1: error: aliases are not supported on darwin
M1(GOMP_parallel_loop_dynamic, GOMP_parallel_loop_nonmonotonic_guided)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:451:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_start, GOMP_loop_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:452:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_next, GOMP_loop_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:453:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_start, GOMP_loop_nonmonotonic_dynamic_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:454:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_next, GOMP_loop_nonmonotonic_dynamic_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:455:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_start, GOMP_loop_nonmonotonic_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:456:1: error: aliases are not supported on darwin
M1(GOMP_loop_dynamic_next, GOMP_loop_nonmonotonic_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:457:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_start, GOMP_loop_ull_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:458:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_next, GOMP_loop_ull_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:459:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_start, GOMP_loop_ull_nonmonotonic_dynamic_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:460:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_next, GOMP_loop_ull_nonmonotonic_dynamic_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:461:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_start, GOMP_loop_ull_nonmonotonic_guided_start)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
miniomp.c:462:1: error: aliases are not supported on darwin
M1(GOMP_loop_ull_dynamic_next, GOMP_loop_ull_nonmonotonic_guided_next)
^
miniomp.c:447:62: note: expanded from macro 'M1'
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
^
15 errors generated.
make: *** [miniomp.o] Error 1
Hi @JanJastrow .
It's a pity. I was hoping there was a cross platform solution. It's not meant to be.
Because macOS uses Clang as its default compiler, aliases for GCC are not needed.
So this line in miniomp.c
can be replaced:
#define M1(fn, copy) extern __typeof(fn) copy __attribute__((alias(#fn)));
With a macro that does nothing:
#define M1(fn, copy)
And then it may compile and run.
Hi, then it can't find omp.h
$ make JPEGSRC=jpeg-9e LIBMINIOMP=libomp.a
cc -Wall -O2 -mcpu=native -Wextra -pedantic -Xpreprocessor -fopenmp -DWITH_JPEGSRC -Ijpeg-9e -I. -DAPPNAME=jpegqs -o jpegqs quantsmooth.c jpeg-9e/jutils.o jpeg-9e/jmemmgr.o jpeg-9e/jmemnobs.o jpeg-9e/jcomapi.o jpeg-9e/jerror.o jpeg-9e/jdapimin.o jpeg-9e/jdcoefct.o jpeg-9e/jdmarker.o jpeg-9e/jdhuff.o jpeg-9e/jdinput.o jpeg-9e/jdtrans.o jpeg-9e/jcapimin.o jpeg-9e/jcmaster.o jpeg-9e/jcmarker.o jpeg-9e/jchuff.o jpeg-9e/jcparam.o jpeg-9e/jctrans.o jpeg-9e/rdswitch.o jpeg-9e/cdjpeg.o jpeg-9e/transupp.o jpeg-9e/jdatasrc.o jpeg-9e/jdatadst.o jpeg-9e/jaricom.o jpeg-9e/jcarith.o jpeg-9e/jdarith.o -L./ -Wl,-dead_strip -lm
In file included from quantsmooth.c:89:
./quantsmooth.h:28:10: fatal error: 'omp.h' file not found
#include <omp.h>
^~~~~~~
1 error generated.
make: *** [jpegqs] Error 1
$ make JPEGSRC=jpeg-9e LIBMINIOMP=libgomp.a
cc -Wall -O2 -mcpu=native -Wextra -pedantic -Xpreprocessor -fopenmp -DWITH_JPEGSRC -Ijpeg-9e -I. -DAPPNAME=jpegqs -o jpegqs quantsmooth.c jpeg-9e/jutils.o jpeg-9e/jmemmgr.o jpeg-9e/jmemnobs.o jpeg-9e/jcomapi.o jpeg-9e/jerror.o jpeg-9e/jdapimin.o jpeg-9e/jdcoefct.o jpeg-9e/jdmarker.o jpeg-9e/jdhuff.o jpeg-9e/jdinput.o jpeg-9e/jdtrans.o jpeg-9e/jcapimin.o jpeg-9e/jcmaster.o jpeg-9e/jcmarker.o jpeg-9e/jchuff.o jpeg-9e/jcparam.o jpeg-9e/jctrans.o jpeg-9e/rdswitch.o jpeg-9e/cdjpeg.o jpeg-9e/transupp.o jpeg-9e/jdatasrc.o jpeg-9e/jdatadst.o jpeg-9e/jaricom.o jpeg-9e/jcarith.o jpeg-9e/jdarith.o -L./ -Wl,-dead_strip -lm
In file included from quantsmooth.c:89:
./quantsmooth.h:28:10: fatal error: 'omp.h' file not found
#include <omp.h>
^~~~~~~
1 error generated.
make: *** [jpegqs] Error 1
This is the same problem I had initially compiling it, where I had to link to LLVM manually
MTOPTS= LDFLAGS="-Wl,-dead_strip,-L/opt/homebrew/opt/llvm/lib"
Try to replace (quantsmooth.c:89):
#include <omp.h>
With:
int omp_get_thread_num();
int omp_get_max_threads();
int omp_get_num_threads();
void omp_set_num_threads(int n);
int omp_get_num_procs();
That's enough definitions for jpegqs.
Both libomp and libgomp:
$ make JPEGSRC=jpeg-9e LIBMINIOMP=libomp.a
cc -Wall -O2 -mcpu=native -Wextra -pedantic -Xpreprocessor -fopenmp -DWITH_JPEGSRC -Ijpeg-9e -I. -DAPPNAME=jpegqs -o jpegqs quantsmooth.c jpeg-9e/jutils.o jpeg-9e/jmemmgr.o jpeg-9e/jmemnobs.o jpeg-9e/jcomapi.o jpeg-9e/jerror.o jpeg-9e/jdapimin.o jpeg-9e/jdcoefct.o jpeg-9e/jdmarker.o jpeg-9e/jdhuff.o jpeg-9e/jdinput.o jpeg-9e/jdtrans.o jpeg-9e/jcapimin.o jpeg-9e/jcmaster.o jpeg-9e/jcmarker.o jpeg-9e/jchuff.o jpeg-9e/jcparam.o jpeg-9e/jctrans.o jpeg-9e/rdswitch.o jpeg-9e/cdjpeg.o jpeg-9e/transupp.o jpeg-9e/jdatasrc.o jpeg-9e/jdatadst.o jpeg-9e/jaricom.o jpeg-9e/jcarith.o jpeg-9e/jdarith.o -L./ -Wl,-dead_strip -lm
Undefined symbols for architecture arm64:
"___kmpc_dispatch_next_4", referenced from:
_.omp_outlined..30 in quantsmooth-8032ff.o
_.omp_outlined..31 in quantsmooth-8032ff.o
"___kmpc_dispatch_init_4u", referenced from:
_.omp_outlined. in quantsmooth-8032ff.o
_.omp_outlined..26 in quantsmooth-8032ff.o
_.omp_outlined..27 in quantsmooth-8032ff.o
_.omp_outlined..28 in quantsmooth-8032ff.o
_.omp_outlined..29 in quantsmooth-8032ff.o
"___kmpc_dispatch_init_4", referenced from:
_.omp_outlined..30 in quantsmooth-8032ff.o
_.omp_outlined..31 in quantsmooth-8032ff.o
"___kmpc_dispatch_next_4u", referenced from:
_.omp_outlined. in quantsmooth-8032ff.o
_.omp_outlined..26 in quantsmooth-8032ff.o
_.omp_outlined..27 in quantsmooth-8032ff.o
_.omp_outlined..28 in quantsmooth-8032ff.o
_.omp_outlined..29 in quantsmooth-8032ff.o
"_omp_set_num_threads", referenced from:
_main in quantsmooth-8032ff.o
"___kmpc_fork_call", referenced from:
_main in quantsmooth-8032ff.o
"_omp_get_max_threads", referenced from:
_main in quantsmooth-8032ff.o
"_omp_get_num_procs", referenced from:
_main in quantsmooth-8032ff.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [jpegqs] Error 1
This should help:
make JPEGSRC=jpeg-9e LIBMINIOMP=libomp.a LDFLAGS="-Wl,-dead_strip -lomp"
I can confirm - it builds now 🎉 Thanks again.
Both libomp and libgomp. Is there any difference for me? Which should I use/compile?
Ah, it builds and I can run the binary, but as soon as I input a JPG, I get an segmentation fault:
$ ./jpegqs_libgomp
JPEG Quant Smooth : Copyright (C) 2020-2021 Ilya Kurdyukov : 1.20210408
Build date: Jan 28 2022
Uses libjpeg, run with "--verbose 1" to show its version and copyright
Usage:
jpegqs [options] input.jpg output.jpg
Options:
-q, --quality n Quality setting (1-6, default is 3)
-n, --niter n Number of iterations (default is 3)
-t, --threads n Set the number of CPU threads to use
-o, --optimize Option for libjpeg to produce smaller output file
-v, --verbose n Print libjpeg debug output
-i, --info n Print quantsmooth debug output (default is 15)
Use the sum of flags: 0 - silent,
1/2/4 - various information,
8 - processing time, 16 - SIMD type.
-p, --cpu n Use to lower the SIMD type if CPU detection fails:
0 - auto, 1 - scalar, 2 - SSE2, 3 - AVX2, 4 - AVX512.
(x86 build selects between modes 1-3, x86_64 from 2-4)
./jpegqs_libgomp 1485863842425057283_1.jpg x.jpg
component[0] : table 0, samp 2x2
component[1] : table 1, samp 1x1
component[2] : table 1, samp 1x1
quant[0]:
0005 0003 0003 0005 0007 000c 000f 0012
0004 0004 0004 0006 0008 0011 0012 0011
0004 0004 0005 0007 000c 0011 0015 0011
0004 0005 0007 0009 000f 001a 0018 0013
0005 0007 000b 0011 0014 0021 001f 0017
0007 000b 0011 0013 0018 001f 0022 001c
000f 0013 0017 001a 001f 0024 0024 001e
0016 001c 001d 001d 0022 001e 001f 001e
quant[1]:
0005 0005 0007 000e 001e 001e 001e 001e
0005 0006 0008 0014 001e 001e 001e 001e
0007 0008 0011 001e 001e 001e 001e 001e
000e 0014 001e 001e 001e 001e 001e 001e
001e 001e 001e 001e 001e 001e 001e 001e
001e 001e 001e 001e 001e 001e 001e 001e
001e 001e 001e 001e 001e 001e 001e 001e
001e 001e 001e 001e 001e 001e 001e 001e
component[0] : size 200x200
zsh: segmentation fault ./jpegqs_libgomp 1485863842425057283_1.jpg x.jpg
This is not a universal solution because it needs to be tested on specific compiler versions because this interface is compiler specific. Still works on Clang-13.0.0 and x86-64. Seems it might also depend on the architecture.
This is a hack to implement the required part of the OpenMP library with pthreads to get rid of the OpenMP runtime dependency. This is written for the Windows port of jpegqs in the first place.
error: aliases are not supported on darwin
I seem to have found a workaround for this, already committed to the libminiomp repo.
/libminiomp
miniomp.c
and omp.h
to the main repo dirquantsmooth.c:89
make JPEGSRC=jpeg-9e LIBMINIOMP=libomp.a LDFLAGS="-Wl,-dead_strip -lomp"
Whichs builds fine, just as with the changes we did before. Sadly it still segfaults when trying to put JPEG through it.
BTW: I tried to build this on my Intel machine with the same steps as above.
make LIBMINIOMP=libomp.a LDFLAGS="-Wl,-dead_strip -lomp"
builds fine and binary works as expected (multithreaded)
I think it's not that important now, I might test it on aarch64 (on Linux) in a while. But this can be a specific macOS issue.
Maybe you are familiar with the macOS GUI to make a jpegqs window application for easier use? Or is there a plugin interface for some image viewer/editor for macOS?
Sorry, I don't know any languages that may help you on macOS (GUI). macOS has a pretty good default image viewer / simple editor ("Preview.app"), but as far as I know it does not support extensions/plugins.
If you are looking for something like IrfanView (which I also prefer when using Windows) I think the next best thing is nomacs, which is cross platform. But, judging by their commits, there are no active developers at the moment.
It's also fine with me that this test segfaults - I have the other binary :)
It might be possible to put jpegqs in nomacs
, I'll have a look at that in a while. Thanks!
Hi @ilyakurdyukov .
See also cross platform (Qt):
Hi @ilyakurdyukov .
See also cross platform (Qt):
* https://github.com/ImageProcessing-ElectronicPublications/photoquick * https://github.com/ImageProcessing-ElectronicPublications/photoquick-plugins
Looks like trash, and no macOS support.
@ilyakurdyukov say:
and no macOS support.
Did not know. Need to ask @JanJastrow .
Did not know. Need to ask @JanJastrow .
It's written big it the title "PhotoQuick (for Linux and Windows)".
But anyway, I'm not interested in unpopular image viewers with bad design.
Hi @ilyakurdyukov .
"Мысли вслух, не более того".
Use default :
Use https://github.com/ilyakurdyukov/libminiomp :
This is wrong!
This is true! (added libminiomp.a)
Patch: