Non-blocking I/O operations

ABT-IO provides an API to issue I/O operations in a non-blocking manner and wait for completion later. The following code examplifies this feature,

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <abt-io.h>

int main(int argc, char** argv)
{
    // Argobots must be initialized, either with ABT_init
    // or with margo_init, thallium::engine, or thallium::abt.
    ABT_init(argc, argv);

    // abt_io_init takes the number of ES to create as a parameter.
    abt_io_instance_id abtio = abt_io_init(2);

    // open a file
    int fd = abt_io_open(abtio, "test.txt", O_WRONLY | O_APPEND | O_CREAT, 0600);

    // write to the file without blocking
    ssize_t ret;
    abt_io_op_t* op = abt_io_pwrite_nb(abtio, fd, "This is a test", 14, 0, &ret);

    // wait for the request to be completed
    abt_io_op_wait(op);

    // free the request
    abt_io_op_free(op);

    // close the file
    abt_io_close(abtio, fd);

    // ABT-IO must be finalized before Argobots it finalized.
    abt_io_finalize(abtio);

    ABT_finalize();

    return 0;
}

The full list of non-blocking functions is the following.

ABT-IO function

Corresponding POSIX function

abt_io_open_nb

open

abt_io_pwrite_nb

pwrite

abt_io_write_nb

write

abt_io_pread_nb

pread

abt_io_read_nb

read

abt_io_mkostemp_nb

mkostemp

abt_io_unlink_nb

unlink

abt_io_close_nb

close

Compared with their blocking versions, these function take an additional parameter which is a pointer to the returned value (will be set when the operation has completed) and return a pointer to an abt_io_op_t object.

The user can then use abt_io_op_wait to wait for the operation to complete, and abt_io_op_free to free the operation once completed.