This function must be called outside of parallel region.