---
name: "pvm_newcontext"
section: "3"
platform: "linux"
package: "pvm-dev"
version: "3.4.2-8"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/pvm_newcontext"
---

# pvm\_newcontext(3)

Request new context. pvm\_setcontext - Change context. pvm\_freecontext - Free existing context. pvm\_getcontext - Get current context.

## NAME

pvm\_newcontext - Request new context.\
 pvm\_setcontext - Change context.\
 pvm\_freecontext - Free existing context.\
 pvm\_getcontext - Get current context.

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

  **Context value.**

- new\_ctx

  **New context value.**

- old\_ctx

  **Prior context value.**

- info

  **Result code.**

## DESCRIPTION

**The context functions provide a system-wide unique context and** **the means to manipulate this context.**

**Contexts provide the ability for communicating tasks to automatically** **differentiate messages by the context in which they were sent.** **Thus a message sent in context A by the sender must be received** **in context A by the recipient.  A sender may send in any context.** **However, a recipient will not accept a message sent in a context**  **that differs from its own.**

**One such use of contexts is with library routines.  Using contexts,** **library routine inter-communication may be logically seperated from the**  **user's application inter-communication. This will prevent the inadvertent** **receipt of one another's messages.**

**Spawned tasks inherit the spawn-time context of their parent.** **Existing PVM applications work unchanged using the default context.**

**pvm\_newcontext returns a newly allocated context.** **However, this new context is not yet active.**

**pvm\_setcontext changes the current context from**  *old\_ctx* to *new\_ctx*.

pvm\_freecontext frees *ctx* so that it may be reused. Contexts are a system resource that will be exhausted if not recycled.

pvm\_getcontext returns the current context of the requesting task.

## EXAMPLES

```
/* 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 - 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

Only system resource errors will be returned as the context programs themselves do not generate errors.

## SEE ALSO
