HPCToolkit
rank.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // This file generalizes how hpcrun computes the 'rank' of a process,
54 // eg: MPI, dmapp, gasnet, etc.
55 //
56 // For now, this API acts passively, that is, it waits for something
57 // else in hpcrun to ask what is the rank. But we may need to
58 // generalize this to actively find the rank in some cases.
59 //
60 // Note: we kinda assume that all methods (if available) return
61 // consistent answers.
62 //
63 //***************************************************************************
64 
65 #include <stdint.h>
66 #include <monitor.h>
67 #include "rank.h"
68 
69 struct jobinfo {
70  int version;
72  int npes;
73  int pe;
74  long pad[20];
75 };
76 
77 int dmapp_get_jobinfo(struct jobinfo *info);
78 
79 extern int32_t gasneti_mynode;
80 
81 
82 //***************************************************************************
83 // interface functions
84 //***************************************************************************
85 
86 // Returns: generalized rank, or else -1 if unknown or unavailable.
87 //
88 int
90 {
91  int rank;
92 
93  rank = monitor_mpi_comm_rank();
94  if (rank >= 0) {
95  return rank;
96  }
97 
98  // Dmapp only runs on Cray systems which pretty much run only static
99  // binaries. The dynamic case probably works but is currently
100  // untested (because there are few or no examples), so ifdef it out
101  // for now.
102  //
103 #ifdef HPCRUN_STATIC_LINK
104  struct jobinfo info;
105  if (dmapp_get_jobinfo(&info) == 0) {
106  rank = info.pe;
107  if (rank >= 0) {
108  return rank;
109  }
110  }
111 #endif
112 
113  // Gasnet stores the rank in a global variable and <gasnet.h> makes
114  // heavy use of macros. So, there is no gasnet_mynode() function to
115  // call. We can catch the variable statically via hpclink, but
116  // basically there's no hope for the dynamic case.
117  //
118 #ifdef HPCRUN_STATIC_LINK
119  rank = (int) gasneti_mynode;
120  if (rank >= 0) {
121  return rank;
122  }
123 #endif
124 
125  return -1;
126 }
int hw_version
Definition: rank.c:71
int dmapp_get_jobinfo(struct jobinfo *info)
int version
Definition: rank.c:70
Definition: rank.c:69
int npes
Definition: rank.c:72
int pe
Definition: rank.c:73
int hpcrun_get_rank(void)
Definition: rank.c:89
long pad[20]
Definition: rank.c:74
int32_t gasneti_mynode