Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ============================================================================
- Name : 1.c
- Author : DaTe
- Version :
- Copyright : Your copyright notice
- Description : Hello OpenMP World in C
- ============================================================================
- */
- #include <omp.h>
- #include <stdio.h>
- #include <stdlib.h>
- /**
- * Hello OpenMP World prints the number of threads and the current thread id
- */
- int main (int argc, char *argv[]) {
- int numThreads, tid;
- int i, j;
- int n = 4;
- int A[]={30,10,40,20};
- int B[]={30,10,40,20};
- int R[2*n-1][n];
- int P[20];
- /* This creates a team of threads; each thread has own copy of variables */
- #pragma omp parallel for
- for(i=0;i<=n-1;++i)
- {
- for(j=0;j<=n-1;++j)
- {
- if(A[i] < A[j])
- {
- R[i+n-1][j] = 1;
- }
- else
- {
- R[i+n-1][j] = 0;
- }
- }
- }
- printf("aa\n");
- #pragma omp parallel for
- for(j=0;j<=n-1;j++)
- {
- for(i=n-2;i>=0;--i)
- {
- R[i][j]=R[2*i+1][j]+R[2*i+2][j];
- }
- }
- printf("aa\n");
- #pragma omp parallel for
- for(j=0;j<n;j++)
- {
- B[R[0][j]] = A[j];
- }
- printf("aa\n");
- for(j=0;j<n;j++){
- printf("%d\n", B[j]);
- }printf("aa\n");
- for(i=0;i<n;++i){
- for(j=0;j<n;j++){
- printf("%d\t", R[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement