fork download
  1. // An example parallel program using MPI
  2.  
  3.  
  4. #include <iostream>
  5. #include <sstream>
  6.  
  7. #include "mpi.h"
  8.  
  9. int main(int argc, char *argv[]) {
  10. // Initialize MPI
  11. MPI_Init(&argc, &argv);
  12.  
  13. // Get the total number of tasks
  14. int num_tasks;
  15. MPI_Comm_size(MPI_COMM_WORLD, &num_tasks);
  16.  
  17. // Get the task ID
  18. int task_id;
  19. MPI_Comm_rank(MPI_COMM_WORLD, &task_id);
  20.  
  21. // Set up the string and print
  22. std::stringstream ss;
  23. ss << "Printing from task " << task_id << '/' << num_tasks << '\n';
  24. std::cout << ss.str();
  25.  
  26. // Finish our MPI work
  27. MPI_Finalize();
  28. return 0;
  29. }
  30.  
Success #stdin #stdout #stderr 0.27s 40616KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected '/' in "/"
Execution halted