amkozlov / raxml-ng

RAxML Next Generation: faster, easier-to-use and more flexible
GNU Affero General Public License v3.0
374 stars 62 forks source link

Error: no matching function for call to 'max(size_t&, long unsigned int)' #136

Closed jdx-gh closed 1 year ago

jdx-gh commented 2 years ago

Windows 10 64 bit, MSYS2/gcc 11.2.0 Configure command: cmake -G "MSYS Makefiles" -DSTATIC_BUILD=ON -DUSE_GMP=ON ..

Compilation fails with the following message:

[ 60%] Building CXX object src/CMakeFiles/raxml_module.dir/ParallelContext.cpp.obj
D:/Works/raxml-ng/src/ParallelContext.cpp: In static member function 'static void ParallelContext::init_pthreads(const Options&, const std::function<void()>&)':
D:/Works/raxml-ng/src/ParallelContext.cpp:121:50: error: no matching function for call to 'max(size_t&, long unsigned int)'
  121 |   size_t group_size = opts.num_threads / std::max(groups_per_rank, 1lu);
      |                                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Tools/MSYS/mingw64/include/c++/11.2.0/vector:60,
                 from D:/Works/raxml-ng/src/ParallelContext.hpp:4,
                 from D:/Works/raxml-ng/src/ParallelContext.cpp:1:
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
D:/Works/raxml-ng/src/ParallelContext.cpp:121:50: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long unsigned int')
  121 |   size_t group_size = opts.num_threads / std::max(groups_per_rank, 1lu);
      |                                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Tools/MSYS/mingw64/include/c++/11.2.0/vector:60,
                 from D:/Works/raxml-ng/src/ParallelContext.hpp:4,
                 from D:/Works/raxml-ng/src/ParallelContext.cpp:1:
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
D:/Works/raxml-ng/src/ParallelContext.cpp:121:50: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long unsigned int')
  121 |   size_t group_size = opts.num_threads / std::max(groups_per_rank, 1lu);
      |                                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Tools/MSYS/mingw64/include/c++/11.2.0/algorithm:62,
                 from D:/Works/raxml-ng/src/Model.hpp:4,
                 from D:/Works/raxml-ng/src/PartitionInfo.hpp:5,
                 from D:/Works/raxml-ng/src/PartitionedMSA.hpp:4,
                 from D:/Works/raxml-ng/src/Options.hpp:5,
                 from D:/Works/raxml-ng/src/ParallelContext.cpp:3:
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
D:/Works/raxml-ng/src/ParallelContext.cpp:121:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
  121 |   size_t group_size = opts.num_threads / std::max(groups_per_rank, 1lu);
      |                                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Tools/MSYS/mingw64/include/c++/11.2.0/algorithm:62,
                 from D:/Works/raxml-ng/src/Model.hpp:4,
                 from D:/Works/raxml-ng/src/PartitionInfo.hpp:5,
                 from D:/Works/raxml-ng/src/PartitionedMSA.hpp:4,
                 from D:/Works/raxml-ng/src/Options.hpp:5,
                 from D:/Works/raxml-ng/src/ParallelContext.cpp:3:
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
C:/Tools/MSYS/mingw64/include/c++/11.2.0/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
D:/Works/raxml-ng/src/ParallelContext.cpp:121:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
  121 |   size_t group_size = opts.num_threads / std::max(groups_per_rank, 1lu);
      |                                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [src/CMakeFiles/raxml_module.dir/build.make:188: src/CMakeFiles/raxml_module.dir/ParallelContext.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:737: src/CMakeFiles/raxml_module.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Of course the compiler is right because "pears and apples" are tried to be compared here. AFAIR on 64-bit machines size_t is defined as unsigned int (4 bytes) while 1 in line 121 is explicitly casted to unsigned long (8 bytes).

I believe line 121 should be: size_t group_size = opts.num_threads / std::max(groups_per_rank, static_cast<size_t>(1));

jdx-gh commented 2 years ago

There are similar issues in main.cpp in lines 942, 973 and 2588.

amkozlov commented 2 years ago

hm are you sure you're using 64 bit compiler?

size_t is memory address size, and so on a 64bit machine it has to be, well. 64 bits = 8 bytes.

amkozlov commented 2 years ago

further, I'd recommend using WSL for compiling raxml-ng on Windows.

jdx-gh commented 2 years ago

I am sure:

$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\Tools\MSYS\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/Tools/MSYS/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-11.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev8, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-boot-ldflags='-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc' 'LDFLAGS_FOR_TARGET=-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high' --enable-linker-plugin-flags='LDFLAGS=-static-libstdc++\ -static-libgcc\ -pipe\ -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high\ -Wl,--stack,12582912'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Rev8, Built by MSYS2 project)

The following test program:

#include <stdio.h>

int main(int argc, char *argv[])
{
  printf("sizeof(int): %d\n", sizeof(int));
  printf("sizeof(long): %d\n", sizeof(long));
  printf("sizeof(long long): %d\n", sizeof(long long));
  printf("sizeof(size_t): %d\n", sizeof(size_t));

  return 0;
}

displays

sizeof(int): 4
sizeof(long): 4
sizeof(long long): 8
sizeof(size_t): 8

Of course there is a mistake in my original post: sizeof(size_t) is indeed 8, but sizeof(unsigned long) is 4. Either way, the compiler is right – different types of different size are compared.

Regarding WSL – what about Ubuntu running on VirtualBox (I've got such a setup)? Shouldn't performance of both solutions be pretty much the same? Perhaps Cygwin? Anyway, I am trying to help my sister who is a biologist but is not fluent in programming, operating systems and similar things. I just want to provide her one native binary which does not require additional stuff, possibly optimized for her CPU.

I can see that util/sysutil.cpp is a bigger problem – it requires some time to port it to Windows/MinGW64. I you are interested I can post my changes later today (or tomorrow).

amkozlov commented 2 years ago

Ok, I see. I tried compiling with Cygwin about a year ago and the performance was pretty bad compared to Ubuntu on the same machine. I also tried to produce a native win binary with minGW and MSVC, but i ran into too many compilation errors. so I gave up. Not sure whether situation improved since then, but I'm afraid not. Maybe your sister could just try VirtualBox and check whether performance will be acceptable for her purposes?.But of course, if you are willing to invest time in Windows porting, your contribution will be much appreciated!

Regarding types: yes. unsigned long is the problem here. I don't quite understand why I have to explain to the compiler that it is perfectly safe to convert constant 1 to size_t (or any int type for that matter)? It seems that template type deduction fails miserably in this case, so presumably std::max<size_t>() will fix it.

jdx-gh commented 1 year ago

The problem has been fixed so I believe the ticket can be closed.