Lecture 13 Notes

Sharedqueueusingatomicaddincuda

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the same object block (suspend execution) until the first thread is done with the object. Figure 1. Nonblocking queue that ensures that at most one thread can access the data structure at one time typedef struct _VertexQueue { int *Queue; int *head; } VertexQueue VertexQueue q; cudaMalloc((void**)&(q.Queue), sizeof(int)*MAX_SIZE); cudaMalloc((void**)&(q.head), sizeof(int)*1); void put (int vertexID) { int index = atomicAdd(q.head, 1); q.Queue[index] = vertexID } Figure 2. Shared Queue using atomicAdd() in CUDA (2‐2) Blocking/Nonblocking queue: What should be done on an empty queue or on a full queue needs to be defined. For the task queue used in the Master/Worker algorithm, the policy depends on how termination will be handled by. Suppose, for example, that all the tasks will be created at startup time by the master. Then an empty task queue will indicate that the UE should terminate, and we will want the take operation on an empty queue to return immediately with an indication that the queue is empty. That is, we want a non‐blocking queue. Another possible...
View Full Document

This document was uploaded on 03/17/2014 for the course CS 4800 at Northeastern.

Ask a homework question - tutors are online