how to change h.parallel_for(range(M, P), [=](auto index) to single_task function
- 3 years ago
Hi Wei-Chih,
Sorry for late reply.
I may not understand the written code that you are trying to work with.
Can you provide more decription on the operation that you are trying to work on?
I think you can split your task using a normal for loop as compared to using parallel_for:
Brief example as below:
// Computes the product of two square matrices.
void matrix_multiply(double** m1, double** m2, double** result, size_t size)
{
for (size_t i = 0; i < size; i++)
{
for (size_t j = 0; j < size; j++)
{
double temp = 0;
for (int k = 0; k < size; k++)
{
temp += m1[i][k] * m2[k][j];
}
result[i][j] = temp;
}
}
}
// Computes the product of two square matrices in parallel.
void parallel_matrix_multiply(double** m1, double** m2, double** result, size_t size)
{
parallel_for (size_t(0), size, [&](size_t i)
{
for (size_t j = 0; j < size; j++)
{
double temp = 0;
for (int k = 0; k < size; k++)
{
temp += m1[i][k] * m2[k][j];
}
result[i][j] = temp;
}
});
}
There is this document that might help to consider how your code will be written:
https://www.colfax-intl.com/downloads/oneAPI_module04_DPCplusplusFundamentals2of2.pdf
Thanks.
Regards,
Aik Eu