The omp_get_active_level routine returns the number of nested, active parallel regions enclosing the task that contains the call.
INTEGER FUNCTION OMP_GET_ACTIVE_LEVEL()
#include <omp.h>
int omp_get_active_level(void);
The routine always returns a nonnegative integer, and returns 0 if it is called from the sequential part of the program.