concept resource in category parallel computing

appears as: resources, resources
Parallel and High Performance Computing

This is an excerpt from Manning's book Parallel and High Performance Computing.

Parallel computing is the execution of many operations at a single instance in time. Fully exploiting parallel computing does not happen automatically. It requires some effort from the programmer. First, you must identify and expose the potential for parallelism in an application. Potential parallelism, or concurrency, means that you certify that it is safe to conduct the operations in any order as the resources become available on the system. For parallel computing there is an additional requirement; these operations must occur at the same time. For this to happen, you must also properly leverage the resources to execute them simultaneously. Parallel computing introduces new concerns that are not present in a serial world. A change in thought process is needed to adapt to the additional complexities of parallel execution, but with practice, it begins to be second nature. This book begins your journey on how to access the power of parallel.

Listing 11.7 Allocating data only on the device
OpenACC/StreamTriad/StreamTriad_par4.c
 1 #include <stdio.h>
 2 #include <openacc.h>
 3 #include "timer.h"
 4 
 5 int main(int argc, char *argv[]){
 6 
 7    int nsize = 20000000, ntimes=16;
 8    double* restrict a_d = acc_malloc(nsize * sizeof(double));    #A
 9    double* restrict b_d = acc_malloc(nsize * sizeof(double));    #A
10    double* restrict c_d = acc_malloc(nsize * sizeof(double));    #A
11 
12    struct timespec tstart;
13    // initializing data and arrays
14    const double scalar = 3.0;
15    double time_sum = 0.0;
16 #pragma acc parallel loop deviceptr(a_d, b_d)    #B
17    for (int i=0; i<nsize; i++) {
18       a_d[i] = 1.0;
19       b_d[i] = 2.0;
20    }
21 
22    for (int k=0; k<ntimes; k++){
23       cpu_timer_start(&tstart);
24       // stream triad loop
25 #pragma acc parallel loop deviceptr(a_d, b_d, c_d)    #B
26       for (int i=0; i<nsize; i++){
27          c_d[i] = a_d[i] + scalar*b_d[i];
28       }
29       time_sum += cpu_timer_stop(tstart);
30    }
31 
32    printf("Average runtime for stream triad loop is %lf msecs\n", time_sum/ntimes);
33 
34    acc_free(a_d);    #C
35    acc_free(b_d);    #C
36    acc_free(c_d);    #C
37 
38    return(0);
39 }