{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## __interop__ Construct" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The __interop__ construct allows OpenMP to interoperate with foreign runtime environments. In the example below, asynchronous cuda memory copies and a _cublasDaxpy_ routine are executed in a cuda stream. Also, an asynchronous target task execution (having a __nowait__ clause) and two explicit tasks are executed through OpenMP directives. Scheduling dependences (synchronization) are imposed on the foreign stream and the OpenMP tasks through __depend__ clauses." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, an interop object, _obj_ , is initialized for synchronization by including the __targetsync__ _interop-type_ in the interop __init__ clause (__init(__ __targetsync,obj__ __)__). The object provides access to the foreign runtime. The __depend__ clause provides a dependence behavior for foreign tasks associated with a valid object." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, the __omp_get_interop_int__ routine is used to extract the foreign runtime id (__omp_ipr_fr_id__), and a test in the next statement ensures that the cuda runtime (__omp_ifr_cuda__) is available." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Within the block for executing the _cublasDaxpy_ routine, a stream is acquired with the __omp_get_interop_ptr__ routine, which returns a cuda stream ( _s_ ). The stream is included in the cublas handle, and used directly in the asynchronous memory routines. The following __interop__ construct, with the __destroy__ clause, ensures that the foreign tasks have completed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "//%compiler: clang\n", "//%cflags: -fopenmp\n", "\n", "/*\n", "* name: interop.1\n", "* type: C\n", "* version: omp_5.1\n", "*/\n", "#include \n", "#include \n", "#include \n", "#include \n", "#include \n", "\n", "#define N 16384\n", "\n", "void myVectorSet(int n, double s, double *x)\n", "{\n", " for(int i=0; i