~ubuntu-branches/ubuntu/vivid/atlas/vivid

« back to all changes in this revision

Viewing changes to src/auxil/ATL_ptflushcache.c

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-06-11 15:58:16 UTC
  • mfrom: (1.1.3 upstream)
  • mto: (2.2.21 experimental)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: package-import@ubuntu.com-20130611155816-b72z8f621tuhbzn0
Tags: upstream-3.10.1
Import upstream version 3.10.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *             Automatically Tuned Linear Algebra Software v3.8.4
 
2
 *             Automatically Tuned Linear Algebra Software v3.10.1
3
3
 *                    (C) Copyright 2000 R. Clint Whaley
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
30
30
#include <pthread.h>
31
31
#define DREAL
32
32
#include "atlas_misc.h"
33
 
#include "atlas_pthreads.h"
 
33
#include "atlas_threads.h"
34
34
 
35
35
typedef struct ATL_FC ATL_FC;
36
36
struct ATL_FC
40
40
   int N;
41
41
};
42
42
 
43
 
void *ATL_ptCF(void *vptr)
 
43
 
 
44
void ATL_DoWorkFC(ATL_LAUNCHSTRUCT_t *lp, void *vp)
44
45
{
45
 
   ATL_FC *tp = vptr;
46
 
   int i, N;
 
46
   ATL_thread_t *tp=vp;
 
47
   ATL_FC *fp=((ATL_FC*)lp->opstruct) + tp->rank;
47
48
   double *cache, dret=0.0;
 
49
   size_t i, N;
48
50
 
49
 
   N = tp->N;
 
51
   N = fp->N;
50
52
   if (N > 0)
51
53
   {
52
 
      cache = tp->dp;
 
54
      cache = fp->dp;
53
55
      for (i=0; i != N; i++) dret += cache[i];
54
56
   }
55
 
   tp->dret = dret;
56
 
   return(NULL);
 
57
   fp->dret = dret;
57
58
}
58
59
 
59
 
double ATL_ptflushcache(int size)
 
60
double ATL_ptflushcache(long long size)
60
61
/*
61
62
 * flush cache by reading enough mem; note that if the compiler gets
62
63
 * really smart, may be necessary to make vp a global variable so it
67
68
  static void *vp=NULL;
68
69
  static double *cache=NULL;
69
70
  double dret=0.0;
70
 
  static int i, N = 0;
71
 
  static pthread_attr_t attr;
72
 
  static pthread_t tp[ATL_NTHREADS];
73
 
  static ATL_FC fct[ATL_NTHREADS];
 
71
  static long long i, N = 0;
 
72
  ATL_FC fct[ATL_NTHREADS];
74
73
 
75
74
  if (size < 0) /* flush cache */
76
75
  {
77
76
     ATL_assert(cache);
78
 
     ATL_thread_init(&attr);
79
 
     for (i=0; i < ATL_NTHREADS-1; i++)
 
77
     for (i=0; i < ATL_NTHREADS; i++)
80
78
     {
81
79
        fct[i].N = N;
82
80
        fct[i].dp = cache+i*N;
83
 
        pthread_create(tp+i, &attr, ATL_ptCF, fct+i);
84
 
     }
85
 
     fct[i].N = N;
86
 
     fct[i].dp = cache+i*N;
87
 
     ATL_ptCF(fct+i);
88
 
     dret = fct[i].dret;
89
 
     for (i=0; i < ATL_NTHREADS-1; i++)
90
 
     {
91
 
        pthread_join(tp[i], NULL);
92
 
        dret += fct[i].dret;
93
 
     }
94
 
     ATL_thread_exit(&attr);
 
81
     }
 
82
     ATL_goparallel(ATL_NTHREADS, ATL_DoWorkFC, fct, NULL);
95
83
  }
96
84
  else if (size > 0) /* initialize */
97
85
  {
109
97
  }
110
98
  return(dret);
111
99
}
 
100
 
 
101
#if ATL_LINEFLUSH  /* do we have option of flushing by cacheline? */
 
102
 
 
103
void ATL_ptCLF(ATL_LAUNCHSTRUCT_t *lp, void *vp)
 
104
{
 
105
   ATL_FlushAreasByCL(lp->opstruct);
 
106
}
 
107
 
 
108
typedef struct
 
109
{
 
110
   size_t N;
 
111
   void *vp;
 
112
} ATL_TFLUSH_t;
 
113
 
 
114
void ATL_DoWorkFCbA(ATL_LAUNCHSTRUCT_t *lp, void *vp)
 
115
{
 
116
   ATL_thread_t *tp=vp;
 
117
   ATL_TFLUSH_t *pd=(ATL_TFLUSH_t*)lp->opstruct;
 
118
   ATL_flushCacheByAddr(pd->N, pd->vp);
 
119
}
 
120
 
 
121
void ATL_ptflushCacheByAddr(size_t N, void *vp)
 
122
{
 
123
   ATL_TFLUSH_t pd;
 
124
   pd.N = N;
 
125
   pd.vp = vp;
 
126
   ATL_goparallel(ATL_NTHREADS, ATL_DoWorkFCbA, &pd, NULL);
 
127
}
 
128
 
 
129
void ATL_ptFlushAreasByCL(FLSTRUCT *fp)
 
130
{
 
131
   ATL_goparallel(ATL_NTHREADS, ATL_ptCLF, fp, NULL);
 
132
}
 
133
 
 
134
#endif