- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I use ICC 2019 update 5 embedded into VS2019 16.1.6. I observed something strange with std::map::insert(). I perform insertion of elements from a std::vector<int> to a std::map<int, int>, using the element value as the map key. Depending on the way I insert them or the compilation switches I use, I don't obtain the same map. See a question on StackOverflow.
Here is the code snippet I used:
#include <map> #include <vector> #include <iostream> std::map<int, int> AddToMapWithDependencyBetweenElementsInLoop(const std::vector<int>& values) { std::map<int, int> myMap; for (int i = 0; i < values.size(); i+=3) { myMap.insert(std::make_pair(values, myMap.size())); myMap.insert(std::make_pair(values[i + 1], myMap.size())); myMap.insert(std::make_pair(values[i + 2], myMap.size())); } return myMap; } std::map<int, int> AddToMapOnePerLoop(const std::vector<int>& values) { std::map<int, int> myMap; for (int i = 0; i < values.size(); ++i) { myMap.insert(std::make_pair(values, 0)); } return myMap; } int main() { std::vector<int> values{ 6, 7, 15, 5, 4, 12, 13, 16, 11, 10, 9, 14, 0, 1, 2, 3, 8, 17 }; { auto myMap = AddToMapWithDependencyBetweenElementsInLoop(values); for (const auto& keyValuePair : myMap) { std::cout << keyValuePair.first << ", "; } std::cout << std::endl; } { auto myMap = AddToMapOnePerLoop(values); for (const auto& keyValuePair : myMap) { std::cout << keyValuePair.first << ", "; } std::cout << std::endl; } return 0; }
If I compile using "icl mycode.cpp" and I run the program, I obtain this:
0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17,
0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 17
(I expected the same number for both lines and 18 numbers on each lines since there are 18 different numbers inserted in the map)
If I compile using "icl /EHsc mycode.cpp" and I run, I obtain:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17,
0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 17
(Again, unexpected results?)
If I compile using "icl /Od mycode.cpp" and I run:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
This is the expected result...
Note that I compared using the same switches but with cl.exe (Microsoft compiler) and I always obtain the expected result.
Any idea about the case? Is it a bug? Did I do something wrong? Thanks for your help!
- Tags:
- CC++
- Development Tools
- Intel® C++ Compiler
- Intel® Parallel Studio XE
- Intel® System Studio
- Optimization
- Parallel Computing
- Vectorization
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I couldn't reproduce it.
C:\temp>icl test_832619.cpp
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.0.5.271 Build 20190724
Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
test_832619.cpp
Microsoft (R) Incremental Linker Version 14.22.27905.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:test_832619.exe
test_832619.obj
C:\temp>test_832619.exe
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
C:\temp>icl /EHsc test_832619.cpp
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.0.5.271 Build 20190724
Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
test_832619.cpp
Microsoft (R) Incremental Linker Version 14.22.27905.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:test_832619.exe
test_832619.obj
C:\temp>test_832619.exe
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
C:\temp>

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page