From: Martin Quinson Date: Mon, 27 Nov 2017 20:10:37 +0000 (+0100) Subject: Merge pull request #244 from Takishipp/actor-yield X-Git-Tag: v3.18~227 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7bc340a73928fe73a57a9664aeba0cf5a92b654c?hp=77bbf3027c4240a2e833209a3a3f186589da8577 Merge pull request #244 from Takishipp/actor-yield S4U version of actor-yield example --- diff --git a/doc/doxygen/image/eclipseScreenShot.png b/doc/doxygen/image/eclipseScreenShot.png new file mode 100644 index 0000000000..4111737ad6 Binary files /dev/null and b/doc/doxygen/image/eclipseScreenShot.png differ diff --git a/doc/doxygen/inside_release.doc b/doc/doxygen/inside_release.doc index 5fbed80d8c..186ec03eff 100644 --- a/doc/doxygen/inside_release.doc +++ b/doc/doxygen/inside_release.doc @@ -100,7 +100,8 @@ the settings icon of the release you want to change. - the ChangeLog chunk as attachment - Also mail some other lists (G5K users), with only the NEWS chunk and the link to the download section -- Release the debian package +- Release the debian package +- Update the simgrid/package.py for spack: https://github.com/solverstack/spack - Create the template for the next release in ChangeLog and NEWS files - Change the release number in CMakeLists.txt diff --git a/doc/doxygen/install_yours.doc b/doc/doxygen/install_yours.doc index da754cda74..e8f454b516 100644 --- a/doc/doxygen/install_yours.doc +++ b/doc/doxygen/install_yours.doc @@ -91,7 +91,17 @@ clean: .PHONY: clean @endverbatim -@section install_yours_javaexamples Building the Java examples in Eclipse +@section install_yours_cppeclipsedevenv Develop in C++ with SimGrid with Eclipse + +If you wish to develop your plugin or modify SimGrid using Eclipse. You have to run cmake and import it as a Makefile project. + +Next you have to activate C++11 in your build settings, add -std=c++11 in the CDT GCC Built-in compiler settings. + + \image html eclipseScreenShot.png "Eclipse preference page" width=10cm + + + +@section install_yours_javaexample Building the Java examples in Eclipse If you want to build our Java examples in Eclipse, get the whole source code and open the archive on your disk. In Eclipse, select diff --git a/examples/java/app/masterworker/Master.java b/examples/java/app/masterworker/Master.java index 6de1072d35..a88332b880 100644 --- a/examples/java/app/masterworker/Master.java +++ b/examples/java/app/masterworker/Master.java @@ -29,7 +29,7 @@ public class Master extends Process { int workersCount = Integer.parseInt(args[3]); - Msg.info("Hello! Got "+ workersCount + " workers and "+tasksCount+" tasks to process"); + Msg.info("Hello! My PID is "+getPID()+". Got "+ workersCount + " workers and "+tasksCount+" tasks to process"); for (int i = 0; i < tasksCount; i++) { Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); diff --git a/examples/java/app/masterworker/Worker.java b/examples/java/app/masterworker/Worker.java index dc7d44fb96..20113dd7e6 100644 --- a/examples/java/app/masterworker/Worker.java +++ b/examples/java/app/masterworker/Worker.java @@ -34,7 +34,7 @@ public class Worker extends Process { if ("finalize".equals(task.getName())) { break; } - Msg.info("Received \"" + task.getName() + "\". Processing it."); + Msg.info("Received \"" + task.getName() + "\". Processing it (my pid is "+getPID()+")."); try { task.execute(); } catch (TaskCancelledException e) { diff --git a/examples/java/app/masterworker/app-masterworker.tesh b/examples/java/app/masterworker/app-masterworker.tesh index e2fcf87955..fdf4de7153 100644 --- a/examples/java/app/masterworker/app-masterworker.tesh +++ b/examples/java/app/masterworker/app-masterworker.tesh @@ -2,12 +2,12 @@ $ java -classpath ${classpath:=.} app/masterworker/Main ${srcdir:=.}/../platforms/small_platform.xml ${srcdir:=.}/app/masterworker/masterworker.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Using regular java threads. -> [ 0.000000] (1:app.masterworker.Master@Jacquelin) Hello! Got 7 workers and 5 tasks to process -> [ 0.860026] (2:app.masterworker.Worker@Tremblay) Received "Task_0". Processing it. -> [ 1.752187] (3:app.masterworker.Worker@Fafard) Received "Task_1". Processing it. -> [ 1.757531] (4:app.masterworker.Worker@Bourassa) Received "Task_2". Processing it. -> [ 2.806417] (5:app.masterworker.Worker@Boivin) Received "Task_3". Processing it. -> [ 2.811761] (6:app.masterworker.Worker@Ginette) Received "Task_4". Processing it. +> [ 0.000000] (1:app.masterworker.Master@Jacquelin) Hello! My PID is 1. Got 7 workers and 5 tasks to process +> [ 0.860026] (2:app.masterworker.Worker@Tremblay) Received "Task_0". Processing it (my pid is 2). +> [ 1.752187] (3:app.masterworker.Worker@Fafard) Received "Task_1". Processing it (my pid is 3). +> [ 1.757531] (4:app.masterworker.Worker@Bourassa) Received "Task_2". Processing it (my pid is 4). +> [ 2.806417] (5:app.masterworker.Worker@Boivin) Received "Task_3". Processing it (my pid is 5). +> [ 2.811761] (6:app.masterworker.Worker@Ginette) Received "Task_4". Processing it (my pid is 6). > [ 2.811761] (1:app.masterworker.Master@Jacquelin) All tasks have been dispatched. Let's tell everybody the computation is over. > [ 3.671783] (2:app.masterworker.Worker@Tremblay) Received Finalize. I'm done. See you! > [ 4.563940] (3:app.masterworker.Worker@Fafard) Received Finalize. I'm done. See you! diff --git a/examples/java/io/file/Main.java b/examples/java/io/file/Main.java index 6134fe81ce..d0dd64c734 100644 --- a/examples/java/io/file/Main.java +++ b/examples/java/io/file/Main.java @@ -15,6 +15,7 @@ public class Main { public static void main(String[] args) { Msg.init(args); + Msg.fileSystemInit(); if(args.length < 1) { Msg.info("Usage : IO platform_file "); Msg.info("example : IO ../platforms/storage/storage.xml "); diff --git a/examples/java/io/storage/Main.java b/examples/java/io/storage/Main.java index 306eee8442..0e8392eadc 100644 --- a/examples/java/io/storage/Main.java +++ b/examples/java/io/storage/Main.java @@ -14,6 +14,7 @@ public class Main { public static void main(String[] args) { Msg.init(args); + Msg.fileSystemInit(); if(args.length < 1) { Msg.info("Usage : Storage platform_file "); Msg.info("example : Storage ../platforms/storage/storage.xml "); diff --git a/examples/msg/io-file/io-file.c b/examples/msg/io-file/io-file.c index c0ad633899..ec150573c7 100644 --- a/examples/msg/io-file/io-file.c +++ b/examples/msg/io-file/io-file.c @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/msg.h" +#include "simgrid/plugins/file_system.h" XBT_LOG_NEW_DEFAULT_CATEGORY(io_file, "Messages specific for this io example"); @@ -88,6 +89,8 @@ static int host(int argc, char *argv[]) int main(int argc, char **argv) { MSG_init(&argc, argv); + MSG_storage_file_system_init(); + MSG_create_environment(argv[1]); xbt_dynar_t hosts = MSG_hosts_as_dynar(); MSG_function_register("host", host); diff --git a/examples/msg/io-file/io-file.tesh b/examples/msg/io-file/io-file.tesh index d3700afca5..34f4ef03c0 100644 --- a/examples/msg/io-file/io-file.tesh +++ b/examples/msg/io-file/io-file.tesh @@ -3,8 +3,11 @@ $ ${bindir:=.}/io-file ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Number of host '4' > [ 0.000000] (1:host@alice) Open file 'c:\Windows\setupact.log' +> [ 0.000000] (1:host@alice) Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000 > [ 0.000000] (2:host@bob) Open file '/home/doc/simgrid/examples/platforms/nancy.xml' +> [ 0.000000] (2:host@bob) Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36933331 / 536870912000 > [ 0.000000] (3:host@carl) Open file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' +> [ 0.000000] (3:host@carl) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36933331 / 536870912000 > [ 0.000000] (4:host@denise) File Descriptor information: > Full path: '/home/doc/simgrid/examples/platforms/g5k.xml' > Size: 17028 @@ -13,9 +16,6 @@ $ ${bindir:=.}/io-file ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r] > Storage Type: 'single_SSD' > File Descriptor Id: 0 > [ 0.000000] (4:host@denise) Open file '/home/doc/simgrid/examples/platforms/g5k.xml' -> [ 0.000000] (1:host@alice) Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000 -> [ 0.000000] (2:host@bob) Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36933331 / 536870912000 -> [ 0.000000] (3:host@carl) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36933331 / 536870912000 > [ 0.000000] (4:host@denise) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13221994 / 536870912000 > [ 0.000040] (2:host@bob) Have read 4028 from '/home/doc/simgrid/examples/platforms/nancy.xml' > [ 0.000085] (4:host@denise) Have read 17028 from '/home/doc/simgrid/examples/platforms/g5k.xml' diff --git a/examples/msg/io-remote/io-remote.c b/examples/msg/io-remote/io-remote.c index 948950bc45..aaece80b15 100644 --- a/examples/msg/io-remote/io-remote.c +++ b/examples/msg/io-remote/io-remote.c @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/msg.h" +#include "simgrid/plugins/file_system.h" #define INMEGA (1024*1024) @@ -55,6 +56,8 @@ int main(int argc, char **argv) msg_storage_t st; MSG_init(&argc, argv); + MSG_storage_file_system_init(); + MSG_create_environment(argv[1]); MSG_function_register("host", host); MSG_launch_application(argv[2]); diff --git a/examples/msg/io-storage/io-storage.c b/examples/msg/io-storage/io-storage.c index 298e6e6501..69d0713305 100644 --- a/examples/msg/io-storage/io-storage.c +++ b/examples/msg/io-storage/io-storage.c @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/msg.h" +#include "simgrid/plugins/file_system.h" XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation"); @@ -114,6 +115,8 @@ static int host(int argc, char *argv[]){ int main(int argc, char *argv[]) { MSG_init(&argc, argv); + MSG_storage_file_system_init(); + MSG_create_environment(argv[1]); MSG_function_register("host", host); xbt_dynar_t hosts = MSG_hosts_as_dynar(); diff --git a/examples/s4u/actions-storage/s4u-actions-storage.cpp b/examples/s4u/actions-storage/s4u-actions-storage.cpp index 79a8ababd3..39d8bd5d3d 100644 --- a/examples/s4u/actions-storage/s4u-actions-storage.cpp +++ b/examples/s4u/actions-storage/s4u-actions-storage.cpp @@ -103,6 +103,7 @@ public: int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); + sg_storage_file_system_init(); xbt_assert(argc > 3, "Usage: %s platform_file deployment_file [action_files]\n" "\texample: %s platform.xml deployment.xml actions # if all actions are in the same file\n" diff --git a/examples/s4u/energy-link/s4u-energy-link.cpp b/examples/s4u/energy-link/s4u-energy-link.cpp index 94de986637..e64eccf1b9 100644 --- a/examples/s4u/energy-link/s4u-energy-link.cpp +++ b/examples/s4u/energy-link/s4u-energy-link.cpp @@ -24,6 +24,7 @@ static void sender(std::vector args) simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::string("message")); + /* Sleep a while before starting the example */ simgrid::s4u::this_actor::sleep_for(10); /* - Send the task to the @ref worker */ diff --git a/examples/s4u/io/s4u-io.cpp b/examples/s4u/io/s4u-io.cpp index 46a50133c6..c78369746d 100644 --- a/examples/s4u/io/s4u-io.cpp +++ b/examples/s4u/io/s4u-io.cpp @@ -86,6 +86,7 @@ public: int main(int argc, char **argv) { simgrid::s4u::Engine e(&argc, argv); + sg_storage_file_system_init(); e.loadPlatform("../../platforms/storage/storage.xml"); simgrid::s4u::Actor::createActor("host", simgrid::s4u::Host::by_name("denise"), MyHost()); e.run(); diff --git a/include/simgrid/plugins/file_system.h b/include/simgrid/plugins/file_system.h new file mode 100644 index 0000000000..bb22a1a63a --- /dev/null +++ b/include/simgrid/plugins/file_system.h @@ -0,0 +1,21 @@ +/* Copyright (c) 2017. 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 SIMGRID_PLUGINS_FILE_SYSTEM_H_ +#define SIMGRID_PLUGINS_FILE_SYSTEM_H_ + +#include +#include + +SG_BEGIN_DECL() + +XBT_PUBLIC(void) sg_storage_file_system_init(); + +#define MSG_storage_file_system_init() sg_storage_file_system_init() + +SG_END_DECL() + +#endif diff --git a/include/simgrid/s4u/File.hpp b/include/simgrid/s4u/File.hpp index 70249e3c55..e821cc196f 100644 --- a/include/simgrid/s4u/File.hpp +++ b/include/simgrid/s4u/File.hpp @@ -6,6 +6,8 @@ #ifndef SIMGRID_S4U_FILE_HPP #define SIMGRID_S4U_FILE_HPP +#include "simgrid/plugins/file_system.h" +#include #include #include @@ -70,6 +72,21 @@ private: sg_size_t current_position_ = SEEK_SET; void* userdata_ = nullptr; }; + +class FileSystemStorageExt { +public: + static simgrid::xbt::Extension EXTENSION_ID; + explicit FileSystemStorageExt(simgrid::s4u::Storage* ptr); + ~FileSystemStorageExt(); + std::map* parseContent(std::string filename); + std::map* getContent() { return content_; } + sg_size_t getUsedSize() { return usedSize_; } + void decrUsedSize(sg_size_t size) { usedSize_ -= size; } + void incrUsedSize(sg_size_t size) { usedSize_ += size; } +private: + std::map* content_; + sg_size_t usedSize_ = 0; +}; } } // namespace simgrid::s4u diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index c009740e9d..8ba939c39e 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -7,6 +7,7 @@ #ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_ #define INCLUDE_SIMGRID_S4U_STORAGE_HPP_ +#include "xbt/Extendable.hpp" #include #include #include @@ -15,11 +16,14 @@ #include namespace simgrid { +namespace xbt { +extern template class XBT_PUBLIC() Extendable; +} namespace s4u { XBT_ATTRIB_PUBLIC std::map* allStorages(); -XBT_PUBLIC_CLASS Storage +XBT_PUBLIC_CLASS Storage : public simgrid::xbt::Extendable { friend s4u::Engine; friend simgrid::surf::StorageImpl; @@ -39,6 +43,7 @@ public: sg_size_t getSizeFree(); sg_size_t getSizeUsed(); void decrUsedSize(sg_size_t size); + void incrUsedSize(sg_size_t size); std::map* getProperties(); const char* getProperty(std::string key); diff --git a/include/xbt/swag.h b/include/xbt/swag.h index 0f25e2b29b..f56e8f64e3 100644 --- a/include/xbt/swag.h +++ b/include/xbt/swag.h @@ -74,6 +74,7 @@ struct xbt_swag { }; typedef struct xbt_swag s_xbt_swag_t; typedef struct xbt_swag* xbt_swag_t; +typedef const struct xbt_swag* const_xbt_swag_t; /**< A typical swag */ /* @} */ @@ -108,13 +109,13 @@ XBT_PUBLIC(void) xbt_swag_insert_at_head(void *obj, xbt_swag_t swag); XBT_PUBLIC(void) xbt_swag_insert_at_tail(void *obj, xbt_swag_t swag); XBT_PUBLIC(void *) xbt_swag_remove(void *obj, xbt_swag_t swag); XBT_PUBLIC(void *) xbt_swag_extract(xbt_swag_t swag); -XBT_PUBLIC(int) xbt_swag_size(xbt_swag_t swag); +XBT_PUBLIC(int) xbt_swag_size(const_xbt_swag_t swag); #define xbt_swag_getPrev(obj, offset) (((xbt_swag_hookup_t)(((char *) (obj)) + (offset)))->prev) #define xbt_swag_getNext(obj, offset) (((xbt_swag_hookup_t)(((char *) (obj)) + (offset)))->next) #define xbt_swag_belongs(obj, swag) (xbt_swag_getNext((obj), (swag)->offset) || (swag)->tail == (obj)) -static inline void *xbt_swag_getFirst(xbt_swag_t swag) +static inline void *xbt_swag_getFirst(const_xbt_swag_t swag) { return (swag->head); } diff --git a/sonar-project.properties b/sonar-project.properties index ab7e01222b..1d43b052a6 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,5 @@ # This file is used to scan the project for issues automatically -# Browse the result here: https://sonarqube.com/dashboard?id=simgrid +# Browse the result here: https://sonarcloud.io/dashboard/?id=simgrid sonar.projectKey=simgrid sonar.projectName=SimGrid diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 21b56a96f4..44f5f5fbcb 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -11,6 +11,7 @@ #include "simgrid/msg.h" #include "simgrid/plugins/energy.h" +#include "simgrid/plugins/file_system.h" #include "simgrid/simix.h" #include "simgrid/s4u/Host.hpp" @@ -239,6 +240,11 @@ Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, jstring jde JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit() { sg_host_energy_plugin_init(); } + +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_fileSystemInit() +{ + sg_storage_file_system_init(); +} } // extern "C" /** Run a Java org.simgrid.msg.Process diff --git a/src/bindings/java/jmsg.hpp b/src/bindings/java/jmsg.hpp index 295a93800b..e7d0919c0f 100644 --- a/src/bindings/java/jmsg.hpp +++ b/src/bindings/java/jmsg.hpp @@ -37,6 +37,7 @@ JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv* env, jclass JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv* env, jclass cls, jobjectArray jargs); JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit(); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_fileSystemInit(); JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_debug(JNIEnv* env, jclass cls, jstring jargs); JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_verb(JNIEnv* env, jclass cls, jstring jargs); diff --git a/src/bindings/java/jmsg_process.cpp b/src/bindings/java/jmsg_process.cpp index 1d4b58eadf..05ba285b57 100644 --- a/src/bindings/java/jmsg_process.cpp +++ b/src/bindings/java/jmsg_process.cpp @@ -127,6 +127,12 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jcl return jprocess; } +JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_nativeGetPID(JNIEnv* env, jobject jprocess) +{ + msg_process_t process = jprocess_to_native(jprocess, env); + return MSG_process_get_PID(process); +} + JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) { msg_process_t process = jprocess_to_native(jprocess, env); diff --git a/src/bindings/java/jmsg_process.h b/src/bindings/java/jmsg_process.h index 597f5b270d..0d5cc44288 100644 --- a/src/bindings/java/jmsg_process.h +++ b/src/bindings/java/jmsg_process.h @@ -50,6 +50,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv* env, jobject JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_daemonize(JNIEnv* env, jobject jprocess); JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll(JNIEnv* env, jclass cls, jint jresetPID); JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv* env, jclass cls, jint pid); +JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_nativeGetPID(JNIEnv* env, jobject jprocess); JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv* env, jobject jprocess, jobject jname); JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getCurrentProcess(JNIEnv* env, jclass cls); JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_suspend(JNIEnv* env, jobject jprocess); diff --git a/src/bindings/java/org/simgrid/msg/Msg.java b/src/bindings/java/org/simgrid/msg/Msg.java index c58b213e37..cc1cb7d0ba 100644 --- a/src/bindings/java/org/simgrid/msg/Msg.java +++ b/src/bindings/java/org/simgrid/msg/Msg.java @@ -40,6 +40,7 @@ public final class Msg { /** Tell the kernel that you want to use the energy plugin */ public static final native void energyInit(); + public static final native void fileSystemInit(); /** Run the MSG simulation. * diff --git a/src/bindings/java/org/simgrid/msg/Process.java b/src/bindings/java/org/simgrid/msg/Process.java index e4c7900eba..ecc7cee6d9 100644 --- a/src/bindings/java/org/simgrid/msg/Process.java +++ b/src/bindings/java/org/simgrid/msg/Process.java @@ -217,8 +217,13 @@ public abstract class Process implements Runnable { * */ public int getPID() { + if (pid == -1) // Don't traverse the JNI barrier if you already have the answer + pid = nativeGetPID(); return pid; } + // This should not be used: the PID is supposed to be initialized from the C directly when the actor is created, + // but this sometimes fail, so let's play nasty but safe here. + private native int nativeGetPID(); /** * This method returns the PID of the parent of a process. * diff --git a/src/bindings/java/org/simgrid/msg/VM.java b/src/bindings/java/org/simgrid/msg/VM.java index 99f3a3add3..cdd7cd797d 100644 --- a/src/bindings/java/org/simgrid/msg/VM.java +++ b/src/bindings/java/org/simgrid/msg/VM.java @@ -13,14 +13,33 @@ public class VM extends Host { private Host currentHost; private int coreAmount = 1; - /** Create a `basic' VM (i.e. 1GB of RAM, other values are not taken into account). */ + /** + * Create a `basic' VM : 1 core and 1GB of RAM. + * @param host Host node + * @param name name of the machine + */ public VM(Host host, String name) { this(host,name, /*coreAmount*/1, 1024, 0, 0); } - + + /** + * Create a VM without useless values (for humans) + * @param host Host node + * @param name name of the machine + * @param coreAmount the amount of cores of the VM + */ public VM(Host host, String name, int coreAmount) { this(host,name, coreAmount, 1024, 0, 0); } + + /** + * Create a VM with 1 core + * @param host Host node + * @param name name of the machine + * @param ramSize size of the RAM that should be allocated (in MBytes) + * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;)) + * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;)) + */ public VM(Host host, String name, int ramSize, int migNetSpeed, int dpIntensity){ this(host, name, /*coreAmount*/1, ramSize, migNetSpeed, dpIntensity); } @@ -29,6 +48,7 @@ public class VM extends Host { * Create a VM * @param host Host node * @param name name of the machine + * @param coreAmount the amount of cores of the VM * @param ramSize size of the RAM that should be allocated (in MBytes) * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;)) * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;)) diff --git a/src/include/surf/datatypes.h b/src/include/surf/datatypes.hpp similarity index 83% rename from src/include/surf/datatypes.h rename to src/include/surf/datatypes.hpp index 445ddc1c60..235dbf1eb5 100644 --- a/src/include/surf/datatypes.h +++ b/src/include/surf/datatypes.hpp @@ -3,13 +3,17 @@ /* 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 MAXMIN_DATATYPES_H -#define MAXMIN_DATATYPES_H +#ifndef MAXMIN_DATATYPES_HPP +#define MAXMIN_DATATYPES_HPP +namespace simgrid { +namespace surf { typedef struct s_lmm_element_t* lmm_element_t; typedef struct s_lmm_variable_t* lmm_variable_t; typedef struct s_lmm_constraint_t* lmm_constraint_t; typedef struct s_lmm_constraint_light_t* lmm_constraint_light_t; typedef struct s_lmm_system_t* lmm_system_t; +} +} #endif diff --git a/src/include/surf/maxmin.hpp b/src/include/surf/maxmin.hpp index 6325d078f0..1012ce1b1c 100644 --- a/src/include/surf/maxmin.hpp +++ b/src/include/surf/maxmin.hpp @@ -7,10 +7,18 @@ #define SURF_MAXMIN_HPP #include "src/internal_config.h" +#include "src/surf/surf_interface.hpp" #include "surf/surf.hpp" #include "xbt/asserts.h" +#include "xbt/mallocator.h" #include "xbt/misc.h" +#include "xbt/swag.h" #include +#include +#include + +namespace simgrid { +namespace surf { /** @addtogroup SURF_lmm * @details @@ -121,295 +129,7 @@ * constraint. */ -XBT_PUBLIC_DATA(double) sg_maxmin_precision; -XBT_PUBLIC_DATA(double) sg_surf_precision; -XBT_PUBLIC_DATA(int) sg_concurrency_limit; - -static inline void double_update(double* variable, double value, double precision) -{ - // printf("Updating %g -= %g +- %g\n",*variable,value,precision); - // xbt_assert(value==0 || value>precision); - // Check that precision is higher than the machine-dependent size of the mantissa. If not, brutal rounding may - // happen, and the precision mechanism is not active... - // xbt_assert(*variable< (2< precision); -} - -static inline int double_equals(double value1, double value2, double precision) -{ - return (fabs(value1 - value2) < precision); -} - -extern "C" { - /** @{ @ingroup SURF_lmm */ -/** - * @brief Create a new Linear MaxMim system - * @param selective_update whether we should do lazy updates - */ -XBT_PUBLIC(lmm_system_t) lmm_system_new(bool selective_update); - -/** - * @brief Free an existing Linear MaxMin system - * @param sys The lmm system to free - */ -XBT_PUBLIC(void) lmm_system_free(lmm_system_t sys); - -/** - * @brief Create a new Linear MaxMin constraint - * @param sys The system in which we add a constraint - * @param id Data associated to the constraint (e.g.: a network link) - * @param bound_value The bound value of the constraint - */ -XBT_PUBLIC(lmm_constraint_t) lmm_constraint_new(lmm_system_t sys, void* id, double bound_value); - -/** - * @brief Share a constraint - * @param cnst The constraint to share - */ -XBT_PUBLIC(void) lmm_constraint_shared(lmm_constraint_t cnst); - -/** - * @brief Check if a constraint is shared (shared by default) - * @param cnst The constraint to share - * @return 1 if shared, 0 otherwise - */ -XBT_PUBLIC(int) lmm_constraint_sharing_policy(lmm_constraint_t cnst); - -/** - * @brief Get the usage of the constraint after the last lmm solve - * @param cnst A constraint - * @return The usage of the constraint - */ -XBT_PUBLIC(double) lmm_constraint_get_usage(lmm_constraint_t cnst); - -XBT_PUBLIC(int) lmm_constraint_get_variable_amount(lmm_constraint_t cnst); - -/** - * @brief Sets the concurrency limit for this constraint - * @param cnst A constraint - * @param concurrency_limit The concurrency limit to use for this constraint - */ -XBT_PUBLIC(void) lmm_constraint_concurrency_limit_set(lmm_constraint_t cnst, int concurrency_limit); - -/** - * @brief Gets the concurrency limit for this constraint - * @param cnst A constraint - * @return The concurrency limit used by this constraint - */ -XBT_PUBLIC(int) lmm_constraint_concurrency_limit_get(lmm_constraint_t cnst); - -/** - * @brief Reset the concurrency maximum for a given variable (we will update the maximum to reflect constraint - * evolution). - * @param cnst A constraint -*/ -XBT_PUBLIC(void) lmm_constraint_concurrency_maximum_reset(lmm_constraint_t cnst); - -/** - * @brief Get the concurrency maximum for a given variable (which reflects constraint evolution). - * @param cnst A constraint - * @return the maximum concurrency of the constraint - */ -XBT_PUBLIC(int) lmm_constraint_concurrency_maximum_get(lmm_constraint_t cnst); - -/** - * @brief Create a new Linear MaxMin variable - * @param sys The system in which we add a constaint - * @param id Data associated to the variable (e.g.: a network communication) - * @param weight_value The weight of the variable (0.0 if not used) - * @param bound The maximum value of the variable (-1.0 if no maximum value) - * @param number_of_constraints The maximum number of constraint to associate to the variable - */ -XBT_PUBLIC(lmm_variable_t) -lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double weight_value, double bound, - int number_of_constraints); -/** - * @brief Free a variable - * @param sys The system associated to the variable - * @param var The variable to free - */ -XBT_PUBLIC(void) lmm_variable_free(lmm_system_t sys, lmm_variable_t var); - -/** - * @brief Get the value of the variable after the last lmm solve - * @param var A variable - * @return The value of the variable - */ -XBT_PUBLIC(double) lmm_variable_getvalue(lmm_variable_t var); - -/** - * @brief Get the maximum value of the variable (-1.0 if no maximum value) - * @param var A variable - * @return The bound of the variable - */ -XBT_PUBLIC(double) lmm_variable_getbound(lmm_variable_t var); - -/** - * @brief Set the concurrent share of the variable - * @param var A variable - * @param concurrency_share The new concurrency share - */ -XBT_PUBLIC(void) lmm_variable_concurrency_share_set(lmm_variable_t var, short int concurrency_share); - -/** - * @brief Associate a variable to a constraint with a coefficient - * @param sys A system - * @param cnst A constraint - * @param var A variable - * @param value The coefficient associated to the variable in the constraint - */ -XBT_PUBLIC(void) lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value); - -/** - * @brief Add value to the coefficient between a constraint and a variable or create one - * @param sys A system - * @param cnst A constraint - * @param var A variable - * @param value The value to add to the coefficient associated to the variable in the constraint - */ -XBT_PUBLIC(void) lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value); - -/** - * @brief Get the numth constraint associated to the variable - * @param sys The system associated to the variable (not used) - * @param var A variable - * @param num The rank of constraint we want to get - * @return The numth constraint - */ -XBT_PUBLIC(lmm_constraint_t) lmm_get_cnst_from_var(lmm_system_t sys, lmm_variable_t var, unsigned num); - -/** - * @brief Get the weigth of the numth constraint associated to the variable - * @param sys The system associated to the variable (not used) - * @param var A variable - * @param num The rank of constraint we want to get - * @return The numth constraint - */ -XBT_PUBLIC(double) lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var, unsigned num); - -/** - * @brief Get the number of constraint associated to a variable - * @param sys The system associated to the variable (not used) - * @param var A variable - * @return The number of constraint associated to the variable - */ -XBT_PUBLIC(int) lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var); - -/** - * @brief Get a var associated to a constraint - * @details Get the first variable of the next variable of elem if elem is not NULL - * @param sys The system associated to the variable (not used) - * @param cnst A constraint - * @param elem A element of constraint of the constraint or NULL - * @return A variable associated to a constraint - */ -XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst(lmm_system_t sys, lmm_constraint_t cnst, lmm_element_t* elem); - -/** - * @brief Get a var associated to a constraint - * @details Get the first variable of the next variable of elem if elem is not NULL - * @param cnst A constraint - * @param elem A element of constraint of the constraint or NULL - * @param nextelem A element of constraint of the constraint or NULL, the one after elem - * @param numelem parameter representing the number of elements to go - * - * @return A variable associated to a constraint - */ -XBT_PUBLIC(lmm_variable_t) -lmm_get_var_from_cnst_safe(lmm_system_t sys, lmm_constraint_t cnst, lmm_element_t* elem, lmm_element_t* nextelem, - int* numelem); - -/** - * @brief Get the first active constraint of a system - * @param sys A system - * @return The first active constraint - */ -XBT_PUBLIC(lmm_constraint_t) lmm_get_first_active_constraint(lmm_system_t sys); - -/** - * @brief Get the next active constraint of a constraint in a system - * @param sys A system - * @param cnst An active constraint of the system - * - * @return The next active constraint - */ -XBT_PUBLIC(lmm_constraint_t) lmm_get_next_active_constraint(lmm_system_t sys, lmm_constraint_t cnst); - -/** - * @brief Get the data associated to a constraint - * @param cnst A constraint - * @return The data associated to the constraint - */ -XBT_PUBLIC(void*) lmm_constraint_id(lmm_constraint_t cnst); - -/** - * @brief Get the data associated to a variable - * @param var A variable - * @return The data associated to the variable - */ -XBT_PUBLIC(void*) lmm_variable_id(lmm_variable_t var); - -/** - * @brief Update the value of element linking the constraint and the variable - * @param sys A system - * @param cnst A constraint - * @param var A variable - * @param value The new value - */ -XBT_PUBLIC(void) lmm_update(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value); - -/** - * @brief Update the bound of a variable - * @param sys A system - * @param var A constraint - * @param bound The new bound - */ -XBT_PUBLIC(void) lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, double bound); - -/** - * @brief Update the weight of a variable - * @param sys A system - * @param var A variable - * @param weight The new weight of the variable - */ -XBT_PUBLIC(void) lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight); - -/** - * @brief Get the weight of a variable - * @param var A variable - * @return The weight of the variable - */ -XBT_PUBLIC(double) lmm_get_variable_weight(lmm_variable_t var); - -/** - * @brief Update a constraint bound - * @param sys A system - * @param cnst A constraint - * @param bound The new bound of the consrtaint - */ -XBT_PUBLIC(void) lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound); - -/** - * @brief [brief description] - * @param sys A system - * @param cnst A constraint - * @return [description] - */ -XBT_PUBLIC(int) lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst); - -/** - * @brief Print the lmm system - * @param sys The lmm system to print - */ -XBT_PUBLIC(void) lmm_print(lmm_system_t sys); /** * @brief Solve the lmm system @@ -439,7 +159,425 @@ XBT_PUBLIC(double) func_vegas_f(lmm_variable_t var, double x); XBT_PUBLIC(double) func_vegas_fp(lmm_variable_t var, double x); XBT_PUBLIC(double) func_vegas_fpi(lmm_variable_t var, double x); +/** + * @brief LMM element + * Elements can be seen as glue between constraint objects and variable objects. + * Basically, each variable will have a set of elements, one for each constraint where it is involved. + * Then, it is used to list all variables involved in constraint through constraint's xxx_element_set lists, or + * vice-versa list all constraints for a given variable. + */ +XBT_PUBLIC_CLASS s_lmm_element_t { +public: + int get_concurrency() const; + void decrease_concurrency(); + void increase_concurrency(); + + void make_active(); + void make_inactive(); + + /* hookup to constraint */ + s_xbt_swag_hookup_t enabled_element_set_hookup; + s_xbt_swag_hookup_t disabled_element_set_hookup; + s_xbt_swag_hookup_t active_element_set_hookup; + + lmm_constraint_t constraint; + lmm_variable_t variable; + + // consumption_weight: impact of 1 byte or flop of your application onto the resource (in byte or flop) + // - if CPU, then probably 1. + // - If network, then 1 in forward direction and 0.05 backward for the ACKs + double consumption_weight; +}; + +struct s_lmm_constraint_light_t { + double remaining_over_usage; + lmm_constraint_t cnst; +}; + +/** + * @brief LMM constraint + * Each constraint contains several partially overlapping logical sets of elements: + * \li Disabled elements which variable's weight is zero. This variables are not at all processed by LMM, but eventually + * the corresponding action will enable it (at least this is the idea). + * \li Enabled elements which variable's weight is non-zero. They are utilized in some LMM functions. + * \li Active elements which variable's weight is non-zero (i.e. it is enabled) AND its element value is non-zero. + * LMM_solve iterates over active elements during resolution, dynamically making them active or unactive. + */ +XBT_PUBLIC_CLASS s_lmm_constraint_t { +public: + s_lmm_constraint_t() = default; + s_lmm_constraint_t(void* id_value, double bound_value); + + /** @brief Unshare a constraint. */ + void unshare() { sharing_policy = 0; } + + /** + * @brief Check if a constraint is shared (shared by default) + * @return 1 if shared, 0 otherwise + */ + int get_sharing_policy() const { return sharing_policy; } + + /** + * @brief Get the usage of the constraint after the last lmm solve + * @return The usage of the constraint + */ + double get_usage() const; + int get_variable_amount() const; + + /** + * @brief Sets the concurrency limit for this constraint + * @param concurrency_limit The concurrency limit to use for this constraint + */ + void set_concurrency_limit(int limit) + { + xbt_assert(limit < 0 || concurrency_maximum <= limit, + "New concurrency limit should be larger than observed concurrency maximum. Maybe you want to call" + " concurrency_maximum_reset() to reset the maximum?"); + concurrency_limit = limit; + } + + /** + * @brief Gets the concurrency limit for this constraint + * @return The concurrency limit used by this constraint + */ + int get_concurrency_limit() const { return concurrency_limit; } + + /** + * @brief Reset the concurrency maximum for a given variable (we will update the maximum to reflect constraint + * evolution). + */ + void reset_concurrency_maximum() { concurrency_maximum = 0; } + + /** + * @brief Get the concurrency maximum for a given variable (which reflects constraint evolution). + * @return the maximum concurrency of the constraint + */ + int get_concurrency_maximum() const + { + xbt_assert(concurrency_limit < 0 || concurrency_maximum <= concurrency_limit, + "Very bad: maximum observed concurrency is higher than limit. This is a bug of SURF, please report it."); + return concurrency_maximum; + } + + int get_concurrency_slack() const + { + return concurrency_limit < 0 ? std::numeric_limits::max() : concurrency_limit - concurrency_current; + } + + /** + * @brief Get a var associated to a constraint + * @details Get the first variable of the next variable of elem if elem is not NULL + * @param elem A element of constraint of the constraint or NULL + * @return A variable associated to a constraint + */ + lmm_variable_t get_variable(lmm_element_t* elem) const; + + /** + * @brief Get a var associated to a constraint + * @details Get the first variable of the next variable of elem if elem is not NULL + * @param elem A element of constraint of the constraint or NULL + * @param nextelem A element of constraint of the constraint or NULL, the one after elem + * @param numelem parameter representing the number of elements to go + * @return A variable associated to a constraint + */ + lmm_variable_t get_variable_safe(lmm_element_t* elem, lmm_element_t* nextelem, int* numelem) const; + + /** + * @brief Get the data associated to a constraint + * @return The data associated to the constraint + */ + void* get_id() const { return id; } + + /* hookup to system */ + s_xbt_swag_hookup_t constraint_set_hookup = {nullptr, nullptr}; + s_xbt_swag_hookup_t active_constraint_set_hookup = {nullptr, nullptr}; + s_xbt_swag_hookup_t modified_constraint_set_hookup = {nullptr, nullptr}; + s_xbt_swag_hookup_t saturated_constraint_set_hookup = {nullptr, nullptr}; + s_xbt_swag_t enabled_element_set; /* a list of lmm_element_t */ + s_xbt_swag_t disabled_element_set; /* a list of lmm_element_t */ + s_xbt_swag_t active_element_set; /* a list of lmm_element_t */ + double remaining; + double usage; + double bound; + // TODO MARTIN Check maximum value across resources at the end of simulation and give a warning is more than e.g. 500 + int concurrency_current; /* The current concurrency */ + int concurrency_maximum; /* The maximum number of (enabled and disabled) variables associated to the constraint at any + * given time (essentially for tracing)*/ + + int sharing_policy; /* see @e_surf_link_sharing_policy_t (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */ + int id_int; + double lambda; + double new_lambda; + lmm_constraint_light_t cnst_light; + +private: + static int Global_debug_id; + int concurrency_limit; /* The maximum number of variables that may be enabled at any time (stage variables if + * necessary) */ + void* id; +}; + +/** + * @brief LMM variable + * + * When something prevents us from enabling a variable, we "stage" the weight that we would have like to set, so that as + * soon as possible we enable the variable with desired weight + */ +XBT_PUBLIC_CLASS s_lmm_variable_t { +public: + void initialize(simgrid::surf::Action* id_value, double sharing_weight_value, double bound_value, + int number_of_constraints, unsigned visited_value); + + /** + * @brief Get the value of the variable after the last lmm solve + * @return The value of the variable + */ + double get_value() const { return value; } + + /** + * @brief Get the maximum value of the variable (-1.0 if no maximum value) + * @return The bound of the variable + */ + double get_bound() const { return bound; } + + /** + * @brief Set the concurrent share of the variable + * @param concurrency_share The new concurrency share + */ + void set_concurrency_share(short int value) { concurrency_share = value; } + + /** + * @brief Get the numth constraint associated to the variable + * @param num The rank of constraint we want to get + * @return The numth constraint + */ + lmm_constraint_t get_constraint(unsigned num) const { return num < cnsts.size() ? cnsts[num].constraint : nullptr; } + + /** + * @brief Get the weigth of the numth constraint associated to the variable + * @param num The rank of constraint we want to get + * @return The numth constraint + */ + double get_constraint_weight(unsigned num) const { return num < cnsts.size() ? cnsts[num].consumption_weight : 0.0; } + + /** + * @brief Get the number of constraint associated to a variable + * @return The number of constraint associated to the variable + */ + int get_number_of_constraint() const { return cnsts.size(); } + + /** + * @brief Get the data associated to a variable + * @return The data associated to the variable + */ + simgrid::surf::Action* get_id() const { return id; } + + /** + * @brief Get the weight of a variable + * @return The weight of the variable + */ + double get_weight() const { return sharing_weight; } + + /** @brief Measure the minimum concurrency slack across all constraints where the given var is involved */ + int get_min_concurrency_slack() const; + + /** @brief Check if a variable can be enabled + * Make sure to set staged_weight before, if your intent is only to check concurrency + */ + int can_enable() const { return staged_weight > 0 && get_min_concurrency_slack() >= concurrency_share; } + + /* hookup to system */ + s_xbt_swag_hookup_t variable_set_hookup = {nullptr, nullptr}; + s_xbt_swag_hookup_t saturated_variable_set_hookup = {nullptr, nullptr}; + + std::vector cnsts; + + // sharing_weight: variable's impact on the resource during the sharing + // if == 0, the variable is not considered by LMM + // on CPU, actions with N threads have a sharing of N + // on network, the actions with higher latency have a lesser sharing_weight + double sharing_weight; + + double staged_weight; /* If non-zero, variable is staged for addition as soon as maxconcurrency constraints will be + * met */ + double bound; + double value; + short int concurrency_share; /* The maximum number of elements that variable will add to a constraint */ + simgrid::surf::Action* id; + int id_int; + unsigned visited; /* used by lmm_update_modified_set */ + /* \begin{For Lagrange only} */ + double mu; + double new_mu; + double (*func_f)(s_lmm_variable_t* var, double x); /* (f) */ + double (*func_fp)(s_lmm_variable_t* var, double x); /* (f') */ + double (*func_fpi)(s_lmm_variable_t* var, double x); /* (f')^{-1} */ + /* \end{For Lagrange only} */ + +private: + static int Global_debug_id; +}; + +inline void s_lmm_element_t::make_active() +{ + xbt_swag_insert_at_head(this, &constraint->active_element_set); +} +inline void s_lmm_element_t::make_inactive() +{ + xbt_swag_remove(this, &constraint->active_element_set); +} + +/** + * @brief LMM system + */ +XBT_PUBLIC_CLASS s_lmm_system_t { +public: + /** + * @brief Create a new Linear MaxMim system + * @param selective_update whether we should do lazy updates + */ + explicit s_lmm_system_t(bool selective_update); + /** @brief Free an existing Linear MaxMin system */ + ~s_lmm_system_t(); + + /** + * @brief Create a new Linear MaxMin constraint + * @param id Data associated to the constraint (e.g.: a network link) + * @param bound_value The bound value of the constraint + */ + lmm_constraint_t constraint_new(void* id, double bound_value); + + /** + * @brief Create a new Linear MaxMin variable + * @param id Data associated to the variable (e.g.: a network communication) + * @param weight_value The weight of the variable (0.0 if not used) + * @param bound The maximum value of the variable (-1.0 if no maximum value) + * @param number_of_constraints The maximum number of constraint to associate to the variable + */ + lmm_variable_t variable_new(simgrid::surf::Action* id, double weight_value, double bound, int number_of_constraints); + + /** + * @brief Free a variable + * @param var The variable to free + */ + void variable_free(lmm_variable_t var); + + /** + * @brief Associate a variable to a constraint with a coefficient + * @param cnst A constraint + * @param var A variable + * @param value The coefficient associated to the variable in the constraint + */ + void expand(lmm_constraint_t cnst, lmm_variable_t var, double value); + + /** + * @brief Add value to the coefficient between a constraint and a variable or create one + * @param cnst A constraint + * @param var A variable + * @param value The value to add to the coefficient associated to the variable in the constraint + */ + void expand_add(lmm_constraint_t cnst, lmm_variable_t var, double value); + + /** + * @brief Update the bound of a variable + * @param var A constraint + * @param bound The new bound + */ + void update_variable_bound(lmm_variable_t var, double bound); + + /** + * @brief Update the weight of a variable + * @param var A variable + * @param weight The new weight of the variable + */ + void update_variable_weight(lmm_variable_t var, double weight); + + /** + * @brief Update a constraint bound + * @param cnst A constraint + * @param bound The new bound of the consrtaint + */ + void update_constraint_bound(lmm_constraint_t cnst, double bound); + + /** + * @brief [brief description] + * @param cnst A constraint + * @return [description] + */ + int constraint_used(lmm_constraint_t cnst) { return xbt_swag_belongs(cnst, &active_constraint_set); } + + /** @brief Print the lmm system */ + void print(); + + /** @brief Solve the lmm system */ + void solve(); + +private: + static void* variable_mallocator_new_f(); + static void variable_mallocator_free_f(void* var); + + void var_free(lmm_variable_t var); + void cnst_free(lmm_constraint_t cnst); + lmm_variable_t extract_variable() { return static_cast(xbt_swag_extract(&variable_set)); } + lmm_constraint_t extract_constraint() { return static_cast(xbt_swag_extract(&constraint_set)); } + void insert_constraint(lmm_constraint_t cnst) { xbt_swag_insert(cnst, &constraint_set); } + void remove_variable(lmm_variable_t var) + { + xbt_swag_remove(var, &variable_set); + xbt_swag_remove(var, &saturated_variable_set); + } + void make_constraint_active(lmm_constraint_t cnst) { xbt_swag_insert(cnst, &active_constraint_set); } + void make_constraint_inactive(lmm_constraint_t cnst) + { + xbt_swag_remove(cnst, &active_constraint_set); + xbt_swag_remove(cnst, &modified_constraint_set); + } + + void enable_var(lmm_variable_t var); + void disable_var(lmm_variable_t var); + void on_disabled_var(lmm_constraint_t cnstr); + + /** + * @brief Update the value of element linking the constraint and the variable + * @param cnst A constraint + * @param var A variable + * @param value The new value + */ + void update(lmm_constraint_t cnst, lmm_variable_t var, double value); + + void update_modified_set(lmm_constraint_t cnst); + void update_modified_set_rec(lmm_constraint_t cnst); + + /** @brief Remove all constraints of the modified_constraint_set. */ + void remove_all_modified_set(); + void check_concurrency(); + +public: + bool modified; + s_xbt_swag_t variable_set; /* a list of lmm_variable_t */ + s_xbt_swag_t active_constraint_set; /* a list of lmm_constraint_t */ + s_xbt_swag_t saturated_variable_set; /* a list of lmm_variable_t */ + s_xbt_swag_t saturated_constraint_set; /* a list of lmm_constraint_t */ + + simgrid::surf::ActionLmmListPtr keep_track; + + void (*solve_fun)(lmm_system_t self); + +private: + bool selective_update_active; /* flag to update partially the system only selecting changed portions */ + unsigned visited_counter; /* used by lmm_update_modified_set and lmm_remove_modified_set to cleverly (un-)flag the + * constraints (more details in these functions) */ + s_xbt_swag_t constraint_set; /* a list of lmm_constraint_t */ + s_xbt_swag_t modified_constraint_set; /* a list of modified lmm_constraint_t */ + xbt_mallocator_t variable_mallocator; +}; + +extern XBT_PRIVATE double (*func_f_def)(lmm_variable_t, double); +extern XBT_PRIVATE double (*func_fp_def)(lmm_variable_t, double); +extern XBT_PRIVATE double (*func_fpi_def)(lmm_variable_t, double); + /** @} */ } +} #endif diff --git a/src/include/surf/surf.hpp b/src/include/surf/surf.hpp index 3214e60756..a6654ac9cc 100644 --- a/src/include/surf/surf.hpp +++ b/src/include/surf/surf.hpp @@ -9,7 +9,7 @@ #include "simgrid/datatypes.h" #include "simgrid/forward.h" #include "src/internal_config.h" -#include "surf/datatypes.h" +#include "surf/datatypes.hpp" #include "xbt/config.h" #include "xbt/dict.h" #include "xbt/dynar.h" diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index aa60f1e31b..1a1f03aa08 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -93,13 +93,13 @@ double VMModel::nextOccuringEvent(double now) surf::Cpu* cpu = ws_vm->pimpl_cpu; xbt_assert(cpu, "cpu-less host"); - double solved_value = ws_vm->pimpl_vm_->action_->getVariable() - ->value; // this is X1 in comment above, what this VM got in the sharing on the PM + double solved_value = ws_vm->pimpl_vm_->action_->getVariable()->get_value(); // this is X1 in comment above, what + // this VM got in the sharing on the PM XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->getCname(), ws_vm->pimpl_vm_->getPm()->getCname()); xbt_assert(cpu->model() == surf_cpu_model_vm); - lmm_system_t vcpu_system = cpu->model()->getMaxminSystem(); - lmm_update_constraint_bound(vcpu_system, cpu->constraint(), virt_overhead * solved_value); + surf::lmm_system_t vcpu_system = cpu->model()->getMaxminSystem(); + vcpu_system->update_constraint_bound(cpu->constraint(), virt_overhead * solved_value); } /* 2. Calculate resource share at the virtual machine layer. */ diff --git a/src/s4u/s4u_file.cpp b/src/s4u/s4u_file.cpp index 5615bac50e..a78e0f93b1 100644 --- a/src/s4u/s4u_file.cpp +++ b/src/s4u/s4u_file.cpp @@ -11,10 +11,17 @@ #include "simgrid/simix.hpp" #include "src/surf/HostImpl.hpp" +#include +#include +#include +#include +#include + XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files"); namespace simgrid { namespace s4u { +simgrid::xbt::Extension FileSystemStorageExt::EXTENSION_ID; File::File(std::string fullpath, void* userdata) : File(fullpath, Host::current(), userdata){}; @@ -75,6 +82,8 @@ sg_size_t File::write(sg_size_t size) localStorage->decrUsedSize(size_ - current_position_); sg_size_t write_size = localStorage->write(size); + localStorage->incrUsedSize(write_size); + current_position_ += write_size; size_ = current_position_; @@ -153,4 +162,70 @@ int File::unlink() } } -}} // namespace simgrid::s4u +FileSystemStorageExt::FileSystemStorageExt(simgrid::s4u::Storage* ptr) +{ + content_ = parseContent(ptr->getImpl()->content_name); +} + +FileSystemStorageExt::~FileSystemStorageExt() +{ + delete content_; +} + +std::map* FileSystemStorageExt::parseContent(std::string filename) +{ + if (filename.empty()) + return nullptr; + + std::map* parse_content = new std::map(); + + std::ifstream* fs = surf_ifsopen(filename); + + std::string line; + std::vector tokens; + do { + std::getline(*fs, line); + boost::trim(line); + if (line.length() > 0) { + boost::split(tokens, line, boost::is_any_of(" \t"), boost::token_compress_on); + xbt_assert(tokens.size() == 2, "Parse error in %s: %s", filename.c_str(), line.c_str()); + sg_size_t size = std::stoull(tokens.at(1)); + + usedSize_ += size; + parse_content->insert({tokens.front(), size}); + } + } while (not fs->eof()); + delete fs; + return parse_content; +} +} +} + +using simgrid::s4u::FileSystemStorageExt; + +static void onStorageCreation(simgrid::s4u::Storage& st) +{ + st.extension_set(new FileSystemStorageExt(&st)); +} + +static void onStorageDestruction(simgrid::s4u::Storage& st) +{ + delete st.extension(); +} + +/* **************************** Public interface *************************** */ +SG_BEGIN_DECL() + +void sg_storage_file_system_init() +{ + + if (FileSystemStorageExt::EXTENSION_ID.valid()) + return; + + FileSystemStorageExt::EXTENSION_ID = simgrid::s4u::Storage::extension_create(); + + simgrid::s4u::Storage::onCreation.connect(&onStorageCreation); + simgrid::s4u::Storage::onDestruction.connect(&onStorageDestruction); +} + +SG_END_DECL() diff --git a/src/s4u/s4u_link.cpp b/src/s4u/s4u_link.cpp index 7a38166c10..dcac704643 100644 --- a/src/s4u/s4u_link.cpp +++ b/src/s4u/s4u_link.cpp @@ -9,6 +9,7 @@ #include "simgrid/sg_config.h" #include "simgrid/simix.hpp" #include "src/surf/network_interface.hpp" +#include "surf/maxmin.hpp" #include "xbt/log.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_link, s4u, "Logging specific to the S4U links"); @@ -116,7 +117,7 @@ int Link::sharingPolicy() double Link::getUsage() { - return lmm_constraint_get_usage(this->pimpl_->constraint()); + return this->pimpl_->constraint()->get_usage(); } void Link::turnOn() diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 5cb09af9e0..9123343960 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -3,6 +3,7 @@ /* 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 "simgrid/s4u/File.hpp" #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" @@ -10,6 +11,10 @@ #include namespace simgrid { +namespace xbt { +template class Extendable; +} + namespace s4u { std::map* allStorages() @@ -52,17 +57,27 @@ Host* Storage::getHost() sg_size_t Storage::getSizeFree() { - return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); }); + FileSystemStorageExt* file_system = extension(); + + return pimpl_->getSize() - file_system->getUsedSize(); } sg_size_t Storage::getSizeUsed() { - return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); }); + FileSystemStorageExt* file_system = extension(); + return file_system->getUsedSize(); } void Storage::decrUsedSize(sg_size_t size) { - simgrid::simix::kernelImmediate([this, size] { pimpl_->usedSize_ -= size; }); + FileSystemStorageExt* file_system = extension(); + file_system->decrUsedSize(size); +} + +void Storage::incrUsedSize(sg_size_t size) +{ + FileSystemStorageExt* file_system = extension(); + file_system->incrUsedSize(size); } sg_size_t Storage::getSize() @@ -87,7 +102,8 @@ void Storage::setProperty(std::string key, std::string value) std::map* Storage::getContent() { - return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); }); + FileSystemStorageExt* file_system = extension(); + return file_system->getContent(); } sg_size_t Storage::read(sg_size_t size) diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 795521e695..21fe9740d2 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -6,6 +6,7 @@ #include "private.hpp" #include "simgrid/modelchecker.h" #include "smpi_comm.hpp" +#include "simgrid/host.h" #include "smpi_process.hpp" #include "src/internal_config.h" #include "src/mc/mc_replay.hpp" @@ -69,7 +70,8 @@ void smpi_execute(double duration) void smpi_execute_benched(double duration) { smpi_bench_end(); - smpi_execute(duration); + double speed = sg_host_speed(sg_host_self()); + smpi_execute_flops(duration*speed); smpi_bench_begin(); } diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 97bd9437b4..2a24cc68e8 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -30,7 +30,7 @@ void HostModel::ignoreEmptyVmInPmLMM() /* iterate for all virtual machines */ for (s4u::VirtualMachine* const& ws_vm : vm::VirtualMachineImpl::allVms_) { Cpu* cpu = ws_vm->pimpl_cpu; - int active_tasks = lmm_constraint_get_variable_amount(cpu->constraint()); + int active_tasks = cpu->constraint()->get_variable_amount(); /* The impact of the VM over its PM is the min between its vCPU amount and the amount of tasks it contains */ int impact = std::min(active_tasks, ws_vm->pimpl_vm_->coreAmount()); diff --git a/src/surf/StorageImpl.cpp b/src/surf/StorageImpl.cpp index cc888ddd19..6b79856682 100644 --- a/src/surf/StorageImpl.cpp +++ b/src/surf/StorageImpl.cpp @@ -5,13 +5,8 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "StorageImpl.hpp" - +#include "surf/maxmin.hpp" #include "surf_private.hpp" -#include -#include -#include -#include -#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module"); @@ -46,12 +41,12 @@ StorageImpl* StorageImpl::byName(std::string name) StorageModel::StorageModel() : Model() { - maxminSystem_ = lmm_system_new(true /* lazy update */); + maxminSystem_ = new s_lmm_system_t(true /* lazy update */); } StorageModel::~StorageModel() { - lmm_system_free(maxminSystem_); + delete maxminSystem_; surf_storage_model = nullptr; } @@ -61,54 +56,25 @@ StorageModel::~StorageModel() StorageImpl::StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite, std::string type_id, std::string content_name, sg_size_t size, std::string attach) - : Resource(model, name.c_str(), lmm_constraint_new(maxminSystem, this, std::max(bread, bwrite))) + : Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite))) , piface_(this) , typeId_(type_id) + , content_name(content_name) , size_(size) , attach_(attach) { - content_ = parseContent(content_name); StorageImpl::turnOn(); XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size); - constraintRead_ = lmm_constraint_new(maxminSystem, this, bread); - constraintWrite_ = lmm_constraint_new(maxminSystem, this, bwrite); + constraintRead_ = maxminSystem->constraint_new(this, bread); + constraintWrite_ = maxminSystem->constraint_new(this, bwrite); storages->insert({name, this}); } StorageImpl::~StorageImpl() { storageDestructedCallbacks(this); - if (content_ != nullptr) - delete content_; } -std::map* StorageImpl::parseContent(std::string filename) -{ - usedSize_ = 0; - if (filename.empty()) - return nullptr; - - std::map* parse_content = new std::map(); - - std::ifstream* fs = surf_ifsopen(filename); - - std::string line; - std::vector tokens; - do { - std::getline(*fs, line); - boost::trim(line); - if (line.length() > 0) { - boost::split(tokens, line, boost::is_any_of(" \t"), boost::token_compress_on); - xbt_assert(tokens.size() == 2, "Parse error in %s: %s", filename.c_str(), line.c_str()); - sg_size_t size = std::stoull(tokens.at(1)); - - usedSize_ += size; - parse_content->insert({tokens.front(), size}); - } - } while (not fs->eof()); - delete fs; - return parse_content; -} bool StorageImpl::isUsed() { @@ -136,22 +102,6 @@ void StorageImpl::turnOff() } } -std::map* StorageImpl::getContent() -{ - /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */ - return content_; -} - -sg_size_t StorageImpl::getFreeSize() -{ - return size_ - usedSize_; -} - -sg_size_t StorageImpl::getUsedSize() -{ - return usedSize_; -} - /********** * Action * **********/ diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index c66f9f96d7..d83cd6231e 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -115,31 +115,9 @@ public: * @return The StorageAction corresponding to the writing */ virtual StorageAction* write(sg_size_t size) = 0; - - /** - * @brief Get the content of the current Storage - * - * @return A map with path as keys and size in bytes as values - */ - virtual std::map* getContent(); - - /** - * @brief Get the available size in bytes of the current Storage - * - * @return The available size in bytes of the current Storage - */ - virtual sg_size_t getFreeSize(); - - /** - * @brief Get the used size in bytes of the current Storage - * - * @return The used size in bytes of the current Storage - */ - virtual sg_size_t getUsedSize(); virtual sg_size_t getSize() { return size_; } virtual std::string getHost() { return attach_; } - std::map* parseContent(std::string filename); static std::unordered_map* storagesMap() { return StorageImpl::storages; } lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/ @@ -147,11 +125,11 @@ public: std::string typeId_; sg_size_t usedSize_ = 0; + std::string content_name; private: sg_size_t size_; static std::unordered_map* storages; - std::map* content_; // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores // the Host directly. std::string attach_; diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 99707a2730..d25bf1f88a 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -6,8 +6,8 @@ #include "cpu_cas01.hpp" #include "cpu_ti.hpp" -#include "maxmin_private.hpp" #include "simgrid/sg_config.h" +#include "surf/maxmin.hpp" #include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf_cpu, "Logging specific to the SURF CPU IMPROVED module"); @@ -53,7 +53,7 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel() } p_cpuRunningActionSetThatDoesNotNeedBeingChecked = new ActionList(); - maxminSystem_ = lmm_system_new(selectiveUpdate_); + maxminSystem_ = new s_lmm_system_t(selectiveUpdate_); if (getUpdateMechanism() == UM_LAZY) { modifiedSet_ = new ActionLmmList(); @@ -63,7 +63,7 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel() CpuCas01Model::~CpuCas01Model() { - lmm_system_free(maxminSystem_); + delete maxminSystem_; maxminSystem_ = nullptr; delete modifiedSet_; @@ -80,9 +80,9 @@ Cpu *CpuCas01Model::createCpu(simgrid::s4u::Host *host, std::vector *spe /************ * Resource * ************/ -CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::s4u::Host *host, std::vector *speedPerPstate, int core) -: Cpu(model, host, lmm_constraint_new(model->getMaxminSystem(), this, core * speedPerPstate->front()), - speedPerPstate, core) +CpuCas01::CpuCas01(CpuCas01Model* model, simgrid::s4u::Host* host, std::vector* speedPerPstate, int core) + : Cpu(model, host, model->getMaxminSystem()->constraint_new(this, core * speedPerPstate->front()), speedPerPstate, + core) { } @@ -98,7 +98,7 @@ std::vector * CpuCas01::getSpeedPeakList(){ bool CpuCas01::isUsed() { - return lmm_constraint_used(model()->getMaxminSystem(), constraint()); + return model()->getMaxminSystem()->constraint_used(constraint()); } /** @brief take into account changes of speed (either load or max) */ @@ -106,12 +106,12 @@ void CpuCas01::onSpeedChange() { lmm_variable_t var = nullptr; lmm_element_t elem = nullptr; - lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(), coresAmount_ * speed_.scale * speed_.peak); - while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) { - CpuCas01Action* action = static_cast(lmm_variable_id(var)); + model()->getMaxminSystem()->update_constraint_bound(constraint(), coresAmount_ * speed_.scale * speed_.peak); + while ((var = constraint()->get_variable(&elem))) { + CpuCas01Action* action = static_cast(var->get_id()); - lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(), - action->requestedCore() * speed_.scale * speed_.peak); + model()->getMaxminSystem()->update_variable_bound(action->getVariable(), + action->requestedCore() * speed_.scale * speed_.peak); } Cpu::onSpeedChange(); @@ -143,8 +143,8 @@ void CpuCas01::apply_event(tmgr_trace_event_t event, double value) turnOff(); - while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), cnst, &elem))) { - Action *action = static_cast(lmm_variable_id(var)); + while ((var = cnst->get_variable(&elem))) { + Action* action = static_cast(var->get_id()); if (action->getState() == Action::State::running || action->getState() == Action::State::ready || @@ -189,7 +189,7 @@ CpuAction *CpuCas01::sleep(double duration) action->getStateSet()->push_back(*action); } - lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), 0.0); + model()->getMaxminSystem()->update_variable_weight(action->getVariable(), 0.0); if (model()->getUpdateMechanism() == UM_LAZY) { // remove action from the heap action->heapRemove(model()->getActionHeap()); // this is necessary for a variable with weight 0 since such variables are ignored in lmm and we need to set its @@ -207,14 +207,14 @@ CpuAction *CpuCas01::sleep(double duration) CpuCas01Action::CpuCas01Action(Model* model, double cost, bool failed, double speed, lmm_constraint_t constraint, int requestedCore) : CpuAction(model, cost, failed, - lmm_variable_new(model->getMaxminSystem(), this, 1.0 / requestedCore, requestedCore * speed, 1)) + model->getMaxminSystem()->variable_new(this, 1.0 / requestedCore, requestedCore * speed, 1)) , requestedCore_(requestedCore) { if (model->getUpdateMechanism() == UM_LAZY) { refreshLastUpdate(); setLastValue(0.0); } - lmm_expand(model->getMaxminSystem(), constraint, getVariable(), 1.0); + model->getMaxminSystem()->expand(constraint, getVariable(), 1.0); } CpuCas01Action::CpuCas01Action(Model* model, double cost, bool failed, double speed, lmm_constraint_t constraint) diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 2c4e30843a..6708124afe 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -28,10 +28,9 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/) CpuAction* action = static_cast(actionHeapPop()); XBT_CDEBUG(surf_kernel, "Something happened to action %p", action); if (TRACE_is_enabled()) { - Cpu *cpu = static_cast(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0))); - TRACE_surf_host_set_utilization(cpu->getCname(), action->getCategory(), - lmm_variable_getvalue(action->getVariable()), action->getLastUpdate(), - now - action->getLastUpdate()); + Cpu* cpu = static_cast(action->getVariable()->get_constraint(0)->get_id()); + TRACE_surf_host_set_utilization(cpu->getCname(), action->getCategory(), action->getVariable()->get_value(), + action->getLastUpdate(), now - action->getLastUpdate()); } action->finish(Action::State::done); @@ -60,20 +59,18 @@ void CpuModel::updateActionsStateFull(double now, double delta) CpuAction& action = static_cast(*it); ++it; // increment iterator here since the following calls to action.finish() may invalidate it if (TRACE_is_enabled()) { - Cpu* cpu = - static_cast(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action.getVariable(), 0))); - - TRACE_surf_host_set_utilization(cpu->getCname(), action.getCategory(), - lmm_variable_getvalue(action.getVariable()), now - delta, delta); + Cpu* cpu = static_cast(action.getVariable()->get_constraint(0)->get_id()); + TRACE_surf_host_set_utilization(cpu->getCname(), action.getCategory(), action.getVariable()->get_value(), + now - delta, delta); TRACE_last_timestamp_to_dump = now - delta; } - action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta); + action.updateRemains(action.getVariable()->get_value() * delta); if (action.getMaxDuration() != NO_MAX_DURATION) action.updateMaxDuration(delta); - if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) || + if (((action.getRemainsNoUpdate() <= 0) && (action.getVariable()->get_weight() > 0)) || ((action.getMaxDuration() != NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) { action.finish(Action::State::done); } @@ -190,7 +187,7 @@ void CpuAction::updateRemainingLazy(double now) updateRemains(getLastValue() * delta); if (TRACE_is_enabled()) { - Cpu *cpu = static_cast(lmm_constraint_id(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0))); + Cpu* cpu = static_cast(getVariable()->get_constraint(0)->get_id()); TRACE_surf_host_set_utilization(cpu->getCname(), getCategory(), getLastValue(), getLastUpdate(), now - getLastUpdate()); } @@ -198,7 +195,7 @@ void CpuAction::updateRemainingLazy(double now) } refreshLastUpdate(); - setLastValue(lmm_variable_getvalue(getVariable())); + setLastValue(getVariable()->get_value()); } simgrid::xbt::signal CpuAction::onStateChange; @@ -223,13 +220,12 @@ void CpuAction::setState(Action::State state){ /** @brief returns a list of all CPUs that this action is using */ std::list CpuAction::cpus() { std::list retlist; - lmm_system_t sys = getModel()->getMaxminSystem(); - int llen = lmm_get_number_of_cnst_from_var(sys, getVariable()); + int llen = getVariable()->get_number_of_constraint(); for (int i = 0; i < llen; i++) { /* Beware of composite actions: ptasks put links and cpus together */ // extra pb: we cannot dynamic_cast from void*... - Resource* resource = static_cast(lmm_constraint_id(lmm_get_cnst_from_var(sys, getVariable(), i))); + Resource* resource = static_cast(getVariable()->get_constraint(i)->get_id()); Cpu* cpu = dynamic_cast(resource); if (cpu != nullptr) retlist.push_back(cpu); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index f360cf1059..ab01fc33b2 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -7,7 +7,7 @@ #define SURF_CPU_INTERFACE_HPP_ #include "simgrid/s4u/Host.hpp" -#include "src/surf/maxmin_private.hpp" +#include "surf/maxmin.hpp" #include diff --git a/src/surf/fair_bottleneck.cpp b/src/surf/fair_bottleneck.cpp index 84be37fc03..26957175e4 100644 --- a/src/surf/fair_bottleneck.cpp +++ b/src/surf/fair_bottleneck.cpp @@ -4,7 +4,7 @@ /* 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 "maxmin_private.hpp" +#include "surf/maxmin.hpp" #include "xbt/log.h" #include "xbt/sysdep.h" #include @@ -17,7 +17,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_maxmin); #define SHOW_EXPR_D(expr) XBT_DEBUG(#expr " = %d",expr); #define SHOW_EXPR_P(expr) XBT_DEBUG(#expr " = %p",expr); -void bottleneck_solve(lmm_system_t sys) +void simgrid::surf::bottleneck_solve(lmm_system_t sys) { void *_var; void *_var_next; @@ -82,7 +82,7 @@ void bottleneck_solve(lmm_system_t sys) do { if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) { XBT_DEBUG("Fair bottleneck done"); - lmm_print(sys); + sys->print(); } XBT_DEBUG("******* Constraints to process: %d *******", xbt_swag_size(cnst_list)); xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list) { @@ -169,9 +169,9 @@ void bottleneck_solve(lmm_system_t sys) } while (xbt_swag_size(var_list)); xbt_swag_reset(cnst_list); - sys->modified = 0; + sys->modified = true; if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) { XBT_DEBUG("Fair bottleneck done"); - lmm_print(sys); + sys->print(); } } diff --git a/src/surf/lagrange.cpp b/src/surf/lagrange.cpp index 447273bede..e81ea8e96f 100644 --- a/src/surf/lagrange.cpp +++ b/src/surf/lagrange.cpp @@ -7,9 +7,9 @@ * Modeling the proportional fairness using the Lagrangian Optimization Approach. For a detailed description see: * "ssh://username@scm.gforge.inria.fr/svn/memo/people/pvelho/lagrange/ppf.ps". */ +#include "surf/maxmin.hpp" #include "xbt/log.h" #include "xbt/sysdep.h" -#include "maxmin_private.hpp" #include #include @@ -21,6 +21,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_lagrange, surf, "Logging specific to SURF ( XBT_LOG_NEW_SUBCATEGORY(surf_lagrange_dichotomy, surf_lagrange, "Logging specific to SURF (lagrange dichotomy)"); #define SHOW_EXPR(expr) XBT_CDEBUG(surf_lagrange,#expr " = %g",expr); +#define VEGAS_SCALING 1000.0 +#define RENO_SCALING 1.0 +#define RENO2_SCALING 1.0 + +namespace simgrid { +namespace surf { double (*func_f_def) (lmm_variable_t, double); double (*func_fp_def) (lmm_variable_t, double); @@ -157,38 +163,23 @@ void lagrange_solve(lmm_system_t sys) double dichotomy_min_error = 1e-14; double overall_modification = 1; - /* Variables to manipulate the data structure proposed to model the maxmin fairness. See documentation for details. */ - xbt_swag_t cnst_list = nullptr; - void *_cnst; - lmm_constraint_t cnst = nullptr; - - xbt_swag_t var_list = nullptr; - void *_var; - lmm_variable_t var = nullptr; - - /* Auxiliary variables. */ - int iteration = 0; - double tmp = 0; - int i; - double obj; - double new_obj; - XBT_DEBUG("Iterative method configuration snapshot =====>"); XBT_DEBUG("#### Maximum number of iterations : %d", max_iterations); XBT_DEBUG("#### Minimum error tolerated : %e", epsilon_min_error); XBT_DEBUG("#### Minimum error tolerated (dichotomy) : %e", dichotomy_min_error); if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) { - lmm_print(sys); + sys->print(); } if (not sys->modified) return; /* Initialize lambda. */ - cnst_list = &(sys->active_constraint_set); + xbt_swag_t cnst_list = &(sys->active_constraint_set); + void* _cnst; xbt_swag_foreach(_cnst, cnst_list) { - cnst = (lmm_constraint_t)_cnst; + lmm_constraint_t cnst = (lmm_constraint_t)_cnst; cnst->lambda = 1.0; cnst->new_lambda = 2.0; XBT_DEBUG("#### cnst(%p)->lambda : %e", cnst, cnst->lambda); @@ -198,22 +189,21 @@ void lagrange_solve(lmm_system_t sys) * Initialize the var list variable with only the active variables. * Associate an index in the swag variables. Initialize mu. */ - var_list = &(sys->variable_set); - i = 0; + xbt_swag_t var_list = &(sys->variable_set); + void* _var; xbt_swag_foreach(_var, var_list) { - var = static_cast(_var); + lmm_variable_t var = static_cast(_var); if (not var->sharing_weight) var->value = 0.0; else { if (var->bound < 0.0) { - XBT_DEBUG("#### NOTE var(%d) is a boundless variable", i); + XBT_DEBUG("#### NOTE var(%p) is a boundless variable", var); var->mu = -1.0; - var->value = new_value(var); } else { var->mu = 1.0; var->new_mu = 2.0; - var->value = new_value(var); } + var->value = new_value(var); XBT_DEBUG("#### var(%p) ->weight : %e", var, var->sharing_weight); XBT_DEBUG("#### var(%p) ->mu : %e", var, var->mu); XBT_DEBUG("#### var(%p) ->weight: %e", var, var->sharing_weight); @@ -226,9 +216,10 @@ void lagrange_solve(lmm_system_t sys) } /* Compute dual objective. */ - obj = dual_objective(var_list, cnst_list); + double obj = dual_objective(var_list, cnst_list); /* While doesn't reach a minimum error or a number maximum of iterations. */ + int iteration = 0; while (overall_modification > epsilon_min_error && iteration < max_iterations) { iteration++; XBT_DEBUG("************** ITERATION %d **************", iteration); @@ -236,16 +227,14 @@ void lagrange_solve(lmm_system_t sys) /* Improve the value of mu_i */ xbt_swag_foreach(_var, var_list) { - var = static_cast(_var); - if (not var->sharing_weight) - break; - if (var->bound >= 0) { + lmm_variable_t var = static_cast(_var); + if (var->sharing_weight && var->bound >= 0) { XBT_DEBUG("Working on var (%p)", var); var->new_mu = new_mu(var); XBT_DEBUG("Updating mu : var->mu (%p) : %1.20f -> %1.20f", var, var->mu, var->new_mu); var->mu = var->new_mu; - new_obj = dual_objective(var_list, cnst_list); + double new_obj = dual_objective(var_list, cnst_list); XBT_DEBUG("Improvement for Objective (%g -> %g) : %g", obj, new_obj, obj - new_obj); xbt_assert(obj - new_obj >= -epsilon_min_error, "Our gradient sucks! (%1.20f)", obj - new_obj); obj = new_obj; @@ -254,13 +243,13 @@ void lagrange_solve(lmm_system_t sys) /* Improve the value of lambda_i */ xbt_swag_foreach(_cnst, cnst_list) { - cnst = static_cast(_cnst); + lmm_constraint_t cnst = static_cast(_cnst); XBT_DEBUG("Working on cnst (%p)", cnst); cnst->new_lambda = dichotomy(cnst->lambda, partial_diff_lambda, cnst, dichotomy_min_error); XBT_DEBUG("Updating lambda : cnst->lambda (%p) : %1.20f -> %1.20f", cnst, cnst->lambda, cnst->new_lambda); cnst->lambda = cnst->new_lambda; - new_obj = dual_objective(var_list, cnst_list); + double new_obj = dual_objective(var_list, cnst_list); XBT_DEBUG("Improvement for Objective (%g -> %g) : %g", obj, new_obj, obj - new_obj); xbt_assert(obj - new_obj >= -epsilon_min_error, "Our gradient sucks! (%1.20f)", obj - new_obj); obj = new_obj; @@ -270,11 +259,11 @@ void lagrange_solve(lmm_system_t sys) XBT_DEBUG("-------------- Check convergence ----------"); overall_modification = 0; xbt_swag_foreach(_var, var_list) { - var = static_cast(_var); + lmm_variable_t var = static_cast(_var); if (var->sharing_weight <= 0) var->value = 0.0; else { - tmp = new_value(var); + double tmp = new_value(var); overall_modification = std::max(overall_modification, fabs(var->value - tmp)); @@ -299,7 +288,7 @@ void lagrange_solve(lmm_system_t sys) } if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) { - lmm_print(sys); + sys->print(); } } @@ -479,8 +468,6 @@ void lmm_set_default_protocol_function(double (*func_f) (lmm_variable_t var, dou * Therefore: $fp(x) = \frac{\alpha D_f}{x}$ * Therefore: $fpi(x) = \frac{\alpha D_f}{x}$ */ -#define VEGAS_SCALING 1000.0 - double func_vegas_f(lmm_variable_t var, double x) { xbt_assert(x > 0.0, "Don't call me with stupid values! (%1.20f)", x); @@ -504,7 +491,6 @@ double func_vegas_fpi(lmm_variable_t var, double x) * Therefore: $fp(x) = \frac{3}{3 D_f^2 x^2+2}$ * Therefore: $fpi(x) = \sqrt{\frac{1}{{D_f}^2 x} - \frac{2}{3{D_f}^2}}$ */ -#define RENO_SCALING 1.0 double func_reno_f(lmm_variable_t var, double x) { xbt_assert(var->sharing_weight > 0.0, "Don't call me with stupid values!"); @@ -536,7 +522,6 @@ double func_reno_fpi(lmm_variable_t var, double x) * Therefore: $fp(x) = 2/(Weight*x + 2) * Therefore: $fpi(x) = (2*Weight)/x - 4 */ -#define RENO2_SCALING 1.0 double func_reno2_f(lmm_variable_t var, double x) { xbt_assert(var->sharing_weight > 0.0, "Don't call me with stupid values!"); @@ -561,3 +546,5 @@ double func_reno2_fpi(lmm_variable_t var, double x) res_fpi = RENO2_SCALING * (-3.0 * tmp + sqrt(res_fpi)) / (4.0 * tmp); return res_fpi; } +} +} diff --git a/src/surf/maxmin.cpp b/src/surf/maxmin.cpp index e9fd4ee864..0ae0d70fbb 100644 --- a/src/surf/maxmin.cpp +++ b/src/surf/maxmin.cpp @@ -5,7 +5,7 @@ /* \file callbacks.h */ -#include "maxmin_private.hpp" +#include "surf/maxmin.hpp" #include "xbt/backtrace.hpp" #include "xbt/log.h" #include "xbt/mallocator.h" @@ -19,33 +19,22 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)"); -typedef std::vector dyn_light_t; - double sg_maxmin_precision = 0.00001; /* Change this with --cfg=maxmin/precision:VALUE */ double sg_surf_precision = 0.00001; /* Change this with --cfg=surf/precision:VALUE */ int sg_concurrency_limit = -1; /* Change this with --cfg=maxmin/concurrency-limit:VALUE */ -static void *lmm_variable_mallocator_new_f(); -static void lmm_variable_mallocator_free_f(void *var); -#define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)nullptr) -static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst); -static void lmm_remove_all_modified_set(lmm_system_t sys); -static int Global_debug_id = 1; -static int Global_const_debug_id = 1; +namespace simgrid { +namespace surf { -static inline void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst); +typedef std::vector dyn_light_t; -static void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr); -static void lmm_enable_var(lmm_system_t sys, lmm_variable_t var); -static int lmm_can_enable_var(lmm_variable_t var); -static void lmm_disable_var(lmm_system_t sys, lmm_variable_t var); -static int lmm_concurrency_slack(lmm_constraint_t cnstr); -static int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var); +int s_lmm_variable_t::Global_debug_id = 1; +int s_lmm_constraint_t::Global_debug_id = 1; -static inline int lmm_element_concurrency(lmm_element_t elem) +int s_lmm_element_t::get_concurrency() const { //Ignore element with weight less than one (e.g. cross-traffic) - return (elem->consumption_weight >= 1) ? 1 : 0; + return (consumption_weight >= 1) ? 1 : 0; //There are other alternatives, but they will change the behaviour of the model.. //So do not use it unless you want to make a new model. //If you do, remember to change the variables concurrency share to reflect it. @@ -54,33 +43,32 @@ static inline int lmm_element_concurrency(lmm_element_t elem) //return (int)ceil(elem->weight);//Include element as the rounded-up integer value of the element weight } -static inline void lmm_decrease_concurrency(lmm_element_t elem) +void s_lmm_element_t::decrease_concurrency() { - xbt_assert(elem->constraint->concurrency_current>=lmm_element_concurrency(elem)); - elem->constraint->concurrency_current-=lmm_element_concurrency(elem); + xbt_assert(constraint->concurrency_current >= get_concurrency()); + constraint->concurrency_current -= get_concurrency(); } -static inline void lmm_increase_concurrency(lmm_element_t elem) +void s_lmm_element_t::increase_concurrency() { - elem->constraint->concurrency_current+= lmm_element_concurrency(elem); + constraint->concurrency_current += get_concurrency(); - lmm_constraint_t cnstr=elem->constraint; + if (constraint->concurrency_current > constraint->concurrency_maximum) + constraint->concurrency_maximum = constraint->concurrency_current; - if(cnstr->concurrency_current > cnstr->concurrency_maximum) - cnstr->concurrency_maximum= cnstr->concurrency_current; - - xbt_assert(cnstr->concurrency_limit<0 || cnstr->concurrency_current<=cnstr->concurrency_limit, + xbt_assert(constraint->get_concurrency_limit() < 0 || + constraint->concurrency_current <= constraint->get_concurrency_limit(), "Concurrency limit overflow!"); } -static void lmm_check_concurrency(lmm_system_t sys) +void s_lmm_system_t::check_concurrency() { // These checks are very expensive, so do them only if we want to debug SURF LMM if (not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) return; void* cnstIt; - xbt_swag_foreach(cnstIt, &(sys->constraint_set)) + xbt_swag_foreach(cnstIt, &constraint_set) { lmm_constraint_t cnst = (lmm_constraint_t)cnstIt; int concurrency = 0; @@ -89,25 +77,26 @@ static void lmm_check_concurrency(lmm_system_t sys) { lmm_element_t elem = (lmm_element_t)elemIt; xbt_assert(elem->variable->sharing_weight > 0); - concurrency += lmm_element_concurrency(elem); + concurrency += elem->get_concurrency(); } xbt_swag_foreach(elemIt, &(cnst->disabled_element_set)) { lmm_element_t elem = (lmm_element_t)elemIt; // We should have staged variables only if concurrency is reached in some constraint - xbt_assert(cnst->concurrency_limit < 0 || elem->variable->staged_weight == 0 || - lmm_cnstrs_min_concurrency_slack(elem->variable) < elem->variable->concurrency_share, + xbt_assert(cnst->get_concurrency_limit() < 0 || elem->variable->staged_weight == 0 || + elem->variable->get_min_concurrency_slack() < elem->variable->concurrency_share, "should not have staged variable!"); } - xbt_assert(cnst->concurrency_limit < 0 || cnst->concurrency_limit >= concurrency, "concurrency check failed!"); + xbt_assert(cnst->get_concurrency_limit() < 0 || cnst->get_concurrency_limit() >= concurrency, + "concurrency check failed!"); xbt_assert(cnst->concurrency_current == concurrency, "concurrency_current is out-of-date!"); } // Check that for each variable, all corresponding elements are in the same state (i.e. same element sets) void* varIt; - xbt_swag_foreach(varIt, &(sys->variable_set)) + xbt_swag_foreach(varIt, &variable_set) { lmm_variable_t var = (lmm_variable_t)varIt; @@ -130,232 +119,149 @@ static void lmm_check_concurrency(lmm_system_t sys) } } -static void lmm_var_free(lmm_system_t sys, lmm_variable_t var) +void s_lmm_system_t::var_free(lmm_variable_t var) { - XBT_IN("(sys=%p, var=%p)", sys, var); - sys->modified = 1; + XBT_IN("(sys=%p, var=%p)", this, var); + modified = true; // TODOLATER Can do better than that by leaving only the variable in only one enabled_element_set, call - // lmm_update_modified_set, and then remove it.. + // update_modified_set, and then remove it.. if (not var->cnsts.empty()) - lmm_update_modified_set(sys, var->cnsts[0].constraint); + update_modified_set(var->cnsts[0].constraint); for (s_lmm_element_t& elem : var->cnsts) { if (var->sharing_weight > 0) - lmm_decrease_concurrency(&elem); + elem.decrease_concurrency(); xbt_swag_remove(&elem, &(elem.constraint->enabled_element_set)); xbt_swag_remove(&elem, &(elem.constraint->disabled_element_set)); xbt_swag_remove(&elem, &(elem.constraint->active_element_set)); int nelements = xbt_swag_size(&(elem.constraint->enabled_element_set)) + xbt_swag_size(&(elem.constraint->disabled_element_set)); if (nelements == 0) - make_constraint_inactive(sys, elem.constraint); + make_constraint_inactive(elem.constraint); else - lmm_on_disabled_var(sys, elem.constraint); - } - - // Check if we can enable new variables going through the constraints where var was. - // Do it after removing all elements, so the first disabled variables get priority over those with smaller requirement - for (s_lmm_element_t& elem : var->cnsts) { - if (xbt_swag_size(&(elem.constraint->disabled_element_set))) - lmm_on_disabled_var(sys, elem.constraint); + on_disabled_var(elem.constraint); } var->cnsts.clear(); - lmm_check_concurrency(sys); + check_concurrency(); - xbt_mallocator_release(sys->variable_mallocator, var); + xbt_mallocator_release(variable_mallocator, var); XBT_OUT(); } -lmm_system_t lmm_system_new(bool selective_update) +s_lmm_system_t::s_lmm_system_t(bool selective_update) : selective_update_active(selective_update) { s_lmm_variable_t var; s_lmm_constraint_t cnst; - lmm_system_t l = new s_lmm_system_t(); - - l->modified = 0; - l->selective_update_active = selective_update; - l->visited_counter = 1; - - XBT_DEBUG("Setting selective_update_active flag to %d", l->selective_update_active); + modified = false; + visited_counter = 1; - xbt_swag_init(&(l->variable_set), xbt_swag_offset(var, variable_set_hookup)); - xbt_swag_init(&(l->constraint_set), xbt_swag_offset(cnst, constraint_set_hookup)); + XBT_DEBUG("Setting selective_update_active flag to %d", selective_update_active); - xbt_swag_init(&(l->active_constraint_set), xbt_swag_offset(cnst, active_constraint_set_hookup)); + xbt_swag_init(&variable_set, xbt_swag_offset(var, variable_set_hookup)); + xbt_swag_init(&constraint_set, xbt_swag_offset(cnst, constraint_set_hookup)); - xbt_swag_init(&(l->modified_constraint_set), xbt_swag_offset(cnst, modified_constraint_set_hookup)); - xbt_swag_init(&(l->saturated_variable_set), xbt_swag_offset(var, saturated_variable_set_hookup)); - xbt_swag_init(&(l->saturated_constraint_set), xbt_swag_offset(cnst, saturated_constraint_set_hookup)); + xbt_swag_init(&active_constraint_set, xbt_swag_offset(cnst, active_constraint_set_hookup)); - l->variable_mallocator = xbt_mallocator_new(65536, - lmm_variable_mallocator_new_f, - lmm_variable_mallocator_free_f, - lmm_variable_mallocator_reset_f); + xbt_swag_init(&modified_constraint_set, xbt_swag_offset(cnst, modified_constraint_set_hookup)); + xbt_swag_init(&saturated_variable_set, xbt_swag_offset(var, saturated_variable_set_hookup)); + xbt_swag_init(&saturated_constraint_set, xbt_swag_offset(cnst, saturated_constraint_set_hookup)); - l->solve_fun = &lmm_solve; - - return l; + keep_track = nullptr; + variable_mallocator = xbt_mallocator_new(65536, s_lmm_system_t::variable_mallocator_new_f, + s_lmm_system_t::variable_mallocator_free_f, nullptr); + solve_fun = &lmm_solve; } -void lmm_system_free(lmm_system_t sys) +s_lmm_system_t::~s_lmm_system_t() { - lmm_variable_t var = nullptr; - lmm_constraint_t cnst = nullptr; - - if (sys == nullptr) - return; + lmm_variable_t var; + lmm_constraint_t cnst; - while ((var = (lmm_variable_t) extract_variable(sys))) { + while ((var = extract_variable())) { auto demangled = simgrid::xbt::demangle(typeid(*var->id).name()); XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.get(), var->id_int); - lmm_var_free(sys, var); + var_free(var); } - while ((cnst = (lmm_constraint_t) extract_constraint(sys))) - lmm_cnst_free(sys, cnst); + while ((cnst = extract_constraint())) + cnst_free(cnst); - xbt_mallocator_free(sys->variable_mallocator); - delete sys; + xbt_mallocator_free(variable_mallocator); } -static inline void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst) +void s_lmm_system_t::cnst_free(lmm_constraint_t cnst) { - make_constraint_inactive(sys, cnst); + make_constraint_inactive(cnst); delete cnst; } -lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, double bound_value) +s_lmm_constraint_t::s_lmm_constraint_t(void* id_value, double bound_value) : bound(bound_value), id(id_value) { - lmm_constraint_t cnst = nullptr; s_lmm_element_t elem; - cnst = new s_lmm_constraint_t(); - cnst->id = id; - cnst->id_int = Global_const_debug_id++; - xbt_swag_init(&(cnst->enabled_element_set), xbt_swag_offset(elem, enabled_element_set_hookup)); - xbt_swag_init(&(cnst->disabled_element_set), xbt_swag_offset(elem, disabled_element_set_hookup)); - xbt_swag_init(&(cnst->active_element_set), xbt_swag_offset(elem, active_element_set_hookup)); - - cnst->bound = bound_value; - cnst->concurrency_maximum=0; - cnst->concurrency_current=0; - cnst->concurrency_limit = sg_concurrency_limit; - cnst->usage = 0; - cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */ - insert_constraint(sys, cnst); - - return cnst; -} - -int lmm_constraint_concurrency_limit_get(lmm_constraint_t cnst) -{ - return cnst->concurrency_limit; -} - -void lmm_constraint_concurrency_limit_set(lmm_constraint_t cnst, int concurrency_limit) -{ - xbt_assert(concurrency_limit<0 || cnst->concurrency_maximum<=concurrency_limit, - "New concurrency limit should be larger than observed concurrency maximum. Maybe you want to call" - " lmm_constraint_concurrency_maximum_reset() to reset the maximum?"); - cnst->concurrency_limit = concurrency_limit; -} - -void lmm_constraint_concurrency_maximum_reset(lmm_constraint_t cnst) -{ - cnst->concurrency_maximum = 0; -} - -int lmm_constraint_concurrency_maximum_get(lmm_constraint_t cnst) -{ - xbt_assert(cnst->concurrency_limit<0 || cnst->concurrency_maximum<=cnst->concurrency_limit, - "Very bad: maximum observed concurrency is higher than limit. This is a bug of SURF, please report it."); - return cnst->concurrency_maximum; -} - -void lmm_constraint_shared(lmm_constraint_t cnst) -{ - cnst->sharing_policy = 0; + id_int = Global_debug_id++; + xbt_swag_init(&enabled_element_set, xbt_swag_offset(elem, enabled_element_set_hookup)); + xbt_swag_init(&disabled_element_set, xbt_swag_offset(elem, disabled_element_set_hookup)); + xbt_swag_init(&active_element_set, xbt_swag_offset(elem, active_element_set_hookup)); + + remaining = 0.0; + usage = 0.0; + concurrency_limit = sg_concurrency_limit; + concurrency_current = 0; + concurrency_maximum = 0; + sharing_policy = 1; /* FIXME: don't hardcode the value */ + + lambda = 0.0; + new_lambda = 0.0; + cnst_light = nullptr; } -/** Return true if the constraint is shared, and false if it's FATPIPE */ -int lmm_constraint_sharing_policy(lmm_constraint_t cnst) +lmm_constraint_t s_lmm_system_t::constraint_new(void* id, double bound_value) { - return (cnst->sharing_policy); + lmm_constraint_t cnst = new s_lmm_constraint_t(id, bound_value); + insert_constraint(cnst); + return cnst; } -static void *lmm_variable_mallocator_new_f() +void* s_lmm_system_t::variable_mallocator_new_f() { return new s_lmm_variable_t; } -static void lmm_variable_mallocator_free_f(void *var) +void s_lmm_system_t::variable_mallocator_free_f(void* var) { delete static_cast(var); } -lmm_variable_t lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double sharing_weight, double bound, - int number_of_constraints) +lmm_variable_t s_lmm_system_t::variable_new(simgrid::surf::Action* id, double sharing_weight, double bound, + int number_of_constraints) { - XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", sys, id, sharing_weight, bound, number_of_constraints); - - lmm_variable_t var = (lmm_variable_t)xbt_mallocator_get(sys->variable_mallocator); - var->id = id; - var->id_int = Global_debug_id++; - var->cnsts.reserve(number_of_constraints); - var->sharing_weight = sharing_weight; - var->staged_weight = 0.0; - var->bound = bound; - var->concurrency_share = 1; - var->value = 0.0; - var->visited = sys->visited_counter - 1; - var->mu = 0.0; - var->new_mu = 0.0; - var->func_f = func_f_def; - var->func_fp = func_fp_def; - var->func_fpi = func_fpi_def; - - var->variable_set_hookup.next = nullptr; - var->variable_set_hookup.prev = nullptr; - var->saturated_variable_set_hookup.next = nullptr; - var->saturated_variable_set_hookup.prev = nullptr; + XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", this, id, sharing_weight, bound, number_of_constraints); + lmm_variable_t var = static_cast(xbt_mallocator_get(variable_mallocator)); + var->initialize(id, sharing_weight, bound, number_of_constraints, visited_counter - 1); if (sharing_weight) - xbt_swag_insert_at_head(var, &(sys->variable_set)); + xbt_swag_insert_at_head(var, &variable_set); else - xbt_swag_insert_at_tail(var, &(sys->variable_set)); + xbt_swag_insert_at_tail(var, &variable_set); XBT_OUT(" returns %p", var); return var; } -void lmm_variable_free(lmm_system_t sys, lmm_variable_t var) +void s_lmm_system_t::variable_free(lmm_variable_t var) { - remove_variable(sys, var); - lmm_var_free(sys, var); + remove_variable(var); + var_free(var); } -double lmm_variable_getvalue(lmm_variable_t var) +void s_lmm_system_t::expand(lmm_constraint_t cnst, lmm_variable_t var, double consumption_weight) { - return (var->value); -} - -void lmm_variable_concurrency_share_set(lmm_variable_t var, short int concurrency_share) -{ - var->concurrency_share=concurrency_share; -} - -double lmm_variable_getbound(lmm_variable_t var) -{ - return (var->bound); -} - -void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double consumption_weight) -{ - sys->modified = 1; + modified = true; //Check if this variable already has an active element in this constraint //If it does, substract it from the required slack @@ -363,16 +269,16 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, dou if(var->concurrency_share>1){ for (s_lmm_element_t& elem : var->cnsts) { if (elem.constraint == cnst && xbt_swag_belongs(&elem, &(elem.constraint->enabled_element_set))) - current_share += lmm_element_concurrency(&elem); + current_share += elem.get_concurrency(); } } //Check if we need to disable the variable - if (var->sharing_weight > 0 && var->concurrency_share - current_share > lmm_concurrency_slack(cnst)) { + if (var->sharing_weight > 0 && var->concurrency_share - current_share > cnst->get_concurrency_slack()) { double weight = var->sharing_weight; - lmm_disable_var(sys,var); + disable_var(var); for (s_lmm_element_t const& elem : var->cnsts) - lmm_on_disabled_var(sys, elem.constraint); + on_disabled_var(elem.constraint); consumption_weight = 0; var->staged_weight=weight; xbt_assert(not var->sharing_weight); @@ -389,28 +295,28 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, dou if (var->sharing_weight) { xbt_swag_insert_at_head(&elem, &(elem.constraint->enabled_element_set)); - lmm_increase_concurrency(&elem); + elem.increase_concurrency(); } else xbt_swag_insert_at_tail(&elem, &(elem.constraint->disabled_element_set)); - if (not sys->selective_update_active) { - make_constraint_active(sys, cnst); + if (not selective_update_active) { + make_constraint_active(cnst); } else if (elem.consumption_weight > 0 || var->sharing_weight > 0) { - make_constraint_active(sys, cnst); - lmm_update_modified_set(sys, cnst); + make_constraint_active(cnst); + update_modified_set(cnst); //TODOLATER: Why do we need this second call? if (var->cnsts.size() > 1) - lmm_update_modified_set(sys, var->cnsts[0].constraint); + update_modified_set(var->cnsts[0].constraint); } - lmm_check_concurrency(sys); + check_concurrency(); } -void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value) +void s_lmm_system_t::expand_add(lmm_constraint_t cnst, lmm_variable_t var, double value) { - sys->modified = 1; + modified = true; - lmm_check_concurrency(sys); + check_concurrency(); //BEWARE: In case you have multiple elements in one constraint, this will always add value to the first element. auto elem_it = std::find_if(begin(var->cnsts), end(var->cnsts), @@ -418,7 +324,7 @@ void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, if (elem_it != end(var->cnsts)) { s_lmm_element_t& elem = *elem_it; if (var->sharing_weight) - lmm_decrease_concurrency(&elem); + elem.decrease_concurrency(); if (cnst->sharing_policy) elem.consumption_weight += value; @@ -427,61 +333,40 @@ void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, //We need to check that increasing value of the element does not cross the concurrency limit if (var->sharing_weight) { - if (lmm_concurrency_slack(cnst) < lmm_element_concurrency(&elem)) { + if (cnst->get_concurrency_slack() < elem.get_concurrency()) { double weight = var->sharing_weight; - lmm_disable_var(sys,var); + disable_var(var); for (s_lmm_element_t const& elem2 : var->cnsts) - lmm_on_disabled_var(sys, elem2.constraint); + on_disabled_var(elem2.constraint); var->staged_weight=weight; xbt_assert(not var->sharing_weight); } - lmm_increase_concurrency(&elem); + elem.increase_concurrency(); } - lmm_update_modified_set(sys, cnst); + update_modified_set(cnst); } else - lmm_expand(sys, cnst, var, value); + expand(cnst, var, value); - lmm_check_concurrency(sys); -} - -lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var, unsigned num) -{ - if (num < var->cnsts.size()) - return (var->cnsts[num].constraint); - else - return nullptr; + check_concurrency(); } -double lmm_get_cnst_weight_from_var(lmm_system_t /*sys*/, lmm_variable_t var, unsigned num) -{ - if (num < var->cnsts.size()) - return (var->cnsts[num].consumption_weight); - else - return 0.0; -} - -int lmm_get_number_of_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var) -{ - return (var->cnsts.size()); -} - -lmm_variable_t lmm_get_var_from_cnst(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem) +lmm_variable_t s_lmm_constraint_t::get_variable(lmm_element_t* elem) const { if (*elem == nullptr) { // That is the first call, pick the first element among enabled_element_set (or disabled_element_set if // enabled_element_set is empty) - *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set)); + *elem = (lmm_element_t)xbt_swag_getFirst(&enabled_element_set); if (*elem == nullptr) - *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set)); + *elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set); } else { //elem is not null, so we carry on - if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){ + if (xbt_swag_belongs(*elem, &enabled_element_set)) { //Look at enabled_element_set, and jump to disabled_element_set when finished - *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset); + *elem = (lmm_element_t)xbt_swag_getNext(*elem, enabled_element_set.offset); if (*elem == nullptr) - *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set)); + *elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set); } else { - *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset); + *elem = (lmm_element_t)xbt_swag_getNext(*elem, disabled_element_set.offset); } } if (*elem) @@ -492,14 +377,13 @@ lmm_variable_t lmm_get_var_from_cnst(lmm_system_t /*sys*/, lmm_constraint_t cnst //if we modify the swag between calls, normal version may loop forever //this safe version ensures that we browse the swag elements only once -lmm_variable_t lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem, - lmm_element_t * nextelem, int * numelem) +lmm_variable_t s_lmm_constraint_t::get_variable_safe(lmm_element_t* elem, lmm_element_t* nextelem, int* numelem) const { if (*elem == nullptr) { - *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set)); - *numelem = xbt_swag_size(&(cnst->enabled_element_set))+xbt_swag_size(&(cnst->disabled_element_set))-1; + *elem = (lmm_element_t)xbt_swag_getFirst(&enabled_element_set); + *numelem = xbt_swag_size(&enabled_element_set) + xbt_swag_size(&disabled_element_set) - 1; if (*elem == nullptr) - *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set)); + *elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set); }else{ *elem = *nextelem; if(*numelem>0){ @@ -509,48 +393,38 @@ lmm_variable_t lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t } if (*elem){ //elem is not null, so we carry on - if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){ + if (xbt_swag_belongs(*elem, &enabled_element_set)) { //Look at enabled_element_set, and jump to disabled_element_set when finished - *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset); + *nextelem = (lmm_element_t)xbt_swag_getNext(*elem, enabled_element_set.offset); if (*nextelem == nullptr) - *nextelem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set)); + *nextelem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set); } else { - *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset); + *nextelem = (lmm_element_t)xbt_swag_getNext(*elem, disabled_element_set.offset); } return (*elem)->variable; }else return nullptr; } -void *lmm_constraint_id(lmm_constraint_t cnst) -{ - return cnst->id; -} - -void *lmm_variable_id(lmm_variable_t var) -{ - return var->id; -} - -static inline void saturated_constraint_set_update(double usage, int cnst_light_num, - dyn_light_t& saturated_constraint_set, double* min_usage) +static inline void saturated_constraints_update(double usage, int cnst_light_num, dyn_light_t& saturated_constraints, + double* min_usage) { xbt_assert(usage > 0,"Impossible"); if (*min_usage < 0 || *min_usage > usage) { *min_usage = usage; XBT_HERE(" min_usage=%f (cnst->remaining / cnst->usage =%f)", *min_usage, usage); - saturated_constraint_set.assign(1, cnst_light_num); + saturated_constraints.assign(1, cnst_light_num); } else if (*min_usage == usage) { - saturated_constraint_set.emplace_back(cnst_light_num); + saturated_constraints.emplace_back(cnst_light_num); } } static inline void saturated_variable_set_update(s_lmm_constraint_light_t* cnst_light_tab, - const dyn_light_t& saturated_constraint_set, lmm_system_t sys) + const dyn_light_t& saturated_constraints, lmm_system_t sys) { /* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate (cnst_light_tab)*/ - for (int const& saturated_cnst : saturated_constraint_set) { + for (int const& saturated_cnst : saturated_constraints) { lmm_constraint_light_t cnst = &cnst_light_tab[saturated_cnst]; void* _elem; xbt_swag_t elem_list = &(cnst->cnst->active_element_set); @@ -564,13 +438,13 @@ static inline void saturated_variable_set_update(s_lmm_constraint_light_t* cnst_ } } -void lmm_print(lmm_system_t sys) +void s_lmm_system_t::print() { std::string buf = std::string("MAX-MIN ( "); void* _var; /* Printing Objective */ - xbt_swag_t var_list = &(sys->variable_set); + xbt_swag_t var_list = &variable_set; xbt_swag_foreach(_var, var_list) { lmm_variable_t var = (lmm_variable_t)_var; buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->sharing_weight) + ") "; @@ -582,7 +456,7 @@ void lmm_print(lmm_system_t sys) XBT_DEBUG("Constraints"); /* Printing Constraints */ void* _cnst; - xbt_swag_t cnst_list = &(sys->active_constraint_set); + xbt_swag_t cnst_list = &active_constraint_set; xbt_swag_foreach(_cnst, cnst_list) { lmm_constraint_t cnst = (lmm_constraint_t)_cnst; double sum = 0.0; @@ -637,7 +511,7 @@ void lmm_print(lmm_system_t sys) } } -void lmm_solve(lmm_system_t sys) +void s_lmm_system_t::solve() { void* _cnst; void* _cnst_next; @@ -645,15 +519,15 @@ void lmm_solve(lmm_system_t sys) double min_usage = -1; double min_bound = -1; - if (not sys->modified) + if (not modified) return; - XBT_IN("(sys=%p)", sys); + XBT_IN("(sys=%p)", this); /* Compute Usage and store the variables that reach the maximum. If selective_update_active is true, only constraints * that changed are considered. Otherwise all constraints with active actions are considered. */ - xbt_swag_t cnst_list = sys->selective_update_active ? &(sys->modified_constraint_set) : &(sys->active_constraint_set); + xbt_swag_t cnst_list = selective_update_active ? &modified_constraint_set : &active_constraint_set; XBT_DEBUG("Active constraints : %d", xbt_swag_size(cnst_list)); /* Init: Only modified code portions: reset the value of active variables */ @@ -669,7 +543,7 @@ void lmm_solve(lmm_system_t sys) s_lmm_constraint_light_t* cnst_light_tab = new s_lmm_constraint_light_t[xbt_swag_size(cnst_list)](); int cnst_light_num = 0; - dyn_light_t saturated_constraint_set; + dyn_light_t saturated_constraints; xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list) { lmm_constraint_t cnst = (lmm_constraint_t)_cnst; @@ -689,33 +563,33 @@ void lmm_solve(lmm_system_t sys) else if (cnst->usage < elem->consumption_weight / elem->variable->sharing_weight) cnst->usage = elem->consumption_weight / elem->variable->sharing_weight; - make_elem_active(elem); + elem->make_active(); simgrid::surf::Action *action = static_cast(elem->variable->id); - if (sys->keep_track && not action->is_linked()) - sys->keep_track->push_back(*action); + if (keep_track && not action->is_linked()) + keep_track->push_back(*action); } } XBT_DEBUG("Constraint '%d' usage: %f remaining: %f concurrency: %i<=%i<=%i", cnst->id_int, cnst->usage, - cnst->remaining,cnst->concurrency_current,cnst->concurrency_maximum,cnst->concurrency_limit); + cnst->remaining, cnst->concurrency_current, cnst->concurrency_maximum, cnst->get_concurrency_limit()); /* Saturated constraints update */ if(cnst->usage > 0) { cnst_light_tab[cnst_light_num].cnst = cnst; cnst->cnst_light = &(cnst_light_tab[cnst_light_num]); cnst_light_tab[cnst_light_num].remaining_over_usage = cnst->remaining / cnst->usage; - saturated_constraint_set_update(cnst_light_tab[cnst_light_num].remaining_over_usage, - cnst_light_num, saturated_constraint_set, &min_usage); + saturated_constraints_update(cnst_light_tab[cnst_light_num].remaining_over_usage, cnst_light_num, + saturated_constraints, &min_usage); xbt_assert(cnst->active_element_set.count>0, "There is no sense adding a constraint that has no active element!"); cnst_light_num++; } } - saturated_variable_set_update( cnst_light_tab, saturated_constraint_set, sys); + saturated_variable_set_update(cnst_light_tab, saturated_constraints, this); /* Saturated variables update */ do { /* Fix the variables that have to be */ - xbt_swag_t var_list = &(sys->saturated_variable_set); + xbt_swag_t var_list = &saturated_variable_set; void* _var; lmm_variable_t var = nullptr; xbt_swag_foreach(_var, var_list) { @@ -777,11 +651,11 @@ void lmm_solve(lmm_system_t sys) } else { cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage; } - make_elem_inactive(&elem); + elem.make_inactive(); } else { // Remember: non-shared constraints only require that max(elem.value * var->value) < cnst->bound cnst->usage = 0.0; - make_elem_inactive(&elem); + elem.make_inactive(); xbt_swag_t elem_list = &(cnst->enabled_element_set); xbt_swag_foreach(_elem, elem_list) { lmm_element_t elem2 = static_cast(_elem); @@ -817,7 +691,7 @@ void lmm_solve(lmm_system_t sys) /* Find out which variables reach the maximum */ min_usage = -1; min_bound = -1; - saturated_constraint_set.clear(); + saturated_constraints.clear(); int pos; for(pos=0; posactive_element_set.count>0, "Cannot saturate more a constraint that has" @@ -825,28 +699,32 @@ void lmm_solve(lmm_system_t sys) " because of possible rounding effects.\n\tFor the record, the usage of this constraint is %g while " "the maxmin precision to which it is compared is %g.\n\tThe usage of the previous constraint is %g.", cnst_light_tab[pos].cnst->usage, sg_maxmin_precision, cnst_light_tab[pos-1].cnst->usage); - saturated_constraint_set_update(cnst_light_tab[pos].remaining_over_usage, pos, saturated_constraint_set, - &min_usage); + saturated_constraints_update(cnst_light_tab[pos].remaining_over_usage, pos, saturated_constraints, &min_usage); } - saturated_variable_set_update(cnst_light_tab, saturated_constraint_set, sys); + saturated_variable_set_update(cnst_light_tab, saturated_constraints, this); } while (cnst_light_num > 0); - sys->modified = 0; - if (sys->selective_update_active) - lmm_remove_all_modified_set(sys); + modified = false; + if (selective_update_active) + remove_all_modified_set(); if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) { - lmm_print(sys); + print(); } - lmm_check_concurrency(sys); + check_concurrency(); delete[] cnst_light_tab; XBT_OUT(); } +void lmm_solve(lmm_system_t sys) +{ + sys->solve(); +} + /** \brief Attribute the value bound to var->bound. * * \param sys the lmm_system_t @@ -856,28 +734,44 @@ void lmm_solve(lmm_system_t sys) * Makes var->bound equal to bound. Whenever this function is called a change is signed in the system. To * avoid false system changing detection it is a good idea to test (bound != 0) before calling it. */ -void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, double bound) +void s_lmm_system_t::update_variable_bound(lmm_variable_t var, double bound) { - sys->modified = 1; + modified = true; var->bound = bound; if (not var->cnsts.empty()) - lmm_update_modified_set(sys, var->cnsts[0].constraint); + update_modified_set(var->cnsts[0].constraint); } -int lmm_concurrency_slack(lmm_constraint_t cnstr) +void s_lmm_variable_t::initialize(simgrid::surf::Action* id_value, double sharing_weight_value, double bound_value, + int number_of_constraints, unsigned visited_value) { - if (cnstr->concurrency_limit < 0) - return std::numeric_limits::max(); - return cnstr->concurrency_limit - cnstr->concurrency_current; + id = id_value; + id_int = Global_debug_id++; + cnsts.reserve(number_of_constraints); + sharing_weight = sharing_weight_value; + staged_weight = 0.0; + bound = bound_value; + concurrency_share = 1; + value = 0.0; + visited = visited_value; + mu = 0.0; + new_mu = 0.0; + func_f = func_f_def; + func_fp = func_fp_def; + func_fpi = func_fpi_def; + + variable_set_hookup.next = nullptr; + variable_set_hookup.prev = nullptr; + saturated_variable_set_hookup.next = nullptr; + saturated_variable_set_hookup.prev = nullptr; } -/** \brief Measure the minimum concurrency slack across all constraints where the given var is involved */ -int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var) +int s_lmm_variable_t::get_min_concurrency_slack() const { int minslack = std::numeric_limits::max(); - for (s_lmm_element_t const& elem : var->cnsts) { - int slack = lmm_concurrency_slack(elem.constraint); + for (s_lmm_element_t const& elem : cnsts) { + int slack = elem.constraint->get_concurrency_slack(); if (slack < minslack) { // This is only an optimization, to avoid looking at more constraints when slack is already zero if (slack == 0) @@ -888,63 +782,57 @@ int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var) return minslack; } -/* /Check if a variable can be enabled - * - * Make sure to set staged_weight before, if your intent is only to check concurrency - */ -int lmm_can_enable_var(lmm_variable_t var){ - return var->staged_weight>0 && lmm_cnstrs_min_concurrency_slack(var)>=var->concurrency_share; -} - //Small remark: In this implementation of lmm_enable_var and lmm_disable_var, we will meet multiple times with var when -// running lmm_update_modified_set. -//A priori not a big performance issue, but we might do better by calling lmm_update_modified_set within the for loops +// running sys->update_modified_set. +// A priori not a big performance issue, but we might do better by calling sys->update_modified_set within the for loops // (after doing the first for enabling==1, and before doing the last for disabling==1) -void lmm_enable_var(lmm_system_t sys, lmm_variable_t var){ - xbt_assert(lmm_can_enable_var(var)); +void s_lmm_system_t::enable_var(lmm_variable_t var) +{ + xbt_assert(not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug) || var->can_enable()); var->sharing_weight = var->staged_weight; var->staged_weight = 0; - // Enabling the variable, move to var to list head. Subtlety is: here, we need to call lmm_update_modified_set AFTER + // Enabling the variable, move to var to list head. Subtlety is: here, we need to call update_modified_set AFTER // moving at least one element of var. - xbt_swag_remove(var, &(sys->variable_set)); - xbt_swag_insert_at_head(var, &(sys->variable_set)); + xbt_swag_remove(var, &variable_set); + xbt_swag_insert_at_head(var, &variable_set); for (s_lmm_element_t& elem : var->cnsts) { xbt_swag_remove(&elem, &(elem.constraint->disabled_element_set)); xbt_swag_insert_at_head(&elem, &(elem.constraint->enabled_element_set)); - lmm_increase_concurrency(&elem); + elem.increase_concurrency(); } if (not var->cnsts.empty()) - lmm_update_modified_set(sys, var->cnsts[0].constraint); + update_modified_set(var->cnsts[0].constraint); - //When used within lmm_on_disabled_var, we would get an assertion fail, because transiently there can be variables + // When used within on_disabled_var, we would get an assertion fail, because transiently there can be variables // that are staged and could be activated. - //Anyway, caller functions all call lmm_check_concurrency() in the end. + // Anyway, caller functions all call check_concurrency() in the end. } -void lmm_disable_var(lmm_system_t sys, lmm_variable_t var){ +void s_lmm_system_t::disable_var(lmm_variable_t var) +{ xbt_assert(not var->staged_weight, "Staged weight should have been cleared"); - // Disabling the variable, move to var to list tail. Subtlety is: here, we need to call lmm_update_modified_set BEFORE - // moving the last element of var. - xbt_swag_remove(var, &(sys->variable_set)); - xbt_swag_insert_at_tail(var, &(sys->variable_set)); + // Disabling the variable, move to var to list tail. Subtlety is: here, we need to call update_modified_set + // BEFORE moving the last element of var. + xbt_swag_remove(var, &variable_set); + xbt_swag_insert_at_tail(var, &variable_set); if (not var->cnsts.empty()) - lmm_update_modified_set(sys, var->cnsts[0].constraint); + update_modified_set(var->cnsts[0].constraint); for (s_lmm_element_t& elem : var->cnsts) { xbt_swag_remove(&elem, &(elem.constraint->enabled_element_set)); xbt_swag_insert_at_tail(&elem, &(elem.constraint->disabled_element_set)); xbt_swag_remove(&elem, &(elem.constraint->active_element_set)); - lmm_decrease_concurrency(&elem); + elem.decrease_concurrency(); } var->sharing_weight = 0.0; var->staged_weight=0.0; var->value = 0.0; - lmm_check_concurrency(sys); + check_concurrency(); } /* /brief Find variables that can be enabled and enable them. @@ -954,9 +842,9 @@ void lmm_disable_var(lmm_system_t sys, lmm_variable_t var){ * If yes, check that none of the constraints that this variable is involved in is at the limit of its concurrency * And then add it to enabled variables */ -void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){ - - if(cnstr->concurrency_limit<0) +void s_lmm_system_t::on_disabled_var(lmm_constraint_t cnstr) +{ + if (cnstr->get_concurrency_limit() < 0) return; int numelem = xbt_swag_size(&(cnstr->disabled_element_set)); @@ -970,15 +858,15 @@ void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){ lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset); - if (elem->variable->staged_weight > 0 && lmm_can_enable_var(elem->variable)) { + if (elem->variable->staged_weight > 0 && elem->variable->can_enable()) { //Found a staged variable //TODOLATER: Add random timing function to model reservation protocol fuzziness? Then how to make sure that //staged variables will eventually be called? - lmm_enable_var(sys, elem->variable); + enable_var(elem->variable); } - xbt_assert(cnstr->concurrency_current<=cnstr->concurrency_limit,"Concurrency overflow!"); - if(cnstr->concurrency_current==cnstr->concurrency_limit) + xbt_assert(cnstr->concurrency_current <= cnstr->get_concurrency_limit(), "Concurrency overflow!"); + if (cnstr->concurrency_current == cnstr->get_concurrency_limit()) break; elem = nextelem; @@ -986,13 +874,13 @@ void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){ //We could get an assertion fail, because transiently there can be variables that are staged and could be activated. //And we need to go through all constraints of the disabled var before getting back a coherent state. - //Anyway, caller functions all call lmm_check_concurrency() in the end. + // Anyway, caller functions all call check_concurrency() in the end. } /* \brief update the weight of a variable, and enable/disable it. * @return Returns whether a change was made */ -void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight) +void s_lmm_system_t::update_variable_weight(lmm_variable_t var, double weight) { xbt_assert(weight>=0,"Variable weight should not be negative!"); @@ -1002,60 +890,40 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double wei int enabling_var = (weight > 0 && var->sharing_weight <= 0); int disabling_var = (weight <= 0 && var->sharing_weight > 0); - XBT_IN("(sys=%p, var=%p, weight=%f)", sys, var, weight); + XBT_IN("(sys=%p, var=%p, weight=%f)", this, var, weight); - sys->modified = 1; + modified = true; //Are we enabling this variable? if (enabling_var){ var->staged_weight = weight; - int minslack = lmm_cnstrs_min_concurrency_slack(var); + int minslack = var->get_min_concurrency_slack(); if (minslack < var->concurrency_share) { XBT_DEBUG("Staging var (instead of enabling) because min concurrency slack %i, with weight %f and concurrency" " share %i", minslack, weight, var->concurrency_share); return; } XBT_DEBUG("Enabling var with min concurrency slack %i", minslack); - lmm_enable_var(sys,var); + enable_var(var); } else if (disabling_var){ //Are we disabling this variable? - lmm_disable_var(sys,var); + disable_var(var); } else { var->sharing_weight = weight; } - lmm_check_concurrency(sys); + check_concurrency(); XBT_OUT(); } -double lmm_get_variable_weight(lmm_variable_t var) -{ - return var->sharing_weight; -} - -void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound) +void s_lmm_system_t::update_constraint_bound(lmm_constraint_t cnst, double bound) { - sys->modified = 1; - lmm_update_modified_set(sys, cnst); + modified = true; + update_modified_set(cnst); cnst->bound = bound; } -int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst) -{ - return xbt_swag_belongs(cnst, &(sys->active_constraint_set)); -} - -inline lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys) -{ - return (lmm_constraint_t)xbt_swag_getFirst(&(sys->active_constraint_set)); -} - -inline lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, lmm_constraint_t cnst) -{ - return (lmm_constraint_t)xbt_swag_getNext(cnst, (sys->active_constraint_set).offset); -} - /** \brief Update the constraint set propagating recursively to other constraints so the system should not be entirely * computed. * @@ -1065,53 +933,48 @@ inline lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, lmm_con * A recursive algorithm to optimize the system recalculation selecting only constraints that have changed. Each * constraint change is propagated to the list of constraints for each variable. */ -static void lmm_update_modified_set_rec(lmm_system_t sys, lmm_constraint_t cnst) +void s_lmm_system_t::update_modified_set_rec(lmm_constraint_t cnst) { void* _elem; - //TODOLATER: Why lmm_modified_set has been changed in git version 2392B5157...? Looks equivalent logically and less obvious.. xbt_swag_foreach(_elem, &cnst->enabled_element_set) { lmm_variable_t var = ((lmm_element_t)_elem)->variable; for (s_lmm_element_t const& elem : var->cnsts) { - if (var->visited == sys->visited_counter) + if (var->visited == visited_counter) break; - if (elem.constraint != cnst && not xbt_swag_belongs(elem.constraint, &sys->modified_constraint_set)) { - xbt_swag_insert(elem.constraint, &sys->modified_constraint_set); - lmm_update_modified_set_rec(sys, elem.constraint); + if (elem.constraint != cnst && not xbt_swag_belongs(elem.constraint, &modified_constraint_set)) { + xbt_swag_insert(elem.constraint, &modified_constraint_set); + update_modified_set_rec(elem.constraint); } } //var will be ignored in later visits as long as sys->visited_counter does not move - var->visited = sys->visited_counter; + var->visited = visited_counter; } } -static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst) +void s_lmm_system_t::update_modified_set(lmm_constraint_t cnst) { /* nothing to do if selective update isn't active */ - if (sys->selective_update_active && not xbt_swag_belongs(cnst, &sys->modified_constraint_set)) { - xbt_swag_insert(cnst, &sys->modified_constraint_set); - lmm_update_modified_set_rec(sys, cnst); + if (selective_update_active && not xbt_swag_belongs(cnst, &modified_constraint_set)) { + xbt_swag_insert(cnst, &modified_constraint_set); + update_modified_set_rec(cnst); } } -/** \brief Remove all constraints of the modified_constraint_set. - * - * \param sys the lmm_system_t - */ -static void lmm_remove_all_modified_set(lmm_system_t sys) +void s_lmm_system_t::remove_all_modified_set() { - // We cleverly un-flag all variables just by incrementing sys->visited_counter - // In effect, the var->visited value will no more be equal to sys->visited counter + // We cleverly un-flag all variables just by incrementing visited_counter + // In effect, the var->visited value will no more be equal to visited counter // To be clean, when visited counter has wrapped around, we force these var->visited values so that variables that // were in the modified a long long time ago are not wrongly skipped here, which would lead to very nasty bugs // (i.e. not readibily reproducible, and requiring a lot of run time before happening). - if (++sys->visited_counter == 1) { + if (++visited_counter == 1) { /* the counter wrapped around, reset each variable->visited */ - void *_var; - xbt_swag_foreach(_var, &sys->variable_set) + void *_var; + xbt_swag_foreach(_var, &variable_set) ((lmm_variable_t)_var)->visited = 0; } - xbt_swag_reset(&sys->modified_constraint_set); + xbt_swag_reset(&modified_constraint_set); } /** @@ -1125,33 +988,37 @@ static void lmm_remove_all_modified_set(lmm_system_t sys) * * \param cnst the lmm_constraint_t associated to the resource */ -double lmm_constraint_get_usage(lmm_constraint_t cnst) { - double usage = 0.0; - xbt_swag_t elem_list = &(cnst->enabled_element_set); +double s_lmm_constraint_t::get_usage() const +{ + double result = 0.0; + const_xbt_swag_t elem_list = &enabled_element_set; void* _elem; xbt_swag_foreach(_elem, elem_list) { lmm_element_t elem = (lmm_element_t)_elem; if (elem->consumption_weight > 0) { - if (cnst->sharing_policy) - usage += elem->consumption_weight * elem->variable->value; - else if (usage < elem->consumption_weight * elem->variable->value) - usage = std::max(usage, elem->consumption_weight * elem->variable->value); + if (sharing_policy) + result += elem->consumption_weight * elem->variable->value; + else if (result < elem->consumption_weight * elem->variable->value) + result = std::max(result, elem->consumption_weight * elem->variable->value); } } - return usage; + return result; } -int lmm_constraint_get_variable_amount(lmm_constraint_t cnst) { - int usage = 0; - xbt_swag_t elem_list = &(cnst->enabled_element_set); +int s_lmm_constraint_t::get_variable_amount() const +{ + int result = 0; + const_xbt_swag_t elem_list = &enabled_element_set; void *_elem; xbt_swag_foreach(_elem, elem_list) { lmm_element_t elem = (lmm_element_t)_elem; if (elem->consumption_weight > 0) - usage++; + result++; } - return usage; + return result; +} +} } diff --git a/src/surf/maxmin_private.hpp b/src/surf/maxmin_private.hpp deleted file mode 100644 index 03505578a2..0000000000 --- a/src/surf/maxmin_private.hpp +++ /dev/null @@ -1,166 +0,0 @@ -/* Copyright (c) 2004-2017. 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 SURF_MAXMIN_PRIVATE_H -#define SURF_MAXMIN_PRIVATE_H - -#include "surf/maxmin.hpp" -#include "surf_interface.hpp" -#include "xbt/mallocator.h" -#include "xbt/swag.h" - -#include - -/** @ingroup SURF_lmm - * @brief LMM element - * Elements can be seen as glue between constraint objects and variable objects. - * Basically, each variable will have a set of elements, one for each constraint where it is involved. - * Then, it is used to list all variables involved in constraint through constraint's xxx_element_set lists, or vice-versa list all constraints for a given variable. - */ -struct s_lmm_element_t { - /* hookup to constraint */ - s_xbt_swag_hookup_t enabled_element_set_hookup; - s_xbt_swag_hookup_t disabled_element_set_hookup; - s_xbt_swag_hookup_t active_element_set_hookup; - - lmm_constraint_t constraint; - lmm_variable_t variable; - - // consumption_weight: impact of 1 byte or flop of your application onto the resource (in byte or flop) - // - if CPU, then probably 1. - // - If network, then 1 in forward direction and 0.05 backward for the ACKs - double consumption_weight; -}; -#define make_elem_active(elem) xbt_swag_insert_at_head((elem), &((elem)->constraint->active_element_set)) -#define make_elem_inactive(elem) xbt_swag_remove((elem), &((elem)->constraint->active_element_set)) - -struct s_lmm_constraint_light_t { - double remaining_over_usage; - lmm_constraint_t cnst; -}; - -/** @ingroup SURF_lmm - * @brief LMM constraint - * Each constraint contains several partially overlapping logical sets of elements: - * \li Disabled elements which variable's weight is zero. This variables are not at all processed by LMM, but eventually the corresponding action will enable it (at least this is the idea). - * \li Enabled elements which variable's weight is non-zero. They are utilized in some LMM functions. - * \li Active elements which variable's weight is non-zero (i.e. it is enabled) AND its element value is non-zero. LMM_solve iterates over active elements during resolution, dynamically making them active or unactive. - * - */ -struct s_lmm_constraint_t { - /* hookup to system */ - s_xbt_swag_hookup_t constraint_set_hookup; - s_xbt_swag_hookup_t active_constraint_set_hookup; - s_xbt_swag_hookup_t modified_constraint_set_hookup; - s_xbt_swag_hookup_t saturated_constraint_set_hookup; - - s_xbt_swag_t enabled_element_set; /* a list of lmm_element_t */ - s_xbt_swag_t disabled_element_set; /* a list of lmm_element_t */ - s_xbt_swag_t active_element_set; /* a list of lmm_element_t */ - double remaining; - double usage; - double bound; - int concurrency_limit; /* The maximum number of variables that may be enabled at any time (stage variables if necessary) */ - //TODO MARTIN Check maximum value across resources at the end of simulation and give a warning is more than e.g. 500 - int concurrency_current; /* The current concurrency */ - int concurrency_maximum; /* The maximum number of (enabled and disabled) variables associated to the constraint at any given time (essentially for tracing)*/ - - int sharing_policy; /* see @e_surf_link_sharing_policy_t (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */ - void *id; - int id_int; - double lambda; - double new_lambda; - lmm_constraint_light_t cnst_light; -}; - -/** @ingroup SURF_lmm - * @brief LMM variable - * - * When something prevents us from enabling a variable, we "stage" the weight that we would have like to set, so that as soon as possible we enable the variable with desired weight - */ -struct s_lmm_variable_t { - /* hookup to system */ - s_xbt_swag_hookup_t variable_set_hookup; - s_xbt_swag_hookup_t saturated_variable_set_hookup; - - std::vector cnsts; - - // sharing_weight: variable's impact on the resource during the sharing - // if == 0, the variable is not considered by LMM - // on CPU, actions with N threads have a sharing of N - // on network, the actions with higher latency have a lesser sharing_weight - double sharing_weight; - - double staged_weight; /* If non-zero, variable is staged for addition as soon as maxconcurrency constraints will be met */ - double bound; - double value; - short int concurrency_share; /* The maximum number of elements that variable will add to a constraint */ - simgrid::surf::Action* id; - int id_int; - unsigned visited; /* used by lmm_update_modified_set */ - /* \begin{For Lagrange only} */ - double mu; - double new_mu; - double (*func_f)(s_lmm_variable_t* var, double x); /* (f) */ - double (*func_fp)(s_lmm_variable_t* var, double x); /* (f') */ - double (*func_fpi)(s_lmm_variable_t* var, double x); /* (f')^{-1} */ - /* \end{For Lagrange only} */ -}; - -/** @ingroup SURF_lmm - * @brief LMM system - */ -struct s_lmm_system_t { - int modified; - bool selective_update_active; /* flag to update partially the system only selecting changed portions */ - unsigned visited_counter; /* used by lmm_update_modified_set and lmm_remove_modified_set to cleverly (un-)flag the constraints (more details in these functions)*/ - s_xbt_swag_t variable_set; /* a list of lmm_variable_t */ - s_xbt_swag_t constraint_set; /* a list of lmm_constraint_t */ - - s_xbt_swag_t active_constraint_set; /* a list of lmm_constraint_t */ - s_xbt_swag_t modified_constraint_set; /* a list of modified lmm_constraint_t */ - - s_xbt_swag_t saturated_variable_set; /* a list of lmm_variable_t */ - s_xbt_swag_t saturated_constraint_set; /* a list of lmm_constraint_t_t */ - - simgrid::surf::ActionLmmListPtr keep_track; - - xbt_mallocator_t variable_mallocator; - - void (*solve_fun)(lmm_system_t self); -}; - -#define extract_variable(sys) xbt_swag_extract(&((sys)->variable_set)) -#define extract_constraint(sys) xbt_swag_extract(&((sys)->constraint_set)) -#define insert_constraint(sys, cnst) xbt_swag_insert((cnst), &((sys)->constraint_set)) -#define remove_variable(sys, var) \ - do { \ - xbt_swag_remove(var, &((sys)->variable_set)); \ - xbt_swag_remove(var, &((sys)->saturated_variable_set)); \ - } while (0) -#define remove_constraint(sys, cnst) \ - do { \ - xbt_swag_remove((cnst), &((sys)->constraint_set)); \ - xbt_swag_remove((cnst), &((sys)->saturated_constraint_set)); \ - } while (0) -#define make_constraint_active(sys, cnst) xbt_swag_insert((cnst), &((sys)->active_constraint_set)) -#define make_constraint_inactive(sys, cnst) \ - do { \ - xbt_swag_remove((cnst), &(sys)->active_constraint_set); \ - xbt_swag_remove((cnst), &(sys)->modified_constraint_set); \ - } while (0) - -/** @ingroup SURF_lmm - * @brief Print information about a lmm system - * - * @param sys A lmm system - */ -//XBT_PRIVATE void lmm_print(lmm_system_t sys); - -extern XBT_PRIVATE double (*func_f_def) (lmm_variable_t, double); -extern XBT_PRIVATE double (*func_fp_def) (lmm_variable_t, double); -extern XBT_PRIVATE double (*func_fpi_def) (lmm_variable_t, double); - -#endif /* SURF_MAXMIN_PRIVATE_H */ diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 943acb8f9e..915e5c21a9 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -5,11 +5,11 @@ #include -#include "maxmin_private.hpp" #include "network_cm02.hpp" #include "simgrid/s4u/Host.hpp" #include "simgrid/sg_config.h" #include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals +#include "surf/maxmin.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); @@ -87,13 +87,14 @@ void surf_network_model_init_Reno() if (surf_network_model) return; - lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi); + lmm_set_default_protocol_function(simgrid::surf::func_reno_f, simgrid::surf::func_reno_fp, + simgrid::surf::func_reno_fpi); xbt_cfg_setdefault_double("network/latency-factor", 13.01); xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97); xbt_cfg_setdefault_double("network/weight-S", 20537); - surf_network_model = new simgrid::surf::NetworkCm02Model(&lagrange_solve); + surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::surf::lagrange_solve); all_existing_models->push_back(surf_network_model); } @@ -103,13 +104,14 @@ void surf_network_model_init_Reno2() if (surf_network_model) return; - lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, func_reno2_fpi); + lmm_set_default_protocol_function(simgrid::surf::func_reno2_f, simgrid::surf::func_reno2_fp, + simgrid::surf::func_reno2_fpi); xbt_cfg_setdefault_double("network/latency-factor", 13.01); xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97); xbt_cfg_setdefault_double("network/weight-S", 20537); - surf_network_model = new simgrid::surf::NetworkCm02Model(&lagrange_solve); + surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::surf::lagrange_solve); all_existing_models->push_back(surf_network_model); } @@ -118,13 +120,14 @@ void surf_network_model_init_Vegas() if (surf_network_model) return; - lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi); + lmm_set_default_protocol_function(simgrid::surf::func_vegas_f, simgrid::surf::func_vegas_fp, + simgrid::surf::func_vegas_fpi); xbt_cfg_setdefault_double("network/latency-factor", 13.01); xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97); xbt_cfg_setdefault_double("network/weight-S", 20537); - surf_network_model = new simgrid::surf::NetworkCm02Model(&lagrange_solve); + surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::surf::lagrange_solve); all_existing_models->push_back(surf_network_model); } @@ -149,7 +152,7 @@ NetworkCm02Model::NetworkCm02Model() xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim.c_str()); } - maxminSystem_ = lmm_system_new(selectiveUpdate_); + maxminSystem_ = new s_lmm_system_t(selectiveUpdate_); loopback_ = NetworkCm02Model::createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE); if (getUpdateMechanism() == UM_LAZY) { @@ -176,13 +179,12 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) NetworkCm02Action* action = static_cast(actionHeapPop()); XBT_DEBUG("Something happened to action %p", action); if (TRACE_is_enabled()) { - int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable()); + int n = action->getVariable()->get_number_of_constraint(); for (int i = 0; i < n; i++){ - lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action->getVariable(), i); - NetworkCm02Link *link = static_cast(lmm_constraint_id(constraint)); - double value = lmm_variable_getvalue(action->getVariable())* - lmm_get_cnst_weight_from_var(maxminSystem_, action->getVariable(), i); + lmm_constraint_t constraint = action->getVariable()->get_constraint(i); + NetworkCm02Link* link = static_cast(constraint->get_id()); + double value = action->getVariable()->get_value() * action->getVariable()->get_constraint_weight(i); TRACE_surf_link_set_utilization(link->getCname(), action->getCategory(), value, action->getLastUpdate(), now - action->getLastUpdate()); } @@ -191,7 +193,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) // if I am wearing a latency hat if (action->getHat() == LATENCY) { XBT_DEBUG("Latency paid for action %p. Activating", action); - lmm_update_variable_weight(maxminSystem_, action->getVariable(), action->weight_); + maxminSystem_->update_variable_weight(action->getVariable(), action->weight_); action->heapRemove(getActionHeap()); action->refreshLastUpdate(); @@ -224,32 +226,31 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta) action.latency_ = 0.0; } if (action.latency_ <= 0.0 && not action.isSuspended()) - lmm_update_variable_weight(maxminSystem_, action.getVariable(), action.weight_); + maxminSystem_->update_variable_weight(action.getVariable(), action.weight_); } if (TRACE_is_enabled()) { - int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action.getVariable()); + int n = action.getVariable()->get_number_of_constraint(); for (int i = 0; i < n; i++) { - lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i); - - NetworkCm02Link* link = static_cast(lmm_constraint_id(constraint)); - TRACE_surf_link_set_utilization(link->getCname(), action.getCategory(), - (lmm_variable_getvalue(action.getVariable()) * - lmm_get_cnst_weight_from_var(maxminSystem_, action.getVariable(), i)), - action.getLastUpdate(), now - action.getLastUpdate()); + lmm_constraint_t constraint = action.getVariable()->get_constraint(i); + NetworkCm02Link* link = static_cast(constraint->get_id()); + TRACE_surf_link_set_utilization( + link->getCname(), action.getCategory(), + (action.getVariable()->get_value() * action.getVariable()->get_constraint_weight(i)), + action.getLastUpdate(), now - action.getLastUpdate()); } } - if (not lmm_get_number_of_cnst_from_var(maxminSystem_, action.getVariable())) { + if (not action.getVariable()->get_number_of_constraint()) { /* There is actually no link used, hence an infinite bandwidth. This happens often when using models like * vivaldi. In such case, just make sure that the action completes immediately. */ action.updateRemains(action.getRemains()); } - action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta); + action.updateRemains(action.getVariable()->get_value() * delta); if (action.getMaxDuration() > NO_MAX_DURATION) action.updateMaxDuration(delta); - if (((action.getRemains() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) || + if (((action.getRemains() <= 0) && (action.getVariable()->get_weight() > 0)) || ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) { action.finish(Action::State::done); } @@ -307,28 +308,32 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz constraints_per_variable += back_route.size(); if (action->latency_ > 0) { - action->setVariable(lmm_variable_new(maxminSystem_, action, 0.0, -1.0, constraints_per_variable)); + action->setVariable(maxminSystem_->variable_new(action, 0.0, -1.0, constraints_per_variable)); if (getUpdateMechanism() == UM_LAZY) { // add to the heap the event when the latency is payed XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency_ + action->getLastUpdate()); action->heapInsert(getActionHeap(), action->latency_ + action->getLastUpdate(), route.empty() ? NORMAL : LATENCY); } } else - action->setVariable(lmm_variable_new(maxminSystem_, action, 1.0, -1.0, constraints_per_variable)); + action->setVariable(maxminSystem_->variable_new(action, 1.0, -1.0, constraints_per_variable)); if (action->rate_ < 0) { - lmm_update_variable_bound(maxminSystem_, action->getVariable(), (action->latCurrent_ > 0) ? sg_tcp_gamma / (2.0 * action->latCurrent_) : -1.0); + maxminSystem_->update_variable_bound(action->getVariable(), + (action->latCurrent_ > 0) ? sg_tcp_gamma / (2.0 * action->latCurrent_) : -1.0); } else { - lmm_update_variable_bound(maxminSystem_, action->getVariable(), (action->latCurrent_ > 0) ? std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_)) : action->rate_); + maxminSystem_->update_variable_bound(action->getVariable(), + (action->latCurrent_ > 0) + ? std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_)) + : action->rate_); } for (auto const& link : route) - lmm_expand(maxminSystem_, link->constraint(), action->getVariable(), 1.0); + maxminSystem_->expand(link->constraint(), action->getVariable(), 1.0); if (not back_route.empty()) { // sg_network_crosstraffic was activated XBT_DEBUG("Fullduplex active adding backward flow using 5%%"); for (auto const& link : back_route) - lmm_expand(maxminSystem_, link->constraint(), action->getVariable(), .05); + maxminSystem_->expand(link->constraint(), action->getVariable(), .05); //Change concurrency_share here, if you want that cross-traffic is included in the SURF concurrency //(You would also have to change lmm_element_concurrency()) @@ -345,7 +350,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz ************/ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model* model, const std::string& name, double bandwidth, double latency, e_surf_link_sharing_policy_t policy, lmm_system_t system) - : LinkImpl(model, name, lmm_constraint_new(system, this, sg_bandwidth_factor * bandwidth)) + : LinkImpl(model, name, system->constraint_new(this, sg_bandwidth_factor * bandwidth)) { bandwidth_.scale = 1.0; bandwidth_.peak = bandwidth; @@ -354,7 +359,7 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model* model, const std::string& nam latency_.peak = latency; if (policy == SURF_LINK_FATPIPE) - lmm_constraint_shared(constraint()); + constraint()->unshare(); simgrid::s4u::Link::onCreation(this->piface_); } @@ -379,8 +384,8 @@ void NetworkCm02Link::apply_event(tmgr_trace_event_t triggered, double value) double now = surf_get_clock(); turnOff(); - while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) { - Action *action = static_cast( lmm_variable_id(var) ); + while ((var = constraint()->get_variable(&elem))) { + Action* action = static_cast(var->get_id()); if (action->getState() == Action::State::running || action->getState() == Action::State::ready) { @@ -399,11 +404,10 @@ void NetworkCm02Link::apply_event(tmgr_trace_event_t triggered, double value) void NetworkCm02Link::setBandwidth(double value) { - bandwidth_.peak = value; - lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(), - sg_bandwidth_factor * (bandwidth_.peak * bandwidth_.scale)); + model()->getMaxminSystem()->update_constraint_bound(constraint(), + sg_bandwidth_factor * (bandwidth_.peak * bandwidth_.scale)); TRACE_surf_link_set_bandwidth(surf_get_clock(), getCname(), sg_bandwidth_factor * bandwidth_.peak * bandwidth_.scale); if (sg_weight_S_parameter > 0) { @@ -413,11 +417,11 @@ void NetworkCm02Link::setBandwidth(double value) lmm_element_t elem = nullptr; lmm_element_t nextelem = nullptr; int numelem = 0; - while ((var = lmm_get_var_from_cnst_safe(model()->getMaxminSystem(), constraint(), &elem, &nextelem, &numelem))) { - NetworkCm02Action *action = static_cast(lmm_variable_id(var)); + while ((var = constraint()->get_variable_safe(&elem, &nextelem, &numelem))) { + NetworkCm02Action* action = static_cast(var->get_id()); action->weight_ += delta; if (not action->isSuspended()) - lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), action->weight_); + model()->getMaxminSystem()->update_variable_weight(action->getVariable(), action->weight_); } } } @@ -432,16 +436,16 @@ void NetworkCm02Link::setLatency(double value) latency_.peak = value; - while ((var = lmm_get_var_from_cnst_safe(model()->getMaxminSystem(), constraint(), &elem, &nextelem, &numelem))) { - NetworkCm02Action *action = static_cast(lmm_variable_id(var)); + while ((var = constraint()->get_variable_safe(&elem, &nextelem, &numelem))) { + NetworkCm02Action* action = static_cast(var->get_id()); action->latCurrent_ += delta; action->weight_ += delta; if (action->rate_ < 0) - lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(), - sg_tcp_gamma / (2.0 * action->latCurrent_)); + model()->getMaxminSystem()->update_variable_bound(action->getVariable(), + sg_tcp_gamma / (2.0 * action->latCurrent_)); else { - lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(), - std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_))); + model()->getMaxminSystem()->update_variable_bound( + action->getVariable(), std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_))); if (action->rate_ < sg_tcp_gamma / (2.0 * action->latCurrent_)) { XBT_INFO("Flow is limited BYBANDWIDTH"); @@ -450,7 +454,7 @@ void NetworkCm02Link::setLatency(double value) } } if (not action->isSuspended()) - lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), action->weight_); + model()->getMaxminSystem()->update_variable_weight(action->getVariable(), action->weight_); } } @@ -478,14 +482,14 @@ void NetworkCm02Action::updateRemainingLazy(double now) setMaxDuration(max_duration); } - if ((getRemainsNoUpdate() <= 0 && (lmm_get_variable_weight(getVariable()) > 0)) || + if ((getRemainsNoUpdate() <= 0 && (getVariable()->get_weight() > 0)) || ((max_duration > NO_MAX_DURATION) && (max_duration <= 0))) { finish(Action::State::done); heapRemove(getModel()->getActionHeap()); } refreshLastUpdate(); - setLastValue(lmm_variable_getvalue(getVariable())); + setLastValue(getVariable()->get_value()); } } diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 8a051ec09b..4752d1af39 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -8,9 +8,9 @@ #include "simgrid/sg_config.h" #include "src/surf/HostImpl.hpp" -#include "src/surf/maxmin_private.hpp" #include "src/surf/network_ib.hpp" #include "src/surf/xml/platf.hpp" +#include "surf/maxmin.hpp" #include #include @@ -174,7 +174,7 @@ void NetworkIBModel::computeIBfactors(IBNode* root) if (not double_equals(penalized_bw, rate_before_update, sg_surf_precision)) { XBT_DEBUG("%d->%d action %p penalty updated : bw now %f, before %f , initial rate %f", root->id, (*it)->destination->id, (*it)->action, penalized_bw, (*it)->action->getBound(), (*it)->init_rate); - lmm_update_variable_bound(maxminSystem_, (*it)->action->getVariable(), penalized_bw); + maxminSystem_->update_variable_bound((*it)->action->getVariable(), penalized_bw); } else { XBT_DEBUG("%d->%d action %p penalty not updated : bw %f, initial rate %f", root->id, (*it)->destination->id, (*it)->action, penalized_bw, (*it)->init_rate); diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index f88a72d106..c52c44342c 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -69,7 +69,7 @@ namespace simgrid { NetworkModel::~NetworkModel() { - lmm_system_free(maxminSystem_); + delete maxminSystem_; delete modifiedSet_; } @@ -138,7 +138,7 @@ namespace simgrid { bool LinkImpl::isUsed() { - return lmm_constraint_used(model()->getMaxminSystem(), constraint()); + return model()->getMaxminSystem()->constraint_used(constraint()); } double LinkImpl::latency() @@ -153,7 +153,7 @@ namespace simgrid { int LinkImpl::sharingPolicy() { - return lmm_constraint_sharing_policy(constraint()); + return constraint()->get_sharing_policy(); } void LinkImpl::turnOn() @@ -201,13 +201,12 @@ namespace simgrid { std::list NetworkAction::links() { std::list retlist; - lmm_system_t sys = getModel()->getMaxminSystem(); - int llen = lmm_get_number_of_cnst_from_var(sys, getVariable()); + int llen = getVariable()->get_number_of_constraint(); for (int i = 0; i < llen; i++) { /* Beware of composite actions: ptasks put links and cpus together */ // extra pb: we cannot dynamic_cast from void*... - Resource* resource = static_cast(lmm_constraint_id(lmm_get_cnst_from_var(sys, getVariable(), i))); + Resource* resource = static_cast(getVariable()->get_constraint(i)->get_id()); LinkImpl* link = dynamic_cast(resource); if (link != nullptr) retlist.push_back(link); diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index 476775c0d7..e678a32419 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -9,6 +9,7 @@ #include "simgrid/s4u/Link.hpp" #include "src/surf/PropertyHolder.hpp" #include "src/surf/surf_interface.hpp" +#include "surf/maxmin.hpp" #include "xbt/base.h" #include #include diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index a66839f20a..21853c6f84 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -174,7 +174,7 @@ void HostEnergy::update() // We consider that the machine is then fully loaded. That's arbitrary but it avoids a NaN cpu_load = 1; else - cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / current_speed; + cpu_load = host->pimpl_cpu->constraint()->get_usage() / current_speed; /** Divide by the number of cores here **/ cpu_load /= host->pimpl_cpu->coreCount(); @@ -250,6 +250,14 @@ double HostEnergy::getCurrentWattsValue(double cpu_load) { xbt_assert(not power_range_watts_list.empty(), "No power range properties specified for host %s", host->getCname()); + /* + * * Return watts_off if pstate == pstate_off + * * this happens when host is off + */ + if (this->pstate == pstate_off) { + return watts_off; + } + /* min_power corresponds to the power consumed when only one core is active */ /* max_power is the power consumed at 100% cpu load */ auto range = power_range_watts_list.at(this->pstate); @@ -510,7 +518,7 @@ double sg_host_get_current_consumption(sg_host_t host) { xbt_assert(HostEnergy::EXTENSION_ID.valid(), "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization."); - double cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / host->getSpeed(); + double cpu_load = host->pimpl_cpu->constraint()->get_usage() / host->getSpeed(); return host->extension()->getCurrentWattsValue(cpu_load); } } diff --git a/src/surf/plugins/host_load.cpp b/src/surf/plugins/host_load.cpp index 3d5a901e56..71e8bf0e09 100644 --- a/src/surf/plugins/host_load.cpp +++ b/src/surf/plugins/host_load.cpp @@ -54,7 +54,7 @@ HostLoad::HostLoad(simgrid::s4u::Host* ptr) : host(ptr) , last_updated(surf_get_clock()) , last_reset(surf_get_clock()) - , current_flops(lmm_constraint_get_usage(host->pimpl_cpu->constraint())) + , current_flops(host->pimpl_cpu->constraint()->get_usage()) { } @@ -66,7 +66,7 @@ void HostLoad::update() if (last_updated < now) { /* Current flop per second computed by the cpu; current_flops = k * pstate_speed_in_flops, k \in {0, 1, ..., cores} * number of active cores */ - current_flops = lmm_constraint_get_usage(host->pimpl_cpu->constraint()); + current_flops = host->pimpl_cpu->constraint()->get_usage(); /* flops == pstate_speed * cores_being_currently_used */ computed_flops += (now - last_updated) * current_flops; diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 7a3c22b6db..9da1734eda 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -34,7 +34,7 @@ namespace simgrid { namespace surf { HostL07Model::HostL07Model() : HostModel() { - maxminSystem_ = lmm_system_new(true /* lazy */); + maxminSystem_ = new s_lmm_system_t(true /* lazy */); maxminSystem_->solve_fun = &bottleneck_solve; surf_network_model = new NetworkL07Model(this,maxminSystem_); surf_cpu_model_pm = new CpuL07Model(this,maxminSystem_); @@ -42,7 +42,7 @@ HostL07Model::HostL07Model() : HostModel() { HostL07Model::~HostL07Model() { - lmm_system_free(maxminSystem_); + delete maxminSystem_; maxminSystem_ = nullptr; delete surf_network_model; delete surf_cpu_model_pm; @@ -101,12 +101,12 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) } if ((action.latency_ <= 0.0) && (action.isSuspended() == 0)) { action.updateBound(); - lmm_update_variable_weight(maxminSystem_, action.getVariable(), 1.0); + maxminSystem_->update_variable_weight(action.getVariable(), 1.0); } } XBT_DEBUG("Action (%p) : remains (%g) updated by %g.", &action, action.getRemains(), - lmm_variable_getvalue(action.getVariable()) * delta); - action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta); + action.getVariable()->get_value() * delta); + action.updateRemains(action.getVariable()->get_value() * delta); if (action.getMaxDuration() > NO_MAX_DURATION) action.updateMaxDuration(delta); @@ -119,22 +119,22 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) * If it's not done, it may have failed. */ - if (((action.getRemains() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) || + if (((action.getRemains() <= 0) && (action.getVariable()->get_weight() > 0)) || ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) { action.finish(Action::State::done); } else { /* Need to check that none of the model has failed */ int i = 0; - lmm_constraint_t cnst = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i); + lmm_constraint_t cnst = action.getVariable()->get_constraint(i); while (cnst != nullptr) { i++; - void *constraint_id = lmm_constraint_id(cnst); + void* constraint_id = cnst->get_id(); if (static_cast(constraint_id)->isOff()) { XBT_DEBUG("Action (%p) Failed!!", &action); action.finish(Action::State::failed); break; } - cnst = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i); + cnst = action.getVariable()->get_constraint(i); } } } @@ -189,13 +189,13 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list, XBT_DEBUG("Creating a parallel task (%p) with %d hosts and %d unique links.", this, host_nb, nb_link); latency_ = latency; - setVariable(lmm_variable_new(model->getMaxminSystem(), this, 1.0, (rate > 0 ? rate : -1.0), host_nb + nb_link)); + setVariable(model->getMaxminSystem()->variable_new(this, 1.0, (rate > 0 ? rate : -1.0), host_nb + nb_link)); if (latency_ > 0) - lmm_update_variable_weight(model->getMaxminSystem(), getVariable(), 0.0); + model->getMaxminSystem()->update_variable_weight(getVariable(), 0.0); for (int i = 0; i < host_nb; i++) - lmm_expand(model->getMaxminSystem(), host_list[i]->pimpl_cpu->constraint(), getVariable(), flops_amount[i]); + model->getMaxminSystem()->expand(host_list[i]->pimpl_cpu->constraint(), getVariable(), flops_amount[i]); if(bytes_amount != nullptr) { for (int i = 0; i < host_nb; i++) { @@ -205,8 +205,8 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list, hostList_->at(i)->routeTo(hostList_->at(j), route, nullptr); for (auto const& link : route) - lmm_expand_add(model->getMaxminSystem(), link->constraint(), this->getVariable(), - bytes_amount[i * host_nb + j]); + model->getMaxminSystem()->expand_add(link->constraint(), this->getVariable(), + bytes_amount[i * host_nb + j]); } } } @@ -248,8 +248,7 @@ LinkImpl* NetworkL07Model::createLink(const std::string& name, double bandwidth, ************/ CpuL07::CpuL07(CpuL07Model* model, simgrid::s4u::Host* host, std::vector* speedPerPstate, int core) - : Cpu(model, host, lmm_constraint_new(model->getMaxminSystem(), this, speedPerPstate->front()), speedPerPstate, - core) + : Cpu(model, host, model->getMaxminSystem()->constraint_new(this, speedPerPstate->front()), speedPerPstate, core) { } @@ -257,13 +256,13 @@ CpuL07::~CpuL07()=default; LinkL07::LinkL07(NetworkL07Model* model, const std::string& name, double bandwidth, double latency, e_surf_link_sharing_policy_t policy) - : LinkImpl(model, name, lmm_constraint_new(model->getMaxminSystem(), this, bandwidth)) + : LinkImpl(model, name, model->getMaxminSystem()->constraint_new(this, bandwidth)) { bandwidth_.peak = bandwidth; latency_.peak = latency; if (policy == SURF_LINK_FATPIPE) - lmm_constraint_shared(constraint()); + constraint()->unshare(); s4u::Link::onCreation(this->piface_); } @@ -284,13 +283,13 @@ Action *CpuL07::sleep(double duration) L07Action *action = static_cast(execution_start(1.0)); action->setMaxDuration(duration); action->suspended_ = 2; - lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), 0.0); + model()->getMaxminSystem()->update_variable_weight(action->getVariable(), 0.0); return action; } bool CpuL07::isUsed(){ - return lmm_constraint_used(model()->getMaxminSystem(), constraint()); + return model()->getMaxminSystem()->constraint_used(constraint()); } /** @brief take into account changes of speed (either load or max) */ @@ -298,11 +297,11 @@ void CpuL07::onSpeedChange() { lmm_variable_t var = nullptr; lmm_element_t elem = nullptr; - lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(), speed_.peak * speed_.scale); - while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) { - Action* action = static_cast(lmm_variable_id(var)); + model()->getMaxminSystem()->update_constraint_bound(constraint(), speed_.peak * speed_.scale); + while ((var = constraint()->get_variable(&elem))) { + Action* action = static_cast(var->get_id()); - lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(), speed_.scale * speed_.peak); + model()->getMaxminSystem()->update_variable_bound(action->getVariable(), speed_.scale * speed_.peak); } Cpu::onSpeedChange(); @@ -310,7 +309,7 @@ void CpuL07::onSpeedChange() { bool LinkL07::isUsed(){ - return lmm_constraint_used(model()->getMaxminSystem(), constraint()); + return model()->getMaxminSystem()->constraint_used(constraint()); } void CpuL07::apply_event(tmgr_trace_event_t triggered, double value) @@ -359,7 +358,7 @@ void LinkL07::apply_event(tmgr_trace_event_t triggered, double value) void LinkL07::setBandwidth(double value) { bandwidth_.peak = value; - lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(), bandwidth_.peak * bandwidth_.scale); + model()->getMaxminSystem()->update_constraint_bound(constraint(), bandwidth_.peak * bandwidth_.scale); } void LinkL07::setLatency(double value) @@ -369,8 +368,8 @@ void LinkL07::setLatency(double value) lmm_element_t elem = nullptr; latency_.peak = value; - while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) { - action = static_cast(lmm_variable_id(var)); + while ((var = constraint()->get_variable(&elem))) { + action = static_cast(var->get_id()); action->updateBound(); } } @@ -410,9 +409,9 @@ void L07Action::updateBound() XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound); if ((latency_ <= 0.0) && (suspended_ == 0)) { if (rate_ < 0) - lmm_update_variable_bound(getModel()->getMaxminSystem(), getVariable(), lat_bound); + getModel()->getMaxminSystem()->update_variable_bound(getVariable(), lat_bound); else - lmm_update_variable_bound(getModel()->getMaxminSystem(), getVariable(), std::min(rate_, lat_bound)); + getModel()->getMaxminSystem()->update_variable_bound(getVariable(), std::min(rate_, lat_bound)); } } @@ -423,7 +422,7 @@ int L07Action::unref() if (action_hook.is_linked()) stateSet_->erase(stateSet_->iterator_to(*this)); if (getVariable()) - lmm_variable_free(getModel()->getMaxminSystem(), getVariable()); + getModel()->getMaxminSystem()->variable_free(getVariable()); delete this; return 1; } diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 54f284761a..f016c1e5aa 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -6,6 +6,7 @@ #include "storage_n11.hpp" #include "simgrid/s4u/Engine.hpp" #include "src/kernel/routing/NetPoint.hpp" +#include "surf/maxmin.hpp" #include /*ceil*/ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage); @@ -78,20 +79,13 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) { StorageAction& action = static_cast(*it); ++it; // increment iterator here since the following calls to action.finish() may invalidate it - double current_progress = lrint(lmm_variable_getvalue(action.getVariable()) * delta); - action.updateRemains(current_progress); - if (action.type_ == WRITE) { - action.storage_->usedSize_ += current_progress; - } + action.updateRemains(lrint(action.getVariable()->get_value() * delta)); if (action.getMaxDuration() > NO_MAX_DURATION) action.updateMaxDuration(delta); - if (action.getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action.getVariable()) > 0 && - action.storage_->usedSize_ == action.storage_->getSize()) { - action.finish(Action::State::failed); - } else if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) || - ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) { + if (((action.getRemainsNoUpdate() <= 0) && (action.getVariable()->get_weight() > 0)) || + ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) { action.finish(Action::State::done); } } @@ -125,18 +119,18 @@ StorageAction* StorageN11::write(sg_size_t size) StorageN11Action::StorageN11Action(Model* model, double cost, bool failed, StorageImpl* storage, e_surf_action_storage_type_t type) - : StorageAction(model, cost, failed, lmm_variable_new(model->getMaxminSystem(), this, 1.0, -1.0, 3), storage, type) + : StorageAction(model, cost, failed, model->getMaxminSystem()->variable_new(this, 1.0, -1.0, 3), storage, type) { XBT_IN("(%s,%g", storage->getCname(), cost); // Must be less than the max bandwidth for all actions - lmm_expand(model->getMaxminSystem(), storage->constraint(), getVariable(), 1.0); + model->getMaxminSystem()->expand(storage->constraint(), getVariable(), 1.0); switch(type) { case READ: - lmm_expand(model->getMaxminSystem(), storage->constraintRead_, getVariable(), 1.0); + model->getMaxminSystem()->expand(storage->constraintRead_, getVariable(), 1.0); break; case WRITE: - lmm_expand(model->getMaxminSystem(), storage->constraintWrite_, getVariable(), 1.0); + model->getMaxminSystem()->expand(storage->constraintWrite_, getVariable(), 1.0); break; default: THROW_UNIMPLEMENTED; @@ -151,7 +145,7 @@ int StorageN11Action::unref() if (action_hook.is_linked()) stateSet_->erase(stateSet_->iterator_to(*this)); if (getVariable()) - lmm_variable_free(getModel()->getMaxminSystem(), getVariable()); + getModel()->getMaxminSystem()->variable_free(getVariable()); xbt_free(getCategory()); delete this; return 1; @@ -168,7 +162,7 @@ void StorageN11Action::suspend() { XBT_IN("(%p)", this); if (suspended_ != 2) { - lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0); + getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0); suspended_ = 1; } XBT_OUT(); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 67c6b6b97a..cb5ed0e386 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -416,7 +416,7 @@ double Model::nextOccuringEventLazy(double now) action->updateRemainingLazy(now); double min = -1; - double share = lmm_variable_getvalue(action->getVariable()); + double share = action->getVariable()->get_value(); if (share > 0) { double time_to_completion; @@ -465,7 +465,7 @@ double Model::nextOccuringEventFull(double /*now*/) { double min = -1; for (Action& action : *getRunningActionSet()) { - double value = lmm_variable_getvalue(action.getVariable()); + double value = action.getVariable()->get_value(); if (value > 0) { if (action.getRemains() > 0) value = action.getRemainsNoUpdate() / value; @@ -646,14 +646,14 @@ void Action::setState(Action::State state) double Action::getBound() const { - return (variable_) ? lmm_variable_getbound(variable_) : 0; + return variable_ ? variable_->get_bound() : 0; } void Action::setBound(double bound) { XBT_IN("(%p,%g)", this, bound); if (variable_) - lmm_update_variable_bound(getModel()->getMaxminSystem(), variable_, bound); + getModel()->getMaxminSystem()->update_variable_bound(variable_, bound); if (getModel()->getUpdateMechanism() == UM_LAZY && getLastUpdate() != surf_get_clock()) heapRemove(getModel()->getActionHeap()); @@ -680,7 +680,7 @@ void Action::setSharingWeight(double weight) { XBT_IN("(%p,%g)", this, weight); sharingWeight_ = weight; - lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), weight); + getModel()->getMaxminSystem()->update_variable_weight(getVariable(), weight); if (getModel()->getUpdateMechanism() == UM_LAZY) heapRemove(getModel()->getActionHeap()); @@ -702,7 +702,7 @@ int Action::unref(){ if (action_hook.is_linked()) stateSet_->erase(stateSet_->iterator_to(*this)); if (getVariable()) - lmm_variable_free(getModel()->getMaxminSystem(), getVariable()); + getModel()->getMaxminSystem()->variable_free(getVariable()); if (getModel()->getUpdateMechanism() == UM_LAZY) { /* remove from heap */ heapRemove(getModel()->getActionHeap()); @@ -719,7 +719,7 @@ void Action::suspend() { XBT_IN("(%p)", this); if (suspended_ != 2) { - lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0); + getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0); if (getModel()->getUpdateMechanism() == UM_LAZY){ heapRemove(getModel()->getActionHeap()); if (getModel()->getUpdateMechanism() == UM_LAZY && stateSet_ == getModel()->getRunningActionSet() && @@ -737,7 +737,7 @@ void Action::resume() { XBT_IN("(%p)", this); if (suspended_ != 2) { - lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), getPriority()); + getModel()->getMaxminSystem()->update_variable_weight(getVariable(), getPriority()); suspended_ = 0; if (getModel()->getUpdateMechanism() == UM_LAZY) heapRemove(getModel()->getActionHeap()); diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 38bdbe0f09..3809adee86 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,10 @@ *********/ /* user-visible parameters */ +XBT_PUBLIC_DATA(double) sg_maxmin_precision; +XBT_PUBLIC_DATA(double) sg_surf_precision; +XBT_PUBLIC_DATA(int) sg_concurrency_limit; + extern XBT_PRIVATE double sg_tcp_gamma; extern XBT_PRIVATE double sg_latency_factor; extern XBT_PRIVATE double sg_bandwidth_factor; @@ -36,6 +41,28 @@ extern XBT_PRIVATE std::vector surf_path; extern XBT_PRIVATE std::unordered_map traces_set_list; extern XBT_PRIVATE std::set watched_hosts; +static inline void double_update(double* variable, double value, double precision) +{ + // printf("Updating %g -= %g +- %g\n",*variable,value,precision); + // xbt_assert(value==0 || value>precision); + // Check that precision is higher than the machine-dependent size of the mantissa. If not, brutal rounding may + // happen, and the precision mechanism is not active... + // xbt_assert(*variable< (2< precision); +} + +static inline int double_equals(double value1, double value2, double precision) +{ + return (fabs(value1 - value2) < precision); +} + extern "C" { XBT_PUBLIC(double) surf_get_clock(); } diff --git a/src/surf/surf_private.hpp b/src/surf/surf_private.hpp index 55a7e4f17e..41c5540b42 100644 --- a/src/surf/surf_private.hpp +++ b/src/surf/surf_private.hpp @@ -7,7 +7,6 @@ #define SURF_SURF_PRIVATE_HPP #include "src/surf/trace_mgr.hpp" -#include "surf/maxmin.hpp" #include "surf/surf.hpp" #define NO_MAX_DURATION -1.0 diff --git a/src/xbt/swag.c b/src/xbt/swag.c index 9d3af40cc0..6bf90c0fab 100644 --- a/src/xbt/swag.c +++ b/src/xbt/swag.c @@ -172,7 +172,7 @@ void *xbt_swag_extract(xbt_swag_t swag) * \param swag a swag * \return the number of objects in \a swag */ -inline int xbt_swag_size(xbt_swag_t swag) +inline int xbt_swag_size(const_xbt_swag_t swag) { return (swag->count); } diff --git a/teshsuite/msg/actions-storage/actions-storage.c b/teshsuite/msg/actions-storage/actions-storage.c index d0fc4239b5..e4cfac8c6e 100644 --- a/teshsuite/msg/actions-storage/actions-storage.c +++ b/teshsuite/msg/actions-storage/actions-storage.c @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/msg.h" +#include "simgrid/plugins/file_system.h" #include XBT_LOG_NEW_DEFAULT_CATEGORY(storage_actions, "Messages specific for this example"); @@ -98,6 +99,7 @@ static void action_close(const char* const* action) int main(int argc, char* argv[]) { MSG_init(&argc, argv); + MSG_storage_file_system_init(); /* Explicit initialization of the action module is required */ MSG_action_init(); diff --git a/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp b/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp index 217a166490..0c1db3c605 100644 --- a/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp +++ b/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp @@ -4,38 +4,27 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/s4u.hpp" -#include - -#define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml" XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test"); static void host() { - char name[2048]; + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk1"); int id = simgrid::s4u::this_actor::getPid(); - snprintf(name, 2048, "%s%i", FILENAME1, id); - simgrid::s4u::File* file = new simgrid::s4u::File(name, NULL); XBT_INFO("process %d is writing!", id); - file->write(3000000); + storage->write(3000000); XBT_INFO("process %d goes to sleep for %d seconds", id, id); simgrid::s4u::this_actor::sleep_for(id); XBT_INFO("process %d is writing again!", id); - file->write(3000000); + storage->write(3000000); XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id); simgrid::s4u::this_actor::sleep_for(6 - id); XBT_INFO("process %d is reading!", id); - file->seek(0); - file->read(3000000); + storage->read(3000000); XBT_INFO("process %d goes to sleep for %d seconds", id, id); simgrid::s4u::this_actor::sleep_for(id); XBT_INFO("process %d is reading again!", id); - file->seek(0); - file->read(3000000); - - XBT_INFO("process %d => Size of %s: %llu", id, name, file->size()); - // Close the file - delete file; + storage->read(3000000); } int main(int argc, char** argv) diff --git a/teshsuite/s4u/concurrent_rw/concurrent_rw.tesh b/teshsuite/s4u/concurrent_rw/concurrent_rw.tesh index 6e2576aa2f..1d46abeb7b 100644 --- a/teshsuite/s4u/concurrent_rw/concurrent_rw.tesh +++ b/teshsuite/s4u/concurrent_rw/concurrent_rw.tesh @@ -30,13 +30,8 @@ $ ./concurrent_rw$EXEEXT ${srcdir:=.}/../../../examples/platforms/storage/storag > [ 6.750000] (host@bob) process 4 goes to sleep for 4 seconds > [ 6.750000] (host@bob) process 5 goes to sleep for 5 seconds > [ 7.750000] (host@bob) process 1 is reading again! -> [ 7.780000] (host@bob) process 1 => Size of /home/doc/simgrid/examples/platforms/g5k.xml1: 6000000 > [ 8.750000] (host@bob) process 2 is reading again! -> [ 8.780000] (host@bob) process 2 => Size of /home/doc/simgrid/examples/platforms/g5k.xml2: 6000000 > [ 9.750000] (host@bob) process 3 is reading again! -> [ 9.780000] (host@bob) process 3 => Size of /home/doc/simgrid/examples/platforms/g5k.xml3: 6000000 > [ 10.750000] (host@bob) process 4 is reading again! -> [ 10.780000] (host@bob) process 4 => Size of /home/doc/simgrid/examples/platforms/g5k.xml4: 6000000 > [ 11.750000] (host@bob) process 5 is reading again! -> [ 11.780000] (host@bob) process 5 => Size of /home/doc/simgrid/examples/platforms/g5k.xml5: 6000000 > [ 11.780000] (maestro@) Simulation time 11.78 diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index 9ef8840fa8..78598bcd5f 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -157,6 +157,7 @@ static void server() int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); + sg_storage_file_system_init(); xbt_assert(argc == 2, "Usage: %s platform_file\n", argv[0]); e.loadPlatform(argv[1]); diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.tesh b/teshsuite/s4u/storage_client_server/storage_client_server.tesh index 08781a10da..0a7dffcdee 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.tesh +++ b/teshsuite/s4u/storage_client_server/storage_client_server.tesh @@ -54,11 +54,11 @@ $ ./storage_client_server$EXEEXT ${srcdir:=.}/../../../examples/platforms/storag > [ 0.806104] (server@alice) 6217 bytes on 6217 bytes have been written by server on /sd1 > [ 1.207952] (server@alice) *** Storage info on alice *** > [ 1.207952] (server@alice) Storage name: Disk2, mount name: c: +> [ 1.207952] (server@alice) Free size: 534479367024 bytes +> [ 1.207952] (server@alice) Used size: 2391544976 bytes > [ 1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 *** > [ 1.207952] (client@bob) Get data: '(null)' > [ 1.207952] (client@bob) Set and get data: 'Some data' -> [ 1.207952] (server@alice) Free size: 534479367024 bytes -> [ 1.207952] (server@alice) Used size: 2391544976 bytes > [ 1.207952] (server@alice) No property attached. > [ 1.207952] (server@alice) *** Dump a storage element *** > [ 1.207952] (server@alice) Print the content of the storage element: Disk2 diff --git a/teshsuite/surf/lmm_usage/lmm_usage.cpp b/teshsuite/surf/lmm_usage/lmm_usage.cpp index 71c2fd4c58..0a9aaf8382 100644 --- a/teshsuite/surf/lmm_usage/lmm_usage.cpp +++ b/teshsuite/surf/lmm_usage/lmm_usage.cpp @@ -17,7 +17,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); -#define PRINT_VAR(var) XBT_DEBUG(#var " = %g",lmm_variable_getvalue(var)) +using namespace simgrid::surf; + +#define PRINT_VAR(var) XBT_DEBUG(#var " = %g", (var)->get_value()) #define SHOW_EXPR(expr) XBT_DEBUG(#expr " = %g",expr) /* ______ */ @@ -94,28 +96,28 @@ static void test1(method_t method) else if (method == LAGRANGE_RENO) lmm_set_default_protocol_function(func_reno_f, func_reno_fpi, func_reno_fpi); - lmm_system_t Sys = lmm_system_new(1); - lmm_constraint_t L1 = lmm_constraint_new(Sys, nullptr, a); - lmm_constraint_t L2 = lmm_constraint_new(Sys, nullptr, b); - lmm_constraint_t L3 = lmm_constraint_new(Sys, nullptr, a); + lmm_system_t Sys = new s_lmm_system_t(true); + lmm_constraint_t L1 = Sys->constraint_new(nullptr, a); + lmm_constraint_t L2 = Sys->constraint_new(nullptr, b); + lmm_constraint_t L3 = Sys->constraint_new(nullptr, a); - lmm_variable_t R_1_2_3 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 3); - lmm_variable_t R_1 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1); - lmm_variable_t R_2 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1); - lmm_variable_t R_3 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1); + lmm_variable_t R_1_2_3 = Sys->variable_new(nullptr, 1.0, -1.0, 3); + lmm_variable_t R_1 = Sys->variable_new(nullptr, 1.0, -1.0, 1); + lmm_variable_t R_2 = Sys->variable_new(nullptr, 1.0, -1.0, 1); + lmm_variable_t R_3 = Sys->variable_new(nullptr, 1.0, -1.0, 1); - lmm_update_variable_weight(Sys, R_1_2_3, 1.0); - lmm_update_variable_weight(Sys, R_1, 1.0); - lmm_update_variable_weight(Sys, R_2, 1.0); - lmm_update_variable_weight(Sys, R_3, 1.0); + Sys->update_variable_weight(R_1_2_3, 1.0); + Sys->update_variable_weight(R_1, 1.0); + Sys->update_variable_weight(R_2, 1.0); + Sys->update_variable_weight(R_3, 1.0); - lmm_expand(Sys, L1, R_1_2_3, 1.0); - lmm_expand(Sys, L2, R_1_2_3, 1.0); - lmm_expand(Sys, L3, R_1_2_3, 1.0); + Sys->expand(L1, R_1_2_3, 1.0); + Sys->expand(L2, R_1_2_3, 1.0); + Sys->expand(L3, R_1_2_3, 1.0); - lmm_expand(Sys, L1, R_1, 1.0); - lmm_expand(Sys, L2, R_2, 1.0); - lmm_expand(Sys, L3, R_3, 1.0); + Sys->expand(L1, R_1, 1.0); + Sys->expand(L2, R_2, 1.0); + Sys->expand(L3, R_3, 1.0); if (method == MAXMIN) { lmm_solve(Sys); @@ -146,20 +148,18 @@ static void test1(method_t method) lagrange_solve(Sys); double max_deviation = 0.0; - max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); - max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); - max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); - max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); + max_deviation = std::max(max_deviation, fabs(R_1->get_value() - x)); + max_deviation = std::max(max_deviation, fabs(R_3->get_value() - x)); + max_deviation = std::max(max_deviation, fabs(R_2->get_value() - (b - a + x))); + max_deviation = std::max(max_deviation, fabs(R_1_2_3->get_value() - (a - x))); if (max_deviation > 0.00001) { // Legacy value used in lagrange.c XBT_WARN("Max Deviation from optimal solution : %g", max_deviation); XBT_WARN("Found x = %1.20f", x); - XBT_WARN("Deviation from optimal solution (R_1 = %g): %1.20f", x, lmm_variable_getvalue(R_1) - x); - XBT_WARN("Deviation from optimal solution (R_2 = %g): %1.20f", b - a + x, - lmm_variable_getvalue(R_2) - (b - a + x)); - XBT_WARN("Deviation from optimal solution (R_3 = %g): %1.20f", x, lmm_variable_getvalue(R_3) - x); - XBT_WARN("Deviation from optimal solution (R_1_2_3 = %g): %1.20f", a - x, - lmm_variable_getvalue(R_1_2_3) - (a - x)); + XBT_WARN("Deviation from optimal solution (R_1 = %g): %1.20f", x, R_1->get_value() - x); + XBT_WARN("Deviation from optimal solution (R_2 = %g): %1.20f", b - a + x, R_2->get_value() - (b - a + x)); + XBT_WARN("Deviation from optimal solution (R_3 = %g): %1.20f", x, R_3->get_value() - x); + XBT_WARN("Deviation from optimal solution (R_1_2_3 = %g): %1.20f", a - x, R_1_2_3->get_value() - (a - x)); } } @@ -168,11 +168,11 @@ static void test1(method_t method) PRINT_VAR(R_2); PRINT_VAR(R_3); - lmm_variable_free(Sys, R_1_2_3); - lmm_variable_free(Sys, R_1); - lmm_variable_free(Sys, R_2); - lmm_variable_free(Sys, R_3); - lmm_system_free(Sys); + Sys->variable_free(R_1_2_3); + Sys->variable_free(R_1); + Sys->variable_free(R_2); + Sys->variable_free(R_3); + delete Sys; } static void test2(method_t method) @@ -182,18 +182,18 @@ static void test2(method_t method) if (method == LAGRANGE_RENO) lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi); - lmm_system_t Sys = lmm_system_new(1); - lmm_constraint_t CPU1 = lmm_constraint_new(Sys, nullptr, 200.0); - lmm_constraint_t CPU2 = lmm_constraint_new(Sys, nullptr, 100.0); + lmm_system_t Sys = new s_lmm_system_t(true); + lmm_constraint_t CPU1 = Sys->constraint_new(nullptr, 200.0); + lmm_constraint_t CPU2 = Sys->constraint_new(nullptr, 100.0); - lmm_variable_t T1 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1); - lmm_variable_t T2 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1); + lmm_variable_t T1 = Sys->variable_new(nullptr, 1.0, -1.0, 1); + lmm_variable_t T2 = Sys->variable_new(nullptr, 1.0, -1.0, 1); - lmm_update_variable_weight(Sys, T1, 1.0); - lmm_update_variable_weight(Sys, T2, 1.0); + Sys->update_variable_weight(T1, 1.0); + Sys->update_variable_weight(T2, 1.0); - lmm_expand(Sys, CPU1, T1, 1.0); - lmm_expand(Sys, CPU2, T2, 1.0); + Sys->expand(CPU1, T1, 1.0); + Sys->expand(CPU2, T2, 1.0); if (method == MAXMIN) { lmm_solve(Sys); @@ -206,9 +206,9 @@ static void test2(method_t method) PRINT_VAR(T1); PRINT_VAR(T2); - lmm_variable_free(Sys, T1); - lmm_variable_free(Sys, T2); - lmm_system_free(Sys); + Sys->variable_free(T1); + Sys->variable_free(T2); + delete Sys; } static void test3(method_t method) @@ -253,25 +253,25 @@ static void test3(method_t method) if (method == LAGRANGE_RENO) lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi); - lmm_system_t Sys = lmm_system_new(1); + lmm_system_t Sys = new s_lmm_system_t(true); /* Creates the constraints */ lmm_constraint_t* tmp_cnst = new lmm_constraint_t[15]; for (int i = 0; i < 15; i++) - tmp_cnst[i] = lmm_constraint_new(Sys, nullptr, B[i]); + tmp_cnst[i] = Sys->constraint_new(nullptr, B[i]); /* Creates the variables */ lmm_variable_t* tmp_var = new lmm_variable_t[16]; for (int j = 0; j < 16; j++) { - tmp_var[j] = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 15); - lmm_update_variable_weight(Sys, tmp_var[j], 1.0); + tmp_var[j] = Sys->variable_new(nullptr, 1.0, -1.0, 15); + Sys->update_variable_weight(tmp_var[j], 1.0); } /* Link constraints and variables */ for (int i = 0; i < 15; i++) for (int j = 0; j < 16; j++) if (A[i][j]) - lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0); + Sys->expand(tmp_cnst[i], tmp_var[j], 1.0); if (method == MAXMIN) { lmm_solve(Sys); @@ -287,10 +287,10 @@ static void test3(method_t method) PRINT_VAR(tmp_var[j]); for (int j = 0; j < 16; j++) - lmm_variable_free(Sys, tmp_var[j]); + Sys->variable_free(tmp_var[j]); delete[] tmp_var; delete[] tmp_cnst; - lmm_system_free(Sys); + delete Sys; for (int i = 0; i < links + 5; i++) delete[] A[i]; delete[] A; diff --git a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp index d3408b10fe..be01e1dd8b 100644 --- a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp +++ b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp @@ -18,6 +18,8 @@ #include #include +using namespace simgrid::surf; + double date; int64_t seedx = 0; @@ -43,10 +45,10 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi lmm_variable_t var[nb_var]; int used[nb_cnst]; - lmm_system_t Sys = lmm_system_new(1); + lmm_system_t Sys = new s_lmm_system_t(true); for (int i = 0; i < nb_cnst; i++) { - cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0)); + cnst[i] = Sys->constraint_new(NULL, float_random(10.0)); int l; if(rate_no_limit>float_random(1.0)) //Look at what happens when there is no concurrency limit @@ -55,14 +57,14 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi //Badly logarithmically random concurrency limit in [2^pw_base_limit+1,2^pw_base_limit+2^pw_max_limit] l=(1<set_concurrency_limit(l); } for (int i = 0; i < nb_var; i++) { - var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem); + var[i] = Sys->variable_new(NULL, 1.0, -1.0, nb_elem); //Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases) int concurrency_share = 1 + int_random(max_share); - lmm_variable_concurrency_share_set(var[i],concurrency_share); + var[i]->set_concurrency_share(concurrency_share); for (int j = 0; j < nb_cnst; j++) used[j] = 0; @@ -72,8 +74,8 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi j--; continue; } - lmm_expand(Sys, cnst[k], var[i], float_random(1.5)); - lmm_expand_add(Sys, cnst[k], var[i], float_random(1.5)); + Sys->expand(cnst[k], var[i], float_random(1.5)); + Sys->expand_add(cnst[k], var[i], float_random(1.5)); used[k]++; } } @@ -87,25 +89,25 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi fprintf(stderr,"Max concurrency:\n"); int l=0; for (int i = 0; i < nb_cnst; i++) { - int j=lmm_constraint_concurrency_maximum_get(cnst[i]); - int k=lmm_constraint_concurrency_limit_get(cnst[i]); + int j = cnst[i]->get_concurrency_maximum(); + int k = cnst[i]->get_concurrency_limit(); xbt_assert(k<0 || j<=k); if(j>l) l=j; fprintf(stderr,"(%i):%i/%i ",i,j,k); - lmm_constraint_concurrency_maximum_reset(cnst[i]); - xbt_assert(not lmm_constraint_concurrency_maximum_get(cnst[i])); + cnst[i]->reset_concurrency_maximum(); + xbt_assert(not cnst[i]->get_concurrency_maximum()); if(i%10==9) fprintf(stderr,"\n"); } fprintf(stderr,"\nTotal maximum concurrency is %i\n",l); - lmm_print(Sys); + Sys->print(); } for (int i = 0; i < nb_var; i++) - lmm_variable_free(Sys, var[i]); - lmm_system_free(Sys); + Sys->variable_free(var[i]); + delete Sys; } unsigned int TestClasses [][4]= diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 510bb81c52..21327c91b6 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -6,7 +6,7 @@ set(EXTRA_DIST src/include/mc/datatypes.h src/include/mc/mc.h src/include/simgrid/sg_config.h - src/include/surf/datatypes.h + src/include/surf/datatypes.hpp src/include/surf/maxmin.hpp src/include/surf/surf.hpp src/include/xbt/parmap.hpp @@ -38,7 +38,6 @@ set(EXTRA_DIST src/surf/cpu_cas01.hpp src/surf/cpu_interface.hpp src/surf/cpu_ti.hpp - src/surf/maxmin_private.hpp src/surf/network_cm02.hpp src/surf/network_constant.hpp src/surf/network_interface.hpp @@ -664,6 +663,7 @@ set(MC_SIMGRID_MC_SRC src/mc/checker/simgrid_mc.cpp) set(headers_to_install include/simgrid/chrono.hpp include/simgrid/plugins/energy.h + include/simgrid/plugins/file_system.h include/simgrid/plugins/load.h include/simgrid/instr.h include/simgrid/msg.h diff --git a/tools/internal/travis-sonarqube.sh b/tools/internal/travis-sonarqube.sh index 65e549f996..922defa2a8 100755 --- a/tools/internal/travis-sonarqube.sh +++ b/tools/internal/travis-sonarqube.sh @@ -21,7 +21,7 @@ installSonarQubeScanner() { export SONAR_SCANNER_OPTS="-server" } installBuildWrapper() { - curl -LsS https://sonarqube.com/static/cpp/build-wrapper-linux-x86.zip > build-wrapper-linux-x86.zip + curl -LsS https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip > build-wrapper-linux-x86.zip unzip build-wrapper-linux-x86.zip } installSonarQubeScanner @@ -49,7 +49,7 @@ ctest -D ExperimentalCoverage # See https://docs.travis-ci.com/user/sonarqube/ for more info on tokens # don't show the token in the logs set +x -sonar-scanner -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN 2>&1 \ +sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN 2>&1 \ | grep -v 'INFO: Parsing /home/travis/build/simgrid/simgrid/Testing/CoverageInfo' \ | grep -v 'WARN: File not analysed by Sonar, so ignoring coverage: /usr/include/' diff --git a/tools/tesh/tesh.py b/tools/tesh/tesh.py index 68a661eb64..25aad527a7 100755 --- a/tools/tesh/tesh.py +++ b/tools/tesh/tesh.py @@ -431,7 +431,7 @@ if __name__ == '__main__': re.compile("For details see http://code.google.com/p/address-sanitizer/issues/detail\\?id=189"), re.compile("For details see https://github.com/google/sanitizers/issues/189"), re.compile("Python runtime initialized with LC_CTYPE=C .*"), - re.compile("^cmake: .*? no version information available (required by cmake)"), # Seen on CircleCI + re.compile("cmake: /usr/local/lib/libcurl.so.4: no version information available (required by cmake)"), # Seen on CircleCI ] TeshState().jenkins = True # This is a Jenkins build