GETFDS(3PVM)

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

πŸ’– GETFDS(3PVM) β€” the pvm_getfds page, bestie edition πŸ’–

okay so you're here because you want the actual file descriptor numbers PVM is secretly using, right? valid. iconic. let's go 🫢

This is pvm_getfds from PVM Version 3.4, and it's giving "I need to select() on PVM and my keyboard at the same time" energy. sit down, hydrate, we're doing this ✨


🌸 NAME 🌸

pvm_getfds β€” get the file descriptors that PVM is currently using, no cap.


πŸŽ€ SYNOPSIS πŸŽ€

int nfds = pvm_getfds( int **fds )

Fortran β€” Not Available πŸ™ˆ (sorry to the Fortran girlies, it's literally just not there)


πŸ¦‹ PARAMETERS πŸ¦‹

  • fds β€” returns you an integer array of file descriptors. it's the whole point. that's the girl. πŸ’…

✨ DESCRIPTION ✨

so a PVM task talks over sockets β€” between libpvm and your other tasks, or between libpvm and the pvmd. and sometimes you really wanna know the actual file descriptor numbers of those sockets, because you want to wait for input from either PVM messages or some external source. like, both. at once. multitasking queen. πŸ‘‘

for example (and this is literally in the docs, so it's canon), the PVM console waits on both keyboard input and notify messages. you could multiplex input by polling every source, but bestie… that wastes CPU cycles. so wasteful. instead you use the select() system call to just chill until one or more sources of input are ready. much better. slay. πŸ”₯

if it completes successfully, pvm_getfds returns the number of sockets in use, and drops the file descriptor numbers into an array (which is allocated and freed by libpvm β€” she handles it, don't worry about it 🫢). at least one socket always exists (that's the task-to-pvmd one), and its descriptor is always fds[0]. the number of sockets varies as direct routes get established to other tasks. so it's a moving target, lowkey.

and here's the part where it gets spicy: it can be difficult to track the set of file descriptors if direct routing is enabled, because routes are created as messages are either sent or received. 😭 the simplest approach? just disable direct routing. periodt.

also, when select returns with a PVM file descriptor ready, a complete message may be ready to be received β€” or instead only a fragment may be waiting. πŸ‘€ so you should use pvm_nrecv or pvm_probe to test without blocking. do not skip this step, i'm begging.


🚧 RESTRICTIONS 🚧

pvm_getfds is only available when running PVM on a Unix or similar system. that's the vibe check and you either pass it or you don't πŸ’€


🌈 EXAMPLES 🌈

this little program fragment waits until either keyboard input is available, or a PVM message has arrived. copy it, love it, run it:

int *d;
fd_set r;

pvm_setopt(PvmRoute, PvmDontRoute);
pvm_getfds(&d);

FD_ZERO(&r);
FD_SET(0, &r);
FD_SET(d[0], &r);
while (1) {
     if (select(d[0] + 1, &r, (fd_set*)0, (fd_set*)0,
                (struct timeval*)0) > 0) {
          if (FD_ISSET(0, &r))
               ...    /* read keyboard input */
          if (FD_ISSET(d[0], &r) && pvm_nrecv(-1, -1) > 0)
               ...    /* got a PVM message */
     }
}

😭 ERRORS 😭

the following error condition can be returned by pvm_getfds:

  • PvmSysErr β€” pvmd not responding. she's ghosting you. πŸ‘»

πŸ‘‘ SEE ALSO πŸ‘‘

  • pvm_notify(3PVM)
  • pvm_trecv(3PVM)

fr fr, the one thing to remember: at least one socket always exists, its descriptor is always fds[0], and the array is allocated and freed by libpvm. don't you dare free it yourself. πŸ’€

and that's the whole page, bestie!! this was PVM Version 3.4, dated 22 Nov, 1994 β€” yeah she's vintage, she's an elder icon, and she still ate. mwah πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from