Hello, I am trying to make a program that adds two matrix's that are created in the main program using pthread commands. For some reason this program compiles correctly on GCC 4.1.2 but when I go to run the program I continue to get the message "segmentation fault". Not quite sure what I am doing wrong here as I know sometimes this fault can happen when you use int's instead of long when creating pointers but I already took care of that issue. Any help is GREATLY appreciated. :)
There are a number of problems with add_arrays.
1. It knows the size of the matrix
2. It knows how many other instances of add_arrays exist
3. Each instance of add_arrays tries to join with the others
4. Each add_array adds a rectangle, destroying the locality of data being accessed, you really should be adding columns as columns are held in contiguous order in C and C++ (which is different for Fortran).
5. Keep it simple--you're trying to do too much in thread classes. It should just be summing a column.
Just a few questions and to clear some stuff I should have mentioned up:
First, why is it a problem that add_arrays knows the size of the matrix and how many other instances of add_arrays exist?
Plus I actually have to add the arrays in the rectangle, this is an assignment for a class and it was assigned that each process is in charge of adding rows 8*i to 8*i+7. For this assignment each process runs off of shared memory so I figured that knowing the size of the arrays wouldn't be a problem. As for the joining, it was the only method I could think of that would allow me to have each process print that it had completed execution in order (from 4 to 1). Is the method I used not correct?
I am not very good at c++ programming as you might have noticed, is there any tips on what I should be doing differently here. Like how could I add the arrays if they don't know the overall size and location of the matrix. I am really lost here and any tips or ideas would be greatly appreciated.