2014-01-07 3 views
1

tl; dr : 코드를 편도로 컴파일하면 실행 파일이 빨리 실행됩니다. 내 makefile을 사용할 때 ~ 10 배 느립니다 (실행 속도, 컴파일 시간 아님).makefile을 사용하여 컴파일 할 때 프로그램이 느려지는 이유는 무엇입니까?

내가 (고유치 패키지를 사용) 다음 코드를 컴파일 할 때 :

#include <Eigen/Dense>   // For matrix math 
#include <iostream> 

using namespace std; 
using namespace Eigen; 

// Loop an infinite number of times, computing dot products. 
int main(int argc, char * argv[]) { 
    setNbThreads(16); 
    initParallel();  // Tell Eigen that we're going to be multithreaded. 

    int n = 100; 
    VectorXf a(n), b(n); 
    for (int counter = 0; true; counter++) { 
     a[0] = a.dot(b)/n; 
     if ((counter + 1) % 10000000 == 0) { 
      cout << counter/10000000 << endl; 
     } 
    } 
} 

라인을 사용 :

g++ *.cpp -o exe -I ./PathToEigen -std=c++11 -O2 -DNDEBUG -msse2 

매우 빠르게 실행합니다. 아래의 makefile을 사용하면 결과 실행 파일이 약 10 배 느려집니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

PROGRAM = EXE 

INCLUDEDIRS = -I ./PathToEigen 
CXXSOURCES = $(wildcard *.cpp) 
CXXOBJECTS = $(CXXSOURCES:.cpp=.o) # expands to list of object files 
CXXFLAGS = -w $(INCLUDEDIRS) 
CXX = g++ 

# 
# Default target: the first target is the default target. 
# Just type "make -f Makefile.Linux" to build it. 
# 

all: $(PROGRAM) 

# 
# Link target: automatically builds its object dependencies before 
# executing its link command. 
# 

$(PROGRAM): $(CXXOBJECTS) 
    $(CXX) -o [email protected] $(CXXOBJECTS) -std=c++11 -O2 -DNDEBUG -msse2 

# Clean target: "make -f Makefile.Linux clean" to remove unwanted objects and executables. 
# 

clean: 
    $(RM) -f $(CXXOBJECTS) $(PROGRAM) 

# 
# Run target: "make -f Makefile.Linux run" to execute the application 
#    You will need to add $(VARIABLE_NAME) for any command line parameters 
#    that you defined earlier in this file. 
# 

run: 
    ./$(PROGRAM) 

답변

8

최적화가 필요하지 않으므로 컴파일해야합니다. (-O2CXXFLAGS이고, -O2$(PROGRAM) 규칙에만 적용됩니다.

관련 문제