I am writing a program that iterates through large square arrays (reads only), it uses multiple threads to access different parts of the array in parallel. And when I have more than 1 thread working it will segfault with the following error:
Code:
==17411== Process terminating with default action of signal 11 (SIGSEGV)
==17411== Access not within mapped region at address 0x4
==17411== at 0x1000021FA: avg_rows (jacobi.c:360)
==17411== by 0x100447C12: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==17411== by 0x100447B8F: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==17411== by 0x100445374: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
here is the code for this loop:
Code:
for (uint32_t i = args->low; i < args->high+1; i++) {
for (uint32_t j = 1; j < args->size+1; j++) {
float test = 0;
test = args->write[i][j];
test = args->read[i-1][j];
printf("%u, %u\n", j, i);
test = args->read[i+1][j]; //line 360
test = args->read[i][j-1];
test = args->read[i][j+1];
}
}
This loop should iterate through all middle indexes of the array within the low/high row range given.
The arrays that I am creating are of size which is why in the nested loop you see Also note that while I refer to these as 2d arrays, they are implemented as double pointers
For this error the size of the array was 602x602 elements and the element being accessed was col 1, row 601. so this value is within the range of the array. Any thoughts on this, or ways to debug are greatly appreciated.