Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

C support for multiport iterator for sparse inputs #95

Merged
merged 24 commits into from
Jul 23, 2022
Merged

Conversation

edwardalee
Copy link
Contributor

This PR enables more efficient access to input multiports that are sparse, meaning that few of the channels (typically) have inputs present. This is used as in the following example:

     @sparse
     input[100] in:int;
     reaction(in) {=
         struct lf_multiport_iterator_t i = lf_multiport_iterator(in_ping);
         while(i.next >= 0) {
             // Input channel i.next is present.
             printf("Received %d on channel %d.\n", in[i.next]->value, i.next);
             lf_multiport_iterator_advance(&i);
         }
    =}

In my informal measurement, this yields a 15% improvement in the unthreaded execution of the Big benchmark (with the default setting of 120 Worker reactors).

@edwardalee edwardalee changed the title Input iterator C support for multiport iterator for sparse inputs Jul 20, 2022
@petervdonovan
Copy link
Contributor

petervdonovan commented Jul 22, 2022

Directly including port.c in reactor_common.c seems to have worked for AppleClang. It is a hack, but we do it in a lot of places, and we may have a full refactoring of the C build process in the near future anyway. Perhaps it would be most expedient to apply that "fix" here and move on?

Edit: Sorry, never mind, I just saw that that causes other problems, which everyone was probably already aware of.

@petervdonovan
Copy link
Contributor

I moved forward with the "hack" I described above, and everything seems to compile now. I propose to merge this branch without bothering to make the build process work "the right way." These kinds of problems might better be addressed by more comprehensive work on the build system to make it more like reactor-cpp. Related: lf-lang/lingua-franca#1245

Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! It looks like if the @sparse annotation is omitted, the iterator just checks all channels, which is the right thing to do.

@lhstrh lhstrh merged commit 0a19794 into main Jul 23, 2022
@lhstrh lhstrh deleted the input-iterator branch July 23, 2022 00:19
@cmnrd
Copy link
Contributor

cmnrd commented Jul 25, 2022

Do we have any results on the performance of this change?

@petervdonovan
Copy link
Contributor

In case anyone is still curious, the Apple Clang bug is explained in this StackOverflow post and will be fixed in c-refactoring2.

(@cmnrd, the decrease in execution time was reported as roughly 15% for the unthreaded runtime.)

@lhstrh lhstrh added the enhancement Enhancement of existing feature label Feb 23, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement Enhancement of existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants