ADDMHF(3PVM)

πŸ“¦ version 3.4.6, in debian bookworm, ubuntu jammy

✨ ADDMHF ✨

okay bestie, pvm_addmhf and pvm_delmhf from PVM Version 3.4 β€” literally the "install a message handler" and "yeet a message handler" duo, and I'm gonna walk you through it like we're texting at 2am 🫢


πŸ’– NAME πŸ’–

pvm_addmhf, pvm_delmhf β€” install or remove message-handler functions. that's it, that's the whole vibe. one puts a handler in, one takes it out, no cap ✨


🌸 SYNOPSIS 🌸

C    int mhid = pvm_addmhf( int src, int tag, int ctx, int (*func)(int mid) )
     int info = pvm_delmhf( int mhid )

Fortran   Not available

Fortran girlies... not available, sorry bestie 😭 it's a C-only situation, periodt.


πŸŽ€ PARAMETERS πŸŽ€

  • src β€” the tid of the sender. like, who's sending this thing.
  • tag β€” the tag that got sent with the message.
  • ctx β€” the context sent with the message.
  • func β€” the function to call when the message is received. your little callback bff πŸ’…
  • mhid β€” message handler id. the receipt for your handler.
  • info β€” result code.
  • mid β€” message buffer identifier for the new active receive buffer.

✨ DESCRIPTION ✨

So pvm_addmhf specifies a function that gets called whenever libpvm copies in a message whose header fields of src, tag, and ctx match those provided to pvm_addmhf(). matching header = handler goes brrr πŸ”₯

The src and tag fields may be left unspecified (wildcard) by setting to -1. yes bestie, wildcards, we love a flexible queen πŸ‘‘

The calling sequence of the message handler function is:

int handler( int mid )

Where mid is the bufid of the received message. The handler function can be used to unpack and process the received message buffer. PVM automatically saves the current send and receive buffers, so the handler need not worry about interfering with message buffers in the regular program flow. PVM also sets the current receive buffer to the received message (using pvm_setrbuf()) before invoking the message handler, so the message can be unpacked directly. PVM will free this message buffer when the message handler returns, if the handler has not already done so. But, any other message buffers created by the handler routine should be freed using pvm_freebuf() before returning. cleanup is self-care, fr fr 🧚

Note: Operation in the message handler context is somewhat restricted. The function may call some PVM functions, but not others. read that again bestie, it's giving "you can't do everything in here."

For example, it may compose and send a reply message as shown:

pvm_packf( "%+ %s", PvmDataDefault, "got your message" );
pvm_send( tid, tag );
pvm_freebuf( pvm_setsbuf( 0 ) );

or equivalently:

pvm_setsbuf( pvm_mkbuf( PvmDataDefault ) );
pvm_pkstr( "got your message" );
pvm_send( tid, tag );
pvm_freebuf( pvm_setsbuf( 0 ) );

but is not allowed to call certain other PVM communication functions, such as multicast or receive. πŸ’€ yeah. those are off-limits in here.

pvm_addmhf returns the id number of the newly created message handler if successful; this number may be passed to pvm_delmhf to remove the entry. There is no guarantee to the ordering of id values returned by pvm_addmhf, or to the order in which message handlers will be invoked. PvmExists is returned if the handler already exists.

pvm_delmhf returns PvmOk if successful. PvmBadParam if pvm_delmhf is passed a negative id value. PvmNotFound if the id value is not found.


πŸ¦‹ EXAMPLES πŸ¦‹

/* Print a message when hosts are added to virtual machine */

int
hostAdded( int mid )
{
     int n;
     pvm_unpackf( "%d", &n );
     printf( "*** %d new hosts just added ***\n", n );
}

void
main()
{
     int src, tag, ctx;

     . . .

     src = -1;
     tag = 99;
     ctx = -1;

     pvm_addmhf( src, tag, ctx, hostAdded );
     pvm_notify( PvmHostAdd, 99, -1, (int *) NULL );

     . . .
}

look at her go 😭 iconic behavior honestly


🌈 ERRORS 🌈

The following error conditions can be returned by pvm_addmhf():

  • PvmExists β€” Can't insert as handler already exists with same (tag, ctx, src) including "wild-cards" (those set to -1). yeah, no duplicates, we don't do that here πŸ’…

The following error conditions can be returned by pvm_delmhf():

  • PvmBadParam β€” Invalid (negative) mhid passed in.
  • PvmNotFound β€” Message handler mhid does not exist. she's not here, bestie πŸ™ˆ

πŸ‘‘ SEE ALSO πŸ‘‘

  • pvm_setrbuf(3PVM)
  • pvm_setsbuf(3PVM)
  • pvm_freebuf(3PVM)

and that's the whole page, bestie πŸ’œ this was PVM Version 3.4, dated 1 April, 1997 β€” go forth and handle those messages, you absolute main character πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from