Opened 6 years ago

Closed 5 years ago

#7202 closed defect (wontfix)

Multi-threading creates the pyramid.

Reported by: liminlu0314 Owned by: warmerdam
Priority: normal Milestone: closed_because_of_github_migration
Component: default Version: svn-trunk
Severity: normal Keywords:
Cc:

Description

When creating a pyramid using multithreading, problems would occur if the cache was set to be too small or the image was too large.

#include "gdal_priv.h"
#include <thread>
using namespace std;

void ImageAddo(const char* pszFilename)
{
	GDALDataset *pDataset = (GDALDataset*)GDALOpen(pszFilename, GA_ReadOnly);
	const char* pszResampling = "nearest";
	if (pDataset == nullptr)
		return ;

	int iWidth = pDataset->GetRasterXSize();
	int iHeigh = pDataset->GetRasterYSize();
	int iNum = iWidth*iHeigh;
	int iRstNum = 16384;
	int iCurNum = iNum;
	int anLevels[1024] = { 0 };
	int nLevelCount = 0;
	do
	{
		anLevels[nLevelCount] = static_cast<int>(pow(2.0, nLevelCount + 2));
		iCurNum = static_cast<int>(iCurNum / 4);
		nLevelCount++;
	} while (iCurNum > iRstNum);

	if (nLevelCount > 0 && pDataset->BuildOverviews(pszResampling, nLevelCount, anLevels, 0, nullptr, nullptr, nullptr) != CE_None)
	{
		const char* pszLastErrMsg = CPLGetLastErrorMsg();
		GDALClose((GDALDatasetH)pDataset);
		return;
	}
	const char* pszLastErrMsg = CPLGetLastErrorMsg();
	GDALClose((GDALDatasetH)pDataset);
}

void main()
{
	GDALAllRegister();
	CPLSetConfigOption("USE_RRD", "NO");//generates the RRD format is fine.
	GDALSetCacheMax64(1*1024*1024);	//small cache

	char **papszFileList = NULL;
	papszFileList = CSLAddString(papszFileList, "E:\\DIM_PLNT_20160912_025516_0C43_MUX_OTH.tif");
	papszFileList = CSLAddString(papszFileList, "E:\\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif");
	
#ifdef OPENMP
#pragma omp parallel for
	for (int i = 0; i < 2; i++)
	{
		ImageAddo(papszFileList[i]);
	}
#else
	thread t1(ImageAddo, papszFileList[0]);
	thread t2(ImageAddo, papszFileList[1]);

	t1.join();
	t2.join();
#endif

	CSLDestroy(papszFileList);
}

output information:

ERROR 1: _tiffWriteProc:No such file or directory
ERROR 1: TIFFResetField:E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr: Can not read TIFF directory entry.
ERROR 1: E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr:Failed to allocate memory for to read TIFF directory (0 elements of 12 bytes each)
ERROR 1: TIFFReadDirectory:Failed to read directory at offset 5594
ERROR 1: IReadBlock failed at X offset 5, Y offset 0: TIFFReadDirectory:Failed to read directory at offset 5594
ERROR 1: TIFFScanlineSize64:Computed scanline size is zero
ERROR 1: E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr:Failed to allocate memory for to read TIFF directory (0 elements of 12 bytes each)
ERROR 1: TIFFWriteEncodedStrip:Must set "ImageWidth" before writing data
ERROR 1: TIFFReadDirectory:Failed to read directory at offset 41524
ERROR 1: An error occurred while writing a dirty block
ERROR 1: E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr:Failed to allocate memory for to read TIFF directory (0 elements of 12 bytes each)
ERROR 1: TIFFReadDirectory:Failed to read directory at offset 5594
ERROR 1: E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr:Failed to allocate memory for to read TIFF directory (0 elements of 12 bytes each)
ERROR 1: TIFFReadDirectory:Failed to read directory at offset 7340
ERROR 1: E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr:Failed to allocate memory for to read TIFF directory (0 elements of 12 bytes each)
ERROR 1: TIFFReadDirectory:Failed to read directory at offset 8030
ERROR 1: E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr:Failed to allocate memory for to read TIFF directory (0 elements of 12 bytes each)
ERROR 1: TIFFReadDirectory:Failed to read directory at offset 8336
ERROR 1: E:\DIM_PLNT_20160912_025515_0C43_MUX_OTH.tif.ovr:Failed to allocate memory for to read TIFF directory (0 elements of 12 bytes each)
ERROR 1: TIFFReadDirectory:Failed to read directory at offset 8546

Attachments (1)

1.png (932.4 KB ) - added by liminlu0314 6 years ago.

Download all attachments as: .zip

Change History (3)

by liminlu0314, 6 years ago

Attachment: 1.png added

comment:1 by liminlu0314, 6 years ago

If USE_RRD=YES is set, there is no output error message, but the result is incorrect.

CPLSetConfigOption("USE_RRD", "YES");

The results refer to the attachment. https://trac.osgeo.org/gdal/attachment/ticket/7202/1.png

comment:2 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.