aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2017-06-30 10:41:43 +0200
committerAnton Khirnov <anton@khirnov.net>2017-06-30 10:41:43 +0200
commit827ccac987a0b297ae02c41acee95689af5a129b (patch)
treeeabb1a8a3b91f601cef119a1d7d0cff3bc9dbc21
parente00a0cc3de18a7bcd8e53761bed037ec0a1dabec (diff)
Drop unused crap, optimize.
-rw-r--r--src/InitialCopy.c191
1 files changed, 29 insertions, 162 deletions
diff --git a/src/InitialCopy.c b/src/InitialCopy.c
index 5cef13c..4c0ee87 100644
--- a/src/InitialCopy.c
+++ b/src/InitialCopy.c
@@ -11,6 +11,7 @@
@version $Header$
@@*/
+#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -73,6 +74,14 @@ void MoL_ReportNumberVariables(CCTK_ARGUMENTS);
@@*/
+#include <sys/time.h>
+static inline int64_t gettime(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
void MoL_InitialCopy(CCTK_ARGUMENTS)
{
@@ -92,15 +101,20 @@ void MoL_InitialCopy(CCTK_ARGUMENTS)
CCTK_REAL * restrict ScratchVar;
CCTK_INT StorageOn;
- /* FIXME */
+ double *y = CCTK_VarDataPtr(cctkGH, 0, "grid::y");
+ double y_idx;
-#ifdef MOLDOESCOMPLEX
+ for (int i = 0; i < cctk_ash[1]; i++) {
+ if (fabs(y[CCTK_GFINDEX3D(cctkGH, 0, i, 0)]) < 1e-8) {
+ y_idx = i;
+ break;
+ }
+ }
- CCTK_COMPLEX * restrict CurrentComplexVar;
- CCTK_COMPLEX const * restrict PreviousComplexVar;
- CCTK_COMPLEX * restrict ScratchComplexVar;
+ static int64_t time, count;
+ int64_t start;
-#endif
+ start = gettime();
totalsize = 1;
for (arraydim = 0; arraydim < cctk_dim; arraydim++)
@@ -125,11 +139,6 @@ void MoL_InitialCopy(CCTK_ARGUMENTS)
CCTK_WARN(0, "The index passed does not correspond to a GF.");
}
else if (StorageOn == 0) {
-#ifdef MOLDEBUG
- printf("Aargh! Vars %d var %d index %d name %s\n",
- MoLNumEvolvedVariables, var, EvolvedVariableIndex[var],
- CCTK_VarName(EvolvedVariableIndex[var]));
-#endif
CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,"Warning for GF %s",
CCTK_VarName(EvolvedVariableIndex[var]));
CCTK_WARN(0, "The grid function does not have storage assigned.");
@@ -221,45 +230,6 @@ void MoL_InitialCopy(CCTK_ARGUMENTS)
}
- /* FIXME */
-
-#ifdef MOLDOESCOMPLEX
-
- for (var = 0; var < MoLNumEvolvedComplexVariables; var++)
- {
-
- StorageOn = CCTK_QueryGroupStorageI(cctkGH,
- CCTK_GroupIndexFromVarI(EvolvedComplexVariableIndex[var]));
-
- if (StorageOn < 0)
- {
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,"Warning for index %i",
- EvolvedComplexVariableIndex[var]);
- CCTK_WARN(0, "The index passed does not correspond to a GF.");
- }
- else if (StorageOn == 0) {
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,"Warning for GF %s",
- CCTK_VarName(EvolvedComplexVariableIndex[var]));
- CCTK_WARN(0, "The grid function does not have storage assigned.");
- }
-
- PreviousComplexVar = (CCTK_COMPLEX const*)CCTK_VarDataPtrI(cctkGH, 1,
- EvolvedComplexVariableIndex[var]);
- CurrentComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0,
- EvolvedComplexVariableIndex[var]);
- if (PreviousComplexVar && CurrentComplexVar)
- {
- memcpy(CurrentComplexVar, PreviousComplexVar, totalsize * sizeof(CCTK_COMPLEX));
- }
- else
- {
- CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,"Null pointer for variable %s",
- CCTK_VarName(EvolvedComplexVariableIndex[var]));
- }
-
- }
-
-#endif
/*
Now the Save and Restore variables. Shift the data in the
@@ -294,14 +264,6 @@ void MoL_InitialCopy(CCTK_ARGUMENTS)
ScratchVar = CCTK_VarDataPtrI(cctkGH, 0,
CCTK_FirstVarIndex("MOL::SANDRSCRATCHSPACE")
+ var);
-#ifdef MOLDEBUG
- printf("Pointers for the SandR vars are to %ld, %ld and %ld.\n",
- PreviousVar, CurrentVar, ScratchVar);
-
- printf("Init1:Variable %s, current %g, previous %g, scratch %g\n",
- CCTK_VarName(SandRVariableIndex[var]), CurrentVar[0],
- PreviousVar[0], ScratchVar[0]);
-#endif
if (PreviousVar && CurrentVar && ScratchVar)
{
memcpy(ScratchVar, CurrentVar, totalsize * sizeof(CCTK_REAL));
@@ -312,60 +274,8 @@ void MoL_InitialCopy(CCTK_ARGUMENTS)
CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,"Null pointer for variable %s",
CCTK_VarName(SandRVariableIndex[var]));
}
-#ifdef MOLDEBUG
- printf("Init2:Variable %s, current %g, previous %g, scratch %g\n",
- CCTK_VarName(SandRVariableIndex[var]), CurrentVar[0],
- PreviousVar[0], ScratchVar[0]);
-#endif
}
- /* FIXME */
-
-#ifdef MOLDOESCOMPLEX
-
- for (var = 0; var < MoLNumSandRComplexVariables; var++)
- {
-
- StorageOn = CCTK_QueryGroupStorageI(cctkGH,
- CCTK_GroupIndexFromVarI(SandRComplexVariableIndex[var]));
-
- if (StorageOn < 0)
- {
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,"Warning for index %i",
- SandRComplexVariableIndex[var]);
- CCTK_WARN(0, "The index passed does not correspond to a GF.");
- }
- else if (StorageOn == 0) {
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,"Warning for GF %s",
- CCTK_VarName(SandRComplexVariableIndex[var]));
- CCTK_WARN(0, "The grid function does not have storage assigned.");
- }
-
- PreviousComplexVar = (CCTK_COMPLEX const*)CCTK_VarDataPtrI(cctkGH, 1,
- SandRComplexVariableIndex[var]);
- CurrentComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0,
- SandRComplexVariableIndex[var]);
- ScratchComplexVar = &ComplexSandRScratchSpace[var*totalsize];
-#ifdef MOLDEBUG
- printf("Pointers for the SandR vars are to %ld, %ld and %ld.\n",
- PreviousComplexVar, CurrentComplexVar, ScratchComplexVar);
-#endif
- if (PreviousComplexVar && CurrentComplexVar && ScratchComplexVar)
- {
- memcpy(ScratchComplexVar, CurrentComplexVar, totalsize *
- sizeof(CCTK_COMPLEX));
- memcpy(CurrentComplexVar, PreviousComplexVar, totalsize *
- sizeof(CCTK_COMPLEX));
- }
- else
- {
- CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,"Null pointer for variable %s",
- CCTK_VarName(SandRComplexVariableIndex[var]));
- }
- }
-
-#endif
-
/*
Now do the constrained variables.
*/
@@ -406,7 +316,11 @@ void MoL_InitialCopy(CCTK_ARGUMENTS)
if (PreviousVar && CurrentVar)
{
- memcpy(CurrentVar, PreviousVar, totalsize * sizeof(CCTK_REAL));
+#pragma omp parallel for
+ for (int k = 0; k < cctk_ash[2]; k++) {
+ int offset = CCTK_GFINDEX3D(cctkGH, 0, y_idx, k);
+ memcpy(CurrentVar + offset, PreviousVar + offset, cctk_ash[0] * sizeof(double));
+ }
}
else
{
@@ -417,60 +331,13 @@ void MoL_InitialCopy(CCTK_ARGUMENTS)
}
}
+ time += gettime() - start;
+ count++;
- /* FIXME */
-
-#ifdef MOLDOESCOMPLEX
- for (var = 0; var < MoLNumConstrainedComplexVariables; var++)
- {
+ //if (!(count & 31))
+ // fprintf(stderr, "%ld %g %g\n", count, (double)time / 1000000.0, (double)time / count);
- StorageOn = CCTK_QueryGroupStorageI(cctkGH,
- CCTK_GroupIndexFromVarI(ConstrainedComplexVariableIndex[var]));
-
- if (StorageOn < 0)
- {
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,"Warning for index %i",
- ConstrainedComplexVariableIndex[var]);
- CCTK_WARN(0, "The index passed does not correspond to a GF.");
- }
- else if (StorageOn == 0) {
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,"Warning for GF %s",
- CCTK_VarName(ConstrainedComplexVariableIndex[var]));
- CCTK_WARN(0, "The grid function does not have storage assigned.");
- }
-
- /*
- Check that there is more than one timelevel.
- If not, copying is unnecessary.
- */
-
- StorageOn = CCTK_ActiveTimeLevelsVI(cctkGH,
- ConstrainedVariableIndex[var]);
-
- if (StorageOn > 1)
- {
-
- PreviousComplexVar = (CCTK_COMPLEX const*)CCTK_VarDataPtrI(cctkGH, 1,
- ConstrainedComplexVariableIndex[var]);
- CurrentComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0,
- ConstrainedComplexVariableIndex[var]);
-
- if (PreviousComplexVar && CurrentComplexVar)
- {
- memcpy(CurrentComplexVar, PreviousComplexVar, totalsize * sizeof(CCTK_COMPLEX));
- }
- else
- {
- CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,"Null pointer for variable %s",
- CCTK_VarName(ConstrainedComplexVariableIndex[var]));
- }
-
- }
-
- }
-
-#endif
return;
}