|
@@ -1,24 +1,32 @@
|
|
| 1 |
#include <mpi.h>
|
|
|
|
| 2 |
#include <stdio.h>
|
| 3 |
|
| 4 |
int main(int argc, char *argv[])
|
| 5 |
{
|
| 6 |
MPI_Init(&argc, &argv);
|
| 7 |
|
| 8 |
int my_rank = -1;
|
| 9 |
int process_count = -1;
|
| 10 |
|
| 11 |
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
|
| 12 |
MPI_Comm_size(MPI_COMM_WORLD, &process_count);
|
| 13 |
|
| 14 |
char hostname[MPI_MAX_PROCESSOR_NAME];
|
| 15 |
int hostname_length = -1;
|
| 16 |
MPI_Get_processor_name(hostname, &hostname_length);
|
| 17 |
|
| 18 |
printf("Hello from main thread of process %d of %d on %s\n"
|
| 19 |
, my_rank, process_count, hostname);
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
MPI_Finalize();
|
| 22 |
return 0;
|
| 23 |
}
|
| 24 |
|
| 1 |
#include <mpi.h>
|
| 2 |
+
#include <omp.h>
|
| 3 |
#include <stdio.h>
|
| 4 |
|
| 5 |
int main(int argc, char *argv[])
|
| 6 |
{
|
| 7 |
MPI_Init(&argc, &argv);
|
| 8 |
|
| 9 |
int my_rank = -1;
|
| 10 |
int process_count = -1;
|
| 11 |
|
| 12 |
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
|
| 13 |
MPI_Comm_size(MPI_COMM_WORLD, &process_count);
|
| 14 |
|
| 15 |
char hostname[MPI_MAX_PROCESSOR_NAME];
|
| 16 |
int hostname_length = -1;
|
| 17 |
MPI_Get_processor_name(hostname, &hostname_length);
|
| 18 |
|
| 19 |
printf("Hello from main thread of process %d of %d on %s\n"
|
| 20 |
, my_rank, process_count, hostname);
|
| 21 |
|
| 22 |
+
#pragma omp parallel
|
| 23 |
+
{
|
| 24 |
+
#pragma omp critical(stdout)
|
| 25 |
+
printf("\tHello from thread %d of %d of process %d on %s\n"
|
| 26 |
+
, omp_get_thread_num(), omp_get_num_threads(), my_rank, hostname);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
MPI_Finalize();
|
| 30 |
return 0;
|
| 31 |
}
|
| 32 |
|