Skip to content

Commit 26b4357

Browse files
committed
fix MSVC build
1 parent 2215db1 commit 26b4357

File tree

8 files changed

+38
-30
lines changed

8 files changed

+38
-30
lines changed

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
66
add_library(cadmium INTERFACE)
77
target_include_directories(cadmium INTERFACE include/ json/include)
88

9-
FILE(GLOB Examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} example/*/main_*.cpp)
10-
foreach(exampleSrc ${Examples})
9+
function(add_example exampleSrc)
1110
get_filename_component(exampleName ${exampleSrc} NAME_WE)
1211
get_filename_component(dirname ${exampleSrc} DIRECTORY)
1312
file(GLOB directorySrc CONFIGURE_DEPENDS "${dirname}/src/*.cpp")
1413
add_executable(${exampleName} ${exampleSrc} ${directorySrc})
1514
target_include_directories(${exampleName} PUBLIC "${dirname}/include")
1615
target_link_libraries(${exampleName} cadmium)
16+
target_compile_options(${exampleName} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/Za>) # Enable and/or aliases on MSVC
17+
endfunction()
18+
19+
FILE(GLOB Examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} example/*/main_*.cpp)
20+
foreach(exampleSrc ${Examples})
21+
add_example(${exampleSrc})
1722
endforeach(exampleSrc)
1823

1924
find_package(OpenMP)
2025
if(OpenMP_CXX_FOUND)
2126
FILE(GLOB Examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} example/*/parallel_main_*.cpp)
2227
foreach(exampleSrc ${Examples})
28+
add_example(${exampleSrc})
2329
get_filename_component(exampleName ${exampleSrc} NAME_WE)
24-
get_filename_component(dirname ${exampleSrc} DIRECTORY)
25-
file(GLOB directorySrc CONFIGURE_DEPENDS "${dirname}/src/*.cpp")
26-
add_executable(${exampleName} ${exampleSrc} ${directorySrc})
27-
target_include_directories(${exampleName} PUBLIC "${dirname}/include")
28-
target_link_libraries(${exampleName} PUBLIC cadmium OpenMP::OpenMP_CXX)
30+
target_link_libraries(${exampleName} OpenMP::OpenMP_CXX)
2931
endforeach(exampleSrc)
3032
else()
3133
message(STATUS "OpenMP not found. You won't be able to use parallel simulation.")

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ git submodule update --init --recursive
33
mkdir build
44
cd build || exit
55
cmake ..
6-
make all
6+
cmake --build .
77
cd ..
88
echo Compilation done. All the examples are in the bin folder

include/cadmium/celldevs/grid/config.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ namespace cadmium::celldevs {
8888
}
8989
else if (type == "chebyshev" || type == "chessboard") {
9090
auto range = (rawNeighbors.contains("range")) ? (int)rawNeighbors["range"].get<double>() : 1;
91-
distances = scenario->mooreNeighborhood(std::floor(range));
91+
distances = scenario->mooreNeighborhood(static_cast<int>(std::floor(range)));
9292
}
9393
else if (type == "von_neumann") {
9494
auto range = (rawNeighbors.contains("range")) ? rawNeighbors["range"].get<int>() : 1;
95-
distances = scenario->vonNeumannNeighborhood(range);
95+
distances = scenario->vonNeumannNeighborhood(static_cast<int>(range));
9696
}
9797
else if (type == "manhattan" || type == "taxicab" || type == "snake") {
9898
auto range = (rawNeighbors.contains("range")) ? (int)rawNeighbors["range"].get<double>() : 1;
99-
distances = scenario->vonNeumannNeighborhood(range);
99+
distances = scenario->vonNeumannNeighborhood(static_cast<int>(range));
100100
}
101101
else if (type == "minkowski" || type == "euclidean") {
102102
auto p = (type == "euclidean") ? 2 : rawNeighbors.at("p").get<int>();

include/cadmium/celldevs/grid/coupled.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace cadmium::celldevs {
9898
for (const auto& cellId: *scenario) {
9999
try {
100100
auto _cell = Coupled::getComponent(CellDEVSCoupled<coordinates , S, V>::cellId(cellId));
101-
} catch (const CadmiumModelException& ex) {
101+
} catch ([[maybe_unused]] const CadmiumModelException& _) {
102102
this->addComponent(factory(cellId, config));
103103
}
104104
}

include/cadmium/core/modeling/component.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace cadmium {
111111
[[nodiscard]] std::shared_ptr<PortInterface> getInPort(const std::string& id) const {
112112
try {
113113
return inPorts.at(id);
114-
} catch (std::out_of_range& _) {
114+
} catch ([[maybe_unused]] std::out_of_range& _) {
115115
throw CadmiumModelException("port not found");
116116
}
117117
}
@@ -141,7 +141,7 @@ namespace cadmium {
141141
[[nodiscard]] std::shared_ptr<PortInterface> getOutPort(const std::string& id) const {
142142
try {
143143
return outPorts.at(id);
144-
} catch (std::out_of_range& _) {
144+
} catch ([[maybe_unused]] std::out_of_range& _) {
145145
throw CadmiumModelException("port not found");
146146
}
147147
}

include/cadmium/core/modeling/coupled.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace cadmium {
118118
[[nodiscard]] std::shared_ptr<Component> getComponent(const std::string& id) const {
119119
try {
120120
return components.at(id);
121-
} catch (std::out_of_range& _) {
121+
} catch ([[maybe_unused]] std::out_of_range& _) {
122122
throw CadmiumModelException("component not found");
123123
}
124124
}

include/cadmium/core/simulation/parallel_root_coordinator.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace cadmium {
6161
rootCoordinator->stop();
6262
}
6363

64-
void simulate(long nIterations, size_t thread_number = std::thread::hardware_concurrency()) {
64+
void simulate(long nIterations, unsigned int thread_number = std::thread::hardware_concurrency()) {
6565
// First, we make sure that Mutexes are activated
6666
if (rootCoordinator->getLogger()) {
6767
rootCoordinator->getLogger()->createMutex();
@@ -82,15 +82,15 @@ namespace cadmium {
8282
while (nIterations-- > 0 && timeNext < std::numeric_limits<double>::infinity()) {
8383
// Step 1: execute output functions
8484
#pragma omp for schedule(static)
85-
for (size_t i = 0; i < nSubcomponents; i++) {
85+
for (long i = 0; i < nSubcomponents; i++) {
8686
subcomponents.at(i)->collection(timeNext);
8787
}
8888
#pragma omp barrier
8989
//end Step 1
9090

9191
// Step 2: route messages
9292
#pragma omp for schedule(static)
93-
for (size_t i = 0; i < nICs; i++) { // We only parallelize by destination port, right?
93+
for (long i = 0; i < nICs; i++) { // We only parallelize by destination port, right?
9494
for (auto& portFrom: stackedIC[i].second) {
9595
stackedIC.at(i).first->propagate(portFrom);
9696
}
@@ -100,7 +100,7 @@ namespace cadmium {
100100

101101
// Step 3: state transitions
102102
#pragma omp for schedule(static)
103-
for (size_t i = 0; i < nSubcomponents; i++) {
103+
for (long i = 0; i < nSubcomponents; i++) {
104104
subcomponents.at(i)->transition(timeNext);
105105
subcomponents.at(i)->clear();
106106
}
@@ -110,7 +110,7 @@ namespace cadmium {
110110
// Step 4: time for next events
111111
localNext = subcomponents[0]->getTimeNext(); // Potential bug: what if model is empty? I'd initialize this to infinity and iterate from 0
112112
#pragma omp for schedule(static)
113-
for (size_t i = 1; i < nSubcomponents; i++){
113+
for (long i = 1; i < nSubcomponents; i++){
114114
if (subcomponents[i]->getTimeNext() < localNext) {
115115
localNext = subcomponents[i]->getTimeNext();
116116
}
@@ -133,7 +133,10 @@ namespace cadmium {
133133
}
134134
}
135135

136-
void simulate(double timeInterval, size_t thread_number = std::thread::hardware_concurrency()) {
136+
void simulate(double timeInterval, unsigned int thread_number = std::thread::hardware_concurrency()) {
137+
// error: only a variable or static member can be used in a data sharing clause
138+
auto rootCoordinator = this->rootCoordinator;
139+
137140
// First, we make sure that Mutexes are activated
138141
if (rootCoordinator->getLogger()) {
139142
rootCoordinator->getLogger()->createMutex();
@@ -155,15 +158,15 @@ namespace cadmium {
155158
while(timeNext < timeFinal) {
156159
// Step 1: execute output functions
157160
#pragma omp for schedule(static)
158-
for (size_t i = 0; i < nSubcomponents; i++) {
161+
for (long i = 0; i < nSubcomponents; i++) {
159162
subcomponents.at(i)->collection(timeNext);
160163
}
161164
#pragma omp barrier
162165
//end Step 1
163166

164167
// Step 2: route messages
165168
#pragma omp for schedule(static)
166-
for (size_t i = 0; i < nICs; i++) {
169+
for (long i = 0; i < nICs; i++) {
167170
for (auto& portFrom: stackedIC[i].second){
168171
stackedIC.at(i).first->propagate(portFrom);
169172
}
@@ -173,7 +176,7 @@ namespace cadmium {
173176

174177
// Step 3: state transitions
175178
#pragma omp for schedule(static)
176-
for (size_t i = 0; i < nSubcomponents; i++){
179+
for (long i = 0; i < nSubcomponents; i++){
177180
subcomponents.at(i)->transition(timeNext);
178181
subcomponents.at(i)->clear();
179182
}
@@ -183,7 +186,7 @@ namespace cadmium {
183186
// Step 4: time for next events
184187
localNext = subcomponents[0]->getTimeNext();
185188
#pragma omp for schedule(static)
186-
for (size_t i = 1; i < nSubcomponents; i++){
189+
for (long i = 1; i < nSubcomponents; i++){
187190
if (subcomponents[i]->getTimeNext() < localNext){
188191
localNext = subcomponents[i]->getTimeNext();
189192
}
@@ -206,7 +209,10 @@ namespace cadmium {
206209
}
207210
}
208211

209-
void simulateSerialCollection(double timeInterval, size_t thread_number = std::thread::hardware_concurrency()) {
212+
void simulateSerialCollection(double timeInterval, unsigned int thread_number = std::thread::hardware_concurrency()) {
213+
// error: only a variable or static member can be used in a data sharing clause
214+
auto rootCoordinator = this->rootCoordinator;
215+
210216
// Firsts, we make sure that Mutexes are activated
211217
if(rootCoordinator->getLogger()) {
212218
rootCoordinator->getLogger()->createMutex();
@@ -228,7 +234,7 @@ namespace cadmium {
228234
while (timeNext < timeFinal) {
229235
// Step 1: execute output functions
230236
#pragma omp for schedule(static)
231-
for (size_t i = 0; i < nSubcomponents; i++){
237+
for (long i = 0; i < nSubcomponents; i++){
232238
subcomponents.at(i)->collection(timeNext);
233239
}
234240
#pragma omp barrier
@@ -244,7 +250,7 @@ namespace cadmium {
244250

245251
// Step 3: state transitions
246252
#pragma omp for schedule(static)
247-
for (size_t i = 0; i < nSubcomponents; i++) {
253+
for (long i = 0; i < nSubcomponents; i++) {
248254
subcomponents.at(i)->transition(timeNext);
249255
subcomponents.at(i)->clear();
250256
}
@@ -254,7 +260,7 @@ namespace cadmium {
254260
// Step 4: time for next events
255261
localNext = subcomponents[0]->getTimeNext();
256262
#pragma omp for schedule(static)
257-
for (size_t i = 1; i < nSubcomponents; i++){
263+
for (long i = 1; i < nSubcomponents; i++){
258264
if (subcomponents[i]->getTimeNext() < localNext) {
259265
localNext = subcomponents[i]->getTimeNext();
260266
}

include/cadmium/lib/iestream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace cadmium::lib {
6464
file >> sigma; // read time of next message
6565
MSG value;
6666
file >> value; // read values to go into message
67-
contents.template emplace(value);
67+
contents.emplace(value);
6868
}
6969
return std::make_pair(sigma,contents);
7070
}

0 commit comments

Comments
 (0)