/* The following semantics descriptions are from version 1.2 of the UPC specification (page 30): 5 upc forall is a collective operation in which, for each execution of the loop body, the controlling expression and affinity expression are single-valued. 6 The affinity field specifies the executions of the loop body which are to be performed by a thread. 7 When affinity is of pointer-to-shared type, the loop body of the upc forall statement is executed for each iteration in which the value of MYTHREAD equals the value of upc threadof(affinity). Each iteration of the loop body is executed by precisely one thread. 8 When affinity is an integer expression, the loop body of the upc forall statement is executed for each iteration in which the value of MYTHREAD equals the value affinity mod THREADS. 9 When affinity is continue or not specified, each loop body of the upc forall statement is performed by every thread and semantic 1 does not apply. 10 If the loop body of a upc forall statement contains one or more upc forall statements, either directly or through one or more function calls, the construct is called a nested upc forall statement. In a nested upc forall, the outermost upc forall statement that has an affinity expression which is not continue is called the controlling upc forall statement. All upc forall statements which are not controlling in a nested upc forall behave as if their affinity expressions were continue. */ #include #include #define N 10 #define M 11 #define check(expr) do { \ if (!(expr)) printf("ERROR: thread %i failed (%s) at %s:%i\n", \ MYTHREAD, #expr, __FILE__, __LINE__); } while (0) #define threadof(p) ((int)upc_threadof(p)) shared int A[N*N*THREADS]; int main() { unsigned int i,j,k; // Note: unsigned avoids pgcc bug. int cnt1, cnt2; shared [1] int *psi1 = (shared [1] int *)&A; shared [N] int *psiN = (shared [N] int *)&A; shared [] int *psiI0 = (shared [] int *)&A; shared [] int *psiITm1; psiITm1 = (shared [] int *)&(A[THREADS-1]); upc_forall (i=0; i