Skip to content

Commit 4e33523

Browse files
committed
Correcting a bug in the batch simulator
The batch simulator was crashing whe giving more tasks to the last process
1 parent e4ef917 commit 4e33523

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/main_batch.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,19 @@ int main(int argc, char **argv) {
6464
num_simulations = total_simulations / num_max_proc;
6565
}
6666

67-
int last_rank_extra = total_simulations % num_max_proc;
67+
//We have to calculate the simulation start offset before adding the rest to the last process
68+
simulation_number_start = rank * num_simulations;
6869

69-
if (rank == num_max_proc - 1) {
70-
num_simulations += last_rank_extra;
70+
//The last process will have the rest of the simulations
71+
int rest = total_simulations % num_max_proc;
72+
if (rest != 0 && rank == num_max_proc - 1) {
73+
num_simulations += rest;
7174
}
7275

73-
simulation_number_start = rank * num_simulations;
76+
if (num_simulations == 0) {
77+
MPI_Finalize();
78+
return EXIT_SUCCESS;
79+
}
7480

7581
struct user_options *options;
7682
options = new_user_options();
@@ -98,12 +104,7 @@ int main(int argc, char **argv) {
98104
options->show_gui = false;
99105

100106
MPI_Barrier(MPI_COMM_WORLD);
101-
102-
if (num_simulations == 0) {
103-
MPI_Finalize();
104-
return EXIT_SUCCESS;
105-
}
106-
107+
107108
for (int s = simulation_number_start; s < simulation_number_start + num_simulations; s++) {
108109

109110
the_grid = new_grid();

0 commit comments

Comments
 (0)