Jump to content

Macroprogramming

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Robyonrails (talk | contribs) at 11:22, 16 February 2023 (Examples in some macroprogramming languages + minor fix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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.[1] 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. 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[2] [3] [4] and found renewed interest in the context of the Internet of Things [5] and swarm robotics [6] [1].

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

Examples

ScaFi

The following program in the ScaFi aggregate programming language [7] [1] 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 {
  def isObstacle = sense[Boolean]("obstacle")
  def isSource = sense[Boolean]("source")
  def isDestination = sense[Boolean]("target")
  
  override def main(): Boolean = 
  branch(isObstacle){ false }{ channel(isSource, isDestination, 5) }

  def channel(src: Boolean, dest: Boolean, width: Double): Boolean =
    dilate(gradient(src) + gradient(dest) <= distBetween(src,dest), width)

  type OB[T] = Builtins.Bounded[T]
  def G[V:OB](src: Boolean, field: V, acc: V=>V, metric: =>Double): V =
    rep( (Double.MaxValue, field) ){ dv =>
      mux(src) { (0.0, field) } {
        minHoodPlus {
          val (d, v) = nbr { (dv._1, dv._2) }
          (d + metric, acc(v))
        } } }._2

  def gradient(source: Boolean): Double =
    G[Double](source, 0, _ + nbrRange(), nbrRange())

  def broadcast[V:OB](source: Boolean, field: V): V =
    G[V](source, field, x=>x, nbrRange())

  def distBetween(source: Boolean, target: Boolean): Double =
    broadcast(source, gradient(target))

  def dilate(region: Boolean, width: Double): Boolean =
    gradient(region) < width
}

Regiment

The following program in the Regiment language [3] can be used to compute the mean temperature perceived by the whole system:

% function definition
doSum :: float (float, int) -> (float, int);
doSum(temperature, (sum, count)) { (sum+temperature, count+1) }

% functional reactive program logic
temperatureRegion = rmap(fun(node){ sense("temperature", node) }, world);
sumSignal = rfold(doSum, (0.0, 0), temperatureRegion)
avgSignal = smap(fun((sum,count)){ sum / count }, sumSignal)

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


PyoT

The following program in PyoT [8] 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 = 24
if avg > TEMP_THRESHOLD:
    Resource.objects.get(title='fan').PUT('on')

TinyDB

In TinyDB [9], 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
2 SAMPLE PERIOD 5 minutes


See also

References

  1. ^ a b Casadei, Roberto (2023-01-11). "Macroprogramming: Concepts, State of the Art, and Opportunities of Macroscopic Behaviour Modelling". ACM Computing Surveys. Association for Computing Machinery (ACM). doi:10.1145/3579353. ISSN 0360-0300.
  2. ^ Newton, Ryan; Welsh, Matt (2004). Region streams. New York, New York, USA: ACM Press. doi:10.1145/1052199.1052213.
  3. ^ a b Newton, Ryan; Morrisett, Greg; Welsh, Matt (2007). The regiment macroprogramming system. New York, New York, USA: ACM Press. doi:10.1145/1236360.1236422.
  4. ^ Gummadi, Ramakrishna; Gnawali, Omprakash; Govindan, Ramesh (2005). "Macro-programming Wireless Sensor Networks Using Kairos". Distributed Computing in Sensor Systems. Berlin, Heidelberg: Springer Berlin Heidelberg. pp. 126–140. doi:10.1007/11502593_12. ISBN 978-3-540-26422-4. ISSN 0302-9743.
  5. ^ Júnior, Iwens G. S.; Santana, Thalia S. de; Bulcão-Neto, Renato de F.; Porter, Barry F. (2022-11-18). "The state of the art of macroprogramming in IoT: An update". Journal of Internet Services and Applications. 13 (1). Sociedade Brasileira de Computacao - SB: 54–65. doi:10.5753/jisa.2022.2372. ISSN 1869-0238.
  6. ^ Mottola, Luca; Picco, Gian Pietro (2011). "Programming wireless sensor networks". ACM Computing Surveys. 43 (3). Association for Computing Machinery (ACM): 1–51. doi:10.1145/1922649.1922656. ISSN 0360-0300.
  7. ^ Casadei, Roberto; Viroli, Mirko; Aguzzi, Gianluca; Pianini, Danilo (2022). "ScaFi: A Scala DSL and Toolkit for Aggregate Programming". SoftwareX. 20. Elsevier BV: 101248. doi:10.1016/j.softx.2022.101248. ISSN 2352-7110.
  8. ^ Azzara, Andrea; Alessandrelli, Daniele; Bocchino, Stefano; Petracca, Matteo; Pagano, Paolo (2014). PyoT, a macroprogramming framework for the Internet of Things. IEEE. doi:10.1109/sies.2014.6871193.
  9. ^ Madden, Samuel R.; Franklin, Michael J.; Hellerstein, Joseph M.; Hong, Wei (2005). "TinyDB: an acquisitional query processing system for sensor networks". ACM Transactions on Database Systems. 30 (1). Association for Computing Machinery (ACM): 122–173. doi:10.1145/1061318.1061322. ISSN 0362-5915.