Issue with Writing Array Elements to File in OpenACC

Hello OpenACC experts,

I'm facing a problem with writing array elements to a file using OpenACC. Here's the relevant code snippet:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ofstream THeOutfile;
    THeOutfile.open("TheIndianNumbers.txt", ios::app);

    const int arraySize = 1000001;
    long long int* thenumbersarray = new long long int[arraySize];

    for (int m = 0; m < 4000; m++)
    {
        #pragma acc parallel loop
        for (int i = 0; i < arraySize - 1; i++)
        {
            thenumbersarray[i] = 6000000000LL + i;
            cout << "Calculation Done " << i << endl;
        }

        for (int x = 0; x < arraySize - 1; x++)
        {
            THeOutfile << thenumbersarray[x] << endl;
            cout << "Writing Done " << x << endl;
        }
    }

    delete[] thenumbersarray;
    THeOutfile.close();

    return 0;
}

The issue lies in the loop responsible for writing the array elements to the file. It's not functioning correctly, and I need your expertise to fix it.

I'm seeking suggestions or code snippets to properly parallelize the loop using OpenACC directives and ensure successful writing of all array elements to the file.

Thank you for your help in advance!

Upvotes: 1

Views: 58

Answers (0)

Related Questions