[GIS] G_malloc error while running r.watershed in GRASS 7.0.4

grassr.watershed

I tried to use r.watershed function in GRASS GIS, and got an error message ERROR: G_malloc: unable to allocate 3837384596 bytes of memory at raster/r.watershed/ram/init_vars.c:146 before getting the outputs. Because I am not sure what caused this, so I would describe my situation from the beginning.

  1. GRASS GIS 7.0.4 was installed by installing OSGeo4W package. (under Win 10, 64-bit, x64, RAM = 8 GB)
  2. I created location 'nl' using GRASS GUI

enter image description here

  1. set the EPSG code based on the actual location of the map I would load to GRASS GIS later

enter image description here
enter image description here

  1. Then I set the extent and resolution of the location. (I loaded the map (later to be loaded in GRASS) to QGIS, and used the 'save as…' to check the extent of this map, and set the extent based on the information from QGIS.) But I didn't change the setting of resolution, just left them as default.

enter image description here
enter image description here

  1. I created the mapset 'nl'

enter image description here

  1. In 'nl' mapset, I used r.import to load the raster map, although there were some warnings, the result looked fine.
r.import input=C:\Users\Heinz\Desktop\GRASStest\hc.tif output=hc
WARNING: Datum <unknown> not recognised by GRASS and no parameters found
WARNING: Datum <unknown> not recognised by GRASS and no parameters found
WARNING: Datum <unknown> not recognised by GRASS and no parameters found
Proceeding with import of 1 raster bands...
Importing raster map <hc>...

enter image description here

  1. I used r.watershed, but the error message occurred:

r.watershed elevation=hc@nl threshold=5000 accumulation=acc
drainage=dra basin=bas stream=str

SECTION 1a (of 5): Initiating Memory.

Current region rows: 57567, cols: 53957

ERROR: G_malloc: unable to allocate 3837384596 bytes of memory at
raster/r.watershed/ram/init_vars.c:146

WARNING: Subprocess failed with exit code 1

WARNING: category information for [acc] in [nl] missing or invalid

WARNING: category information for [dra] in [nl] missing or invalid

WARNING: category information for [bas] in [nl] missing or invalid

WARNING: category information for [str] in [nl] missing or invalid

I don't know what stage-setting causing this error, and how to solve this error.


Update#1:
I installed GRASS GIS 7.0.5 through OSGeo4W 64bit installer (under Win 10, 64-bit, x64, RAM = 8 GB), and ran r.watershed with the same raster file loaded into the mapset, but got the same error message I posted above.

It's weird because I successfully ran r.watershed on the same notebook before, just with GRASS GIS version 6. (This NB had been reformatted once.)

The result of g.region -p:

enter image description here

Besides, as I launched GRASS GIS GUI, some error messages showed up:

enter image description here

I am wondering if these errors in relation to the error message showed as I ran r.watershed, and I have checked that under C:\OSGeo4W64\apps\Python27\Lib\site-packages I got numpy installed.

Best Answer

You are simply running out of memory while using the in-memory-mode of r.watershed. Proof: your current computational region (g.region -p) output is

> 57567 * 53957
[1] 3106142619

which exceeds, according to the r.watershed manual page, the in-memory-mode limit of:

> 2^31
[1] 2147483648

Solution: switch to disk swap mode ("seg" mode, see the r.watershed manual page) by setting the -m flag. Be sure to have enough free disk space then for the needed swapping.

Related Question