1

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?

Hassam Khan
  • 21
  • 1
  • 5
  • To maximize the ability for us to help you, you should reduce this to a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). You might even find out the issue by doing so. – Ken Wayne VanderLinde Apr 24 '20 at 19:47
  • I have done some changes to the code so that you can easily understand what I want to implement. – Hassam Khan Apr 24 '20 at 21:12

1 Answers1

1

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.

pbrubaker
  • 51
  • 5
  • That's great to hear! Also if you run into issues in the future the [ispc-users Google Group](https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!forum/ispc-users) is probably the best place to seek feedback. – pbrubaker May 12 '20 at 06:58