SimGrid 【2】 s4u的使用 - mailbox 与 actor create

本文档介绍了SimGrid的s4u接口,用于在C++中描述抽象算法。重点讲解了Actors、Platform和Deployment的定义,并通过actor-create示例详细阐述了mailbox的概念和使用,以及同步阻塞消息传递方式put()和get()。同时,分析了示例程序的运行结果和执行流程。
摘要由CSDN通过智能技术生成

目录

 

1. s4u概念与使用简介

2. mailbox的概念与使用简介

3. actor-create 例子

3.1 actor-create.cpp

3.2 small_platform.xml

3.3 deployment:li-s4u-actor-create_d.xml

3.4 运行结果

 

3.5 程序分析

参考文献


1. s4u概念与使用简介

s4u全称为 SimGrid for you,具体介绍如官网[1]中所写:The S4U interface (SimGrid for you) mixes the full power of SimGrid with the full power of C++. This is the preferred interface to describe abstract algorithms in the domains of Cloud, P2P, HPC, IoT, and similar settings.

简单而言就是,SimGrid推荐使用s4u来进行编写C++程序,可以表示云计算,P2P,HPC,IoT等抽象算法。

要使用s4u进行模拟,必须要自己写一下几部分的代码。

(1)Actors:显示的s4u描述Actors的Activities,包括, computation, communication, disk usage, and other Activities

(2)Platform:Platform files define the simulated platform on which the provided application will take place. In contains one or several Network Zone that contain both Host and Link Resources, as well as routing information.

(3)deployment:Deployment files specify the execution scenario: it lists the actors that should be started, along with their parameter.

2. mailbox的概念与使用简介

mailbox这一概念出现在通信的时候,在SimGrid中communication不是直接一个Actor至另一个Actor,是通过mailbox进行中转的(这里没能理解),可以是同步阻塞的也可以是异步的。官方文档中的比喻是相当于电话号码,caller可以通过其查找到receiver。Mailboxes are rendez-vous points for network communications, similar to URLs on which you could post and retrieve data. Actually, the mailboxes are not involved in the communication once it starts, but only to find the contact with which you want to communicate.

They are similar to many common things: The phone number, which allows the caller to find the receiver. The twitter hashtag, which help senders and receivers to find each others. In TCP, the pair {host name, host port} to which you can connect to find your peer. In HTTP, URLs through which the clients can connect to the servers. In ZeroMQ, the queues are used to match senders and receivers.

put()与get()是同步阻塞式的消息传递方式,The matching algorithm simple: first come, first serve. When a new send arrives, it matches the oldest enqueued receive. If no receive is currently enqueued, then the incoming send is enqueued. As you can see, the mailbox cannot contain both send and receive requests: all enqueued requests must be of the same sort.(没懂,以后遇到代码在进行理解......)

3. actor-create 例子

安装SimGrid后,其example夹下自带很多的例子,我学习与修改的是example/s4u/actor-create的例子。主要说明的是SimGrid代码中3大元素的actor如何定义与启动。

3.1 actor-create.cpp

/* Copyright (c) 2006-2020. The SimGrid Team. All rights reserved.          */

/* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */

/* This example shows how to declare and start your actors.
 *
 * The first step is to declare the code of your actors (what they do exactly does not matter to this example) and then
 * you ask SimGrid to start your actors. There is three ways of doing so:
 *  - Directly, by instantiating your actor as parameter to Actor::create()
 *  - By first registering your actors before instantiating it
 *  - Through the deployment file.
 *
 * This example shows all these solutions, even if you obviously should use only one of these solutions to start your
 * actors. The most advised solution is to use a deployment file, as it creates a clear separation between your
 * application and the settings to test it. This is a better scien
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值