| UPC Frequently Asked Questions |
#include<upc.h>
#include<upc_strict.h>
#define N 4
#define P 4
#define M 4
shared [N*P /THREADS] int a[N][P] , c[N][M];
shared int b[P][M] ;
void main(void) {
int i,j,l;
// Arrays initialization by thread 0
if(MYTHREAD==0) {
for(i=0;i<N;i++)
for(j=0;j<P;j++) a[i][j] = i * j ;
for(i=0;i<P;i++)
for(j=0;j<M;j++) b[i][j] = i * N +j ;
}
upc_barrier;
// all threads perform matrix multiplication
upc_forall(i=0;i<N;i++;&a[i][0])
// &a[i][0] specifies that this iteration will be executed
by the thread that has affinity to
// element
a[i][0]
for (j=0; j<M;
j++) {
c[i][j] = 0;
for(l=0; l< P; l++) c[i][j] +=a[i][l]*b[l][j];
}
upc_barrier;
// thread 0 displays results
if(MYTHREAD==0) {
printf("\n\n");
for(i=0;i<N;i++)
for(j=0;j<M;j++)
printf("c[%d][%d]=%d\n",i,j,c[i][j]);
}
}
| Home | Projects | Tutorials | Publications | Documentation | Downloads | News | Forum | Events | Working Groups | FAQ | |