From: Yann Duplouy Date: Sat, 19 Oct 2019 16:53:02 +0000 (+0200) Subject: Removing RngStream X-Git-Tag: v3.25~516^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5997f75835d50b618ea8f7030ff2f554b32350d9 Removing RngStream --- diff --git a/COPYING b/COPYING index ca840492be..5eeebe3eda 100644 --- a/COPYING +++ b/COPYING @@ -64,11 +64,6 @@ License: other product, or process disclosed, or represents that its use would not infringe privately owned rights. -Files: src/xbt/RngStream.c include/xbt/RngStream.h -Copyright: 2001 Pierre L'Ecuyer, University of Montreal -License: GPL-2+ and LGPL-2.1 -Comment: The author granted us the right to distribute this files under the LGPL-2.1 as long as it is bundled with SimGrid. - Files: src/simdag/dax_dtd.c src/simdag/dax_dtd.h diff --git a/MANIFEST.in b/MANIFEST.in index 85d7b34c28..7858f399a8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1986,7 +1986,6 @@ include include/smpi/smpi_helpers_internal.h include include/smpi/smpi_main.h include include/xbt.h include include/xbt/Extendable.hpp -include include/xbt/RngStream.h include include/xbt/asserts.h include include/xbt/automaton.h include include/xbt/automaton.hpp @@ -2063,7 +2062,6 @@ include src/bindings/java/org/simgrid/msg/Mutex.java include src/bindings/java/org/simgrid/msg/Process.java include src/bindings/java/org/simgrid/msg/ProcessKilledError.java include src/bindings/java/org/simgrid/msg/ProcessNotFoundException.java -include src/bindings/java/org/simgrid/msg/RngStream.java include src/bindings/java/org/simgrid/msg/Semaphore.java include src/bindings/java/org/simgrid/msg/Storage.java include src/bindings/java/org/simgrid/msg/StorageNotFoundException.java @@ -2552,7 +2550,6 @@ include src/surf/xml/simgrid_dtd.h include src/surf/xml/surfxml_parseplatf.cpp include src/surf/xml/surfxml_sax_cb.cpp include src/xbt/OsSemaphore.hpp -include src/xbt/RngStream.c include src/xbt/automaton/automaton.c include src/xbt/automaton/automaton_lexer.yy.c include src/xbt/automaton/automatonparse_promela.c diff --git a/examples/deprecated/java/app/bittorrent/Main.java b/examples/deprecated/java/app/bittorrent/Main.java index eeef12d41a..11773d462b 100644 --- a/examples/deprecated/java/app/bittorrent/Main.java +++ b/examples/deprecated/java/app/bittorrent/Main.java @@ -6,7 +6,6 @@ package app.bittorrent; import org.simgrid.msg.Msg; -import org.simgrid.msg.RngStream; class Main{ private Main() { @@ -14,9 +13,6 @@ class Main{ } public static void main(String[] args) { - int[] seed = { 12345, 12345, 12345, 12345, 12345, 12345 }; - RngStream.setPackageSeed(seed); - Msg.init(args); if(args.length < 2) { Msg.info("Usage : Bittorrent platform_file deployment_file"); diff --git a/examples/deprecated/java/app/bittorrent/Peer.java b/examples/deprecated/java/app/bittorrent/Peer.java index ab394a0db9..17ba118ae2 100644 --- a/examples/deprecated/java/app/bittorrent/Peer.java +++ b/examples/deprecated/java/app/bittorrent/Peer.java @@ -9,20 +9,20 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; +import java.util.Random; import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; -import org.simgrid.msg.RngStream; import org.simgrid.msg.MsgException; public class Peer extends Process { + Random rand = new Random(); protected int round = 0; protected double beginReceiveTime; protected double deadline; - protected static RngStream stream = new RngStream(); protected int id; protected String mailbox; protected String mailboxTracker; @@ -384,7 +384,7 @@ public class Peer extends Process { //TODO: trivial min algorithm when pieces >= 3 do { - currentPiece = stream.randInt(0,Common.FILE_PIECES - 1); + currentPiece = rand.nextInt(Common.FILE_PIECES); } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece))); currentPieces.add(currentPiece); @@ -424,7 +424,7 @@ public class Peer extends Process { int j = 0; do { int i = 0; - int idChosen = stream.randInt(0,peers.size() - 1); + int idChosen = rand.nextInt(peers.size()); for (Connection connection : peers.values()) { if (i == idChosen) { peerChoosed = connection; diff --git a/examples/deprecated/java/app/bittorrent/Tracker.java b/examples/deprecated/java/app/bittorrent/Tracker.java index da6e81ec41..6621939d1f 100644 --- a/examples/deprecated/java/app/bittorrent/Tracker.java +++ b/examples/deprecated/java/app/bittorrent/Tracker.java @@ -6,17 +6,17 @@ package app.bittorrent; import java.util.ArrayList; +import java.util.Random; import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; -import org.simgrid.msg.RngStream; import org.simgrid.msg.MsgException; public class Tracker extends Process { - protected RngStream stream; + Random rand = new Random(); protected ArrayList peersList; protected double deadline; protected Comm commReceived = null; @@ -31,8 +31,6 @@ public class Tracker extends Process { Msg.info("Wrong number of arguments for the tracker."); return; } - //Build the RngStream object for randomness - stream = new RngStream("tracker"); //Retrieve the end time deadline = Double.parseDouble(args[0]); //Building peers array @@ -53,7 +51,7 @@ public class Tracker extends Process { while (nbPeers < Common.MAXIMUM_PEERS && nbPeers < peersList.size()) { int nextPeer; do { - nextPeer = stream.randInt(0, peersList.size() - 1); + nextPeer = rand.nextInt(peersList.size()); } while (tTask.peers.contains(peersList.get(nextPeer))); tTask.peers.add(peersList.get(nextPeer)); nbPeers++; diff --git a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp index de5ca5048b..899802c6be 100644 --- a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp +++ b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp @@ -8,7 +8,7 @@ #include "s4u-peer.hpp" #include "s4u-tracker.hpp" -simgrid::xbt::Extension HostBittorrent::EXTENSION_ID; +std::default_random_engine generator; int main(int argc, char* argv[]) { @@ -19,12 +19,6 @@ int main(int argc, char* argv[]) e.load_platform(argv[1]); - /* Install our extension on all existing hosts */ - HostBittorrent::EXTENSION_ID = simgrid::s4u::Host::extension_create(); - std::vector list = simgrid::s4u::Engine::get_instance()->get_all_hosts(); - for (auto const& host : list) - host->extension_set(new HostBittorrent(host)); - e.register_actor("tracker"); e.register_actor("peer"); e.load_deployment(argv[2]); diff --git a/examples/s4u/app-bittorrent/s4u-bittorrent.hpp b/examples/s4u/app-bittorrent/s4u-bittorrent.hpp index b2113cac89..089535410c 100644 --- a/examples/s4u/app-bittorrent/s4u-bittorrent.hpp +++ b/examples/s4u/app-bittorrent/s4u-bittorrent.hpp @@ -7,8 +7,8 @@ #ifndef BITTORRENT_BITTORRENT_HPP_ #define BITTORRENT_BITTORRENT_HPP_ +#include #include -#include constexpr char TRACKER_MAILBOX[] = "tracker_mailbox"; /** Max number of peers sent by the tracker to clients */ @@ -78,22 +78,14 @@ public: }; class HostBittorrent { - std::unique_ptr::type, std::function> stream_ = { - nullptr, [](RngStream stream) { RngStream_DeleteStream(&stream); }}; simgrid::s4u::Host* host = nullptr; public: - static simgrid::xbt::Extension EXTENSION_ID; - - explicit HostBittorrent(simgrid::s4u::Host* ptr) : host(ptr) - { - std::string descr = std::string("RngSream<") + host->get_cname() + ">"; - stream_.reset(RngStream_CreateStream(descr.c_str())); - } + explicit HostBittorrent(simgrid::s4u::Host* ptr) : host(ptr) {} HostBittorrent(const HostBittorrent&) = delete; HostBittorrent& operator=(const HostBittorrent&) = delete; - - RngStream getStream() { return stream_.get(); }; }; +extern std::default_random_engine generator; + #endif /* BITTORRENT_BITTORRENT_HPP_ */ diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index ff9a09476c..360bb203ac 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -44,8 +44,6 @@ Peer::Peer(std::vector args) } xbt_assert(deadline > 0, "Wrong deadline supplied"); - stream = simgrid::s4u::this_actor::get_host()->extension()->getStream(); - if (args.size() == 4 && args[3] == "1") { bitfield_ = (1U << FILE_PIECES) - 1U; bitfield_blocks = (1ULL << (FILE_PIECES * PIECES_BLOCKS)) - 1ULL; @@ -456,7 +454,8 @@ int Peer::selectPieceToDownload(Connection* remote_peer) xbt_assert(nb_interesting_pieces != 0); // get a random interesting piece - int random_piece_index = RngStream_RandInt(stream, 0, nb_interesting_pieces - 1); + std::uniform_int_distribution dist(0, nb_interesting_pieces - 1); + int random_piece_index = dist(generator); int current_index = 0; for (unsigned int i = 0; i < FILE_PIECES; i++) { if (hasNotPiece(i) && remote_peer->hasPiece(i)) { @@ -479,7 +478,8 @@ int Peer::selectPieceToDownload(Connection* remote_peer) nb_interesting_pieces++; xbt_assert(nb_interesting_pieces != 0); // get a random interesting piece - int random_piece_index = RngStream_RandInt(stream, 0, nb_interesting_pieces - 1); + std::uniform_int_distribution dist(0, nb_interesting_pieces - 1); + int random_piece_index = dist(generator); int current_index = 0; for (unsigned int i = 0; i < FILE_PIECES; i++) { if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i)) { @@ -510,7 +510,11 @@ int Peer::selectPieceToDownload(Connection* remote_peer) xbt_assert(nb_min_pieces != 0 || not isInterestedByFree(remote_peer)); // get a random rarest piece - int random_rarest_index = RngStream_RandInt(stream, 0, nb_min_pieces - 1); + int random_rarest_index = 0; + if (nb_min_pieces > 0) { + std::uniform_int_distribution dist(0, nb_min_pieces - 1); + random_rarest_index = dist(generator); + } for (unsigned int i = 0; i < FILE_PIECES; i++) if (pieces_count[i] == min && hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i)) { if (random_rarest_index == current_index) { @@ -559,7 +563,8 @@ void Peer::updateChokedPeers() do { // We choose a random peer to unchoke. std::unordered_map::iterator chosen_peer_it = connected_peers.begin(); - std::advance(chosen_peer_it, RngStream_RandInt(stream, 0, connected_peers.size() - 1)); + std::uniform_int_distribution dist(0, connected_peers.size() - 1); + std::advance(chosen_peer_it, dist(generator)); chosen_peer = &chosen_peer_it->second; if (not chosen_peer->interested || not chosen_peer->choked_upload) chosen_peer = nullptr; diff --git a/examples/s4u/app-bittorrent/s4u-peer.hpp b/examples/s4u/app-bittorrent/s4u-peer.hpp index fa0418d799..ecc5994743 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.hpp +++ b/examples/s4u/app-bittorrent/s4u-peer.hpp @@ -31,7 +31,6 @@ public: class Peer { int id; double deadline; - RngStream stream; simgrid::s4u::Mailbox* mailbox_; std::unordered_map connected_peers; std::set active_peers; // active peers list diff --git a/examples/s4u/app-bittorrent/s4u-tracker.cpp b/examples/s4u/app-bittorrent/s4u-tracker.cpp index a8a34461b2..390020a0b7 100644 --- a/examples/s4u/app-bittorrent/s4u-tracker.cpp +++ b/examples/s4u/app-bittorrent/s4u-tracker.cpp @@ -6,7 +6,6 @@ #include "s4u-tracker.hpp" #include -#include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_tracker, "Messages specific for the tracker"); @@ -22,8 +21,6 @@ Tracker::Tracker(std::vector args) } xbt_assert(deadline > 0, "Wrong deadline supplied"); - stream = simgrid::s4u::this_actor::get_host()->extension()->getStream(); - mailbox = simgrid::s4u::Mailbox::by_name(TRACKER_MAILBOX); XBT_INFO("Tracker launched."); @@ -55,7 +52,8 @@ void Tracker::operator()() while (tried < max_tries) { do { next_peer = known_peers.begin(); - std::advance(next_peer, RngStream_RandInt(stream, 0, nb_known_peers - 1)); + std::uniform_int_distribution dist(0, nb_known_peers - 1); + std::advance(next_peer, dist(generator)); } while (ta->getPeers().find(*next_peer) != ta->getPeers().end()); ta->addPeer(*next_peer); tried++; diff --git a/examples/s4u/app-bittorrent/s4u-tracker.hpp b/examples/s4u/app-bittorrent/s4u-tracker.hpp index d4af5d6404..2beffd4a45 100644 --- a/examples/s4u/app-bittorrent/s4u-tracker.hpp +++ b/examples/s4u/app-bittorrent/s4u-tracker.hpp @@ -32,7 +32,6 @@ public: class Tracker { double deadline; - RngStream stream; simgrid::s4u::Mailbox* mailbox; std::set known_peers; diff --git a/examples/s4u/dht-chord/s4u-dht-chord-node.cpp b/examples/s4u/dht-chord/s4u-dht-chord-node.cpp index 9ad0c03570..992d3a2047 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord-node.cpp +++ b/examples/s4u/dht-chord/s4u-dht-chord-node.cpp @@ -52,7 +52,6 @@ Node::Node(std::vector args) // initialize my node id_ = std::stoi(args[1]); - stream = simgrid::s4u::this_actor::get_host()->extension()->getStream(); mailbox_ = simgrid::s4u::Mailbox::by_name(std::to_string(id_)); next_finger_to_fix = 0; fingers_.resize(nb_bits, id_); @@ -135,7 +134,8 @@ void Node::notifyAndQuit() void Node::randomLookup() { int res = id_; - int random_index = RngStream_RandInt(stream, 0, nb_bits - 1); + std::uniform_int_distribution dist(0, nb_bits - 1); + int random_index = dist(generator); int random_id = fingers_[random_index]; XBT_DEBUG("Making a lookup request for id %d", random_id); if (random_id != id_) diff --git a/examples/s4u/dht-chord/s4u-dht-chord.cpp b/examples/s4u/dht-chord/s4u-dht-chord.cpp index ca06eb4a41..221099c840 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.cpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.cpp @@ -12,6 +12,8 @@ int nb_bits = 24; int nb_keys = 0; int timeout = 50; +std::default_random_engine generator; + int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); diff --git a/examples/s4u/dht-chord/s4u-dht-chord.hpp b/examples/s4u/dht-chord/s4u-dht-chord.hpp index 12b6921640..353a10cbd3 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.hpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.hpp @@ -6,8 +6,8 @@ #ifndef S4U_CHORD_HPP #define S4U_CHORD_HPP #include "simgrid/s4u.hpp" +#include #include -#include #include constexpr double MAX_SIMULATION_TIME = 1000; @@ -21,23 +21,18 @@ extern int nb_bits; extern int nb_keys; extern int timeout; +extern std::default_random_engine generator; + class HostChord { - std::unique_ptr::type, std::function> stream_ = { - nullptr, [](RngStream stream) { RngStream_DeleteStream(&stream); }}; simgrid::s4u::Host* host = nullptr; public: static simgrid::xbt::Extension EXTENSION_ID; - explicit HostChord(simgrid::s4u::Host* ptr) : host(ptr) - { - std::string descr = std::string("RngSream<") + host->get_cname() + ">"; - stream_.reset(RngStream_CreateStream(descr.c_str())); - } + explicit HostChord(simgrid::s4u::Host* ptr) : host(ptr) {} HostChord(const HostChord&) = delete; HostChord& operator=(const HostChord&) = delete; - RngStream getStream() { return stream_.get(); }; }; /* Types of tasks exchanged between nodes. */ @@ -80,7 +75,6 @@ class Node { simgrid::s4u::Mailbox* mailbox_; // my mailbox std::vector fingers_; // finger table,(fingers[0] is my successor) int next_finger_to_fix; // index of the next finger to fix in fix_fingers() - RngStream stream; public: explicit Node(std::vector args); diff --git a/examples/s4u/dht-chord/s4u-dht-chord.tesh b/examples/s4u/dht-chord/s4u-dht-chord.tesh index 9e8fe7c93d..a89aaf6794 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.tesh +++ b/examples/s4u/dht-chord/s4u-dht-chord.tesh @@ -167,64 +167,50 @@ $ ${bindir:=.}/s4u-dht-chord -nb_bits=3 ${platfdir}/cluster_backbone.xml s4u-dht > [ 345.18145] (node@node-5.simgrid.org) 0 | 10874876 > [ 345.18145] (node@node-5.simgrid.org) Predecessor: 42 > [ 350.17354] (node@node-2.simgrid.org) My new predecessor is 42 -> [ 350.18135] (node@node-0.simgrid.org) My new finger #0 is 533744 -> [ 360.19676] (node@node-0.simgrid.org) My new finger #2 is 533744 -> [ 360.19676] (node@node-0.simgrid.org) My finger table: -> [ 360.19676] (node@node-0.simgrid.org) Start | Succ -> [ 360.19676] (node@node-0.simgrid.org) 3 | 533744 -> [ 360.19676] (node@node-0.simgrid.org) 4 | 16509405 -> [ 360.19676] (node@node-0.simgrid.org) 6 | 533744 -> [ 360.19676] (node@node-0.simgrid.org) Predecessor: 533744 -> [ 420.25020] (node@node-2.simgrid.org) Well Guys! I Think it's time for me to leave ;) -> [ 425.24229] (node@node-0.simgrid.org) My new predecessor is 42 -> [ 475.24229] (node@node-0.simgrid.org) My new finger #0 is 42 -> [ 480.24219] (node@node-0.simgrid.org) My new predecessor is 16728096 -> [ 480.24219] (node@node-0.simgrid.org) My finger table: -> [ 480.24219] (node@node-0.simgrid.org) Start | Succ -> [ 480.24219] (node@node-0.simgrid.org) 3 | 42 -> [ 480.24219] (node@node-0.simgrid.org) 4 | 16509405 -> [ 480.24219] (node@node-0.simgrid.org) 6 | 533744 -> [ 480.24219] (node@node-0.simgrid.org) Predecessor: 16728096 -> [ 485.24990] (node@node-6.simgrid.org) My new finger #2 is 42 -> [ 485.24990] (node@node-6.simgrid.org) My finger table: -> [ 485.24990] (node@node-6.simgrid.org) Start | Succ -> [ 485.24990] (node@node-6.simgrid.org) 1 | 42 -> [ 485.24990] (node@node-6.simgrid.org) 2 | 42 -> [ 485.24990] (node@node-6.simgrid.org) 4 | 42 -> [ 485.24990] (node@node-6.simgrid.org) Predecessor: -1 -> [ 495.25751] (node@node-0.simgrid.org) My new finger #0 is 16728096 -> [ 525.28032] (node@node-6.simgrid.org) My new predecessor is 42 -> [ 525.28032] (node@node-6.simgrid.org) My finger table: -> [ 525.28032] (node@node-6.simgrid.org) Start | Succ -> [ 525.28032] (node@node-6.simgrid.org) 1 | 42 -> [ 525.28032] (node@node-6.simgrid.org) 2 | 42 -> [ 525.28032] (node@node-6.simgrid.org) 4 | 42 -> [ 525.28032] (node@node-6.simgrid.org) Predecessor: 42 -> [ 600.31785] (node@node-0.simgrid.org) My new finger #1 is 16728096 -> [ 600.31785] (node@node-0.simgrid.org) My finger table: -> [ 600.31785] (node@node-0.simgrid.org) Start | Succ -> [ 600.31785] (node@node-0.simgrid.org) 3 | 16728096 -> [ 600.31785] (node@node-0.simgrid.org) 4 | 16728096 -> [ 600.31785] (node@node-0.simgrid.org) 6 | 533744 -> [ 600.31785] (node@node-0.simgrid.org) Predecessor: 16728096 -> [ 720.40913] (node@node-0.simgrid.org) My new finger #2 is 16728096 -> [ 720.40913] (node@node-0.simgrid.org) My finger table: -> [ 720.40913] (node@node-0.simgrid.org) Start | Succ -> [ 720.40913] (node@node-0.simgrid.org) 3 | 16728096 -> [ 720.40913] (node@node-0.simgrid.org) 4 | 16728096 -> [ 720.40913] (node@node-0.simgrid.org) 6 | 16728096 -> [ 720.40913] (node@node-0.simgrid.org) Predecessor: 16728096 -> [ 850.49239] (node@node-5.simgrid.org) Well Guys! I Think it's time for me to leave ;) -> [ 855.50791] (node@node-6.simgrid.org) My new finger #2 is 16728096 -> [ 855.50791] (node@node-6.simgrid.org) My finger table: -> [ 855.50791] (node@node-6.simgrid.org) Start | Succ -> [ 855.50791] (node@node-6.simgrid.org) 1 | 42 -> [ 855.50791] (node@node-6.simgrid.org) 2 | 42 -> [ 855.50791] (node@node-6.simgrid.org) 4 | 16728096 -> [ 855.50791] (node@node-6.simgrid.org) Predecessor: 42 -> [ 860.50781] (node@node-6.simgrid.org) Well Guys! I Think it's time for me to leave ;) -> [ 865.49990] (node@node-0.simgrid.org) My new predecessor is 42 -> [ 915.49990] (node@node-0.simgrid.org) My new finger #0 is 42 -> [ 920.49980] (node@node-0.simgrid.org) My new finger #0 is 16509405 -> [1030.49960] (node@node-0.simgrid.org) Well Guys! I Think it's time for me to leave ;) -> [1080.49960] (maestro@) Simulated time: 1080.5 +> [ 395.18925] (node@node-0.simgrid.org) My new finger #0 is 533744 +> [ 395.20486] (node@node-0.simgrid.org) My new finger #2 is 533744 +> [ 395.20486] (node@node-0.simgrid.org) My finger table: +> [ 395.20486] (node@node-0.simgrid.org) Start | Succ +> [ 395.20486] (node@node-0.simgrid.org) 3 | 533744 +> [ 395.20486] (node@node-0.simgrid.org) 4 | 16509405 +> [ 395.20486] (node@node-0.simgrid.org) 6 | 533744 +> [ 395.20486] (node@node-0.simgrid.org) Predecessor: 533744 +> [ 420.21217] (node@node-2.simgrid.org) Well Guys! I Think it's time for me to leave ;) +> [ 420.23559] (node@node-0.simgrid.org) My new predecessor is 42 +> [ 425.23549] (node@node-0.simgrid.org) My new finger #0 is 42 +> [ 440.23519] (node@node-0.simgrid.org) My new predecessor is 16728096 +> [ 440.23519] (node@node-0.simgrid.org) My finger table: +> [ 440.23519] (node@node-0.simgrid.org) Start | Succ +> [ 440.23519] (node@node-0.simgrid.org) 3 | 42 +> [ 440.23519] (node@node-0.simgrid.org) 4 | 16509405 +> [ 440.23519] (node@node-0.simgrid.org) 6 | 533744 +> [ 440.23519] (node@node-0.simgrid.org) Predecessor: 16728096 +> [ 440.23519] (node@node-0.simgrid.org) My new finger #0 is 16728096 +> [ 470.24239] (node@node-6.simgrid.org) My new predecessor is 42 +> [ 470.24239] (node@node-6.simgrid.org) My finger table: +> [ 470.24239] (node@node-6.simgrid.org) Start | Succ +> [ 470.24239] (node@node-6.simgrid.org) 1 | 42 +> [ 470.24239] (node@node-6.simgrid.org) 2 | 42 +> [ 470.24239] (node@node-6.simgrid.org) 4 | 16728096 +> [ 470.24239] (node@node-6.simgrid.org) Predecessor: 42 +> [ 635.37180] (node@node-0.simgrid.org) My new finger #1 is 16728096 +> [ 635.37180] (node@node-0.simgrid.org) My finger table: +> [ 635.37180] (node@node-0.simgrid.org) Start | Succ +> [ 635.37180] (node@node-0.simgrid.org) 3 | 16728096 +> [ 635.37180] (node@node-0.simgrid.org) 4 | 16728096 +> [ 635.37180] (node@node-0.simgrid.org) 6 | 533744 +> [ 635.37180] (node@node-0.simgrid.org) Predecessor: 16728096 +> [ 755.43185] (node@node-0.simgrid.org) My new finger #2 is 16728096 +> [ 755.43185] (node@node-0.simgrid.org) My finger table: +> [ 755.43185] (node@node-0.simgrid.org) Start | Succ +> [ 755.43185] (node@node-0.simgrid.org) 3 | 16728096 +> [ 755.43185] (node@node-0.simgrid.org) 4 | 16728096 +> [ 755.43185] (node@node-0.simgrid.org) 6 | 16728096 +> [ 755.43185] (node@node-0.simgrid.org) Predecessor: 16728096 +> [ 850.51581] (node@node-5.simgrid.org) Well Guys! I Think it's time for me to leave ;) +> [ 860.51561] (node@node-6.simgrid.org) Well Guys! I Think it's time for me to leave ;) +> [ 865.52332] (node@node-0.simgrid.org) My new predecessor is 42 +> [ 870.52322] (node@node-0.simgrid.org) My new finger #0 is 42 +> [ 950.52262] (node@node-0.simgrid.org) My new finger #0 is 16509405 +> [1000.52262] (node@node-0.simgrid.org) Well Guys! I Think it's time for me to leave ;) +> [1050.52262] (maestro@) Simulated time: 1050.52 diff --git a/include/xbt/RngStream.h b/include/xbt/RngStream.h deleted file mode 100644 index a9a675dee7..0000000000 --- a/include/xbt/RngStream.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2012-2019. 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. */ - -/* RngStream.h for ANSI C */ -#ifndef RNGSTREAM_H -#define RNGSTREAM_H - -#include - -typedef struct RngStream_InfoState * RngStream; - -struct RngStream_InfoState { - double Cg[6]; - double Bg[6]; - double Ig[6]; - int Anti; - int IncPrec; - char *name; -}; - -SG_BEGIN_DECL(); - -XBT_PUBLIC int RngStream_SetPackageSeed(unsigned long seed[6]); -XBT_PUBLIC RngStream RngStream_CreateStream(const char name[]); -XBT_PUBLIC void RngStream_DeleteStream(RngStream* pg); -XBT_PUBLIC RngStream RngStream_CopyStream(const RngStream src); -XBT_PUBLIC void RngStream_ResetStartStream(RngStream g); -XBT_PUBLIC void RngStream_ResetStartSubstream(RngStream g); -XBT_PUBLIC void RngStream_ResetNextSubstream(RngStream g); -XBT_PUBLIC void RngStream_SetAntithetic(RngStream g, int a); -XBT_PUBLIC void RngStream_IncreasedPrecis(RngStream g, int incp); -XBT_PUBLIC int RngStream_SetSeed(RngStream g, unsigned long seed[6]); -XBT_PUBLIC void RngStream_AdvanceState(RngStream g, long e, long c); -XBT_PUBLIC void RngStream_GetState(RngStream g, unsigned long seed[6]); -XBT_PUBLIC void RngStream_WriteState(RngStream g); -XBT_PUBLIC void RngStream_WriteStateFull(RngStream g); -XBT_PUBLIC double RngStream_RandU01(RngStream g); -XBT_PUBLIC int RngStream_RandInt(RngStream g, int i, int j); - -SG_END_DECL(); - -#endif - - diff --git a/sonar-project.properties b/sonar-project.properties index b1ac57cfe4..4d3c444092 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -145,8 +145,7 @@ sonar.issue.ignore.multicriteria.s4.resourceKey=src/smpi/**/*.cpp # - Collectives that we borrowed elsewhere (mpich, openMPI and other implems) # - the NAS, that are included in our examples # - The Catch2 library, that is included in our unit tests -# - RngStream, that is included in SimGrid -sonar.exclusions=src/include/catch.hpp,src/*_unit.c*,teshsuite/smpi/mpich3-test/**,teshsuite/smpi/isp/**,**/*_dtd.c,**/*_dtd.h,**/*yy.c,src/xbt/automaton/parserPromela.tab.*,src/smpi/colls/**/*,examples/smpi/NAS/*,examples/smpi/gemm/gemm.c,src/xbt/RngStream.c,include/xbt/RngStream.h +sonar.exclusions=src/include/catch.hpp,src/*_unit.c*,teshsuite/smpi/mpich3-test/**,teshsuite/smpi/isp/**,**/*_dtd.c,**/*_dtd.h,**/*yy.c,src/xbt/automaton/parserPromela.tab.*,src/smpi/colls/**/*,examples/smpi/NAS/*,examples/smpi/gemm/gemm.c # Exclude our examples from the duplication detection. # Examples are expected to be somehow repetitive diff --git a/src/bindings/java/jmsg_rngstream.cpp b/src/bindings/java/jmsg_rngstream.cpp deleted file mode 100644 index 1d4987cf87..0000000000 --- a/src/bindings/java/jmsg_rngstream.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* Java binding of the RngStream library */ - -/* Copyright (c) 2007-2019. 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. */ - -#include "xbt/sysdep.h" - -#include "jmsg_rngstream.h" -#include "jxbt_utilities.hpp" - -jfieldID jrngstream_bind; - -RngStream jrngstream_to_native(JNIEnv *env, jobject jrngstream) { - RngStream rngstream = (RngStream)(intptr_t)env->GetLongField(jrngstream, jrngstream_bind); - if (not rngstream) { - jxbt_throw_notbound(env, "rngstream", jrngstream); - return nullptr; - } - return rngstream; -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeInit(JNIEnv *env, jclass cls) { - jclass class_RngStream = env->FindClass("org/simgrid/msg/RngStream"); - - jrngstream_bind = jxbt_get_jfield(env, class_RngStream, "bind", "J"); -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_create(JNIEnv *env, jobject jrngstream, jstring jname) { - const char *name = env->GetStringUTFChars(jname, 0); - RngStream rngstream = RngStream_CreateStream(name); - //Bind the RngStream object - env->SetLongField(jrngstream, jrngstream_bind, (intptr_t)rngstream); - - env->ReleaseStringUTFChars(jname, name); -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - RngStream_DeleteStream(&rngstream); - env->SetLongField(jrngstream, jrngstream_bind, (intptr_t)nullptr); -} - -JNIEXPORT jboolean JNICALL -Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv *env, jobject jrngstream, jintArray jseed) { - - if (jseed == nullptr) { - jxbt_throw_null(env, xbt_strdup("seed argument is null")); - return JNI_FALSE; - } - - jint buffer[6]; - env->GetIntArrayRegion(jseed, 0, 6, buffer); - - // The C API expects unsigned long which are wider than int on LP64. - // We need to convert: - unsigned long seed[6]; - for (int i = 0; i != 6; ++i) - seed[i] = buffer[i]; - - int result = RngStream_SetPackageSeed(seed); - return result == -1 ? JNI_FALSE : JNI_TRUE; -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetStart(JNIEnv *env, jobject jrngstream) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return; - - RngStream_ResetStartStream(rngstream); -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetStartSubstream(JNIEnv *env, jobject jrngstream) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return; - - RngStream_ResetStartSubstream(rngstream); -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetNextSubstream(JNIEnv *env, jobject jrngstream) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return; - - RngStream_ResetNextSubstream(rngstream); -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_setAntithetic(JNIEnv *env, jobject jrngstream, jboolean ja) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return; - - if (ja == JNI_TRUE) { - RngStream_SetAntithetic(rngstream,-1); - } - else { - RngStream_SetAntithetic(rngstream,0); - } -} - -JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setSeed(JNIEnv *env, jobject jrngstream, jintArray jseed) { - jint buffer[6]; - - env->GetIntArrayRegion(jseed, 0, 6, buffer); - - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return JNI_FALSE; - - // The C API expects unsigned long which are wider than int on LP64. - // We need to convert: - unsigned long seed[6]; - for (int i = 0; i != 6; ++i) - seed[i] = buffer[i]; - - int result = RngStream_SetSeed(rngstream, seed); - - return result == -1 ? JNI_FALSE : JNI_TRUE; -} - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_advanceState(JNIEnv *env, jobject jrngstream, jint e, jint g) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return; - - RngStream_AdvanceState(rngstream, (long)e, (long)g); -} - -JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_RngStream_randU01(JNIEnv *env, jobject jrngstream) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return 0; - - return (jdouble)RngStream_RandU01(rngstream); -} - -JNIEXPORT jint JNICALL Java_org_simgrid_msg_RngStream_randInt(JNIEnv *env, jobject jrngstream, jint i, jint j) { - RngStream rngstream = jrngstream_to_native(env, jrngstream); - if (not rngstream) - return 0; - - return (jint)RngStream_RandInt(rngstream, (int)i, (int)j); -} diff --git a/src/bindings/java/jmsg_rngstream.h b/src/bindings/java/jmsg_rngstream.h deleted file mode 100644 index e92b58707a..0000000000 --- a/src/bindings/java/jmsg_rngstream.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Java binding of the RngStream library */ - -/* Copyright (c) 2007-2019. 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. */ - -#ifndef MSG_RNGSTREAM_H -#define MSG_RNGSTREAM_H - -#include "xbt/RngStream.h" -#include - -SG_BEGIN_DECL() - -/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ -#ifndef JNIEXPORT -#define JNIEXPORT -#endif -#ifndef JNICALL -#define JNICALL -#endif -/* end of eclipse-mandated pimple */ - -RngStream jrngstream_to_native(JNIEnv *env, jobject jrngstream); - -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeInit(JNIEnv *env, jclass cls); -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_create(JNIEnv *env, jobject jrngstream, jstring name); -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream); -JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv* env, jobject jrngstream, - jintArray seed); -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetStart(JNIEnv *env, jobject jrngstream); -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetStartSubstream(JNIEnv *env, jobject jrngstream); -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetNextSubstream(JNIEnv *env, jobject jrngstream); -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_setAntithetic(JNIEnv *env, jobject jrngstream, jboolean ja); -JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setSeed(JNIEnv *env, jobject jrngstream, jintArray jseed); -JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_advanceState(JNIEnv *env, jobject jrngstream, jint e, jint g); -JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_RngStream_randU01(JNIEnv *env, jobject jrngstream); -JNIEXPORT jint JNICALL Java_org_simgrid_msg_RngStream_randInt(JNIEnv *env, jobject jrngstream, jint i, jint j); - -SG_END_DECL() -#endif diff --git a/src/bindings/java/org/simgrid/msg/RngStream.java b/src/bindings/java/org/simgrid/msg/RngStream.java deleted file mode 100644 index 2209f49472..0000000000 --- a/src/bindings/java/org/simgrid/msg/RngStream.java +++ /dev/null @@ -1,117 +0,0 @@ -/* JNI interface to C RngStream code */ - -/* Copyright (c) 2006-2019. 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. */ - -package org.simgrid.msg; -/** - * Export of RngStreams for Java - */ -public class RngStream { - /** - * Represents the bind between the RngStream java object and the C object. - */ - private long bind; - /** - * Creates and returns a new stream without identifier. - * This procedure reserves space to keep the information relative to - * the RngStream, initializes its seed Ig , sets Bg and Cg equal to Ig , sets its antithetic and - * precision switches to 0. The seed Ig is equal to the initial seed of the package given by - * setPackageSeed if this is the first stream created, otherwise it is Z steps ahead - * of that of the most recently created stream. - */ - public RngStream() { - create(""); - } - /** - * Creates and returns a new stream with identifier "name". - * This procedure reserves space to keep the information relative to - * the RngStream, initializes its seed Ig , sets Bg and Cg equal to Ig , sets its antithetic and - * precision switches to 0. The seed Ig is equal to the initial seed of the package given by - * setPackageSeed if this is the first stream created, otherwise it is Z steps ahead - * of that of the most recently created stream. - */ - public RngStream(String name) { - create(name); - } - /** - * The natively implemented method to create a C RngStream object. - */ - private native void create(String name); - - /** @deprecated (from Java9 onwards) */ - @Deprecated @Override - protected void finalize() throws Throwable{ - nativeFinalize(); - } - /** - * Release the C RngStream object - */ - private native void nativeFinalize(); - - /** - * Sets the initial seed of the package RngStreams to the six integers in the vector seed. This will - * be the seed (initial state) of the first stream. If this procedure is not called, the default initial - * seed is (12345, 12345, 12345, 12345, 12345, 12345). If it is called, the first 3 values of the seed - * must all be less than m1 = 4294967087, and not all 0; and the last 3 values must all be less - * than m2 = 4294944443, and not all 0. Returns false for invalid seeds, and true otherwise. - */ - public static native boolean setPackageSeed(int[] seed); - /** - * Reinitializes the stream g to its initial state: Cg and Bg are set to Ig . - */ - public native void resetStart(); - /** - * Reinitializes the stream g to the beginning of its current substream: Cg is set to Bg . - */ - public native void restartStartSubstream(); - /** - * Reinitializes the stream g to the beginning of its next substream: Ng is computed, and Cg and - * Bg are set to Ng . - */ - public native void resetNextSubstream(); - /** - * If a = true the stream g will start generating antithetic variates, i.e., 1 - U instead of U , until - * this method is called again with a = false. - */ - public native void setAntithetic(boolean a); - /** - * Sets the initial seed Ig of stream g to the vector seed. This vector must satisfy the same - * conditions as in setPackageSeed. The stream is then reset to this initial seed. The - * states and seeds of the other streams are not modified. As a result, after calling this procedure, - * the initial seeds of the streams are no longer spaced Z values apart. We discourage the use of - * this procedure. Returns false for invalid seeds, and true otherwise. - */ - public native boolean setSeed(int[] seed); - /** - * Advances the state of the stream by k values, without modifying the states of other streams (as - * in RngStream_SetSeed), nor the values of Bg and Ig associated with this stream. If e > 0, then - * k = 2e + c; if e < 0, then k = -2-e + c; and if e = 0, then k = c. Note: c is allowed to take - * negative values. We discourage the use of this procedure. - */ - public native void advanceState(int e, int g); - - /** - * Returns a (pseudo)random number from the uniform distribution over the interval (0, 1), after advancing the state by one step. The returned number has 32 bits of precision - * in the sense that it is always a multiple of 1/(232 - 208), unless RngStream_IncreasedPrecis - * has been called for this stream. - */ - public native double randU01(); - /** - * Returns a (pseudo)random number from the discrete uniform distribution over the integers - * {i, i + 1, . . . , j} - */ - public native int randInt(int i, int j); - - /** - * Class initializer, to initialize various JNI stuff - */ - public static native void nativeInit(); - static { - org.simgrid.NativeLib.nativeInit(); - nativeInit(); - } -} diff --git a/src/xbt/RngStream.c b/src/xbt/RngStream.c deleted file mode 100644 index 4638fce239..0000000000 --- a/src/xbt/RngStream.c +++ /dev/null @@ -1,478 +0,0 @@ -/* Copyright (c) 2012-2019. 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. */ - -/***********************************************************************\ - * - * File: RngStream.c for multiple streams of Random Numbers - * Language: ANSI C - * Copyright: Pierre L'Ecuyer, University of Montreal - * Date: 14 August 2001 - * License: GPL version 2 or later - * - * Notice: Please contact P. L'Ecuyer at - * for commercial purposes. - * -\***********************************************************************/ - -#include "xbt/RngStream.h" -#include "xbt/sysdep.h" -#include -#include -#include - -/*---------------------------------------------------------------------*/ -/* Private part. */ -/*---------------------------------------------------------------------*/ - -#define norm 2.328306549295727688e-10 -#define m1 4294967087.0 -#define m2 4294944443.0 -#define a12 1403580.0 -#define a13n 810728.0 -#define a21 527612.0 -#define a23n 1370589.0 - -#define two17 131072.0 -#define two53 9007199254740992.0 -#define fact 5.9604644775390625e-8 /* 1 / 2^24 */ - -/* Default initial seed of the package. Will be updated to become the seed of the next created stream. */ -static double nextSeed[6] = { 12345, 12345, 12345, 12345, 12345, 12345 }; - -/* The following are the transition matrices of the two MRG components */ -/* (in matrix form), raised to the powers -1, 1, 2^76, and 2^127, resp.*/ -static double InvA1[3][3] = { /* Inverse of A1p0 */ - { 184888585.0, 0.0, 1945170933.0 }, - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 } - }; - -static double InvA2[3][3] = { /* Inverse of A2p0 */ - { 0.0, 360363334.0, 4225571728.0 }, - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 } - }; - -static double A1p0[3][3] = { - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - { -810728.0, 1403580.0, 0.0 } - }; - -static double A2p0[3][3] = { - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - { -1370589.0, 0.0, 527612.0 } - }; - -static double A1p76[3][3] = { - { 82758667.0, 1871391091.0, 4127413238.0 }, - { 3672831523.0, 69195019.0, 1871391091.0 }, - { 3672091415.0, 3528743235.0, 69195019.0 } - }; - -static double A2p76[3][3] = { - { 1511326704.0, 3759209742.0, 1610795712.0 }, - { 4292754251.0, 1511326704.0, 3889917532.0 }, - { 3859662829.0, 4292754251.0, 3708466080.0 } - }; - -static double A1p127[3][3] = { - { 2427906178.0, 3580155704.0, 949770784.0 }, - { 226153695.0, 1230515664.0, 3580155704.0 }, - { 1988835001.0, 986791581.0, 1230515664.0 } - }; - -static double A2p127[3][3] = { - { 1464411153.0, 277697599.0, 1610723613.0 }, - { 32183930.0, 1464411153.0, 1022607788.0 }, - { 2824425944.0, 32183930.0, 2093834863.0 } - }; - -static double MultModM (double a, double s, double c, double m) - /* Compute (a*s + c) % m. m must be < 2^35. Works also for s, c < 0 */ -{ - double v; - long a1; - v = a * s + c; - if ((v >= two53) || (v <= -two53)) { - a1 = (long) (a / two17); - a -= a1 * two17; - v = a1 * s; - a1 = (long) (v / m); - v -= a1 * m; - v = v * two17 + a * s + c; - } - a1 = (long) (v / m); - if ((v -= a1 * m) < 0.0) - return v += m; - else - return v; -} - -static void MatVecModM (double A[3][3], double s[3], double v[3], double m) - /* Returns v = A*s % m. Assumes that -m < s[i] < m. */ - /* Works even if v = s. */ -{ - int i; - double x[3]; - for (i = 0; i < 3; ++i) { - x[i] = MultModM (A[i][0], s[0], 0.0, m); - x[i] = MultModM (A[i][1], s[1], x[i], m); - x[i] = MultModM (A[i][2], s[2], x[i], m); - } - for (i = 0; i < 3; ++i) - v[i] = x[i]; -} - -static void MatMatModM (double A[3][3], double B[3][3], double C[3][3], double m) - /* Returns C = A*B % m. Work even if A = C or B = C or A = B = C. */ -{ - int i, j; - double V[3], W[3][3]; - for (i = 0; i < 3; ++i) { - for (j = 0; j < 3; ++j) - V[j] = B[j][i]; - MatVecModM (A, V, V, m); - for (j = 0; j < 3; ++j) - W[j][i] = V[j]; - } - for (i = 0; i < 3; ++i) { - for (j = 0; j < 3; ++j) - C[i][j] = W[i][j]; - } -} - -static void MatTwoPowModM (double A[3][3], double B[3][3], double m, long e) - /* Compute matrix B = (A^(2^e) % m); works even if A = B */ -{ - int i, j; - - /* initialize: B = A */ - if (A != B) { - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; ++j) - B[i][j] = A[i][j]; - } - } - /* Compute B = A^{2^e} */ - for (i = 0; i < e; i++) - MatMatModM (B, B, B, m); -} - -static void MatPowModM (double A[3][3], double B[3][3], double m, long n) - /* Compute matrix B = A^n % m ; works even if A = B */ -{ - int i, j; - double W[3][3]; - - /* initialize: W = A; B = I */ - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; ++j) { - W[i][j] = A[i][j]; - B[i][j] = 0.0; - } - } - for (j = 0; j < 3; ++j) - B[j][j] = 1.0; - - /* Compute B = A^n % m using the binary decomposition of n */ - while (n > 0) { - if (n % 2) - MatMatModM (W, B, B, m); - MatMatModM (W, W, W, m); - n /= 2; - } -} - -static double U01 (RngStream g) -{ - long k; - double p1, p2, u; - - /* Component 1 */ - p1 = a12 * g->Cg[1] - a13n * g->Cg[0]; - k = p1 / m1; - p1 -= k * m1; - if (p1 < 0.0) - p1 += m1; - g->Cg[0] = g->Cg[1]; - g->Cg[1] = g->Cg[2]; - g->Cg[2] = p1; - - /* Component 2 */ - p2 = a21 * g->Cg[5] - a23n * g->Cg[3]; - k = p2 / m2; - p2 -= k * m2; - if (p2 < 0.0) - p2 += m2; - g->Cg[3] = g->Cg[4]; - g->Cg[4] = g->Cg[5]; - g->Cg[5] = p2; - - /* Combination */ - u = ((p1 > p2) ? (p1 - p2) * norm : (p1 - p2 + m1) * norm); - return (g->Anti) ? (1 - u) : u; -} - -static double U01d (RngStream g) -{ - double u; - u = U01(g); - if (g->Anti == 0) { - u += U01(g) * fact; - return (u < 1.0) ? u : (u - 1.0); - } else { - /* Don't forget that U01() returns 1 - u in the antithetic case */ - u += (U01(g) - 1.0) * fact; - return (u < 0.0) ? u + 1.0 : u; - } -} - -static int CheckSeed (unsigned long seed[6]) -{ - /* Check that the seeds are legitimate values. Returns 0 if legal seeds, -1 otherwise */ - int i; - - for (i = 0; i < 3; ++i) { - if (seed[i] >= m1) { - fprintf (stderr, "****************************************\n" - "ERROR: Seed[%1d] >= m1, Seed is not set.\n" - "****************************************\n\n", i); - return (-1); - } - } - for (i = 3; i < 6; ++i) { - if (seed[i] >= m2) { - fprintf (stderr, "****************************************\n" - "ERROR: Seed[%1d] >= m1, Seed is not set.\n" - "****************************************\n\n", i); - return (-1); - } - } - if (seed[0] == 0 && seed[1] == 0 && seed[2] == 0) { - fprintf (stderr, "****************************\n" - "ERROR: First 3 seeds = 0.\n" - "****************************\n\n"); - return (-1); - } - if (seed[3] == 0 && seed[4] == 0 && seed[5] == 0) { - fprintf (stderr, "****************************\n" - "ERROR: Last 3 seeds = 0.\n" - "****************************\n\n"); - return (-1); - } - - return 0; -} - -/*---------------------------------------------------------------------*/ -/* Public part. */ -/*---------------------------------------------------------------------*/ - -RngStream RngStream_CreateStream (const char name[]) -{ - int i; - RngStream g; - size_t len; - - g = (RngStream) xbt_malloc (sizeof (struct RngStream_InfoState)); - if (g == NULL) { - printf ("RngStream_CreateStream: No more memory\n\n"); - exit (EXIT_FAILURE); - } - if (name) { - len = strlen (name); - g->name = (char *) xbt_malloc ((len + 1) * sizeof (char)); - memcpy(g->name, name, len + 1); - } else - g->name = 0; - g->Anti = 0; - g->IncPrec = 0; - - for (i = 0; i < 6; ++i) { - g->Bg[i] = g->Cg[i] = g->Ig[i] = nextSeed[i]; - } - MatVecModM (A1p127, nextSeed, nextSeed, m1); - MatVecModM (A2p127, &nextSeed[3], &nextSeed[3], m2); - return g; -} - -void RngStream_DeleteStream (RngStream * p) -{ - if (*p == NULL) - return; - free((*p)->name); - free (*p); - *p = NULL; -} - -RngStream RngStream_CopyStream (const RngStream src) -{ - RngStream g; - - if(src == NULL) { - printf ("RngStream_CopyStream: 'src' not initialized\n\n"); - exit (EXIT_FAILURE); - } - - g = (RngStream) xbt_malloc (sizeof (struct RngStream_InfoState)); - if (g == NULL) { - printf ("RngStream_CopyStream: No more memory\n\n"); - exit (EXIT_FAILURE); - } - memcpy((void*) g, (void*) src, sizeof (struct RngStream_InfoState)); - - return g; -} - -void RngStream_ResetStartStream (RngStream g) -{ - int i; - for (i = 0; i < 6; ++i) - g->Cg[i] = g->Bg[i] = g->Ig[i]; -} - -void RngStream_ResetNextSubstream (RngStream g) -{ - int i; - MatVecModM (A1p76, g->Bg, g->Bg, m1); - MatVecModM (A2p76, &g->Bg[3], &g->Bg[3], m2); - for (i = 0; i < 6; ++i) - g->Cg[i] = g->Bg[i]; -} - -void RngStream_ResetStartSubstream (RngStream g) -{ - int i; - for (i = 0; i < 6; ++i) - g->Cg[i] = g->Bg[i]; -} - -int RngStream_SetPackageSeed (unsigned long seed[6]) -{ - int i; - if (CheckSeed (seed)) - return -1; /* FAILURE */ - for (i = 0; i < 6; ++i) - nextSeed[i] = seed[i]; - return 0; /* SUCCESS */ -} - -int RngStream_SetSeed (RngStream g, unsigned long seed[6]) -{ - int i; - if (CheckSeed (seed)) - return -1; /* FAILURE */ - for (i = 0; i < 6; ++i) - g->Cg[i] = g->Bg[i] = g->Ig[i] = seed[i]; - return 0; /* SUCCESS */ -} - -void RngStream_AdvanceState (RngStream g, long e, long c) -{ - double B1[3][3], C1[3][3], B2[3][3], C2[3][3]; - - if (e > 0) { - MatTwoPowModM (A1p0, B1, m1, e); - MatTwoPowModM (A2p0, B2, m2, e); - } else if (e < 0) { - MatTwoPowModM (InvA1, B1, m1, -e); - MatTwoPowModM (InvA2, B2, m2, -e); - } - - if (c >= 0) { - MatPowModM (A1p0, C1, m1, c); - MatPowModM (A2p0, C2, m2, c); - } else { - MatPowModM (InvA1, C1, m1, -c); - MatPowModM (InvA2, C2, m2, -c); - } - - if (e) { - MatMatModM (B1, C1, C1, m1); - MatMatModM (B2, C2, C2, m2); - } - - MatVecModM (C1, g->Cg, g->Cg, m1); - MatVecModM (C2, &g->Cg[3], &g->Cg[3], m2); -} - -void RngStream_GetState (RngStream g, unsigned long seed[6]) -{ - int i; - for (i = 0; i < 6; ++i) - seed[i] = g->Cg[i]; -} - -void RngStream_WriteState (RngStream g) -{ - int i; - if (g == NULL) - return; - printf ("The current state of the Rngstream"); - if (g->name && (strlen (g->name) > 0)) - printf (" %s", g->name); - printf (":\n Cg = { "); - - for (i = 0; i < 5; i++) { - printf ("%lu, ", (unsigned long) g->Cg[i]); - } - printf ("%lu }\n\n", (unsigned long) g->Cg[5]); -} - -void RngStream_WriteStateFull (RngStream g) -{ - int i; - if (g == NULL) - return; - printf ("The RngStream"); - if (g->name && (strlen (g->name) > 0)) - printf (" %s", g->name); - printf (":\n Anti = %s\n", (g->Anti ? "true" : "false")); - printf (" IncPrec = %s\n", (g->IncPrec ? "true" : "false")); - - printf (" Ig = { "); - for (i = 0; i < 5; i++) { - printf ("%lu, ", (unsigned long) (g->Ig[i])); - } - printf ("%lu }\n", (unsigned long) g->Ig[5]); - - printf (" Bg = { "); - for (i = 0; i < 5; i++) { - printf ("%lu, ", (unsigned long) (g->Bg[i])); - } - printf ("%lu }\n", (unsigned long) g->Bg[5]); - - printf (" Cg = { "); - for (i = 0; i < 5; i++) { - printf ("%lu, ", (unsigned long) (g->Cg[i])); - } - printf ("%lu }\n\n", (unsigned long) g->Cg[5]); -} - -void RngStream_IncreasedPrecis (RngStream g, int incp) -{ - g->IncPrec = incp; -} - -void RngStream_SetAntithetic (RngStream g, int a) -{ - g->Anti = a; -} - -double RngStream_RandU01 (RngStream g) -{ - if (g->IncPrec) - return U01d (g); - else - return U01 (g); -} - -int RngStream_RandInt (RngStream g, int i, int j) -{ - return i + (int) ((j - i + 1.0) * RngStream_RandU01 (g)); -} diff --git a/teshsuite/msg/app-bittorrent/bittorrent-peer.c b/teshsuite/msg/app-bittorrent/bittorrent-peer.c index 308a7b8392..e1b6cba2d8 100644 --- a/teshsuite/msg/app-bittorrent/bittorrent-peer.c +++ b/teshsuite/msg/app-bittorrent/bittorrent-peer.c @@ -8,7 +8,6 @@ #include "connection.h" #include "tracker.h" #include -#include #include #include /* snprintf */ @@ -246,7 +245,6 @@ peer_t peer_init(int id, int seed) peer->pieces_count = xbt_new0(short, FILE_PIECES); - peer->stream = (RngStream)MSG_host_get_data(MSG_host_self()); peer->comm_received = NULL; peer->round = 0; @@ -499,7 +497,7 @@ int select_piece_to_download(peer_t peer, connection_t remote_peer) } xbt_assert(nb_interesting_pieces != 0); // get a random interesting piece - int random_piece_index = RngStream_RandInt(peer->stream, 0, nb_interesting_pieces - 1); + int random_piece_index = rand() % nb_interesting_pieces; int current_index = 0; for (int i = 0; i < FILE_PIECES; i++) { if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i)) { @@ -525,7 +523,7 @@ int select_piece_to_download(peer_t peer, connection_t remote_peer) } xbt_assert(nb_interesting_pieces != 0); // get a random interesting piece - int random_piece_index = RngStream_RandInt(peer->stream, 0, nb_interesting_pieces - 1); + int random_piece_index = rand() % nb_interesting_pieces; int current_index = 0; for (int i = 0; i < FILE_PIECES; i++) { if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) && @@ -558,7 +556,10 @@ int select_piece_to_download(peer_t peer, connection_t remote_peer) } xbt_assert(nb_min_pieces != 0 || (is_interested_and_free(peer, remote_peer) == 0)); // get a random rarest piece - int random_rarest_index = RngStream_RandInt(peer->stream, 0, nb_min_pieces - 1); + int random_rarest_index = 0; + if (nb_min_pieces > 0) { + random_rarest_index = rand() % nb_min_pieces; + } for (int i = 0; i < FILE_PIECES; i++) { if (peer->pieces_count[i] == min && peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) && peer_is_not_downloading_piece(peer, i)) { @@ -615,7 +616,10 @@ void update_choked_peers(peer_t peer) int j = 0; do { // We choose a random peer to unchoke. - int id_chosen = RngStream_RandInt(peer->stream, 0, xbt_dict_length(peer->peers) - 1); + int id_chosen = 0; + if (xbt_dict_length(peer->peers) > 0) { + id_chosen = rand() % xbt_dict_length(peer->peers); + } int i = 0; connection_t connection; xbt_dict_foreach (peer->peers, cursor, key, connection) { diff --git a/teshsuite/msg/app-bittorrent/bittorrent-peer.h b/teshsuite/msg/app-bittorrent/bittorrent-peer.h index 0ffdd83328..21d6a13ace 100644 --- a/teshsuite/msg/app-bittorrent/bittorrent-peer.h +++ b/teshsuite/msg/app-bittorrent/bittorrent-peer.h @@ -9,7 +9,6 @@ #include "bittorrent.h" #include "connection.h" #include -#include #include #include @@ -34,8 +33,6 @@ typedef struct s_peer { msg_task_t task_received; // current task being received msg_comm_t comm_received; // current comm - RngStream stream; // RngStream for - double begin_receive_time; // time when the receiving communication has begun, useful for calculating host speed. } s_peer_t; typedef s_peer_t* peer_t; diff --git a/teshsuite/msg/app-bittorrent/bittorrent.c b/teshsuite/msg/app-bittorrent/bittorrent.c index debad6f06f..d278ae055b 100644 --- a/teshsuite/msg/app-bittorrent/bittorrent.c +++ b/teshsuite/msg/app-bittorrent/bittorrent.c @@ -7,7 +7,6 @@ #include "bittorrent-peer.h" #include "tracker.h" #include -#include #include /* snprintf */ @@ -28,8 +27,6 @@ int main(int argc, char* argv[]) xbt_dynar_foreach (host_list, i, host) { char descr[512]; snprintf(descr, sizeof descr, "RngSream<%s>", MSG_host_get_name(host)); - RngStream stream = RngStream_CreateStream(descr); - MSG_host_set_data(host, stream); } MSG_function_register("tracker", tracker); @@ -39,11 +36,6 @@ int main(int argc, char* argv[]) MSG_main(); - xbt_dynar_foreach (host_list, i, host) { - RngStream stream = (RngStream)MSG_host_get_data(host); - RngStream_DeleteStream(&stream); - MSG_host_set_data(host, NULL); - } xbt_dynar_free(&host_list); return 0; diff --git a/teshsuite/msg/app-bittorrent/tracker.c b/teshsuite/msg/app-bittorrent/tracker.c index dab3a1c3dd..ba830b700c 100644 --- a/teshsuite/msg/app-bittorrent/tracker.c +++ b/teshsuite/msg/app-bittorrent/tracker.c @@ -6,7 +6,6 @@ #include "tracker.h" #include -#include static void task_free(void* data); @@ -24,7 +23,6 @@ int tracker(int argc, char* argv[]) double deadline = xbt_str_parse_double(argv[1], "Invalid deadline: %s"); xbt_assert(deadline > 0, "Wrong deadline supplied"); - RngStream stream = (RngStream)MSG_host_get_data(MSG_host_self()); // Building peers array xbt_dynar_t peers_list = xbt_dynar_new(sizeof(int), NULL); @@ -51,7 +49,7 @@ int tracker(int argc, char* argv[]) int peers_length = xbt_dynar_length(peers_list); for (int i = 0; i < MAXIMUM_PEERS && i < peers_length; i++) { do { - next_peer = xbt_dynar_get_as(peers_list, RngStream_RandInt(stream, 0, peers_length - 1), int); + next_peer = xbt_dynar_get_as(peers_list, rand() % peers_length, int); } while (is_in_list(data->peers, next_peer)); xbt_dynar_push_as(data->peers, int, next_peer); } diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index b987e4a9a0..180f99e848 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -266,7 +266,6 @@ set(SMPI_SRC ) set(XBT_SRC - src/xbt/RngStream.c src/xbt/automaton/automaton.c src/xbt/automaton/automatonparse_promela.c src/xbt/backtrace.cpp @@ -496,8 +495,6 @@ set(JMSG_C_SRC src/bindings/java/jmsg_host.h src/bindings/java/jmsg_process.cpp src/bindings/java/jmsg_process.h - src/bindings/java/jmsg_rngstream.cpp - src/bindings/java/jmsg_rngstream.h src/bindings/java/jmsg_synchro.cpp src/bindings/java/jmsg_synchro.h src/bindings/java/jmsg_task.cpp @@ -527,7 +524,6 @@ set(JMSG_JAVA_SRC src/bindings/java/org/simgrid/msg/Process.java src/bindings/java/org/simgrid/msg/ProcessKilledError.java src/bindings/java/org/simgrid/msg/ProcessNotFoundException.java - src/bindings/java/org/simgrid/msg/RngStream.java src/bindings/java/org/simgrid/msg/Semaphore.java src/bindings/java/org/simgrid/msg/Storage.java src/bindings/java/org/simgrid/msg/StorageNotFoundException.java @@ -777,7 +773,6 @@ set(headers_to_install include/xbt/parmap.h include/xbt/range.hpp include/xbt/replay.hpp - include/xbt/RngStream.h include/xbt/signal.hpp include/xbt/str.h include/xbt/string.hpp