Default construction of future, promise, global_ptr and persona before init()

Issue #90 resolved
Amir Kamil created an issue

The spec requires UPC++ to be initialized before any UPC++ function can be called. This prohibits any UPC++ type from having static storage duration (since initializing it would entail a call to its constructor). This includes global pointers, which should likely be exempt from this restriction, as it prevents an application from keeping track of global pointers in static storage.

I suggest that we slightly loosen this restriction to something like the following: Unless otherwise stated, it is illegal to call a UPC++ function, including a constructor, when UPC++ is in the uninitialized state. We then exempt the following functions from this restriction:

  • init()
  • global_ptr<T>::global_ptr(std::nullptr_t)
  • global_ptr<T>::global_ptr() (This doesn't exist at the moment, but it would be nice for global_ptr to be DefaultConstructible. This would just construct a null pointer. It would likely necessitate a rank-independent representation of a null global pointer, which our implementation already does.)

Comments (10)

  1. Dan Bonachea

    I agree with all of Amir's observations.

    For the same usability reasons, we may also want to allow the default constructor for DefaultConstructible types upcxx::promise<...T> and upcxx:persona. However these might entail more significant implementation effort.

    I'm not even sure what the semantics of a default constructed persona would be, except to serve as an empty variable that will be overwritten by a real persona after init.

  2. Scott Baden

    Would is be accurate to say that, anything requiring progress is off-limits? I'm not sure because of Amir's comment "a rank-independent representation of a null global pointer."

  3. Amir Kamil reporter

    I don't think that's a sufficient restriction. My comment was alluding to the fact that global pointers contain a rank as part of their representation, and rank_me() would not be available before initialization. Thus, their must be a representation of null that does not depend on knowing the rank of the creator.

  4. Amir Kamil reporter

    My implementation uses a rank of 0 to represent a global pointer, regardless of which rank creates the pointer.

  5. Dan Bonachea

    For the record, we think future<T> should also be made DefaultConstructible and declarable at static scope, for the convenience of a statically-scoped container to hold futures created at runtime. The "null" future created should by the default constructor should probably just be trivially ready (or trivially never ready).

  6. Dan Bonachea

    At the 8-9-17 Pagoda meeting we resolved that future, promise, global_ptr and possibly persona should all be DefaultConstructible and declarable at static scope. This needs to be added to the spec, along with the semantics for a default constructed object of each type (ie when functions are called on them after init).

    team and dist_object need to still prohibit default construction due to the collective initialization requirement and the lack of ordering guarantees for static initializers in general.

  7. Log in to comment