cparallel-processingspmdispc

Task is to parallelize matrix multiplication with p-threads and vectorized with Intel ISPC compiler


In .ispc file using pthread generates errors as follows: (1) t.ispc:2:13: Error: Illegal to return a "varying" or vector type from exported function "matrix_mult_pl" export void * matrix_mult_pl( void *arg )

(2) t.ispc:2:36: Error: Varying pointer type parameter "arg" is illegal in an exported function. export void * matrix_mult_pl( void *arg )

(3) t.ispc:6:11: Error: syntax error, unexpected 'int'. tid = *(int *)(arg); // get the thread ID assigned sequentially. ^^^

and many more errors. Coder is attached below. Kindly look into the issue of using pthreads in ISPC.

threads.c file
/**
 * Thread routine.
 * Each thread works on a portion of the 'matrix1'.
 * The start and end of the portion depend on the 'arg' which
 * is the ID assigned to threads sequentially. 
 */
void * matrix_mult_pl( void *arg )
{
  int rows, cols, j, tid, portion_size, row_start, row_end;

  tid = *(int *)(arg); // get the thread ID assigned sequentially.
  portion_size = size / num_threads;
  row_start = tid * portion_size;
  row_end = (tid+1) * portion_size;

  for (rows = row_start; rows < row_end; ++rows) { // hold row index of 'matrix1'
    for (j = 0; j < size; ++j) { // hold column index of 'matrix2'
     // hold value of a cell
      /* one pass to sum the multiplications of corresponding cells
     in the row vector and column vector. */
      for(cols=0; cols<size; cols++) { 
        result_pl[ rows ][ cols ] += matrix1[ rows ][ j ] * matrix2[ j ][ cols ];
      }
    }
  }
}

threads.ispc file

export void * matrix_mult_pl( void *arg )
{
  int rows, cols, j, tid, portion_size, row_start, row_end;

  tid = *(int *)(arg); // get the thread ID assigned sequentially.
  portion_size = size / num_threads;
  row_start = tid * portion_size;
  row_end = (tid+1) * portion_size;

  for (rows = row_start; rows < row_end; ++rows) { // hold row index of 'matrix1'
    for (j = 0; j < size; ++j) { // hold column index of 'matrix2'
     // hold value of a cell
      /* one pass to sum the multiplications of corresponding cells
     in the row vector and column vector. */
      for(cols=0; cols<size; cols++) { 
        result_pl[ rows ][ cols ] += matrix1[ rows ][ j ] * matrix2[ j ][ cols ];
      }
    }
  }
}

Why is ISPC file not vectorizing the execution with parallelization by pthreads?


Solution

  • The problem you're having is because ISPC defaults to varying type. int x = 0 is the same as varying int x = 0. This applies to pointer types as well void *arg as void varying * uniform arg and you can't have varying types in exported functions. When porting and first getting started with ISPC it's best to be explicit with uniform and varying keywords.