unable to use c++amp in vs 2017 - visual-c++

I tried to use C++ amp in Visual Studio 2017, but compiler said, "error C3564" and I tried the old code(which worked in Visual Studio 2015), and it said same thing.
Does Visual Studio 2017 support C++ amp?
#include "stdafx.h"
using namespace concurrency;
int main(void){
int size;
scanf_s("%d", &size);
array_view<int, 1> a(1);
parallel_for_each(extent<1>(1),
[=](index<1> &idx) restrict(amp)
{
a(idx) = size;
});
}
the code above will generate problem.

just added the amp.h file and the code above compiles.
i am also working on other project with C++AMP in vs 2017 and it working fine.
#include "stdafx.h"
#include <amp.h>
using namespace concurrency;
int main(void) {
int size;
scanf_s("%d", &size);
array_view<int, 1> a(1);
parallel_for_each(extent<1>(1),
[=](index<1> &idx) restrict(amp)
{
a(idx) = size;
});
}

Related

Visual C++ compiler bug?

I've reduced my case as much as possible below.
#include <vector>
#include <atomic>
#include <chrono>
using namespace std;
class Unused
{
private:
vector<vector<unsigned>> data;
atomic<unsigned> counter;
};
class Timer
{
private:
chrono::time_point<chrono::high_resolution_clock> begin;
public:
void start()
{
begin = std::chrono::high_resolution_clock::now();
}
};
int main()
{
Unused unused;
vector<Timer> timers;
timers.resize(1);
timers[0].start();
}
I've compiled it as (note the specific flags):
cl /O2 /GL /EHsc driver.cpp
This is with
Microsoft (R) C/C++-Optimierungscompiler Version 19.27.29111 für x86
Microsoft (R) Incremental Linker Version 14.27.29111.0
but I've tried a couple of other recent versions as well. The executable segfaults with a memory access violation. It works with g++, and it works if I change the compile flags. It also works is I simplify the code further.
Is this a compiler bug?
It was indeed a compiler bug, https://developercommunity.visualstudio.com/content/problem/1157189/possible-compiler-bug-1.html.

msvc 15.3.1 compiler issue

I have found a strange behavior (probably an issue) while trying to compile a simple application with MS VC 15.3.1 (after applying VC 2017 Upgrade 3):
#include <iostream>
#include <algorithm>
#include <string>
// compiles if commenting out the line below
#include <vector>
#include <list>
class A
{
std::string s;
public:
A(const std::string& str) : s(str)
{
}
A(A&& other)
{
// compiles if changing std::swap<std::string>() to std::swap()
std::swap<std::string>(s, other.s);
}
};
int main(int argc, char *argv[])
{
return 0;
}
the compiler emits error :
1>d:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.11.25503\include\vector(2131):
error C2039: '_Alloc': is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
This code compiles without any issues with VC 15.2, VS2015 and VS2013 toolsets.

I can't figure out how to link msi.lib to my Visual Studio C++ project

I'm trying to write a simple application that will enumerate all the ProductCodes installed on my machine.
I've started a new project in Visual Studio 2013, but whenever I build I get the error:
"LNK2019: unresolved external symbol _MsiEnumProductsExA#32 referenced in function _main"
I've been trying to figure out how to add msi.lib to my project include path, but I can't seem to figure it out.
Here's my code:
#define _WIN32_MSI 300
#include <Windows.h>
#include <iostream>
#include <string>
#include <Msi.h>
using namespace std;
int main() {
// Get a list of all installed MSIs
DWORD index = 0;
TCHAR currentProductCode[40] = {0};
unsigned int result = ERROR_SUCCESS;
// Open an MSI handle
while (ERROR_SUCCESS == result) {
result = MsiEnumProductsEx(NULL, "s-1-1-0",
MSIINSTALLCONTEXT_USERMANAGED | MSIINSTALLCONTEXT_USERUNMANAGED | MSIINSTALLCONTEXT_MACHINE,
index, currentProductCode, NULL, NULL, NULL);
if (result == ERROR_SUCCESS) {
cout << "current ProductCode: " << currentProductCode;
}
index++;
}
return 0;
}
I've been trying to update the project's Property Pages by adding the path to the msi.lib to the "Library Directories" property, but that doesn't seem to work:
This is like Visual Studio 101, what am I missing?!
Goto Configuration Properties>Linker>Input
Add msi.lib in Additional Dependencies Thats it! Make sure you are using same calling conversion, which used to built the lib. i.e either stdcall or cdecl.

visual studio 2013 C++ - console output not visible

Recently i installed visual studio community edition and tried to write small console application.
Program is getting build successfully. But console window is not getting pop up.
Is there a problem, i installed the visual studio on my System "D" drive.
My code snippet :
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Hello world";
return 0;
}
Kindly help
Add a cin.get() like so:
int main() {
cout << "Hello world";
cin.get(); // <- Waits for any key press directed at the console window
return 0;
}

Visual Studio Settings For Multithreading

I'm trying to run the below c++ code in Visual Studio compiling with both Visual C++ and İntel Compiler. I'm setting the /Qopenmp option. Although the omp_get_max_threads() result is 2 the "printf("Running on multiple threads\n")" part is not printed twice.
This is the code:
#include <omp.h>
int main(int argc, char* argv[])
{
printf("Starting Program!\n");
int ntr;
omp_set_dynamic(0);
omp_set_num_threads(2);
#pragma omp parallel
{
printf("Running on multiple threads\n");
ntr = omp_get_max_threads();
printf("%d\n",ntr);
}
printf("Finished!\n");
return 0;
}
This is the output
Starting Program!
Running on multiple threads
2
Finished!
What is wrong with this code or Visual Studio settings?

Resources