nd these will be discussed in the next section. Once the call to 'acc_set_device_num()' has completed, other OpenACC functions can be called as seen with multiple calls being made to 'acc_copyin()'. In addition, calls can be made to functions in the CUBLAS library. In the use case a call to 'cublasCreate()' is made subsequent to the calls to 'acc_copyin()'. As seen in the previous use case, a call to 'cublasCreate()' initializes the CUBLAS library and allocates the hardware resources on the host and the device. However, since the device has already been allocated, 'cublasCreate()' will only initialize the CUBLAS library and allocate the appropriate hardware resources on the host. The context that was created as part of the OpenACC initialization is shared with the CUBLAS library, similarly to the first use case. dev = 0; acc_set_device_num(dev, acc_device_nvidia); /* Copy the first set to the device */ d_X = acc_copyin(&h_X[0], N * sizeof (float)); if (d_X == NULL) { fprintf(stderr, "copyin error h_X\n"); exit(EXIT_FAILURE); } /* Copy the second set to the device */ d_Y = acc_copyin(&h_Y1[0], N * sizeof (float)); if (d_Y == NULL) { fprintf(stderr, "copyin error h_Y1\n"); exit(EXIT_FAILURE); } /* Create the handle */ s = cublasCreate(&h); if (s != CUBLAS_STATUS_SUCCESS) { fprintf(stderr, "cublasCreate failed %d\n", s); exit(EXIT_FAILURE); } /* Perform saxpy using CUBLAS library function */ s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1); if (s != CUBLAS_STATUS_SUCCESS) { fprintf(stderr, "cublasSaxpy failed %d\n", s); exit(EXIT_FAILURE); } /* Copy the results from the device */ acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float)); Use Case 2 8.4 OpenACC library and environment variables ============================================= There are two environment variables associated with the OpenACC library that may be used to control the device type and device number: 'ACC_DEVICE_TYPE' and 'ACC_DEVICE_NUM', respectively. These two environment variables can be used as an alternative to calling 'acc_set_device_num()'. As seen in the second use case, the device type and device number were specified using 'acc_set_device_num()'. If however, the aforementioned environment variables were set, then the call to 'acc_set_device_num()' would not be required. The use of the environment variables is only relevant when an OpenACC function is called prior to a call to 'cudaCreate()'. If 'cudaCreate()' is called prior to a call to an OpenACC function, then you must call 'acc_set_device_num()'(2) ---------- Footnotes ---------- (1) See section 2.26, "Interactions with the CUDA Driver API" in "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5, for additional information on library interoperability. (2) More complete information about 'ACC_DEVICE_TYPE' and 'ACC_DEVICE_NUM' can be found in sections 4.1 and 4.2 of the OpenACC (https://www.openacc.org) Application Programming Interface”, Version 2.6.