gmegan / specification

OpenSHMEM Application Programming Interface
http://www.openshmem.org
1 stars 0 forks source link

Understanding the context destroy operation with respect to SHMEM_CTX_INVALID #143

Open naveen-rn opened 4 years ago

naveen-rn commented 4 years ago

The example code https://github.com/gmegan/specification/blob/teams/example_code/shmem_team_context.c is bit confusing. I'm not sure what is the requirement of the most recent spec where we are trying to destroy a context with SHMEM_CTX_INVALID option. Is it a silent error? Or is it invalid, or is it undefined. If invalid or undefined, then I think the example needs modification.

nspark commented 4 years ago

@naveen-rn I think the first issue you're raising—whether shmem_ctx_destroy(SHMEM_CTX_INVALID) is defined, non-erroneous behavior—should probably be raised on the main spec repo.

IIUC, for the second issue, you're saying the example needs modification because the two team-based contexts, ctx_2s and ctx_3s, may be invalid. Is that correct?

naveen-rn commented 4 years ago

If I'm correct SHMEM_CTX_INVALID is added after OpenSHMEM-1.4.

@nspark As you said, there are two issues I see here:

  1. Clarifying what happens when we destroy a context handle with SHMEM_CTX_INVALID.

The shmem_ctx_destroy API description in the current master branch of the specification says, If \VAR{ctx} has the value \CONST{SHMEM\_CTX\_INVALID}, no operation is performed., while the API notes say the following: It is invalid to pass \CONST{SHMEM\_CTX\_DEFAULT} to this routine.

To me this is confusing. I suppose the intent of this description is that, destroying SHMEM_CTX_INVALID is not allowed and the implementation functionality on seeing this option is return without performing anything - so a silent error. Needs clarification.

  1. Issue in Teams Example:

If we follow the above semantics - then the context destroy in teams example (https://github.com/gmegan/specification/blob/teams/example_code/shmem_team_context.c) is incorrect. We should have a conditional check before destroying the context.

nspark commented 4 years ago

Yes, I forgot that I added SHMEM_CTX_INVALID after OpenSHMEM 1.4

These two statements about shmem_ctx_destroy are not in conflict:

If ctx has the value SHMEM_CTX_INVALID, no operation is performed.

It is invalid to pass SHMEM_CTX_DEFAULT to this routine.

The former makes a call such as shmem_ctx_destroy(SHMEM_CTX_INVALID) well-defined and non-erroneous, akin to the behavior of free(NULL).

The latter is referring to the default context—the now-implicit communication resources of the OpenSHMEM 1.3 API—which should not be destroyed by any user program.