B1 - OpenMP

thread

  • the smallest sequence of programmed instruction that can be managed independently by a scheduler

#pragma omp parallel default(shared) private(x,y)
#include <omp.h>
#include <stdio.h>

int main()
{
    int nthreads, tid;

    #pragma omp parallel private(tid)
    {
        tid = omp_get_thread_num();
        printf("Hello world from thread = %d\n", tid);

        if (tid == 0)
        {
            nthreads = omp_get_num_threads();
            printf("Number of threads = %d\n", nthreads);
        }
    }
}
#pragma omp parallel for
	for (i = 0; i < i_max; i++)
	{
		z[i] = a * x[i] + y;
	}