PAPI 7.1.0.0
Loading...
Searching...
No Matches
query_device_mpi.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <mpi.h>
5#include "papi.h"
6#include "papi_test.h"
7#define MAX_LOCAL_RANKS (512)
8
9#define MPI_CALL(call, err_handle) do { \
10 int _status = (call); \
11 if (_status == MPI_SUCCESS) \
12 break; \
13 err_handle; \
14} while(0)
15
16static int
17cmp_fn(const void *a, const void *b)
18{
19 return (*(unsigned long *)a - *(unsigned long *)b);
20}
21
22static int
23print_cuda_affinity( MPI_Comm comm, void *handle )
24{
25 int shm_comm_size;
26 MPI_Comm shm_comm = MPI_COMM_NULL;
27 const char *name;
28 int dev_count;
29 int rank, local_rank;
30 int ranks[MAX_LOCAL_RANKS] = { 0 };
31 unsigned long uid;
32 unsigned long uids[MAX_LOCAL_RANKS] = { 0 };
33
34 MPI_CALL(MPI_Comm_rank(comm, &rank), return _status);
35 MPI_CALL(MPI_Comm_split_type(comm, MPI_COMM_TYPE_SHARED,
36 rank, MPI_INFO_NULL, &shm_comm),
37 return _status);
38 MPI_CALL(MPI_Comm_size(shm_comm, &shm_comm_size), return _status);
39 MPI_CALL(MPI_Comm_rank(shm_comm, &local_rank), return _status);
40
42 int i;
43 for (i = 0; i < dev_count; ++i) {
46
47 MPI_CALL(MPI_Alltoall(&rank, 1, MPI_INT, ranks, 1, MPI_INT,
48 shm_comm),
49 return _status);
50 MPI_CALL(MPI_Alltoall(&uid, 1, MPI_UNSIGNED_LONG, uids, 1,
51 MPI_UNSIGNED_LONG, shm_comm),
52 return _status);
53
54 unsigned long sorted_uids[MAX_LOCAL_RANKS] = { 0 };
55 unsigned long uniq_sorted_uids[MAX_LOCAL_RANKS] = { 0 };
56 memcpy(sorted_uids, uids, sizeof(unsigned long) * shm_comm_size);
57 qsort(sorted_uids, shm_comm_size, sizeof(unsigned long), cmp_fn);
58
59 if (local_rank == 0) {
60 int j, uniq_uids = 0;
61 unsigned long curr_uid = 0;
62 for (j = 0; j < shm_comm_size; ++j) {
63 if (sorted_uids[j] != curr_uid) {
64 curr_uid = sorted_uids[j];
65 uniq_sorted_uids[uniq_uids++] = curr_uid;
66 }
67 }
68
69 int k, l, list[MAX_LOCAL_RANKS] = { 0 };
70 for (j = 0, l = 0; j < uniq_uids; ++j) {
71 for (k = 0; k < shm_comm_size; ++k) {
72 if (uids[k] == uniq_sorted_uids[j]) {
73 list[l++] = ranks[k];
74 }
75 }
76
77 printf( "GPU-%i Affinity : Name: %s, UID: %lu, Ranks: [ ",
78 i, name, uniq_sorted_uids[j] );
79 for (k = 0; k < l; ++k) {
80 printf( "%d ", list[k] );
81 }
82 printf( "]\n" );
83 }
84 }
85 }
86
87 MPI_CALL(MPI_Comm_free(&shm_comm), return _status);
88 return 0;
89}
90
91int main(int argc, char *argv[])
92{
93 int quiet = 0;
94 quiet = tests_quiet(argc, argv);
95
96 MPI_Init(&argc, &argv);
97
98 int rank;
99 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
100
102 if (retval != PAPI_VER_CURRENT) {
103 test_fail(__FILE__, __LINE__, "PAPI_library_init failed\n", retval);
104 }
105
106 if (!quiet && rank == 0) {
107 printf("Testing systedect component with PAPI %d.%d.%d\n",
111 }
112
113 void *handle;
114 int enum_modifier = PAPI_DEV_TYPE_ENUM__CUDA;
115
116 while (PAPI_enum_dev_type(enum_modifier, &handle) == PAPI_OK) {
117 if (!quiet) {
118 print_cuda_affinity(MPI_COMM_WORLD, handle);
119 }
120 }
121
122 MPI_Barrier(MPI_COMM_WORLD);
123 if (rank == 0) {
124 test_pass(__FILE__);
125 }
126
127 MPI_Finalize();
129 return 0;
130}
static papi_handle_t handle
Definition: Gamum.c:21
int i
returns handle of next device type
returns device attributes
returns device type attributes
initialize the PAPI library.
Finish using PAPI and free all related resources.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_VERSION
Definition: f90papi.h:193
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_DEV_ATTR__CUDA_ULONG_UID
Definition: f90papi.h:192
#define PAPI_DEV_TYPE_ENUM__CUDA
Definition: f90papi.h:264
#define PAPI_DEV_TYPE_ATTR__INT_COUNT
Definition: f90papi.h:140
#define PAPI_DEV_ATTR__CUDA_CHAR_DEVICE_NAME
Definition: f90papi.h:81
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
Return codes and api definitions.
#define PAPI_VERSION_REVISION(x)
Definition: papi.h:221
#define PAPI_VERSION_MAJOR(x)
Definition: papi.h:219
#define PAPI_VERSION_MINOR(x)
Definition: papi.h:220
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int main()
Definition: pernode.c:20
#define MPI_CALL(call, err_handle)
#define MAX_LOCAL_RANKS
static int cmp_fn(const void *a, const void *b)
static int print_cuda_affinity(MPI_Comm comm, void *handle)
int quiet
Definition: rapl_overflow.c:19
const char * name
Definition: rocs.c:225
int retval
Definition: zero_fork.c:53