
Hi Folx, Well, the final calls for the SAGA task model are resembling several of the more long running TV soaps by now: there always seems to be another season coming... Anyway, triggered by a comment from Ceriel, we discussed a change to the task model at last OGF, agreed upon accepting it, and this is, as said, the final call for that change. The proposal is as follows: the original task model resulted in the following code (C++): ------------------------------------------------------------ std::size_t len_in = 11; std::char data[12] = "hello world"; std::ssize_t len_out; saga::file f (url); saga::task t = f.read <saga::task::Async> (buffer (data, len_in), &len_out); // some time later, in a different code section t.wait (); std::cout << "read " << len_out << " bytes" << std::endl; ------------------------------------------------------------ That would change to: ------------------------------------------------------------ std::size_t len_in = 11; std::char data[12] = "hello world"; saga::file f (url); saga::task t = f.read <saga::task::Async> (buffer (data, len_in)); // some time later, in a different code section std::ssize_t len_out = t.get_result <std::ssize_t> (); std::cout << "read " << len_out << " bytes" << std::endl; ------------------------------------------------------------ change: - task gets a templatized member function get_result(), which returns the return value of the async funtion after the task gets completed. Calling get_result() implies a wait(). PROs: - no need to carry the return value from task creation to where it is getting used. - no possibility to access the uninitialized return value - sync and async calls have _exactly_ the same signature now, and only differ in their return values. CON: - adding templates for member functions in application space. As a side note: earlier in the evolution of the spec, we dropped the following mechanism: ------------------------------------------------------------ saga::task t = f.seek <saga::task::Async> (where, whence)); // some time later, in a different code section t.wait(); saga::file f2 = (saga::file) t.get_object (); f2.read (...); ------------------------------------------------------------ which allowed to get the originall calling object back from a task, and thus eliminating the need for the application to keep track of task/object relations. That was removed because of the cast implied, and a UUID was added instead to simplify the application level book keeping. However, we could, with the same mechanism, add a type safe get_object again, with no penalty: ------------------------------------------------------------ saga::task t = f.seek <saga::task::Async> (where, whence)); // some time later, in a different code section t.wait(); saga::file f2 = t.get_object <saga::file> (); f2.read (...); ------------------------------------------------------------ which would eliminate (or at least minimize) the need for application level book keeping. Opinions would be very welcome, otherwise the spec gets updated as decided at the last meeting. Thanks, Andre. -- No trees were destroyed in the sending of this message, however, a significant number of electrons were terribly inconvenienced.

Andre,
The proposal is as follows: the original task model resulted in the following code (C++):
------------------------------------------------------------ std::size_t len_in = 11; std::char data[12] = "hello world"; std::ssize_t len_out;
saga::file f (url);
saga::task t = f.read <saga::task::Async> (buffer (data, len_in), &len_out);
// some time later, in a different code section
t.wait (); std::cout << "read " << len_out << " bytes" << std::endl; ------------------------------------------------------------
That would change to:
------------------------------------------------------------ std::size_t len_in = 11; std::char data[12] = "hello world";
saga::file f (url);
saga::task t = f.read <saga::task::Async> (buffer (data, len_in));
// some time later, in a different code section
std::ssize_t len_out = t.get_result <std::ssize_t> ();
std::cout << "read " << len_out << " bytes" << std::endl; ------------------------------------------------------------
change: - task gets a templatized member function get_result(), which returns the return value of the async funtion after the task gets completed. Calling get_result() implies a wait().
PROs: - no need to carry the return value from task creation to where it is getting used. - no possibility to access the uninitialized return value - sync and async calls have _exactly_ the same signature now, and only differ in their return values.
CON: - adding templates for member functions in application space.
I all agree to change it this way, even if I'm a bit hesitant to do so, because it involves an almost complete rewrite of our existing C++ SAGA implementation (at least as far as tasks are involved) and breaks backwards compatibility. Additionally I find it - let's say amusing - that after long discussions around templates, which have been furiously rejected mainly by Java people, we are now back to templates. Is this because our well respected colleagues using Java suddenly discovered to have templates available in newer versions of the language? SCR. :-P Leaves us with the question if this is implementable in other languages as well, such as C, FORTRAN or scripting languages. I'm not sure if that's possible. Especially scripting languages often rely on runtime polymorphism, not compile time polymorphism. Wouldn't it be better to leave the templated interface as an implementation detail and just to require to store the result inside the task? As I said - I'm not sure.
As a side note: earlier in the evolution of the spec, we dropped the following mechanism:
------------------------------------------------------------ saga::task t = f.seek <saga::task::Async> (where, whence));
// some time later, in a different code section
t.wait(); saga::file f2 = (saga::file) t.get_object ();
f2.read (...); ------------------------------------------------------------
which allowed to get the originall calling object back from a task, and thus eliminating the need for the application to keep track of task/object relations.
That was removed because of the cast implied, and a UUID was added instead to simplify the application level book keeping.
However, we could, with the same mechanism, add a type safe get_object again, with no penalty:
------------------------------------------------------------ saga::task t = f.seek <saga::task::Async> (where, whence));
// some time later, in a different code section
t.wait(); saga::file f2 = t.get_object <saga::file> ();
f2.read (...); ------------------------------------------------------------
which would eliminate (or at least minimize) the need for application level book keeping.
Again, I agree with this, but same comments apply as above. Templates should be left as an implementation detail. Furthermore, even in C++, this can be written as: ------------------------------------------------------------ saga::task t = f.seek <saga::task::Async> (where, whence)); // some time later, in a different code section t.wait(); saga::file f2(t.get_object()); f2.read (...); ------------------------------------------------------------ where the constructor takes the saga::object directly, checking for matching types and throwing an exception if not. The disadvantage is that we move the check from compile time to the run time, which is undesireable. OTOH, the get_object<saga::file>() above does enforce the type matching at runtime only as well. So well, we wouldn't loose anything here. The advantage is simplicity and a similar interface if compared with other languages. Regards Hartmut

Hartmut Kaiser wrote:
I all agree to change it this way, even if I'm a bit hesitant to do so, because it involves an almost complete rewrite of our existing C++ SAGA implementation (at least as far as tasks are involved) and breaks backwards compatibility. Additionally I find it - let's say amusing - that after long discussions around templates, which have been furiously rejected mainly by Java people, we are now back to templates. Is this because our well respected colleagues using Java suddenly discovered to have templates available in newer versions of the language? SCR. :-P
Well, as both the "origin" of this change and one of those respected colleagues using Java, I cannot not react to this. I haven't been involved in SAGA for very long, so don't know about the history or any of the discussions that have been going on about templates and/or Java. I just found the way in which tasks were supposed to return their value ugly and cumbersome, because there was no protection against accessing the result value before the task is finished. Therefore I suggested to Andre to do it differently, and to obtain the result from the task object in some way. You don't need generics or templates to do it, you could use type casts as well, but using templates would make it compile-time type-safe.
Leaves us with the question if this is implementable in other languages as well, such as C, FORTRAN or scripting languages. I'm not sure if that's possible. Especially scripting languages often rely on runtime polymorphism, not compile time polymorphism. Wouldn't it be better to leave the templated interface as an implementation detail and just to require to store the result inside the task? As I said - I'm not sure.
I agree with this. It is an implementation detail. It is up to the implementation to provide a mechanism for obtaining the result from the task, and give an exception if this is attempted while the task is not finished yet. If the specification language used for SAGA allows for templates, I would suggest to use them, but to specify that an implementation is allowed to use runtime polymorphism instead. Ceriel Jacobs
participants (3)
-
Andre Merzky
-
Ceriel JH Jacobs
-
Hartmut Kaiser