C API: AllocatorsΒΆ

The fundamental concept for accessing memory through Umpire is an umpire:Allocator. In C, this means using the type umpire_allocator. There are corresponding functions that take an umpire_allocator and let you allocate and deallocate memory.

As with the native C++ interface, all allocators are accessed via the umpire::ResourceManager. In the C API, there is a corresponding umpire_resourcemanager type. To get an umpire_allocator:

  umpire_resourcemanager rm;
  umpire_resourcemanager_get_instance(&rm);

  umpire_allocator allocator;
  umpire_resourcemanager_get_allocator_by_name(&rm, "HOST", &allocator);

Once you have an umpire_allocator, you can use it to allocate and deallocate memory:

  double* data = (double*) umpire_allocator_allocate(&allocator, SIZE*sizeof(double));

  printf("Allocated %lu bytes using the %s allocator...", (SIZE*sizeof(double)), umpire_allocator_get_name(&allocator));

  umpire_allocator_deallocate(&allocator, data);

In the next section, we will see how to allocate memory in different places.