LNK1169 : 하나 이상의 다중 정의 된 기호가 발견되었습니다.LNK1169 오류
내 프로젝트는 MPI와 병렬 접두어 알고리즘을 사용하여 병렬화 된 난수 생성기입니다. LNK1169 오류에 대한 많은 해결책을 찾았습니다. 그것을 방지하기 위해 많은 변수를 정적으로 만들었고, 정의 된 변수가 여러 개 발견되어 아무 것도 찾을 수 없었습니다. 변수가 여러 번 정의 될 수있는 헤더 파일이 없습니다. 누구든지 내가 오류를 찾도록 도울 수 있다면 크게 감사하겠습니다. parallel_prefix 함수를 구현하려고 시도하기 전에 모든 것이 올바르게 구축 되었기 때문에 어딘가에 functions.cpp에서 오류가 발생했다는 것이 확실합니다.
또한 여기 LNK2005로부터의 출력이다
LNK2005 "클래스 STD : 벡터> 클래스 표준 : 할당" "> __cdecl parallel_prefix (클래스 STD : 벡터> 클래스 표준 : 할당>> >, class std :: allocator>, 클래스 std :: allocator >>>, int, int) "(? parallel_prefix @@ YA? AV? $ vector @V? $ vector @HV? $ allocator @ H @ std @@@ std @@ V? $ allocator @V? $ vector @H?? $ allocator @ H @ std @@@ std @@@ 2 @@ std @@ V? $ vector @V? $ vector @ V? $ 벡터 @ HV? $ allocator @ H @ std @@@ std @@ V? $ allocator @V? $ vector @HV? $ allocator @ H @ std @@@ std @@@ 2 @@ std @@ V? $ allocator @ V? $ vector @V? $ vector @HV? $ allocator @H @ std @@@ std @@ V? $ allocator @V? $ vector @HV? $ allocator @ H @ std @@@ std @@ @ 2 @@ std @@@ 2 @@ 2 @ HH @ Z) function.obj에서 이미 정의 됨 RandomNumberGenerator
여기 내 코드입니다.
RandomNumberGenerator.cpp
#include "functions.cpp"
int main(int argc, char *argv[])
{
// Establishes what rank it is, and how many processes are running.
static int rank, p, n, per_Process;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
static vector<int> Broadcast_data;
n = 100;
per_Process = n/p;
// The first and second arguments are constants for number generation, the third is a large prime to mod by, and the fourth is a random seed. x1 is calculated based off x0.
// All provided by the user except x1.
// Rank 0 broadcasts the data to all processes.
if (rank == 0)
{
for (static int i = 1; i < 5; i++)
{
Broadcast_data.push_back(std::atoi(argv[i]));
}
Broadcast_data.push_back(std::atoi(argv[1]) *std::atoi(argv[4]) % std::atoi(argv[3]));
// NOTE: THIS PUSH BACK IS HOW MANY RANDOM NUMBERS WILL BE GENERATED
Broadcast_data.push_back(n);
cout << "Rank " << rank << " Broadcast Data: ";
for (static int i = 0; i < 6; i++)
{
cout << Broadcast_data[i] << " ";
}
cout << endl;
}
else
{
Broadcast_data.resize(6);
}
MPI_Bcast(Broadcast_data.data(), 6, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
// Initialize an array of n/p values at every process. Each of the n/p values is the matrix M.
// M is this 2 dimmensional array:
// [ a 1 ]
// [ b 0 ]
static vector<vector<int>> M;
M.resize(2);
M[0].resize(2);
M[1].resize(2);
M[0][0] = Broadcast_data[0];
M[0][1] = Broadcast_data[1];
M[1][0] = 1;
M[1][1] = 0;
// Now we must initialize the array of these M values. Notation might get complex here
// as we are dealing with 3D arrays.
static vector<vector<vector<int>>> M_values;
M_values.resize(per_Process);
for (static int i = 0; i < per_Process; i++)
{
M_values.push_back(M);
}
// Now we are ready for the parallel prefix operation. Note that the operator here
// is matrix multiplication.
static vector<vector<int>> prefix;
prefix = parallel_prefix(M_values, rank, p);
MPI_Finalize();
return 0;
}
functions.cpp
#include <mpi.h>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <time.h>
using namespace std;
// This is parallel prefix with the operator being matrix multiplication
vector<vector<int>> parallel_prefix(vector<vector<vector<int>>> Matrices, int rank, int p)
{
// The first step is a local multiplication of all M values.
// In a matrix represented by:
// [ a b ]
// [ c d ]
// The new matrix will be this:
// [ a^2+bc ab+bd ]
// [ ca+dc cb+d^2 ]
// So the first step will be to complete this operation once for every matrix M in M_values
static vector<vector<int>> local_sum;
local_sum = Matrices[0];
for (static int i = 1; i < Matrices.size(); i++)
{
vector<vector<int>> temp_vector;
temp_vector = local_sum;
temp_vector[0][0] = local_sum[0][0] * Matrices[i][0][0] + local_sum[1][0] * Matrices[i][0][1];
temp_vector[0][1] = local_sum[0][1] * Matrices[i][0][0] + local_sum[1][1] * Matrices[i][0][1];
temp_vector[1][0] = local_sum[0][0] * Matrices[i][1][0] + local_sum[0][1] * Matrices[i][1][1];
temp_vector[1][1] = local_sum[0][1] * Matrices[i][1][0] + local_sum[1][1] * Matrices[i][1][1];
local_sum = temp_vector;
}
// Now that all the local sums have been computed we can start step 2: communication.
// Determine how many steps it will take
int steps = 0;
while (int j = 1 < p)
{
j *= 2;
steps++;
}
while (int k = 0 < steps)
{
// First determine the rank's mate.
static int mate;
mate = rank | (1u << steps);
// Now we send the local sum to mate, and receive our mate's local sum.
// First modify the local sum vector to a vector that can be sent.
// Send vector syntax is [ a c b d ]
static vector<int> send_vector, recv_vector;
send_vector.resize(4);
recv_vector.resize(4);
send_vector[0] = local_sum[0][0];
send_vector[1] = local_sum[0][1];
send_vector[2] = local_sum[1][0];
send_vector[3] = local_sum[1][1];
// Send the vector to your mate, and recieve a vector from your mate.
static MPI_Status status;
MPI_Send(send_vector.data(), 4, MPI_INT, mate, 0, MPI_COMM_WORLD);
MPI_Recv(recv_vector.data(), 4, MPI_INT, mate, 1, MPI_COMM_WORLD, &status);
// Update the local sum if your mate rank is lower than your rank.
if (mate < rank)
{
static vector<vector<int>> temp_vector;
temp_vector = local_sum;
temp_vector[0][0] = local_sum[0][0] * recv_vector[0] + local_sum[1][0] * recv_vector[1];
temp_vector[0][1] = local_sum[0][1] * recv_vector[0] + local_sum[1][1] * recv_vector[1];
temp_vector[1][0] = local_sum[0][0] * recv_vector[2] + local_sum[0][1] * recv_vector[3];
temp_vector[1][1] = local_sum[0][1] * recv_vector[2] + local_sum[1][1] * recv_vector[3];
local_sum = temp_vector;
}
MPI_Barrier(MPI_COMM_WORLD);
k++;
// After completion of this loop the local sum is the parallel prefix output for each process.
}
return local_sum;
}