Macroprogramming: Difference between revisions

Content deleted Content added
Examples in some macroprogramming languages + minor fix
Fixed grammar
Tags: canned edit summary Mobile edit Mobile app edit iOS app edit App section source
 
(22 intermediate revisions by 12 users not shown)
Line 1:
{{Short description|Programming paradigm to program distributed systems with a single program by a global perspective.}}
{{distinguish|Macro (programming)}}
In [[computer science]], '''macroprogramming''' is a [[programming paradigm]]
Inaimed [[computerat science]],expressing '''macroprogramming'''the ismacroscopic, aglobal [[programming paradigm]] where programs for the individual componentsbehaviour of aan [[distributedentire system]] areof compiledagents or interpretedcomputing from a ''macro-program'' expressed by a system-level perspective or in terms of the intended global goaldevices.<ref name="Casadei 2023">{{cite journal | last=Casadei | first=Roberto | title=Macroprogramming: Concepts, State of the Art, and Opportunities of Macroscopic Behaviour Modelling | journal=ACM Computing Surveys | publisher=Association for Computing Machinery (ACM) | date=2023-01-11 | volume=55 | issue=13s | pages=1–37 | issn=0360-0300 | doi=10.1145/3579353 | pages2cid=245837830 | arxiv=2201.03473 }}</ref>
In macroprogramming, the local programs for the individual components of a [[distributed system]] are compiled or interpreted from a ''macro-program'' typically expressed by a system-level perspective or in terms of the intended global goal.<ref name="Casadei 2023" />
The aim of macroprogramming approaches is to support expressing the macroscopic interactive behaviour of a whole distributed system of computing devices or [[software agent|agents]] in a single program, or, similarly, to promote their [[collective intelligence]].<ref name="CI 2023">{{cite journal | last=Casadei | first=Roberto | title=Artificial Collective Intelligence Engineering: A Survey of Concepts and Perspectives | journal=Artificial Life | publisher=MIT Press | date=2023-11-01 | volume=29 | issue=4 | pages=433–467 | issn=0360-0300 | doi=10.1162/artl_a_00408 | arxiv=2304.05147 }}</ref>
It hasis not to be confused with [[Macro (computer science)|macros]], the mechanism often found in programming languages (like [[C (programming language)|C]] or [[Scala (programming language)|Scala]]) to express substitution rules for program pieces.
 
Macroprogramming originated in the context of [[wireless sensor network]] programming<ref name="Newton Welsh 2004 p. ">{{cite conference | lastlast1=Newton | firstfirst1=Ryan | last2=Welsh | first2=Matt | title=Proceeedings of the 1st international workshop on Data management for sensor networks in conjunction with VLDB 2004 - DMSN '04 | chapter=Region streams | publisher=ACM Press | publication-place=New York, New York, USA | year=2004 | doi=10.1145/1052199.1052213 | page=78}}</ref> <ref name="Newton Morrisett Welsh 2007 p. ">{{cite conference | lastlast1=Newton | firstfirst1=Ryan | last2=Morrisett | first2=Greg | last3=Welsh | first3=Matt | title=Proceedings of the 6th international conference on Information processing in sensor networks - IPSN '07 | chapter=The regiment macroprogramming system | publisher=ACM Press | publication-place=New York, New York, USA | year=2007 | doi=10.1145/1236360.1236422 | page=489| isbn=978-1-59593-638-7 }}</ref> <ref name="Gummadi Gnawali Govindan 2005 pp. 126–140">{{cite book | lastlast1=Gummadi | firstfirst1=Ramakrishna | last2=Gnawali | first2=Omprakash | last3=Govindan | first3=Ramesh | title=Distributed Computing in Sensor Systems | chapter=Macro-programming Wireless Sensor Networks Using Kairos | publisher=Springer Berlin Heidelberg | publication-place=Berlin, Heidelberg | year=2005 | isbn=978-3-540-26422-4 | issn=0302-9743 | doi=10.1007/11502593_12 | pages=126–140}}</ref>
{{Programming paradigms}}
and found renewed interest in the context of the [[Internet of Things]] <ref name="Júnior Santana Bulcão-Neto Porter 2022 pp. 54–65">{{cite journal | lastlast1=Júnior | firstfirst1=Iwens G. S. | last2=Santana | first2=Thalia S. de | last3=Bulcão-Neto | first3=Renato de F. | last4=Porter | first4=Barry F. | title=The state of the art of macroprogramming in IoT: An update | journal=Journal of Internet Services and Applications | publisher=Sociedade Brasileira de Computacao - SB | volume=13 | issue=1 | date=2022-11-18 | issn=1869-0238 | doi=10.5753/jisa.2022.2372 | pages=54–65| s2cid=254365168 | doi-access=free }}</ref> and [[swarm robotics]] .<ref name="Mottola Picco 2011 pp. 1–51">{{cite journal | lastlast1=Mottola | firstfirst1=Luca | last2=Picco | first2=Gian Pietro | title=Programming wireless sensor networks | journal=ACM Computing Surveys | publisher=Association for Computing Machinery (ACM) | volume=43 | issue=3 | year=2011 | issn=0360-0300 | doi=10.1145/1922649.1922656 | pages=1–51| hdl=11311/635123 | s2cid=1837434 | hdl-access=free }}</ref> <ref name="Casadei 2023" />.
 
Macroprogramming shares similar goals (related to programming a system by a global perspective) with [[multitier programming]], [[choreographic programming]], and [[aggregate computing]].
In [[computer science]], '''macroprogramming''' is a [[programming paradigm]] where programs for the individual components of a [[distributed system]] are compiled or interpreted from a ''macro-program'' expressed by a system-level perspective or in terms of the intended global goal.<ref name="Casadei 2023">{{cite journal | last=Casadei | first=Roberto | title=Macroprogramming: Concepts, State of the Art, and Opportunities of Macroscopic Behaviour Modelling | journal=ACM Computing Surveys | publisher=Association for Computing Machinery (ACM) | date=2023-01-11 | issn=0360-0300 | doi=10.1145/3579353 | page=}}</ref>
The aim of macroprogramming approaches is to support expressing the macroscopic interactive behaviour of a whole distributed system of computing devices or [[software agent|agents]] in a single program.
It has not to be confused with [[Macro (computer science)|macros]], the mechanism often found in programming languages (like [[C (programming language)|C]] or [[Scala (programming language)|Scala]]) to express substitution rules for program pieces.
 
== Context and motivation ==
Macroprogramming originated in the context of [[wireless sensor network]] programming<ref name="Newton Welsh 2004 p. ">{{cite conference | last=Newton | first=Ryan | last2=Welsh | first2=Matt | title=Region streams | publisher=ACM Press | publication-place=New York, New York, USA | year=2004 | doi=10.1145/1052199.1052213 | page=}}</ref> <ref name="Newton Morrisett Welsh 2007 p. ">{{cite conference | last=Newton | first=Ryan | last2=Morrisett | first2=Greg | last3=Welsh | first3=Matt | title=The regiment macroprogramming system | publisher=ACM Press | publication-place=New York, New York, USA | year=2007 | doi=10.1145/1236360.1236422 | page=}}</ref> <ref name="Gummadi Gnawali Govindan 2005 pp. 126–140">{{cite book | last=Gummadi | first=Ramakrishna | last2=Gnawali | first2=Omprakash | last3=Govindan | first3=Ramesh | title=Distributed Computing in Sensor Systems | chapter=Macro-programming Wireless Sensor Networks Using Kairos | publisher=Springer Berlin Heidelberg | publication-place=Berlin, Heidelberg | year=2005 | isbn=978-3-540-26422-4 | issn=0302-9743 | doi=10.1007/11502593_12 | pages=126–140}}</ref>
and found renewed interest in the context of the [[Internet of Things]] <ref name="Júnior Santana Bulcão-Neto Porter 2022 pp. 54–65">{{cite journal | last=Júnior | first=Iwens G. S. | last2=Santana | first2=Thalia S. de | last3=Bulcão-Neto | first3=Renato de F. | last4=Porter | first4=Barry F. | title=The state of the art of macroprogramming in IoT: An update | journal=Journal of Internet Services and Applications | publisher=Sociedade Brasileira de Computacao - SB | volume=13 | issue=1 | date=2022-11-18 | issn=1869-0238 | doi=10.5753/jisa.2022.2372 | pages=54–65}}</ref> and [[swarm robotics]] <ref name="Mottola Picco 2011 pp. 1–51">{{cite journal | last=Mottola | first=Luca | last2=Picco | first2=Gian Pietro | title=Programming wireless sensor networks | journal=ACM Computing Surveys | publisher=Association for Computing Machinery (ACM) | volume=43 | issue=3 | year=2011 | issn=0360-0300 | doi=10.1145/1922649.1922656 | pages=1–51}}</ref> <ref name="Casadei 2023" />.
 
Programming [[distributed systems]], [[multi-agent systems]], and [[collectives]] of software agents (e.g., [[swarm robotics|robotic swarms]]) is difficult, for many issues (like communication, concurrency, and failure) have to be properly considered. In particular, a general recurrent problem is how to induce the intended global behaviour by defining the behaviour of the individual components or agents involved. The problem can be addressed through learning approaches, such as [[multi-agent reinforcement learning]], or by manually defining the control program driving each component. However, addressing the problem by a fully individual (or single-node) perspective may be error-prone, because it is generally difficult to foresee the overall behaviour emerging from complex networks of activities and interactions (cf. [[complex systems]] and [[emergence]]). Therefore, researchers have started investigated ways to raise the abstraction level, promoting programming of distributed systems by a more global perspective or in terms of the overall goal to be collectively attained.
Macroprogramming shares similar goals (related to programming a system by a global perspective) with [[multitier programming]], [[choreographic programming]], and [[aggregate computing]].
 
== Examples ==
Line 16 ⟶ 20:
=== ScaFi ===
 
The following program in the ScaFi aggregate programming language <ref name="Casadei Viroli Aguzzi Pianini 2022 p=101248">{{cite journal | lastlast1=Casadei | firstfirst1=Roberto | last2=Viroli | first2=Mirko | last3=Aguzzi | first3=Gianluca | last4=Pianini | first4=Danilo | title=ScaFi: A Scala DSL and Toolkit for Aggregate Programming | journal=SoftwareX | publisher=Elsevier BV | volume=20 | year=2022 | issn=2352-7110 | doi=10.1016/j.softx.2022.101248 | page=101248| hdl=11585/903248 | hdl-access=free }}</ref> [https://scafi.github.io/] defines the loop control logic needed to compute a channel (a Boolean field where the devices yielding <ttcode>true</ttcode> are those connecting, through a hop-by-hop path, a source device to a target device) across a large set of situated devices interacting with neighbours.
 
<syntaxhighlight lang="scala" line="1">
Line 28 ⟶ 32:
 
def channel(src: Boolean, dest: Boolean, width: Double): Boolean =
dilate(gradientdistanceTo(src) + gradientdistanceTo(dest) <= distBetweendistanceBetween(src,dest), width)
 
type OB[T] = Builtins.Bounded[T]
Line 39 ⟶ 43:
} } }._2
 
def gradientdistanceTo(source: Boolean): Double =
G[Double](source, 0, _ + nbrRange(), nbrRange())
 
Line 45 ⟶ 49:
G[V](source, field, x=>x, nbrRange())
 
def distBetweendistanceBetween(source: Boolean, target: Boolean): Double =
broadcast(source, gradient(target))
 
Line 52 ⟶ 56:
}
</syntaxhighlight>
 
What is interesting to note is that the <code>channel</code> function, as well as the functions that are used to implement it, namely <code>distanceTo</code>, <code>distanceBetween</code>, <code>dilate</code>, <code>broadcast</code> etc.
can be interpreted not just in terms of the individual behaviour of a device, but rather ''by a macroscopic perspective''.
In fact, for instance, <code>distanceTo(s)</code> is used to compute the field of minimum distances from the closest device for which expression <code>s</code> yields <code>true</code>: this is effectively a ''distributed data structure'' that is sustained through processing ''and'' communication with neighbours, in a self-organising way.
Semantically, such functions define a macro-level (or collective) behaviour that yields a macro-level (or collective) data structure. Such macro-level functions/behaviours can be ''composed'' together to obtain another more complex macro-level function/behaviours.
 
=== Regiment ===
 
The following program in the Regiment language <ref name="Newton Morrisett Welsh 2007 p. ">{{cite conference | last=Newton | first=Ryan | last2=Morrisett | first2=Greg | last3=Welsh | first3=Matt | title=The regiment macroprogramming system | publisher=ACM Press | publication-place=New York, New York, USA | year=2007 | doi=10.1145/1236360.1236422 | page=}}</ref> can be used to compute the mean temperature perceived by the whole system:
 
<syntaxhighlight lang="prolog" line="1">
Line 69 ⟶ 78:
BASE <- avgSignal % move such information to the base station
</syntaxhighlight>
 
 
=== PyoT ===
 
The following program in PyoT <ref name="Azzara Alessandrelli Bocchino Petracca 2014 p. ">{{cite conference | lastlast1=Azzara | firstfirst1=Andrea | last2=Alessandrelli | first2=Daniele | last3=Bocchino | first3=Stefano | last4=Petracca | first4=Matteo | last5=Pagano | first5=Paolo | title=Proceedings of the 9th IEEE International Symposium on Industrial Embedded Systems (SIES 2014) | chapter=PyoT, a macroprogramming framework for the Internet of Things | publisher=IEEE | year=2014 | pages=96–103 | doi=10.1109/sies.2014.6871193 | pageisbn=978-1-4799-4023-3 }}</ref> can be used to turn on a fan if the mean temperature computed by several sensors exceeds a certain threshold.
 
<syntaxhighlight lang="python" line="1">
temperatures = Resource.objects.filter(title='"temp'")
results = [temp.GET() for temp in temperatures]
avg = sum (results) / len(results)
TEMP_THRESHOLD = 24
if avg > TEMP_THRESHOLD:
Resource.objects.get(title='"fan'").PUT('"on'")
</syntaxhighlight>
 
=== TinyDB ===
 
In TinyDB ,<ref name="Madden Franklin Hellerstein Hong 2005 pp. 122–173">{{cite journal | lastlast1=Madden | firstfirst1=Samuel R. | last2=Franklin | first2=Michael J. | last3=Hellerstein | first3=Joseph M. | last4=Hong | first4=Wei | title=TinyDB: an acquisitional query processing system for sensor networks | journal=ACM Transactions on Database Systems | publisher=Association for Computing Machinery (ACM) | volume=30 | issue=1 | year=2005 | issn=0362-5915 | doi=10.1145/1061318.1061322 | pages=122–173| s2cid=2239670 }}</ref>, a data-oriented macroprogramming approach is used where the programmer writes a query which turns into single-node operations and routing in a wireless sensor network.
 
<syntaxhighlight lang="sql" line="1">
SELECT nodeId , temperature WHERE temperature > k FROM sensors SAMPLE PERIOD 5 minutes
2 SAMPLE PERIOD 5 minutes
</syntaxhighlight>
 
 
== See also ==
Line 104 ⟶ 110:
 
{{reflist}}
 
{{Programming paradigms navbox}}
 
[[Category:Programming paradigms]]
[[Category:Programming languages]]
[[Category:Distributed computing]]
[[Category:Articles with example Python (programming language) code]]
[[Category:Articles with example Scala code]]