1

こんにちは、私はこのサイトと c++11 を初めて使用します。これを調べてみたところ、次のエラーが発生しているようです。それはまさにエラーが言ったことであり、変数を初期化していなかったと思いましたが、何度もチェックしましたが、初期化されていない理由を見つけられないようです。うまくいけば、誰かが助けることができます。ここに私のコードがあります:

void cipher(array<char, array_rows>& text1, array<char, array_rows>& text2, array<int, 52>& key)
{

int i1=0;                 // Index into first text array.
int i2=0;                 // Index into second text array.
int ik=0;                     // Index into key array.
int x1=0;
int x2=0;
int x3=0;   
int x4=0; 
int t1=0; 
int t2=0; // Four "16-bit" blocks, two temps.
int r=0;                      // Eight rounds of processing.
int i=0;

auto num_threads = thread::hardware_concurrency();


#pragma omp  parallel  num_threads(num_threads) default(none) shared(text1, text2, key) private(i, i1,i2,ik,x1,x2,x3,x4,t1,t2,r)  
//#pragma for <----- this commented or not gives same error 
for ( i = 0; i < text1.size(); i += 8)
{
    ik = 0;                 // Restart key index.
    r = 8;                  // Eight rounds of processing.

    // Load eight plain1 bytes as four 16-bit "unsigned" integers.
    // Masking with 0xff prevents sign extension with cast to int.

    x1 = text1[i1++] & 0xff;          // Build 16-bit x1 from 2 bytes,
    x1 |= (text1[i1++] & 0xff) << 8;  // assuming low-order byte first.
    x2 = text1[i1++] & 0xff;
    x2 |= (text1[i1++] & 0xff) << 8;
    x3 = text1[i1++] & 0xff;
    x3 |= (text1[i1++] & 0xff) << 8;
    x4 = text1[i1++] & 0xff;
    x4 |= (text1[i1++] & 0xff) << 8;

    do 
    {
        // 1) Multiply (modulo 0x10001), 1st text sub-block
        // with 1st key sub-block.

        x1 = (int) ((long long) x1 * key[ik++] % 0x10001L & 0xffff);

        // 2) Add (modulo 0x10000), 2nd text sub-block
        // with 2nd key sub-block.

        x2 = x2 + key[ik++] & 0xffff;

        // 3) Add (modulo 0x10000), 3rd text sub-block
        // with 3rd key sub-block.

        x3 = x3 + key[ik++] & 0xffff;

        // 4) Multiply (modulo 0x10001), 4th text sub-block
        // with 4th key sub-block.

        x4 = (int) ((long long) x4 * key[ik++] % 0x10001L & 0xffff);

        // 5) XOR results from steps 1 and 3.

        t2 = x1 ^ x3;

        // 6) XOR results from steps 2 and 4.
        // Included in step 8.

        // 7) Multiply (modulo 0x10001), result of step 5
        // with 5th key sub-block.

        t2 = (int) ((long long) t2 * key[ik++] % 0x10001L & 0xffff);

        // 8) Add (modulo 0x10000), results of steps 6 and 7.

        t1 = t2 + (x2 ^ x4) & 0xffff;

        // 9) Multiply (modulo 0x10001), result of step 8
        // with 6th key sub-block.

        t1 = (int) ((long long) t1 * key[ik++] % 0x10001L & 0xffff);

        // 10) Add (modulo 0x10000), results of steps 7 and 9.

        t2 = t1 + t2 & 0xffff;

        // 11) XOR results from steps 1 and 9.

        x1 ^= t1;

        // 14) XOR results from steps 4 and 10. (Out of order).

        x4 ^= t2;

        // 13) XOR results from steps 2 and 10. (Out of order).

        t2 ^= x2;

        // 12) XOR results from steps 3 and 9. (Out of order).

        x2 = x3 ^ t1;

        x3 = t2;        // Results of x2 and x3 now swapped.

    } while(--r != 0);  // Repeats seven more rounds.

    // Final output transform (4 steps).

    // 1) Multiply (modulo 0x10001), 1st text-block
    // with 1st key sub-block.

    x1 = (int) ((long long) x1 * key[ik++] % 0x10001L & 0xffff);

    // 2) Add (modulo 0x10000), 2nd text sub-block
    // with 2nd key sub-block. It says x3, but that is to undo swap
    // of subblocks 2 and 3 in 8th processing round.

    x3 = x3 + key[ik++] & 0xffff;

    // 3) Add (modulo 0x10000), 3rd text sub-block
    // with 3rd key sub-block. It says x2, but that is to undo swap
    // of subblocks 2 and 3 in 8th processing round.

    x2 = x2 + key[ik++] & 0xffff;

    // 4) Multiply (modulo 0x10001), 4th text-block
    // with 4th key sub-block.

    x4 = (int) ((long long) x4 * key[ik++] % 0x10001L & 0xffff);

    // Repackage from 16-bit sub-blocks to 8-bit byte array text2.

    text2[i2++] = (char)x1;
    text2[i2++] = (char)(x1 >> 8);
    text2[i2++] = (char)x3;                // x3 and x2 are switched
    text2[i2++] = (char)(x3 >> 8);        // only in name.
    text2[i2++] = (char)x2;
    text2[i2++] = (char)(x2 >> 8);
    text2[i2++] = (char)x4;
    text2[i2++] = (char)(x4 >> 8);

}   // End for loop.
}
4

2 に答える 2

1

OpenMP データ句を使用してprivate( ... i1 ... )います。つまり、これらは、並列セクションのスコープ外では見えないローカルの初期化されていない変数です。並列ブロックで初期化を移動する必要があります。

#pragma omp  parallel  num_threads(num_threads) default(none) shared(text1, text2, key) private(i, i1,i2,ik,x1,x2,x3,x4,t1,t2,r)  

i=i1=i2=ik=x1=x2=x3=x4=t1=t2=r=0;

//...
于 2013-11-01T12:04:18.127 に答える
0

i1などの変数は、並列領域を開く前に初期化されますが、その内部ではプライベートであると宣言できますfirstprivate

于 2013-11-01T12:38:19.457 に答える