Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug in gsHDomainBoundaryIterator.h when using openMP. #666

Open
wj902911 opened this issue Nov 27, 2023 · 1 comment
Open

A bug in gsHDomainBoundaryIterator.h when using openMP. #666

wj902911 opened this issue Nov 27, 2023 · 1 comment
Assignees

Comments

@wj902911
Copy link

https://github.com/gismo/gismo/blob/74b2d0c85407013d35bf6d07192c6954868acd3d/src/gsHSplines/gsHDomainBoundaryIterator.h#L98C48-L98C48
This will cause the iterator go outside the domain when using openMP.

@wj902911
Copy link
Author

wj902911 commented Jan 10, 2024

I found the problem will happen only when iterating through boundaries, so I compared the implementation btween gsHDomainBoundaryIterator.h and gsHDomainIterator.h. I noticed that the next() function in gsHDomainIterator.h (Line 93) has a different implementation with the one in gsHDomainBoundaryIterator.h (Line 96).
In gsHDomainIterator.h:

bool next(index_t increment)
    {
        for (index_t i = 0; i != increment && this->m_isGood; ++i)
        {
            this->m_isGood = nextLexicographic(m_curElement, m_meshStart, m_meshEnd);
            if (!this->m_isGood)
                this->m_isGood = nextLeaf();
        }

        if (this->m_isGood)
            updateElement();

        m_id += increment; //increment id
        return this->m_isGood;
    }

In gsHDomainBoundaryIterator.h:

bool next(index_t increment)
    {
        for (index_t i = 0; i < increment; i++)
            this->m_isGood = nextLexicographic(m_curElement, m_meshStart, m_meshEnd);

        if (this->m_isGood) // new element in m_leaf
            updateElement();
        else // went through all elements in m_leaf
            this->m_isGood = nextLeaf();

        return this->m_isGood;
    }

Finally, by replacing Line 9899 in gsHDomainBoundaryIterator.h with Line 95100 in gsHDomainIterator.h, this issue can be fixed. Although this works for me now, I don't know if it will cause some other issues in the future.
Modified next() in gsHDomainBoundaryIterator.h:

bool next(index_t increment)
    {
        /*
        for (index_t i = 0; i < increment; i++)
            this->m_isGood = nextLexicographic(m_curElement, m_meshStart, m_meshEnd);
        */
        for (index_t i = 0; i != increment && this->m_isGood; ++i)
        {
            this->m_isGood = nextLexicographic(m_curElement, m_meshStart, m_meshEnd);
            if (!this->m_isGood)
                this->m_isGood = nextLeaf();
        }

        if (this->m_isGood) // new element in m_leaf
            updateElement();
        else // went through all elements in m_leaf
            this->m_isGood = nextLeaf();

        return this->m_isGood;
    }

@filiatra filiatra self-assigned this Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants