int main(){
  int i, cnt = 0;;
  inverse_pair(A, 0, 9, &cnt, T);
  printf("%d\n", cnt);
  while(1); 
  return 0;
}
Beispiel #2
0
void inverse_pair(int* A, int x, int y, int* cnt, int* T) {
  if(y-x > 1){
    int m = x + (y-x)/2;
    int p = x, q = m, i = x;
    inverse_pair(A, x, m, cnt, T);
    inverse_pair(A, m, y, cnt, T);
    while(p < m || q < y) {
      if(q >= y || (p < m && A[p] <= A[q]))
        T[i++] = A[p++];
      else {
        T[i++] = A[q++];
        *cnt += m-p;
      }
    }
    for(i = x; i < y; i++) A[i] = T[i];
  }
}
Beispiel #3
0
void thread_code(void *arg) {
	int cpuid = (int)arg;
	set_affinity(cpuid);
	
	int core_id = sched_getcpu();

	double X = logistic_map (X0, a, iters);
	if (core_id == 0) { X = X + errta; }
#if DEBUG
	fprintf(stdout, "core %d at step 1 get result: %.16f \n", core_id, X);
#endif

	double Y = inverse_pair(X, A, M);
#if DEBUG
	fprintf(stdout, "core %d at step 2 get result: %.16f \n", core_id, Y);
#endif
	double Z = logistic_map (Y, a, iters);

	fprintf(stdout, "core %d get result: %.16f \n", core_id, Z);
	pthread_exit(1);
}