The Array Compaction Assignment. Programming Assignment 0. Due: March 31, 2004 In the array compaction assignment (one of many versions) there are 3 arrays A,C & D with the same number of elements (N). The goal is to compact the elements of array A into array D according to the elements of array C. Specifically if C[i] (0<=i<=N) is equal to 1 then A[i] is copied into the next free element in D. To get the next free element number in D, a prefix sum (ps) instruction is used. Here is a program that implements the array compaction assignment: #include int A[8]; // Global variables are initiated during the execution int C[8]; // of the XMT simulator with an input data file. int D[8]; main() { int i; register int LR,low,high; // The variables of 'spawn' & 'ps' must be held in global register GR; // registers. The global register of 'ps' is // defined here. Global registers must be the // last ones to be defined. GR = 0; low=0; high=7; spawn low,high; // A special instruction in a separate line. { if ( c[$] == 1) // '$' represents a running virtual thread ID. { LR = 1; ps LR , GR; // The left parameter of 'ps' is local and d[LR]= a[$]; // the right parameter is global. } } join; // A special instruction in a separate line. // For now it is recommended to print inside main(). // You are supposed to print in serial mode only. for ( i=0 ; i<8 ; i++ ) printf( "A[%]=%d ",i,A[i]); // At most 3 parameters can // be passed to 'printf'. printf("\n"); // Do not use '"' inside a string. for ( i=0 ; i<8 ; i++ ) printf( "C[%]=%d ",i,C[i]); printf("\n"); for ( i=0 ; i<8 ; i++ ) printf( "D[%]=%d ",i,D[i]); printf("\n"); }