But none of these tutorial deals with a simple “for loop” multithreading. I just want to loop over the data, and save the results in a vector for analyzing it later with some functions, and plot it to the histogram. (It’s only the loop that take all computing time )
Right now my code produce a map< double,vector<double> >, which contains max 2000 keys and 10 to 20 “double" values for each keys, and it is analyzed in different functions. And all the functions produce 5 histograms, which is plottet on top of each other.
I have uploaded the code, and I have marked the part that should be multithreaded.
Hope someone have a solution thanks. ep.cpp (8.38 KB)
I understand you want to want to parallelise this portion of the code*.
Now, it is not clear what the MCP class is and what the MCP_Intersection function actually does but what I think it’s on your plate is:
to figure our what is the input and the output of the calculations in the body of the loop
figure out if there are side effects in the afore mentioned class and method in order to decide for a multithreaded or multiprocess approach
match the outcome of the analysis of the previous two points to one of the cases illustrated in the tutorials, for example understanding if a multithreaded approach is possible (no side effects) or a multiprocess approach is needed.
Note that a reformulation of the calculations in the body of the for loop might be needed in order to fit the map or map/reduce paradigms proposed by the TProcPool class.
Sorry, no magic when it comes to expressing parallelism in real life.
Danilo
for (unsigned int i = 0; i < position_array_quartz_T0A.size(); i++){ // Search intersection for each detectors
// For T0C
MCP_detector_T0C = new MCP(nameC, Mcp_dimension, position_array_quartz_T0C[i], Quartz_Dimension, number_of_sub_quartz,space_between_the_sub_quartz,Reflective_index,$
MCP_detector_T0C->MCP_Intersection(in, IP, MCP_detector_T0C, Intersection_plot_T0C, Output, pore_positions, particles_intersection_mcp,0);
// For T0A
MCP_detector_T0A = new MCP(nameA, Mcp_dimension, position_array_quartz_T0A[i], Quartz_Dimension, number_of_sub_quartz,space_between_the_sub_quartz,Reflective_index,$
MCP_detector_T0A->MCP_Intersection(in, IP, MCP_detector_T0A, Intersection_plot_T0A, Output, pore_positions, particles_intersection_mcp,0);
delete MCP_detector_T0C;
delete MCP_detector_T0A;}
}