magento2 – Check if the product is a variant / has a parent?

This should be easy, but I have trouble finding / finding a solution.

What code could I use to check if a product is a variant or if it has a parent? I want to run code if a product is a configurable product or a simple product without a parent, ignoring any simple products that are not variants. Thoughts?