MIDAPACK - MIcrowave Data Analysis PACKage  1.1b
Parallel software tools for high performance CMB DA analysis
 All Data Structures Files Functions Variables Typedefs Groups Pages
cindex.c
Go to the documentation of this file.
1 
10 #include <stdlib.h>
18 int sindex(int *T, int nT, int *A, int nA){
19  int i, tmp;
20  i=0;
21  for(i=0; i<nA; i++){
22  tmp = A[i];
23  A[i] =dichotomy(nT, T, tmp);
24  }
25 }
26 
27 
28 #ifdef W_OPENMP
29 
36 int omp_pindex(int *T, int nT, int *A, int nA){
37 // printf("\nomp_pindex");
38  int i;
39  int *count, *disp;
40  int q, r;
41  int tid, nths;
42 
43  #pragma omp parallel private(tid) shared(nths)
44  {//---fork---just to get the number of threads
45  nths = omp_get_num_threads();
46  tid = omp_get_thread_num();
47 // printf("\ntid %d nths %d", tid, nths);
48  }//---join---
49 
50  q = nA/nths;
51  r = nA%nths;
52 
53  count = (int *) malloc(nths *sizeof(int));
54  disp = (int *) malloc(nths *sizeof(int));
55 
56  for(i=0; i<nths; i++){
57  if(i<r){
58  count[i] = q+1;
59  }
60  else{
61  count[i] = q;
62  }
63  }
64 
65  disp[0] = 0;
66  for(i=0; i<nths-1; i++){
67  disp[i+1] = disp[i] + count[i];
68  }
69 
70  #pragma omp parallel private(tid) shared(T, nT, A, disp, count)
71  {//---fork---1st step, sort on local chunk
72  tid = omp_get_thread_num();
73  sindex(T, nT, A+disp[tid], count[tid]);
74  }//---join---
75  free(count);
76  free(disp);
77  return 0;
78 }
79 #endif
80 
81 
82 
88 int dichotomy(int nT, int *T, int e){
89  int min, max, pivot;
90  min=0;
91  max=nT-1;
92  pivot=(max-min)/2;
93  while(e != T[pivot] && max > min ){
94  if(T[pivot]<e){
95  min=pivot+1;
96  }
97  else{
98  max=pivot;
99  }
100  pivot= min + (max-min)/2;
101  }
102  return pivot;
103 }
104