The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

66 lines
2.2 KiB

4 weeks ago
  1. Thread local memory example
  2. ===========================
  3. The GLPK library, when compiled with default options, uses a separate environment
  4. for each thread that is executed. So each thread is isolated. The only exeption
  5. is error handling. An error in any of the library functions will not only
  6. terminate the active thread but the complete process.
  7. This can be circumvented by defining an error handling routine with
  8. glp_error_hook(). This directory contains an example demonstrating running a
  9. multithreaded application with error handling.
  10. The example code
  11. ----------------
  12. The program multiseed solves a MathProg model multiple times in separate parallel
  13. threads. Each threads uses a different seed for the MathProg pseudo random number
  14. generator.
  15. The MathProg model clustering.mod generates 50 randomly distributed "towns". Out
  16. of the towns it selects 3 to be cluster centers and assign the other towns to the
  17. clusters such that the sum of the population weighted euclidian distances between
  18. towns and centers is minimized.
  19. The solution is written to a Scalable Vector File which can be viewed with a web
  20. browser.
  21. For demonstration purposes at the end of every third thread the error handling
  22. routine is triggered by calling glp_error(). This results in output like
  23. 18-00086 Model has been successfully processed
  24. 18-00087 Voluntarily throwing an error in multiseed.c at line 147
  25. 18-00088 Error detected in file multiseed.c at line 146
  26. 18-00089 Error caught
  27. Terminal output is preceeded by numbers indicating the thread index and the
  28. output line. You can pipe it through sort to get a better overiew, e.g.
  29. multiseed clustering.mod 20 | sort
  30. Building and running the example code
  31. -------------------------------------
  32. On Linux multiseed can be compiled with gcc by calling
  33. make
  34. The code can be executed with
  35. make check
  36. For compiling the example on 64bit Windows with Microsoft Visual Studio C++ run
  37. Build_Multiseed.bat
  38. You may have to adust the variable HOME in the batch file depending on the
  39. installation path of Visual Studio.
  40. You can run multiseed with
  41. multiseed <filename> <count>
  42. Where filename is the path to the model file and count is the number of parallel
  43. threads.