Skip Navigation Links 
NOAA logo - Click to go to the NOAA home page National Weather Service   NWS logo - Click to go to the NWS home page
Climate Prediction Center

About Us
   Our Mission
   Who We Are

Contact Us
   CPC Information
   CPC Web Team

HOME > Monitoring_and_Data > Oceanic and Atmospheric Data > Reanalysis: Atmospheric Data > wgrib2 -ncpu

wgrib2: -ncpu

The number of threads

Wgrib2 can be compiled to use multiple threads. By default, an OpenMP-enabled version of wgrib2 will use the environement variable OMP_NUM_THREADS to control the number of threads. If the environment variable OMP_NUM_THREADS is not defined, the number of threads created is usually the same as the number of cores. The -ncpu option controls the number of threads that will be used by wgrib2. If wgrib2 is not compiled to use OpenMP, this option is quietly ignored. The -ncpu option overrides the OMP_NUM_THREADS environment variable.

When you run an OpenMP-enabled wgrib2 version on a shared system, the performance may be suboptimal if you use too many threads. For example, on one of our linux systems, we have 32 cores. The system is shared by many users and during a busy time, there may only be a few cores free at any one time. When using 32 threads, there is often a thread that doesn't get much time in the beginning and is slow to finish.

The main usage of the -ncpu option is to allocate threads/cpus when you are running multiple copies of wgrib2.


-ncpu N
  N = number of threads


   $ wgrib2 IN.grb -ncpu 3 -new_grid_winds grid -new_grid ncep grid 221 - | wgrib2 - -ncpu 1 -set_grib_type j -ncep_uv OUT.grb

The above line uses 3 threads for regridding and one thread for jpeg2000 compression. The jpeg2000 compression routines can't take advantage of more than one thread.

See also:

NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5830 University Research Court
College Park, Maryland 20740
Climate Prediction Center Web Team
Page last modified: July 10, 2014
Disclaimer Privacy Policy