Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multithreading windows 10 #264

Closed
flacroze opened this issue Sep 23, 2019 · 26 comments
Closed

multithreading windows 10 #264

flacroze opened this issue Sep 23, 2019 · 26 comments

Comments

@flacroze
Copy link

Hello,

I struggle for months with multithreads version of CBC (32 bits) for windows 10.

Has someone succeed to make it ? And can publish the method step by step ?

We followed these instructions found on CBC project, but no result. Has someone tried it with success ?


If you want to build a parallel version of CBC using Visual Studio you can following instructions: (thanks to Tobias Stengel and Alexis Guigue).

Assumptions:

A VS solution with all necessary projects (libCbc, libClp, libCbcSolver, libCgl, libCoinUtils, libOsi, libOsiCbc, libOsiClp). The project files can be found inside the "MSVisualStudio" folders.
Steps (based on VS 2013):

for each of the lib* projects do: add CBC_THREAD under Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions (a subset of the lib* projects may be sufficient, but it doesn't hurt to do it for all)

Link against a pthreads library. PThreadsWin32 works (even in 64 bits systems) and is distributed under the LGPL. If you decide to use the precompiled binaries: both pthreadVC2 and pthreadVS2 seem to work. Otherwise: third party VS project files for pthreads4win can be found on github.

Note: If you use C++/Cli, make sure that no callback (eventHandlers, custom cut generators, custom heuristics, ...) contains managed code. Otherwise your code will crash at runtime with AssembyNotFoundExceptions inside the native threads created by Cbc. Even if not, problems with the GC are likely.

If you link statically against pthreads4win, you have to define PTW32_STATIC_LIB when building your program/Cbc (e.g. via Properties -> C/C++/Preprocessor -> Preprocessor Definitions) AND - only if you build pthreads yourself - when building pthreads. Linking pthreads dynamically works without additional preprocessor definitions.

pass "-threads" "yourNumber" to CbcMain1

Thanks

@tkralphs
Copy link
Member

If you say what steps you followed and where they failed, it will be easier to help.

@flacroze
Copy link
Author

flacroze commented Sep 24, 2019 via email

@svigerske
Copy link
Member

Building multithreaded Cbc works for me with MinGW and MSVC or Intel compilers. I use this in my config.site:

CC=cl
CXX=cl
enable_msvc=yes
OPT_CXXFLAGS="-O2 -EHsc -GR -MD -DNDEBUG"
OPT_CFLAGS="-O2 -EHsc -GR -MD -DNDEBUG"
OPT_FFLAGS="-O3 -fpp -MD"
ADD_CXXFLAGS="-nologo -wd4274 -D_CRT_SECURE_NO_DEPRECATE -DDISALLOW_PRINTING -DCLP_FAST_CODE -DCOIN_FAST_CODE -DNEW_STYLE_SOLVER=0 -DCBC_QUIET=1 -DCBC_THREAD_SAFE"
ADD_CXXFLAGS="$ADD_CXXFLAGS -DHAVE_PTW32_CONFIG_H"
ADD_CFLAGS="-nologo -wd4274 -D_CRT_SECURE_NO_DEPRECATE"
ADD_FFLAGS="-nologo"

enable_cbc_parallel=yes
with_pthreadsw32_lib=/path/to/pthreads-w32/pthreads.lib
with_pthreadsw32_incdir=/path/to/pthreads-w32

One may not need all of these flags.

@flacroze
Copy link
Author

flacroze commented Oct 3, 2019 via email

@svigerske
Copy link
Member

When using the usual COIN-OR build procedure (before "coinbrew"):

svn co https://projects.coin-or.org/svn/Cbc/stable/2.10 Cbc-2.10
cd Cbc-2.10
mkdir build
cd build
mkdir share
cp /path/to/above/text share/config.site
../configure -C
make
make test
make install

See also https://github.com/coin-or-tools/BuildTools/wiki

If using coinbrew, then maybe pass these as arguments to coinbrew, so they are passed on to configure, as I'm not sure that builds by coinbrew would pick up a /share/config.site at the moment.

@tkralphs
Copy link
Member

tkralphs commented Oct 7, 2019

It should be easy to add the ability to read a config.site file to coinbrew, but in the meantime, in case it was not clear, you can add those flags that @svigerske specified to the coinbrew command line, e.g.,

coinbrew build Cbc CC=cl CXX=cl --enable_msvc ADD_CXXFLAGS="-nologo -wd4274 -D_CRT_SECURE_NO_DEPRECATE -DDISALLOW_PRINTING -DCLP_FAST_CODE -DCOIN_FAST_CODE -DNEW_STYLE_SOLVER=0 -DCBC_QUIET=1 -DCBC_THREAD_SAFE" ...

It's not necessary to set CC and CXX when also setting --enable-msvc, as cl is the default. It's likely that some of the other flags are also not necessary. In general, it's probably best not to set the OPT_* variables, just use the ADD_* variables to add flags as needed. I would try with only those first and see if it works. You probably only need

coinbrew --enable-msvc --enable-cbc-parallel --with-pthreadsw32-lib=/path/to/pthreads-w32/pthreads.lib --with-pthreadsw32-incdir=/path/to/pthreads-w32 ADD_CXXFLAGS=-DCBC_THREAD_SAFE"

I would steer clear of using the old build procedure, as that is deprecated and will not be working for long.

@flacroze
Copy link
Author

flacroze commented Oct 9, 2019 via email

@tkralphs
Copy link
Member

It seems the image containing the error got stripped out. Could you either attach it again or just cut and paste the exact text?

@flacroze
Copy link
Author

flacroze commented Oct 10, 2019 via email

@svigerske
Copy link
Member

You should be in MSys' bash, not the "ms-dos command window".

@flacroze
Copy link
Author

flacroze commented Oct 10, 2019 via email

@svigerske
Copy link
Member

Looks like you need to make C and C++ compilers available.

@flacroze
Copy link
Author

flacroze commented Oct 10, 2019 via email

@flacroze
Copy link
Author

flacroze commented Oct 10, 2019 via email

@flacroze
Copy link
Author

flacroze commented Oct 10, 2019 via email

@tkralphs
Copy link
Member

tkralphs commented Oct 10, 2019

You may not have the compilers installed. If you do which gcc, what happens? To be sure, you can do

pacman -S mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain

This should install both 32- and 64-bit versions of MinGW.

@flacroze
Copy link
Author

flacroze commented Oct 11, 2019 via email

@svigerske
Copy link
Member

Try to add --build=x86_64-w64-mingw32 to the call of coinbrew.

@flacroze
Copy link
Author

flacroze commented Oct 11, 2019 via email

@tkralphs
Copy link
Member

I just updated the documentation at https://coin-or.github.io/user_introduction.html with a lot more details, especially for the Windows case (including adding the trick that Stefan just pointed out). See https://coin-or.github.io/user_introduction.html#windows-1 If you get stuck again.

@flacroze
Copy link
Author

flacroze commented Oct 14, 2019 via email

@fl8k
Copy link

fl8k commented Apr 22, 2022

I just updated the documentation at https://coin-or.github.io/user_introduction.html with a lot more details, especially for the Windows case (including adding the trick that Stefan just pointed out). See https://coin-or.github.io/user_introduction.html#windows-1 If you get stuck again.

Hi @tkralphs - I followed the instructions you reference, and I get errors while attempting to use the CBC that was built - the errors indicate missing dlls: libbz2-1.dll and libz1.dll

I used Msys2 + coinbrew approach.

@fl8k
Copy link

fl8k commented Apr 22, 2022

I just updated the documentation at https://coin-or.github.io/user_introduction.html with a lot more details, especially for the Windows case (including adding the trick that Stefan just pointed out). See https://coin-or.github.io/user_introduction.html#windows-1 If you get stuck again.

Hi @tkralphs - I followed the instructions you reference, and I get errors while attempting to use the CBC that was built - the errors indicate missing dlls: libbz2-1.dll and libz1.dll

I used Msys2 + coinbrew approach.

The reason I am trying to build cbc manually is because the version I have hangs for some reason. I see that the thread were changed, but it just stops and doesn't do anything:
image

@tkralphs
Copy link
Member

What version do you have? What version are you trying to build? With what compiler? I guess you are trying to build master. Can you delete the build directory and re-run the build with --verbosity 4, then attach the output here (as a file, not copy-paste). If possible, you could also attach build/CoinUtils/master/config.log.

@fl8k
Copy link

fl8k commented Apr 23, 2022

What version do you have? What version are you trying to build? With what compiler? I guess you are trying to build master. Can you delete the build directory and re-run the build with --verbosity 4, then attach the output here (as a file, not copy-paste). If possible, you could also attach build/CoinUtils/master/config.log.
cbc_build.log

coinutils_config.log

Yes, I am trying to build the latest version. I have attached the requested files. Here is the build command I used.
./coinbrew build Cbc --build=x86_64-w64-mingw32 --enable-cbc-parallel --verbosity 4 --with-pthreadsw32-lib=/home/<user>/coinbrew/prebuilt-dll-2-9-1-release/lib/x64/pthreadVC2.lib --with-pthreadsw32-incdir=/home/<user>/coinbrew/prebuilt-dll-2-9-1-release/include ADD_CXXFLAGS=-DCBC_THREAD_SAFE

@tkralphs
Copy link
Member

OK, sorry, I didn't realize that the build was successful, so the problem is not there. It's probably then just a paths issue. You probably need to add whatever directory those DLLs are in to your Windows PATH variable. On my computer, the directory would be C:\msys64\usr\bin. You would do something like

set PATH=%PATH%;C:\msys64\usr\bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants