50 likes | 279 Views
Unified Parallel C. Farhad Kajabadi Dharmanna Pidagannavar Sandeep Menon. The PGAS Model (for UPC). Concurrent threads with a partitioned shared space - A datum may reference data in other partitions - Global arrays have fragments in multiple partitions.
E N D
Unified Parallel C Farhad Kajabadi Dharmanna Pidagannavar Sandeep Menon
The PGAS Model (for UPC) Concurrent threads with a partitioned shared space - A datum may reference data in other partitions - Global arrays have fragments in multiple partitions Ref: http://upc.gwu.edu/tutorials.html
UPC Memory Model • Each of the threads can access private space and shared space which is partitioned into portions each of which has affinity (or logical association). • UPC implementation typically maps a thread along with its private space and the shared memory portion that has affinity to that thread onto one node. • Place shared data close to threads that will need them the most, which can reduce remote memory accesses and increase performance.
Example CODE //matrix_vect_mult1.c #include <upc_relaxed.h> #define N 1000*THREADS shared double A[N][N], X[N], Y[N]; void main() { int i,j; // Y has already been zeroed for(i=0; i<N; i++) if (i%THREADS==MYTHREAD) for (j=0; j<N; j++) Y[i] += X[j] * A[i][j]; } • #include <upc_relaxed.h> - tells the compiler that it can order shared accesses in any way if it sees that performance can be optimized • if (i%THREADS==MYTHREAD) - distributes the iterations onto the threads in a roundrobin fashion
Data Distribution for Example Ref: UPC: Distributed Shared Memory Programming Ghazawi, Carlson, Sterling & Yelick (Wiley, May 2005) http://cnx.org/content/m20649/latest/ http://upc.lbl.gov/docs/