CONTEXT(3PVM)

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

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

okay so bestie, this is the PVM Version 3.4 page for contexts, and honestly? it's giving "group chat for your processes but with receipts." the functions are pvm_newcontext, pvm_setcontext, pvm_freecontext, and pvm_getcontext β€” and yes, that's four whole queens, each doing one job. requesting a new context, changing context, freeing an existing context, and getting the current context. respectively, periodt. πŸ’…


✨ NAME ✨

pvm_newcontext, pvm_setcontext, pvm_freecontext, pvm_getcontext β€” request new context, change context, free existing context, and get current context, respectively.


πŸ¦‹ SYNOPSIS πŸ¦‹

C:

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

Fortran:

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

πŸŽ€ PARAMETERS πŸŽ€

  • ctx β€” a context value. just a little guy holding a number πŸ’–
  • new_ctx β€” the new context value. the upgrade. the glow-up. ✨
  • old_ctx β€” the prior context value, aka where you were before.
  • info β€” result code. it tells you how it went.

🌸 DESCRIPTION 🌸

so the context functions give you a system-wide unique context plus all the tools to manipulate it. that's the whole vibe.

contexts are literally how communicating tasks automatically tell messages apart by the context they were sent in. so a message sent in context A by the sender must be received in context A by the recipient. a sender can send in any context it wants, no rules, live your truth. but a recipient will not accept a message sent in a context that's different from its own. it's not being rude, it's just boundaries. 🫢

one use for contexts is library routines. with contexts, a library routine's inter-communication can be logically separated from the user's application inter-communication. that way nobody accidentally receives the other one's messages, which is a whole mess you simply do not need. πŸ’€

spawned tasks inherit the spawn-time context of their parent β€” yes, the family trauma is inherited too, but here it's a feature. and existing PVM applications work unchanged using the default context. no cap. πŸ‘‘

here's each function, one by one:

  • pvm_newcontext returns a newly allocated context. but heads up bestie β€” 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.
  • pvm_freecontext frees ctx so that it may be reused. and listen β€” contexts are a system resource that will be exhausted if you don't recycle them. so free them. don't hoard them. that's not the vibe. πŸ—‘οΈ
  • pvm_getcontext returns the current context of the requesting task.

🌈 EXAMPLES 🌈

parent task with context:

/* 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 remember, the child inherits the parent's context as its default:

/* 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, only system resource errors will be returned. that's it. because the context programs themselves do not generate errors β€” they're that well-behaved. iconic behaviour, honestly.


πŸ”₯ SEE ALSO πŸ”₯

nothing here, bestie. this page is standing on its own two feet. main character energy only. πŸ’…

the cute sign-off β€” this was CONTEXT(3PVM) from PVM Version 3.4, dated 8 April, 1997. yeah, she's vintage. she's still slaying. take care of your contexts and they'll take care of you. πŸ¦‹βœ¨πŸŽ€

πŸ“¦ where this page comes from