I have a function like below,
in line 49 the size of p is 6. but when I go inside while loop, when calling MPI_MxV function, p becomes zero and I don't know why. any help would be appreciated.
The rest of the processors currently don't see anything inside your if block, so it is irrelevant whether you broadcast p or not.
I'm sorry, but this application is not one in which MPI is going to help you. You will spend far too long sending and receiving bits of data between processors. It will run many times slower than the equivalent serial version.
MPI works best when:
- you can partition your domain into essentially independent chunks (not sparse matrices);
- the amount of information sent between parts is minimal.
MPI_Send and MPI_Recv are fundamentally slow operations.