Hi all,
I am trying to understand the AM mechanism for updating remote values. I wrote a simple program below to block remote process until the AM function is called on the receiver side. However, the receiver process never gets out of the while loop.
Is there a way to make sure to provide consistency without using a barrier?
int complete = 1;
void am_handler (gex_Token_t token) { complete = 1; }
int main() {
…
int sender = 3;
int recver = 0;
if (myrank == recver)
complete = 0;
gex_Event_Wait(gex_Coll_barrierNB(myteam, 0));
if (myrank == sender)
gex_AM_RequestShort0 (myteam, recver, GEX_AM_INDEX_BASE, 0);
while (!complete);
gex_Event_Wait (gex_Coll_barrierNB(myteam, 0));
}
I appreciate any help to understand proper way of updating remote values.
Best regards,
Mert
I understand that I need to use HSL for ensuring consistency: https://gasnet.lbl.gov/docs/gasnet.html#Handler_002dSafe-Locks
I updated my code accordingly, but I am still missing something because the receiver process does not break out of the loop.
Am I placing the locks & unlocks at the right locations?
int complete = 1;
gex_HSL_t hsl = GEX_HSL_INITIALIZER;
void am_handler (gex_Token_t token) {
gex_HSL_Lock(&hsl);
complete = 1;
gex_HSL_Unlock(&hsl);
}
int main() {
…
int sender = 3;
int recver = 0;
if (myrank == recver)
complete = 0;
gex_Event_Wait(gex_Coll_barrierNB(myteam, 0));
if (myrank == sender)
gex_AM_RequestShort0 (myteam, recver, GEX_AM_INDEX_BASE, 0);
do {
gex_HSL_Lock(&hsl);
if (complete) {
gex_HSL_Unlock(&hsl); // leave no HSL locked
break;
}
gex_HSL_Unlock(&hsl);
} while (true)
gex_Event_Wait (gex_Coll_barrierNB(myteam, 0));
}
I appreciate any help to understand proper way of using HSL mechanism.
Best regards,
Mert
gex_HSL_Lock(&hsl);
int result = complete;
gex_HSL_Unlock(&hsl);
--
You received this message because you are subscribed to the Google Groups "gasnet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gasnet-users...@lbl.gov.
To view this discussion on the web visit https://groups.google.com/a/lbl.gov/d/msgid/gasnet-users/SJ0PR02MB73575C9F36D9A2C4E6D41CF9D1FC2%40SJ0PR02MB7357.namprd02.prod.outlook.com.
Thanks for your help, Paul! gasnet_AMPoll() solves the problem. As you said, the update in my example is trivial, so no need for HSL unless multiple threads try to update the same value.
“
You could write
while (!complete) gasnet_AMPoll();
or
GASNET_BLOCKUNTIL(complete);
”
I found GASNET_BLOCKUNTIL macro handy. What are the implications of choosing one over the other? Should I assume the macro is preferred over looping over gasnet_AMPoll() in this case?
Mert