Author Topic: Using OpenMP in Thread  (Read 2776 times)

Offline seeing

  • Single posting newcomer
  • *
  • Posts: 4
Using OpenMP in Thread
« on: October 23, 2010, 05:59:54 am »
I have Created a DLL using openmp, the file is
Code
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}
//---------------------------------------------------------------------------

DLL_EXPORT void __stdcall Test(Byte *Source, int size)
{
  #pragma omp parallel for
    for(int i=0; i<size; i++)
    {
        if(Source[i] == 5)
            Source[i] = 22;
    }
}
//---------------------------------------------------------------------------

And I write a test program using by bcb, the code is
Code
    int size = 10;
    Byte *src = new Byte[size];

    for(int i=0; i<size; i++)
        src[i] = i % 10;

    Test(src, size);
if I run this code in botton click event, it's ok.
But, if I run this code in Thread, it has crashed. Using GDB to debug, ths program received signal SIGSEGV, Segmentation fault.

why?

thanks a lot.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Using OpenMP in Thread
« Reply #1 on: October 23, 2010, 12:02:18 pm »
Unrelated to C::B and therefore vioalting our forums/websites rules.

Please ask in an appropriate c++/openMP forum.

If you know what is wrong, but you don't know how (or where) to set it up in C::B, feel free to come back and ask again.

Topic locked !