source: CIVL/examples/mpi-pthread/anl_hybrid.c@ cf6056d

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since cf6056d was 390bb88, checked in by Stephen Siegel <siegel@…>, 11 years ago

Adding Argonne Hybrid program using pthreads+MPI. Fixed bug in the CIVL version of that program too.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1973 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 961 bytes
Line 
1#include <pthread.h>
2#include <mpi.h>
3
4#define TAG 99
5
6$input int _NPROCS = 2;
7
8void * Thread(void * tid) {
9 int rank, x, y;
10
11 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
12 x = 2*rank + (int)tid;
13 for (int j=0; j<2; j++) {
14 if (rank == 0) {
15 for (int i=0; i<2; i++)
16 MPI_Send(&x, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD);
17 for (int i=0; i<2; i++)
18 MPI_Recv(&y, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
19 } else if (rank == 1) {
20 for (int i=0; i<2; i++)
21 MPI_Recv(&y, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
22 for (int i=0; i<2; i++)
23 MPI_Send(&x, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD);
24 }
25 }
26 pthread_exit(NULL);
27}
28
29int main(int argc, char * argv[]) {
30 pthread_t threads[2];
31
32 MPI_Init(&argc, &argv);
33 for (int i=0; i<2; i++) {
34 pthread_create(&threads[i], NULL, Thread, (void *)(long)i);
35 }
36 for (int i=0; i<2; i++) {
37 pthread_join(threads[i], NULL);
38 }
39 MPI_Finalize();
40}
Note: See TracBrowser for help on using the repository browser.