#include <mpi.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <unistd.h>
usingnamespace std;
//Defining the GLOBAL variable I need
int COMPLETE=0;
int main(int argc, char * argv[])
{
MPI::Init(argc, argv);
//MPI job
//Updating GLOBAL variable
COMPLETE++;
if (COMPLETE==Vector.size())
{
//Do something
}
MPI::Finalize();
return 0;
}
Code like above does not work since COMPLETE variable is used independantly in all classes. What I want is to update this variable by ++1 every time a thread finishes.
My question is:
1/ How can I set I global variable for MPI?
2/ How should I synchronyze writing permissions for this variable
This is not really a "General C++ Programming" question. While you may get a useful answer here, you are much more likely to get such questions answered on a forum dedicated to MPI programming.