Q:

Is there a way to cancel from inside ordered clause? 

I'm developing a program that calculates a certain number of prime numbers using multiple threads.  Now I have run into a problem of exiting from threads after said number of primes. 
I've tried #pragma omp cancel for, but I cannot use it inside an ordered clause.  Is there another way to "break" the loop? 
void get_primes(prime_type start, prime_type end) {
  #pragma omp parallel for ordered schedule(dynamic) shared(prime_counter)
  for (candidate = start; candidate <= end; candidate += 2) {
    if (is_prime(candidate)) {
      #pragma omp ordered
      {
        primes[prime_counter] = candidate;
        prime_counter++;
        if (prime_counter >= max_primes) {
          #pragma omp cancel for
        }
        #pragma omp cancellation point for
      }
    }
  }
}

I want to immediately "break" the loop when I've found the desired number of primes and if I'm not mistaken that must be done inside the ordered clause. 

A:

No.  It is not possible to cancel an ordered loop. 

A loop construct that is canceled must not have an ordered clause. 

(cf.  2.14.1 of the OpenMP standard)
One of the workaround to emulate cancellation is to add a skip at the beginning of the loop, e.g.
#pragma omp parallel for ordered schedule(dynamic) shared(prime_counter)
for (candidate = start; candidate <= end; candidate += 2) {
  if (prime_counter >= max_primes) {
    continue;
  }
  if (is_prime(candidate)) {

However, that is not yet a thread safe access to prime_counter.  In order to avoid race conditions, you must do something along the lines of:
  int local_prime_counter;
  #pragma omp atomic read
  local_prime_counter = prime_counter;
  if (local_prime_counter >= max_primes)

  ...

  #pragma omp atomic update
  prime_counter++;

P.S. I'm not quite 100% sure if it is standard conforming to have a conditional ordered construct.