How to connect OpenMPI library to Visual Studio 2015 - c++

I need to connect OpenMPI library to Visual Studio 2015. I can't use other liblaries instead of OpenMPI. I setup OpenMPI_v1.6.2-1_win32.exe and specified:
Include Directories: C:\Program Files\OpenMPI_v1.6.2-win32\include
Library Directories: C:\Program Files\OpenMPI_v1.6.2-win32\lib
Additional Dependencies: libmpi.lib
Open MP Support: Yes
When I try to compile the code:
#include <stdio.h>
#include "mpi.h"
int main(int argc, char* argv[]) {
int ProcNum, ProcRank, RecvRank;
MPI_Status Status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &ProcNum);
MPI_Comm_rank(MPI_COMM_WORLD, &ProcRank);
if (ProcRank == 0) {
// Действия, выполняемые только процессом с рангом 0
printf("\n Hello from process %3d", ProcRank);
for (int i = 1; i < ProcNum; i++) {
MPI_Recv(&RecvRank, 1, MPI_INT, MPI_ANY_SOURCE,
MPI_ANY_TAG, MPI_COMM_WORLD, &Status);
printf("\n Hello from process %3d", RecvRank);
}
}
else // Сообщение, отправляемое всеми процессами,
// кроме процесса с рангом 0
MPI_Send(&ProcRank, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
Visual Studio show errors:
1>------ Build started: Project: OpenMPISample, Configuration: Debug
Win32 ------ 1>Source.obj : error LNK2001: unresolved external symbol
_ompi_mpi_comm_world 1>Source.obj : error LNK2001: unresolved external symbol _ompi_mpi_int 1>C:\Users\Andriy\Documents\Visual Studio
2015\Projects\OpenMPISample\Debug\OpenMPISample.exe : fatal error
LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How to connect OpenMPI library to Visual Studio 2015 correctly? Thanks in advance!

Related

CUDA and C++ simple project

I am trying to create a CUDA + C++ project. Basically a .cpp project that calls for some CUDA kernel. So I simply followed the example here, which basically adds two vectors. The kernel does the summation job:
http://blog.norture.com/2012/10/gpu-parallel-programming-in-vs2012-with-nvidia-cuda/
Here is the code,
#include <iostream>
#include "cuda_runtime.h"
#include "cuda.h"
#include "device_launch_parameters.h"
using namespace std;
__global__ void saxpy(int n, float a, float *x, float *y)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < n) y[i] = a*x[i] + y[i];
}
int main(void)
{
int N = 1<<20;
float *x, *y, *d_x, *d_y;
x = (float*)malloc(N*sizeof(float));
y = (float*)malloc(N*sizeof(float));
cudaMalloc(&d_x, N*sizeof(float));
cudaMalloc(&d_y, N*sizeof(float));
for (int i = 0; i < N; i++) {
x[i] = 1.0f;
y[i] = 2.0f;
}
cudaMemcpy(d_x, x, N*sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_y, y, N*sizeof(float), cudaMemcpyHostToDevice);
// Perform SAXPY on 1M elements
saxpy<<<(N+255)/256, 256>>>(N, 2.0, d_x, d_y);
cudaMemcpy(y, d_y, N*sizeof(float), cudaMemcpyDeviceToHost);
float maxError = 0.0f;
for (int i = 0; i < N; i++)
maxError = max(maxError, abs(y[i]-4.0f));
cout << "Max error: " << maxError;
}
When I built I got this error:
1>------ Rebuild All started: Project: CUDATest001, Configuration: Debug x64 ------
1> CUDATestZeroZeroOne.cpp
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol threadIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockDim
1>D:\Projects\CUDATest001\x64\Debug\CUDATest001.exe : fatal error LNK1120: 3 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
If the line saxpy<<<(N+255)/256, 256>>>(N, 2.0, d_x, d_y); is commented out, then this error appeared:
1>------ Rebuild All started: Project: CUDATest001, Configuration: Debug x64 ------
1> CUDATestZeroZeroOne.cpp
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol threadIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockDim
1>D:\Projects\CUDATest001\x64\Debug\CUDATest001.exe : fatal error LNK1120: 3 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I am using vs2012 + CUDA 5.5. I started with a empty C++ win32 console project, added a .cpp file which includes all the code above. I am not even sure at this point should it be a .cu or a .cpp file?
Anyone has any idea how to make this work? Thanks.
In the context menu for your project, click Build Customizations. Turn on the CUDA 5.5 target.
In the context menu for your .cpp file, click Rename and rename it to .cu.
In the context menu for your .cu file (that you just renamed), select Properties. Then go to General and make sure Item Type is set to CUDA C/C++.
Rebuild.
When you start a new CUDA project, you can select Templates > NVIDIA > CUDA 5.5 > CUDA 5.5 Runtime to get a project that should compile without any modifications.

Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt' on Visual Studio 2010 C ++? [duplicate]

This question already has answers here:
error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
(13 answers)
Closed 9 years ago.
I get the following error Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt' when I compile my code using Win32 Console Application.
I tried fixing it my going into Projects -> Properties -> General -> Linker -> Enable Incremental Linking and I changed it from "Yes" to No (/INCREMENTAL:NO) and then I tried to debug my code again but got another error message :
1>------ Build started: Project: Someproject, Configuration: Debug Win32 ------
1>project1.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
1>c:\users\anne\documents\visual studio 2010\Projects\Someproject\Debug\Someproject.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How can I fix it?
#include <Windows.h>
#include <process.h>
#include <stdio.h>
#include <math.h>
volatile int counter = 0;
int isPrime(int n)
{
for(int i = 2; i < (int)(sqrt((float)n) + 1.0) ; i++) {
if (n % i == 0) return 0;
}
return 1;
}
unsigned int __stdcall mythread(void*)
{
char* s;
while (counter < 25) {
int number = counter++;
s = "No";
if(isPrime(number)) s = "Yes";
printf("Thread %d value = %d is prime = %s\n",
GetCurrentThreadId(), number, s);
}
return 0;
}
int main(int argc, char* argv[])
{
HANDLE myhandleA, myhandleB;
myhandleA = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);
myhandleB = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);
WaitForSingleObject(myhandleA, INFINITE);
WaitForSingleObject(myhandleB, INFINITE);
CloseHandle(myhandleA);
CloseHandle(myhandleB);
getchar();
system("pause");
return 0;
}
The basic problem is that you somehow specified "windows app" in your project settings. You want "console app" instead.
Windows apps use "WinMain()"; console apps use "main()".
Look at this link for details:
error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
See also:
Building Console Applications

OpenSSL fatal error LNK1120: 3 unresolved externals

I've installed OpenSSL to Windows 8, and did the necessary modifications to the OpenSSL library, without installing it as a native library. But I've a specific error message that I couldn't find it on internet.
1>------ Build started: Project: CryptoProject, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _BN_new referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_bn2dec referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_generate_prime referenced in function _main
1>C:\Users\...\...\...\Debug\EXAMPLE.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hope you guys find something. So here it goes:
#include <iostream>
#include <string>
#include "openssl/bn.h"
using namespace std;
int main()
{
BIGNUM * q = BN_new();
BIGNUM * two = BN_new();
long int num_bits_q = 160;
long int num_bits_p = 1024;
BN_generate_prime(q, num_bits_q, 0, two, NULL,NULL,NULL);
cout << "q is: " << BN_bn2dec(q) << endl;
return 0;
}
I ran that code and it compiled successfully in visual studio 2012, I used OpenSSL-Win32. If OpenSSL-Win64 does not work use OpenSSL-Win32, I also had the same problem. Don't forget to include ssleay32.lib, I hope you know how to configure OpenSSl in visual studio.

Compiling Mathlink Code in Visual Studio 2010 Express LNK2019 Error

I'm attempting to compile a simple C file for use with Mathematica. (Note: I did follow the rest of the instructions, creating the empty addtwotm.c file and adding addtwo.tm)
#include "mathlink.h"
extern int addtwo( int i, int j);
int addtwo( int i, int j)
{
return i+j;
}
#if WINDOWS_MATHLINK
#if __BORLANDC__
#pragma argsused
#endif
int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow)
{
char buff[512];
char FAR * buff_start = buff;
char FAR * argv[32];
char FAR * FAR * argv_end = argv + 32;
hinstPrevious = hinstPrevious; /* suppress warning */
if( !MLInitializeIcon( hinstCurrent, nCmdShow)) return 1;
MLScanString( argv, &argv_end, &lpszCmdLine, &buff_start);
return MLMain( (int)(argv_end - argv), argv);
}
#else
int main(int argc, char* argv[])
{
return MLMain(argc, argv);
}
#endif
However, on build, I get this output:
1>------ Build started: Project: addtwo, Configuration: Debug Win32 ------
1> Performing Custom Build Tools
1> on "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\VC\bin\mprep.exe" "" -o "D:\Applications\Mathematica\SystemFiles\Links\MathLink\DeveloperKit\Windows\MathLinkExamples\addtwo\addtwo\..\addtwotm.c"
1>addtwo.obj : error LNK2019: unresolved external symbol _MLMain referenced in function _WinMain#16
1>addtwo.obj : error LNK2019: unresolved external symbol _MLInitializeIcon referenced in function _WinMain#16
1>D:\Applications\Mathematica\SystemFiles\Links\MathLink\DeveloperKit\Windows\MathLinkExamples\addtwo\Debug\addtwo.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I've followed all provided instructions from Wolfram's MathLink Developer Guide, and made sure to add "ml32i3m.lib" to Linker>Input>Additional Dependencies. Supposedly the ml32/ml64 lib files contain the information for MlMain. Any help is appreciated :)

error LNK2019: unresolved external symbol

Ok, so I'm having a problem trying figure out the problem in my code. I have a lot of code so I'm only going to post the relevant parts that are messing up when I compile. I have the following function inside of a class and it will compile and everything will run fine until I call the function "CalculateProbabilityResults" and it runs the 7th line of code within it. I've "de-commented" this line of code in my program so you can find it easier. I'm pretty sure I have the right #include directives needed since it compiles fine when not calling the function, so that can't be the problem can it? I know some of my naming notation needs a little help, so please bear with me. Thanks in advance for the help guys.
int SQLServer::CalculateProbabilityResults(int profile, int frame, int time_period, int TimeWindowSize) {
ofstream ResultFile;
stringstream searchFileName;
stringstream outputName;
vector<vector<int>> timeFrameItemsets;
int num = getTimeFrameFile(frame*TimeWindowSize, TimeWindowSize);
cout << num << endl;
//outputName << "Results" << getTimeFrameFile((frame*TimeWindowSize), TimeWindowSize) << ".csv";
cout << outputName.str() << endl;
outputName.clear();
//ResultFile.open(outputName.str().c_str());
ResultFile.close();
result.resize(0);
return 0;
}
int getTimeFrameFile(int timeInHours, int timeFrameSize) {
int fileNum = 0;
int testWin;
if (timeInHours > 24) {
while (timeInHours >24)
timeInHours -= 24;
}
for (testWin = 0; testWin < 24/timeFrameSize; testWin++) {
if (timeInHours >= testWin*timeFrameSize && timeInHours < (testWin+1)*timeFrameSize)
fileNum = testWin+1;
}
if (fileNum == 0)
fileNum = testWin+1;
return fileNum;
}
Call Log
1>------ Rebuild All started: Project: MobileSPADE_1.3, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'MobileSPADE_1.3', configuration 'Debug|Win32'
1>Compiling...
1>main.cpp
1>MobileSPADE.cpp
1>SQLServer.cpp
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>LINK : C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe not found or not built by the last incremental link; performing full link
1>SQLServer.obj : error LNK2019: unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)" (?getTimeFrameFile#SQLServer##QAEHHH#Z) referenced in function "public: int __thiscall SQLServer::CalculateProbabilityResults(int,int,int,int)" (?CalculateProbabilityResults#SQLServer##QAEHHHHH#Z)
1>C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\MobileSPADE_1.3\Debug\BuildLog.htm"
1>MobileSPADE_1.3 - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
The compiler thinks that getTimeFrameFile is a SQLServer method:
unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)"
but you have it defined as a free function:
int getTimeFrameFile(int timeInHours, int timeFrameSize) {
Change that from a free function to a class method will solve the problem:
int SQLServer::getTimeFrameFile(int timeInHours, int timeFrameSize)
Put the function getTimeFrameFile above SQLServer::CalculateProbabilityResults.