Research Article

Multi-GPU Support on Single Node Using Directive-Based Programming Model

Algorithm 7

The master algorithm for multi-GPU programming in OpenACC.
(1)     function  ENQUEUE_TASK_XXXX
(2)        Allocate memory and populate the task argument
(3)        Allocate memory and populate the task
(4)        pthread_mutex_lock(&cur_thread queue_lock)
(5)        if    then     push the task into the FIFO queue
(6)            cur_thread queue_head = cur_task;
(7)            cur_thread queue_tail = cur_task;
(8)            pthread_cond_signal(&cur_thread queue_ready); signal the worker that the queue is not empty and the task is ready
(9)        else
(10)          cur_thread queue_tail next = cur_task;
(11)           cur_thread queue_tail = cur_task;
(12)      end if
(13)      cur_thread queue_size++;
(14)      pthread_mutex_unlock(&cur_thread queue_lock);
(15)      if    then         if the task is synchronous
(16)          pthread_mutex_lock(&cur_thread queue_lock);
(17)          while    do    wait until this task is done
(18)              pthread_cond_wait(&cur_thread work_done, &cur_thread queue_lock);
(19)          end while
(20)         pthread_mutex_unlock(&cur_thread queue_lock);
(21)      end if
(22) end function