Задача - распараллелить умножение матриц с помощью p-потоков и векторизовать с помощью компилятора Intel ISPC.
В файле.ispc при использовании pthread возникают следующие ошибки: (1) t.ispc:2:13: Ошибка: недопустимо возвращать "изменяющийся" или векторный тип из экспортированной функции "matrix_mult_pl" export void * matrix_mult_pl (void * arg)
(2) t.ispc:2:36: Ошибка: параметр типа изменяющегося указателя "arg" недопустим в экспортируемой функции. экспорт void * matrix_mult_pl (void * arg)
(3) t.ispc:6:11: Ошибка: синтаксическая ошибка, неожиданное значение int. tid = *(int *)(аргумент); // получение идентификатора потока, назначенного последовательно. ^^^
и еще много ошибок. Кодер прикреплен ниже. Пожалуйста, рассмотрите вопрос использования pthreads в ISPC.
файл threads.c/**
* 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
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 ];
}
}
}
}
Почему файл ISPC не векторизует выполнение с распараллеливанием по потокам pthreads?
1 ответ
Проблема в том, что ISPC по умолчанию varying
тип. int x = 0
такой же как varying int x = 0
. Это относится и к типам указателей.void *arg
как void varying * uniform arg
и у вас не может быть разных типов в экспортируемых функциях. При переносе и первом начале работы с ISPC лучше всего явно указатьuniform
а также varying
ключевые слова.