I have an application in which there are several modes of parallelization. However, when I am going to parallelize through fork () the barrier is not shared between the processes, is there any difference of Shm in dealing with instantiation via new or is there another way to provide the sharing of this barrier?
#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);
}