How to perform multithreaded GU_Detail->load() ?

   933   5   3
User Avatar
Member
4 posts
Joined: 10月 2012
Offline
I'm trying to parallelize geometry loading in standalone application.
When I'm wrapping this call in OMP or TBB loops it's randomly failing

GU_Detail *gdp = new GU_Detail;
if (gdp->load( filename.c_str() ).success() ){
...
}

Is it possible to load several bgeo multithreaded?
Edited by AlexeySmolenchuk - 2023年12月30日 20:24:00
User Avatar
スタッフ
729 posts
Joined: 10月 2012
Offline
Loading bgeo files in parallel should be safe (as long as you're using separate GU_Detail's per thread, of course)
User Avatar
Member
4 posts
Joined: 10月 2012
Offline
cwhite
Loading bgeo files in parallel should be safe (as long as you're using separate GU_Detail's per thread, of course)

I've just tried with simplified example:
#include <omp.h>
#include <GU/GU_Detail.h>
#include <UT/UT_Exit.h>
#include <iostream>
#include <vector>

int main()
{
    std::vector<std::string> files = {
        "Flip.bgeo.sc",
        "pighead.bgeo.sc",
        "SquidCrab.bgeo.sc"
    };

    #pragma omp parallel for
    for ( int i = 0; i < 10; i++)
    {
        GU_Detail *gdp = new GU_Detail;
        if (gdp->load( files[ i%files.size() ].c_str() ).success())
            std::cout << "Loaded "<< gdp->getNumPoints() << " points in thread " << omp_get_thread_num() << std::endl;
        else
            std::cout << ":(" << std::endl;
            
        delete gdp;
    }

    UT_Exit::exit(UT_Exit::EXIT_OK);
    return 0;
}

This in my CMakeLists.txt:
find_package(OpenMP)
find_package(Houdini REQUIRED
PATHS ${HFS}/toolkit/cmake)

add_executable(standalone src/standalone.cpp)
target_link_libraries( standalone Houdini OpenMP::OpenMP_CXX)

Results on my Windows machine and HDK from 19.5.605:
:(
:(
:(
:(
Loaded 2789 points in thread 4
Loaded 12874 points in thread 6
Loaded 12874 points in thread 9
Loaded 20109 points in thread 5
Loaded 12874 points in thread 0
Loaded 20109 points in thread 8

Can someone please check it for sanity?
Edited by AlexeySmolenchuk - 2024年1月2日 20:19:50
User Avatar
Member
4 posts
Joined: 10月 2012
Offline
OK, seems I figured this out.
Looks like sort of initialize or license check supposed to happen before multi threaded execution.
When I'm adding
    GU_Detail *temp = new GU_Detail;
    delete temp;
in the beginning of my program it works fine.

Is there a clear way to do this?
User Avatar
スタッフ
729 posts
Joined: 10月 2012
Offline
It shouldn't be required to do anything like that - I've filed a bug to investigate what's happening
User Avatar
スタッフ
467 posts
Joined: 8月 2019
Offline
fyi, I would stay away from OpenMP in Houdini as it doesn't work with our thread composition. I would recommend looking at the family of UTparallelFor methods which use TBB in the back-end. This will make sure that you'll avoid oversubscription.

https://www.sidefx.com/docs/hdk/_u_t___parallel_util_8h.html [www.sidefx.com]
  • Quick Links