I'm trying to use MPI to re-write the paralellization routine for a simulation package I'm using. I'm trying to implement a specific feature and have been having trouble. I'm going to illustrate my problem using another simpler example that shows what I'm trying to do.
I'm basically trying to have a counter that would be shared by all MPI threads. Everytime this counter would be incremented, the specific thread would then broadcast it to everyone else so that each thread would have an up-to-date version of the counter when they want to increment it. I understand that this would be easily doable using OpenMP with shared memory, but I'm wondering if there's a way to make this work with MPI across more than just one CPU (for example, doing a 500-core simulation on a supercomputer).
I've tried pretty much every combination of MPI_Bcast, MPI_Send and MPI_Recv that I could think of, but I think there's something I might not be understanding properly.