1616#include "orte/runtime/orte_globals.h"
1717#include "orte/mca/errmgr/errmgr.h"
1818
19+ static int rank , size ;
1920static volatile int active ;
2021static volatile bool wait_for_release = true;
2122#define MEMPROBE_RELEASE 12345
@@ -26,9 +27,10 @@ static void _release_fn(int status,
2627 opal_pmix_notification_complete_fn_t cbfunc ,
2728 void * cbdata )
2829{
30+ fprintf (stderr , "Rank %d: Release recvd\n" , rank );
2931 /* must let the notifier know we are done */
3032 if (NULL != cbfunc ) {
31- cbfunc (0 , NULL , NULL , NULL , cbdata );
33+ cbfunc (OPAL_ERR_HANDLERS_COMPLETE , NULL , NULL , NULL , cbdata );
3234 }
3335 /* flag that the debugger is complete so we can exit */
3436 wait_for_release = false;
@@ -47,20 +49,39 @@ static void _register_fn(int status,
4749 * active = status ;
4850}
4951
52+ static void qcbfunc (int status ,
53+ opal_list_t * info ,
54+ void * cbdata ,
55+ opal_pmix_release_cbfunc_t release_fn ,
56+ void * release_cbdata )
57+ {
58+ opal_list_t * results = (opal_list_t * )cbdata ;
59+ opal_value_t * kv ;
60+
61+ fprintf (stderr , "Rank %d: Query returned status %d\n" , rank , status );
62+ if (NULL != info ) {
63+ while (NULL != (kv = (opal_value_t * )opal_list_remove_first (info ))) {
64+ opal_list_append (results , & kv -> super );
65+ }
66+ }
67+ if (NULL != release_fn ) {
68+ release_fn (release_cbdata );
69+ }
70+ wait_for_release = false;
71+ }
72+
5073int main (int argc , char * argv [])
5174{
52- int rank , size ;
5375 opal_list_t * codes ;
5476 opal_value_t * kv ;
77+ opal_pmix_query_t * q ;
78+ opal_list_t query , response ;
5579
5680 MPI_Init (& argc , & argv );
5781 MPI_Comm_rank (MPI_COMM_WORLD , & rank );
5882 MPI_Comm_size (MPI_COMM_WORLD , & size );
5983
60- if (0 == rank ) {
61- fprintf (stderr , "Sampling memory usage after MPI_Init\n" );
62- }
63-
84+ /* everyone registers their event handler */
6485 codes = OBJ_NEW (opal_list_t );
6586 kv = OBJ_NEW (opal_value_t );
6687 kv -> key = strdup ("errorcode" );
@@ -74,9 +95,59 @@ int main(int argc, char* argv[])
7495 usleep (10 );
7596 }
7697
77- /* now wait for notification */
78- while (wait_for_release ) {
79- usleep (10 );
98+ /* rank 0 asks for memory to be sampled, while everyone else waits */
99+ if (0 == rank ) {
100+ fprintf (stderr , "Sampling memory usage after MPI_Init\n" );
101+ OBJ_CONSTRUCT (& query , opal_list_t );
102+ OBJ_CONSTRUCT (& response , opal_list_t );
103+ q = OBJ_NEW (opal_pmix_query_t );
104+ opal_list_append (& query , & q -> super );
105+ opal_argv_append_nosize (& q -> keys , OPAL_PMIX_QUERY_MEMORY_USAGE );
106+ /* qualify that we just want avg, min/max values reported */
107+ kv = OBJ_NEW (opal_value_t );
108+ kv -> key = strdup (OPAL_PMIX_QUERY_REPORT_AVG );
109+ kv -> type = OPAL_BOOL ;
110+ kv -> data .flag = true;
111+ opal_list_append (& q -> qualifiers , & kv -> super );
112+ kv = OBJ_NEW (opal_value_t );
113+ kv -> key = strdup (OPAL_PMIX_QUERY_REPORT_MINMAX );
114+ kv -> type = OPAL_BOOL ;
115+ kv -> data .flag = true;
116+ opal_list_append (& q -> qualifiers , & kv -> super );
117+ /* issue the request */
118+ wait_for_release = true;
119+ opal_pmix .query (& query , qcbfunc , (void * )& response );
120+ while (wait_for_release ) {
121+ usleep (10 );
122+ }
123+ /* output the results */
124+ OPAL_LIST_FOREACH (kv , & response , opal_value_t ) {
125+ fprintf (stderr , "\tResults: %s\n" , kv -> key );
126+ }
127+ OPAL_LIST_DESTRUCT (& response );
128+ /* send the notification to release the other procs */
129+ wait_for_release = true;
130+ OBJ_CONSTRUCT (& response , opal_list_t );
131+ kv = OBJ_NEW (opal_value_t );
132+ kv -> key = strdup (OPAL_PMIX_EVENT_NON_DEFAULT );
133+ kv -> type = OPAL_BOOL ;
134+ kv -> data .flag = true;
135+ opal_list_append (& response , & kv -> super );
136+ if (OPAL_SUCCESS != opal_pmix .notify_event (MEMPROBE_RELEASE , NULL ,
137+ OPAL_PMIX_RANGE_GLOBAL , & response ,
138+ NULL , NULL )) {
139+ fprintf (stderr , "Notify event failed\n" );
140+ exit (1 );
141+ }
142+ while (wait_for_release ) {
143+ usleep (10 );
144+ }
145+ OPAL_LIST_DESTRUCT (& response );
146+ } else {
147+ /* now wait for notification */
148+ while (wait_for_release ) {
149+ usleep (10 );
150+ }
80151 }
81152 wait_for_release = true;
82153
@@ -86,13 +157,60 @@ int main(int argc, char* argv[])
86157
87158 if (0 == rank ) {
88159 fprintf (stderr , "\n\nSampling memory usage after MPI_Barrier\n" );
160+ OBJ_CONSTRUCT (& query , opal_list_t );
161+ OBJ_CONSTRUCT (& response , opal_list_t );
162+ q = OBJ_NEW (opal_pmix_query_t );
163+ opal_list_append (& query , & q -> super );
164+ opal_argv_append_nosize (& q -> keys , OPAL_PMIX_QUERY_MEMORY_USAGE );
165+ /* qualify that we just want avg, min/max values reported */
166+ kv = OBJ_NEW (opal_value_t );
167+ kv -> key = strdup (OPAL_PMIX_QUERY_REPORT_AVG );
168+ kv -> type = OPAL_BOOL ;
169+ kv -> data .flag = true;
170+ opal_list_append (& q -> qualifiers , & kv -> super );
171+ kv = OBJ_NEW (opal_value_t );
172+ kv -> key = strdup (OPAL_PMIX_QUERY_REPORT_MINMAX );
173+ kv -> type = OPAL_BOOL ;
174+ kv -> data .flag = true;
175+ opal_list_append (& q -> qualifiers , & kv -> super );
176+ /* issue the request */
177+ wait_for_release = true;
178+ opal_pmix .query (& query , qcbfunc , (void * )& response );
179+ while (wait_for_release ) {
180+ usleep (10 );
181+ }
182+ /* output the results */
183+ OPAL_LIST_FOREACH (kv , & response , opal_value_t ) {
184+ fprintf (stderr , "\tResults: %s\n" , kv -> key );
185+ }
186+ OPAL_LIST_DESTRUCT (& response );
187+ /* send the notification to release the other procs */
188+ wait_for_release = true;
189+ OBJ_CONSTRUCT (& response , opal_list_t );
190+ kv = OBJ_NEW (opal_value_t );
191+ kv -> key = strdup (OPAL_PMIX_EVENT_NON_DEFAULT );
192+ kv -> type = OPAL_BOOL ;
193+ kv -> data .flag = true;
194+ opal_list_append (& response , & kv -> super );
195+ if (OPAL_SUCCESS != opal_pmix .notify_event (MEMPROBE_RELEASE , NULL ,
196+ OPAL_PMIX_RANGE_GLOBAL , & response ,
197+ NULL , NULL )) {
198+ fprintf (stderr , "Notify event failed\n" );
199+ exit (1 );
200+ }
201+ while (wait_for_release ) {
202+ usleep (10 );
203+ }
204+ OPAL_LIST_DESTRUCT (& response );
205+ } else {
206+ /* wait again while memory is sampled */
207+ while (wait_for_release ) {
208+ usleep (10 );
209+ }
89210 }
90211
91- /* wait again while memory is sampled */
92- while (wait_for_release ) {
93- usleep (10 );
94- }
95-
212+ fprintf (stderr , "%d: FINALIZING\n" , rank );
213+ fflush (stderr );
96214 MPI_Finalize ();
97215 return 0 ;
98216}
0 commit comments