2016-12-02 3 views
0

Ich habe einen seltsamen Fehler bei der Kompilierung der folgenden Quelle:Fehler: ‚ALIGN‘ nicht deklariert (erste Benutzung in dieser Funktion) mit ALIGN definiert in Makro

#include <stdio.h> 
#include <stdlib.h> 
#include <mach/mach_time.h> 
#include <mm_malloc.h> 

#ifdef SSE 
#include <x86intrin.h> 
#define ALIGN 16 
void addition_tab(int size, double *a, double *b, double *c) 
{ 

int i; 
// Main loop 
for (i=size-1; i>=0; i-=2) 
{ 
    // Intrinsic SSE syntax 
    const __m128d x = _mm_loadu_pd(a); // Load two x elements 
    const __m128d y = _mm_loadu_pd(b); // Load two y elements 
    const __m128d sum = _mm_add_pd(x, y); // Compute two sum elements 
    _mm_storeu_pd(c, sum); // Store two sum elements 

    // Increment pointers by 2 since SSE vectorizes on 128 bits = 16 bytes = 2*sizeof(double) 
    a += 2; 
    b += 2; 
    c += 2; 
} 

} 
#endif 

int main(int argc, char *argv[]) 
{ 
    // Array index 
    int i; 

    // Array size as argument 
    int size = atoi(argv[1]); 

    // Time elapsed 
    uint64_t t1, t2; 
    float duration; 

    // Two input arrays 
    double *tab_x; 
    double *tab_y; 
    double *tab_z; 

    // Get the timebase info 
    mach_timebase_info_data_t info; 
    mach_timebase_info(&info); 

#ifdef NOVEC 
    // Allocation 
    tab_x = (double*) malloc(size*sizeof(double)); 
    tab_y = (double*) malloc(size*sizeof(double)); 
    tab_z = (double*) malloc(size*sizeof(double)); 
#else 
    // Allocation 
    tab_x = (double*) _mm_malloc(size*sizeof(double),ALIGN); 
    tab_y = (double*) _mm_malloc(size*sizeof(double),ALIGN); 
    tab_z = (double*) _mm_malloc(size*sizeof(double),ALIGN); 
#endif 
} 

Wenn ich kompilieren mit:

gcc-mp-4.9 -DNOVEC -O0 main.c -o exe 

Zusammenstellung erfolgt jedoch mit:

gcc-mp-4.9 -DSSE -O3 -msse main.c -o exe 

bekomme ich folgende Fehlermeldung:

012.351.
main.c: In function 'main': 
main.c:96:52: error: 'ALIGN' undeclared (first use in this function) 
    tab_x = (double*) _mm_malloc(size*sizeof(double),ALIGN); 

jedoch variable ALIGN definiert ist, wenn ich SSE Makro mit gcc-mp-4.9 -DSSE passieren, ist es nicht?

Danke für Ihre Hilfe

+1

Ja sein: '' -DSSE' SSE' für precomplier definieren. Sind Sie sich über den Fehler sicher? Ist das dein echter Code? Der gepostete Code scheint in Ordnung zu sein. – LPs

+0

Auf den ersten Blick, was ich sehen kann, ist, dass "ALIGN" auch im Fall '# Kompilieren mit AVX256' verwendet wird, aber mit diesem Makro' ALIGN' ist nicht definiert. jedoch – LPs

+0

, ich habe in main.c: #ifdef AVX256 #include #define ALIGN 32 – youpilat13

Antwort

0

fand ich die Ursache in Ihrem Skript aus: Sie sind nicht die Novec zu isolieren, so dass die Zusammenstellung mit NOVEC Makro wird immer getan. Man könnte es isolieren mit:

if [ "$1" == "novec" ]; then 
# Compile no vectorized and vectorized executables 
$GCC -DNOVEC -O0 main_benchmark.c -o noVectorizedExe 
$GCC -DNOVEC -O0 main_benchmark.c -S -o noVectorizedExe.s 
elif [ "$1" == "sse" ]; then 
# Compile with SSE 
$GCC -DSSE -O3 -msse main_benchmark.c -o vectorizedExe 
$GCC -DSSE -O3 -msse main_benchmark.c -S -o vectorizedExe.s 
echo "Test" 
elif [ "$1" == "avx" ]; then 
# Compile with AVX256 
$GCC -DAVX256 -O3 -mavx main_benchmark.c -o vectorizedExe 
$GCC -DAVX256 -O3 -mavx main_benchmark.c -S -o vectorizedExe.s 
fi 

EDIT

ich es erfuhr, haben Sie einen Tippfehler !!

$GCC -DNOVEV -O0 main_benchmark.c -S -o noVectorizedExe.s 

sollte

$GCC -DNOVEC -O0 main_benchmark.c -S -o noVectorizedExe.s 
+0

die systematische "NOVEC" Compilation gesucht, ich will immer eine nicht-vektorisierte Version (noVectorizedExe ausführbar), wenn ich dieses Skript ausführen. Können Sie erklären, warum dies ein Problem wäre? – youpilat13

+0

@ youpilat13 Herausgefunden !! Sieh dir meinen Schnitt an. ;) – LPs

+0

vielen dank! Grüße – youpilat13

Verwandte Themen