gdal icon indicating copy to clipboard operation
gdal copied to clipboard

-co NUM_THREADS option behaving weirdly since GDAL 3.6

Open ThomasCusson opened this issue 3 years ago • 5 comments

Expected behavior and actual behavior.

I previously used a gdal 3.3 environment to make previews, merging numerous files with various projections. I tried to modernize my conda environment, but I have two problems :

  • The warping is ~15× slower than before
  • The output file is ~30× bigger than before

I identified the source of the problem : it's the usage of -co NUM_THREADS with gdal ≥ 3.6, when warping numerous files together.

Steps to reproduce the problem.

  • Make 2 conda environments (gdal_35 and gdal_36)
  • Install the corresponding versions of gdal in each environment
  • Gdalwarp multiple .tif images together using -co NUM_THREADS=ALL_CPUS with both environments.
  • Gdalwarp multiple .tif images together without using the -co NUM_THREADS option in gdal 3.6.
  • The image resulting from warping with GDAL 3.6 with -co NUM_THREADS option should be much bigger, and should take much longer to process.

Here's the command to reproduce the problem : gdalwarp -tr 1000 1000 -t_srs EPSG:3857 input_files_folder/*.tif output_file.tif -co NUM_THREADS=ALL_CPUS -wo NUM_THREADS=ALL_CPUS -co COMPRESS=ZSTD

It goes smoothly with gdal 3.5, but extremely slow with gdal 3.6, and the compression ratio is worse than no compression at all. (It's probably a problem of dictionnary compression, when using multiple input files. Because if you warp the obtained file again, the file size goes back to normal.)

Removing the -co NUM_THREADS option brings back normal speed and file size.

Operating system

Ubuntu 22.04.3 LTS 64 bits

GDAL version and provenance

Version with no problem : gdal 3.5.3 from conda-forge Versions with the problem : all gdal versions ≥ 3.6.0 from conda-forge

ThomasCusson avatar Nov 16 '23 13:11 ThomasCusson

I recommend to test with 3.7.3 or 3.8.0. They contain at least this fix https://github.com/OSGeo/gdal/issues/8470 for multithreading.

jratike80 avatar Nov 16 '23 14:11 jratike80

I discovered the problem using a 3.7.3 environment, I tried previous versions to pinpoint the fact that it appeared with 3.6. I just tried with a 3.8.0 environment, final file is as big, slowness is still the same.

ThomasCusson avatar Nov 16 '23 14:11 ThomasCusson

@ThomasCusson Can you provide a minimum set of files to reproduce the issue?

rouault avatar Nov 16 '23 16:11 rouault

@rouault Yes, here is a reduced version of my dataset, with only 23 tif files (instead of 20k) : 11R.zip

Here's the command line I used : gdalwarp 11R*.tif gdal××.tif -co NUM_THREADS=ALL_CPUS -wo NUM_THREADS=ALL_CPUS -co COMPRESS=ZSTD -co BIGTIFF=YES -srcnodata 0

The effect on size is way less dramatic with this smaller set (~4.5× bigger instead of 30× bigger), but it's still very noticeable.

image

ThomasCusson avatar Nov 20 '23 11:11 ThomasCusson

fix in https://github.com/OSGeo/gdal/pull/8784.

however I'd strongly suggest you add -co TILED=YES. Otherwise your method will not scale well on large output files compared to the the maximum size of the GDAL block cache.

rouault avatar Nov 21 '23 23:11 rouault