1

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.

  • 2
    It sounds like it's trying to allocate 3.57 gigabytes of contiguous memory. Are you sure that you have the 64bit version of OSGeo4W/Grass installed? Also, even with 8 GB of RAM available, it's not unlikely that you wouldn't have a continuous block of over 3.5GB free. – Evil Genius Oct 18 '16 at 17:03
  • I checked the version earlier, I seemed to install 'not-64bit' version, and now I am installing the 64bit version of OSGeo4W. Should I uninstall the earlier version I installed? – Heinz Oct 19 '16 at 5:03
  • I don't see a reason to have both, although it should work as long as you don't install them in the same location. – Evil Genius Oct 19 '16 at 10:55
  • I installed GRASS GIS 7.0.5 through OSGeo4W 64bit installer, but got the same error. (OSGeo4W 32bit not being uninstalled) – Heinz Oct 19 '16 at 15:12
  • 1
    Please add the output of "g.region -p" to your posting (to verify the actual grasswiki.osgeo.org/wiki/Computational_region) – markusN Oct 20 '16 at 18:32
3

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.

0

If I ran g.region to set region to match raster map(s) before I ran r.watershed, error would not show up and the result are correct.

I don't know why, but this would solve the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.