Original Post
Hello,
I am writing a library that will operate on huge arrays.
For now I am creating it's basics like copy functions etc.
And I thought that it is a good way to split 1D array into few smaller, and use std::copy in each omp thread, however this approach fails. Errors that occur are each time different, but it seems like a reason for this is memory access violation.
The code is as follows:
I checked the ranges many times, there is no way in which the range on which copy is operating is covered by any other.
Why doesn't it work? Is using std lib in sych manner a poor idea or just my concept is bad?
Thanks in advance,
Regards
I am writing a library that will operate on huge arrays.
For now I am creating it's basics like copy functions etc.
And I thought that it is a good way to split 1D array into few smaller, and use std::copy in each omp thread, however this approach fails. Errors that occur are each time different, but it seems like a reason for this is memory access violation.
The code is as follows:
INT_TYPE TN=omp_get_num_threads( );
INT_TYPE dN=N/TN; //array size divided by threads number
TN--; //decrement because threads are numbered from 0 to TN-1
#pragma omp parallel default (none) shared(First,Last,Result,N,dN,TN)
{
INT_TYPE TID=omp_get_thread_num( );
if (TID==TN) std::copy(First+TID*dN,Last,Result);
else std::copy(First+TID*dN,First+(TID+1)*dN,Result); //this line causes an error
}
I checked the ranges many times, there is no way in which the range on which copy is operating is covered by any other.
Why doesn't it work? Is using std lib in sych manner a poor idea or just my concept is bad?
Thanks in advance,
Regards