Combining OpenMP with asynchronous C API


#1

Hello, I just discovered Aerospike and I’m trying it out for my C/C++ application, but I’m not sure about its design.

The main body of the application is an OpenMP parallel for loop that inserts a set of key-value pairs into a database. The basic requirements are: insertions are done in parallel by the different OpenMP threads and insertions must be asynchronous (as the threads will do other work while waiting for the insertions to finish).

The pseudo-code should look something like this:

// 1 - Parallel, async insertions
#pragma omp parallel for
for (int i = 0; i < num_kv; i++) {
    insert_asynchronous(key[i], value[i]);
}
// 2 - Do some other stuff
// 3 - Wait for the insertions to finish (ideally, in parallel, but could be serial)
#pragma omp parallel for
for (int i = 0; i < num_kv; i++) {
    wait_for_insertion(i);
}

I’ve read as much documentation as I could and checked the async tutorial: http://www.aerospike.com/docs/client/c/usage/async.html

So far, I’ve been able to try some of the approaches explained in the docs, but the application is crashing some times and I’m not sure I’m doing it the right way. According to the docs, asynchronous applications should follow an event loop style to match perfectly with Aerospike’s async C/C++ API. And regarding async calls, the tutorials give basically two options:

  1. Create new “as_event_loop” entities (threads) that will call the appropriate callbacks once async operations finish.

  2. Share parallelism between the application and Aerospike by creating “shared event loops” (e.g. the application creates PThreads that will be used by Aerospike to call the callbacks once async operations finish).

While I conceptually understand the differences between the two approaches, I’m not sure which one I should use for the aforementioned code, as it is clearly not an event loop design.

Could someone help me pointing out what would be the pros and cons of both approaches, or which one should fit better my requirements in terms of performance?

If needed, I can provide more details about software (library versions, configurations, etc) and hardware specs.

Thanks in advance!

Judit