CONTEXT(3PVM)

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

πŸ’– CONTEXT(3PVM) πŸ’–

okay bestie, so this is a page from the PVM Version 3.4 manual, and it's literally all about contexts. yes. contexts. the glow-up your messages needed so they don't get mixed up with everybody else's. stay with me, it's actually so good.


✨ NAME ✨

pvm_newcontext, pvm_setcontext, pvm_freecontext, pvm_getcontext β€” these four are the squad, and respectively they: request a new context, change context, free an existing context, and get the current context. that's the whole vibe check. πŸŽ€


🌸 SYNOPSIS 🌸

C side of things:

int ctx = pvm_newcontext( void )
int old_ctx = pvm_setcontext( int new_ctx )
int info = pvm_freecontext( ctx )
int ctx = pvm_getcontext( void )

Fortran side of things:

call pvmfnewcontext( ctx )
call pvmfsetcontext( new_ctx, old_ctx )
call pvmffreecontext( ctx, info )
call pvmfgetcontext( ctx )

πŸ¦‹ PARAMETERS πŸ¦‹

  • ctx β€” the context value itself. that's her. πŸ‘‘
  • new_ctx β€” the new context value, as in the one you're switching to.
  • old_ctx β€” the prior context value, the one you're leaving behind like a text you're not gonna reply to.
  • info β€” result code. it's giving "receipts".

πŸ’… DESCRIPTION πŸ’…

so here's the tea: the context functions hand you a system-wide unique context and give you all the tools to manipulate it. iconic behaviour, honestly.

contexts are the reason communicating tasks can automatically tell messages apart based on which context they were sent in. no cap. so like, if a message gets sent in context A by the sender, it must be received in context A by the recipient. the sender can send in any context they want, sure. but a recipient will not accept a message sent in a context that differs from its own. boundaries, bestie. we love them.

one big use of contexts? library routines. with contexts, library routine inter-communication can be logically seperated from the user's application inter-communication. translation: nobody accidentally receives somebody else's messages ever again. prevented. slay. 🫢

spawned tasks inherit the spawn-time context of their parent. it's hereditary, it's generational, it's the family business. and existing PVM applications? they work unchanged using the default context. no migration arc needed.

okay now the four besties one by one:

  • pvm_newcontext returns a newly allocated context. but heads up: this new context is not yet active. it exists, it's just not the main character yet. πŸ™ˆ
  • pvm_setcontext changes the current context from old_ctx to new_ctx. the switcheroo.
  • pvm_freecontext frees ctx so that it may be reused. contexts are a system resource and they will be exhausted if not recycled. yes this is a real warning. recycle your contexts or the whole thing runs out. periodt. πŸ’€
  • pvm_getcontext returns the current context of the requesting task. "who am I right now?" answered.

🌈 EXAMPLES 🌈

parent task with context β€” look at her go:

/* parent task with context */
     int cc, context0, context1;
     char buf[25];

     context0 = pvm_getcontext();       /*  get my current context */
     context1 = pvm_newcontext();       /*  get a new context */
     pvm_setcontext(context1);          /*  set my context to new context */
     printf("My context is: %d", context1);
     pvm_spawn("child", (char**)0, PvmTaskDefault, "", 1, &tid);
     cc = pvm_recv(-1, -1);             /*  receive message from child - in context1 */
     pvm_upkstr(buf);
     printf("%s", buf);
     pvm_setcontext(context0);          /*  reset my context to my original context0 */

child task with context β€” and the child inherits the parent's context as the default, as promised:

/* child task with context - child inherits parent's context as default */
     int context;
     int ptid;
     char buf[25];

     ptid = pvm_parent();
     context = pvm_getcontext();        /*  get my current context */
     sprintf(buf, "Greetings from child who's context is: %d.", context);
     pvm_initsend(PvmDataDefault);
     pvm_pkstr(buf);
     pvm_send(ptid, 1);

😭 ERRORS 😭

ngl this part is chill: only system resource errors will be returned, because the context programs themselves do not generate errors. they simply do not miss. ✨


πŸ‘‘ SEE ALSO πŸ‘‘

that's it, that's the section. the original really did just leave this one empty, bestie. not me checking twice. πŸ“

okay that's the whole page, and yes we made it. this was the CONTEXT(3PVM) page from PVM Version 3.4, dated 8 April, 1997. she's older than most of us and she still ate. πŸ’œβœ¨ go recycle your contexts, mwah. 🧚

πŸ“¦ where this page comes from