@@ -213,12 +213,11 @@ int main(int argc, char *argv[]) {
213213 token = strtok (NULL , ";" );
214214 }
215215
216- // Execute Queries
216+ // Execute Queries - Distribute across MPI ranks
217217 for (int i = 0 ; i < query_count ; i ++ ) {
218- // Divide queries among ranks
218+ // Round-robin distribution: each rank processes queries where i % size == rank
219219 if (i % size != rank ) continue ;
220-
221- // Get the current query and trim whitespace
220+
222221 char * query = trim (queries [i ]);
223222 if (!* query ) continue ;
224223
@@ -283,9 +282,13 @@ int main(int argc, char *argv[]) {
283282 parseFailed = true;
284283 }
285284
286- // Print results (Rank 0 only)
287- if (rank == 0 ) {
288- printf ("Executing Query: %s\n" , query );
285+ // Synchronize all ranks before printing to ensure ordered output
286+ MPI_Barrier (MPI_COMM_WORLD );
287+
288+ // Print results in rank order
289+ for (int print_rank = 0 ; print_rank < size ; print_rank ++ ) {
290+ if (rank == print_rank ) {
291+ printf ("Executing Query: %s\n" , query );
289292
290293 if (parseFailed ) {
291294 printf ("Tokenization failed.\n" );
@@ -313,6 +316,8 @@ int main(int argc, char *argv[]) {
313316 fprintf (stderr , "Unsupported command.\n" );
314317 }
315318 }
319+ }
320+ MPI_Barrier (MPI_COMM_WORLD );
316321 }
317322
318323 // Cleanup
0 commit comments