3
I have an application in which there are several parallelization modes. However, when I will parallelize through Fork() the barrier is not shared between processes, there is some difference of the Shm in dealing with the instantiation via new or there is another way to provide the sharing of this barrier?
Note: I don’t know if it makes a difference, but the Barrier is an object Static in the parent class.
#include "ProcessMode.hpp"
ProcessMode::ProcessMode(IndexGenerator *index_generator_template, numerical *numerical_array, short number_of_processors)
: ParalelizationMode(index_generator_template, numerical_array, number_of_processors) {
// Sharing the barrier for use among the processes
int ptr_id = shmget(IPC_PRIVATE, sizeof(Barrier), IPC_CREAT | 0666);
ParalelizationMode::barrier = (Barrier*) shmat(ptr_id, NULL, 0);
ParalelizationMode::barrier = new Barrier(number_of_processors);
}
void ProcessMode::run() {
pid_t pid;
int id = 0;
// Create processes
for (short i = 1; i < number_of_processors; i++) {
pid = fork();
if(pid > 0) {
continue;
}
else {
id = i;
break;
}
}
calculate(new Calculator(numerical_array, index_generator_template->clone(id)));
ParalelizationMode::barrier->wait();
if (pid == 0) exit(0);
}
I tested the solution and unfortunately it didn’t work. When I place a printf within the Wait() function the value of the barrier counter remains unchanged in both processes, indicating that there was no sharing. Normal barrier with other parallelization methods works correctly, prints show values being lowered.
– Dario