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

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[390bb88]1#include <pthread.h>
2#include <mpi.h>
[f42467f]3#include <stdio.h>
[390bb88]4
5#define TAG 99
6
[024a9eb]7$input int _mpi_nprocs = 2;
[390bb88]8
9void * Thread(void * tid) {
10 int rank, x, y;
11
12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
13 x = 2*rank + (int)tid;
14 for (int j=0; j<2; j++) {
15 if (rank == 0) {
[f42467f]16 for (int i=0; i<2; i++){
17 printf("thread %d of rank %d sends at iteration %d.\n", tid, rank, j);
[390bb88]18 MPI_Send(&x, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD);
[f42467f]19 }
20 for (int i=0; i<2; i++){
21 printf("thread %d of rank %d receives at iteration %d.\n", tid, rank, j);
[390bb88]22 MPI_Recv(&y, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
[f42467f]23 }
[390bb88]24 } else if (rank == 1) {
[f42467f]25 for (int i=0; i<2; i++){
26 printf("thread %d of rank %d receives at iteration %d.\n", tid, rank, j);
[390bb88]27 MPI_Recv(&y, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
[f42467f]28 }
29 for (int i=0; i<2; i++){
30 printf("thread %d of rank %d sends at iteration %d.\n", tid, rank, j);
[390bb88]31 MPI_Send(&x, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD);
[f42467f]32 }
[390bb88]33 }
34 }
35 pthread_exit(NULL);
36}
37
38int main(int argc, char * argv[]) {
39 pthread_t threads[2];
40
41 MPI_Init(&argc, &argv);
42 for (int i=0; i<2; i++) {
43 pthread_create(&threads[i], NULL, Thread, (void *)(long)i);
44 }
45 for (int i=0; i<2; i++) {
46 pthread_join(threads[i], NULL);
47 }
48 MPI_Finalize();
49}
Note: See TracBrowser for help on using the repository browser.