Remote update of values

9 views
Skip to first unread message

Mert Hidayetoglu

unread,
May 31, 2024, 4:56:52 PM5/31/24
to gasnet...@lbl.gov

 

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

Mert Hidayetoglu

unread,
May 31, 2024, 7:12:55 PM5/31/24
to gasnet...@lbl.gov

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

Paul H. Hargrove

unread,
Jun 1, 2024, 1:06:16 AM6/1/24
to Mert Hidayetoglu, gasnet...@lbl.gov
Mert,

Active Messages do not, in general, run asynchronously.
You need to call `gasnet_AMPoll()` or a blocking function (such as gex_Event_Wait()) to process in-bound AM Requests and Replies.
The optional receive progress thread in ibv-conduit is an exception, not present for other networks.

You are correct about the need for HSLs if you were doing a non-trivial state change, in particular if multiple threads are running.
However, I believe you can safely eliminate the HSL for the simple case of a `complete` transitioning from 0 to 1.

You could write
    while (!complete) gasnet_AMPoll();
or
   GASNET_BLOCKUNTIL(complete);

If there is a non-trivial transition
   GASNET_BLOCKUNTIL(is_complete());

Where is_complete() is
  int is_complete(void) {

     gex_HSL_Lock(&hsl);

     int result = complete;

     gex_HSL_Unlock(&hsl);

     return result;
  }

I hope that helps.

Have a good weekend,
-Paul


--
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.


--
Paul H. Hargrove <PHHar...@lbl.gov>
Pronouns: he, him, his
Computer Languages & Systems Software (CLaSS) Group
Computer Science Department
Lawrence Berkeley National Laboratory

Mert Hidayetoglu

unread,
Jun 1, 2024, 5:25:08 AM6/1/24
to Paul H. Hargrove, gasnet...@lbl.gov

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

Paul H. Hargrove

unread,
Jun 1, 2024, 2:03:28 PM6/1/24
to Mert Hidayetoglu, gasnet...@lbl.gov
Mert,

I recommend the GASNET_BLOCKUNTIL macro.
In the future, implementations on some systems may be able to block rather than spin poll, reducing energy usage and/or resource contention.

-Paul

Mert Hidayetoglu

unread,
Jun 2, 2024, 4:18:03 AM6/2/24
to Paul H. Hargrove, gasnet...@lbl.gov
Noted with thanks!

Mert

From: Mert Hidayetoglu <me...@stanford.edu>
Sent: Saturday, June 1, 2024 2:25:02 AM
To: Paul H. Hargrove <phhar...@lbl.gov>
Reply all
Reply to author
Forward
0 new messages