Macroprogramming Explained

Macroprogramming should not be confused with Macro (programming).

In computer science, macroprogramming is a programming paradigm aimed at expressing the macroscopic, global behaviour of an entire system of agents or computing devices.[1] 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.The aim of macroprogramming approaches is to support expressing the macroscopic interactive behaviour of a whole distributed system of computing devices or agents in a single program, or, similarly, to promote their collective intelligence.[2] It has not to be confused with macros, the mechanism often found in programming languages (like C or Scala) to express substitution rules for program pieces.

Macroprogramming originated in the context of wireless sensor network programming[3] [4] [5] and found renewed interest in the context of the Internet of Things[6] and swarm robotics.[7]

Macroprogramming shares similar goals (related to programming a system by a global perspective) with multitier programming, choreographic programming, and aggregate computing.

Context and motivation

Programming distributed systems, multi-agent systems, and collectives of software agents (e.g., 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.

Examples

ScaFi

The following program in the ScaFi aggregate programming language [8] https://scafi.github.io/ defines the loop control logic needed to compute a channel (a Boolean field where the devices yielding true 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.

class SelfContainedChannel extends AggregateProgram with SensorDefinitions

What is interesting to note is that the channel function, as well as the functions that are used to implement it, namely distanceTo, distanceBetween, dilate, broadcast 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, distanceTo(s) is used to compute the field of minimum distances from the closest device for which expression s yields true: 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 [4] can be used to compute the mean temperature perceived by the whole system:

% function definitiondoSum :: float (float, int) -> (float, int);doSum(temperature, (sum, count))

% functional reactive program logictemperatureRegion = rmap(fun(node), world);sumSignal = rfold(doSum, (0.0, 0), temperatureRegion)avgSignal = smap(fun((sum,count)), sumSignal)

BASE <- avgSignal % move such information to the base station

PyoT

The following program in PyoT [9] can be used to turn on a fan if the mean temperature computed by several sensors exceeds a certain threshold.

temperatures = Resource.objects.filter(title="temp")results = [temp.GET for temp in temperatures]avg = sum(results) / len(results)TEMP_THRESHOLD = 24if avg > TEMP_THRESHOLD: Resource.objects.get(title="fan").PUT("on")

TinyDB

In TinyDB,[10] 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.

SELECT nodeId, temperature WHERE temperature > k FROM sensors SAMPLE PERIOD 5 minutes

See also

Notes and References

  1. Casadei . Roberto . Macroprogramming: Concepts, State of the Art, and Opportunities of Macroscopic Behaviour Modelling . ACM Computing Surveys . Association for Computing Machinery (ACM) . 2023-01-11 . 55 . 13s . 1–37 . 0360-0300 . 10.1145/3579353 . 245837830 . 2201.03473 .
  2. Casadei . Roberto . Artificial Collective Intelligence Engineering: A Survey of Concepts and Perspectives . Artificial Life . MIT Press . 2023-11-01 . 29 . 4 . 433–467 . 0360-0300 . 10.1162/artl_a_00408 . 2304.05147 .
  3. Newton . Ryan . Welsh . Matt . Proceeedings of the 1st international workshop on Data management for sensor networks in conjunction with VLDB 2004 - DMSN '04 . Region streams . ACM Press . New York, New York, USA . 2004 . 10.1145/1052199.1052213 . 78.
  4. Newton . Ryan . Morrisett . Greg . Welsh . Matt . Proceedings of the 6th international conference on Information processing in sensor networks - IPSN '07 . The regiment macroprogramming system . ACM Press . New York, New York, USA . 2007 . 10.1145/1236360.1236422 . 489. 978-1-59593-638-7 .
  5. Book: Gummadi . Ramakrishna . Gnawali . Omprakash . Govindan . Ramesh . Distributed Computing in Sensor Systems . Macro-programming Wireless Sensor Networks Using Kairos . Springer Berlin Heidelberg . Berlin, Heidelberg . 2005 . 978-3-540-26422-4 . 0302-9743 . 10.1007/11502593_12 . 126–140.
  6. Júnior . Iwens G. S. . Santana . Thalia S. de . Bulcão-Neto . Renato de F. . Porter . Barry F. . The state of the art of macroprogramming in IoT: An update . Journal of Internet Services and Applications . Sociedade Brasileira de Computacao - SB . 13 . 1 . 2022-11-18 . 1869-0238 . 10.5753/jisa.2022.2372 . 54–65. 254365168 . free .
  7. Mottola . Luca . Picco . Gian Pietro . Programming wireless sensor networks . ACM Computing Surveys . Association for Computing Machinery (ACM) . 43 . 3 . 2011 . 0360-0300 . 10.1145/1922649.1922656 . 1–51. 11311/635123 . 1837434 . free .
  8. Casadei . Roberto . Viroli . Mirko . Aguzzi . Gianluca . Pianini . Danilo . ScaFi: A Scala DSL and Toolkit for Aggregate Programming . SoftwareX . Elsevier BV . 20 . 2022 . 2352-7110 . 10.1016/j.softx.2022.101248 . 101248. 11585/903248 . free .
  9. Azzara . Andrea . Alessandrelli . Daniele . Bocchino . Stefano . Petracca . Matteo . Pagano . Paolo . Proceedings of the 9th IEEE International Symposium on Industrial Embedded Systems (SIES 2014) . PyoT, a macroprogramming framework for the Internet of Things . IEEE . 2014 . 96–103 . 10.1109/sies.2014.6871193 . 978-1-4799-4023-3 .
  10. Madden . Samuel R. . Franklin . Michael J. . Hellerstein . Joseph M. . Hong . Wei . TinyDB: an acquisitional query processing system for sensor networks . ACM Transactions on Database Systems . Association for Computing Machinery (ACM) . 30 . 1 . 2005 . 0362-5915 . 10.1145/1061318.1061322 . 122–173. 2239670 .