public void BenchSetup() { bodyPtr = (Body *)Marshal.AllocHGlobal(Marshal.SizeOf <Body>() * 6); rsPtr = (RS *)Marshal.AllocHGlobal(3 * 1024 * sizeof(double)); nBodyPP = Marshal.AllocHGlobal(Marshal.SizeOf <BodyVector>() * 12); nBodyPtr = (BodyVector *)((ulong)nBodyPP - ((ulong)nBodyPP + 16) % 16); rPtr = (R *)Marshal.AllocHGlobal(Marshal.SizeOf <R>() * 1024); magPtr = (double *)Marshal.AllocHGlobal(sizeof(double) * 1024); bodySystem = new NBodySystem(bodyPtr); NBodySystem.Initialize(nBodyPtr); }
public static void Initialize(BodyVector *bodyVector) { NBodyVector = bodyVector; double *x = NBodyVector->X; fixed(double *xSource = new [] { 0.0, 4.84143144246472090e+00, 8.34336671824457987e+00, 1.28943695621391310e+01, 1.53796971148509165e+01, 8.34336671824457987e+00, 1.28943695621391310e+01, 1.53796971148509165e+01, 1.28943695621391310e+01, 1.53796971148509165e+01 }) { for (int i = 0; i < BodyVector.BodyLength; i += 2) { StoreAligned(x + i, LoadVector128(xSource + i)); } } x = NBodyVector->Y; fixed(double *xSource = new[] { 0.0, -1.16032004402742839e+00, 4.12479856412430479e+00, -1.51111514016986312e+01, -2.59193146099879641e+01, 0.0, -1.16032004402742839e+00, 4.12479856412430479e+00, -1.51111514016986312e+01, -2.59193146099879641e+01 }) { for (int i = 0; i < BodyVector.BodyLength; i += 2) { StoreAligned(x + i, LoadVector128(xSource + +i)); } } x = NBodyVector->Z; fixed(double *xSource = new[] { 0.0, -1.03622044471123109e-01, -4.03523417114321381e-01, -2.23307578892655734e-01, 1.79258772950371181e-01, 0.0, -1.03622044471123109e-01, -4.03523417114321381e-01, -2.23307578892655734e-01, 1.79258772950371181e-01 }) { for (int i = 0; i < BodyVector.BodyLength; i += 2) { StoreAligned(x + i, LoadVector128(xSource + +i)); } } x = NBodyVector->VX; var daysPY = SetAllVector128(BodyVector.DausPerYear); fixed(double *xSource = new[] { 0.0, 1.66007664274403694e-03, -2.76742510726862411e-03, 2.96460137564761618e-03, 2.68067772490389322e-03, 0.0, 1.66007664274403694e-03, -2.76742510726862411e-03, 2.96460137564761618e-03, 2.68067772490389322e-03 }) { for (int i = 0; i < BodyVector.BodyLength; i += 2) { StoreAligned(x + i, Multiply(daysPY, LoadVector128(xSource + i))); } } x = NBodyVector->VY; fixed(double *xSource = new[] { 0.0, 7.69901118419740425e-03, 4.99852801234917238e-03, 2.37847173959480950e-03, 1.62824170038242295e-03, 0.0, 7.69901118419740425e-03, 4.99852801234917238e-03, 2.37847173959480950e-03, 1.62824170038242295e-03 }) { for (int i = 0; i < BodyVector.BodyLength; i += 2) { StoreAligned(x + i, Multiply(daysPY, LoadVector128(xSource + i))); } } x = NBodyVector->VZ; fixed(double *xSource = new[] { 0.0, -6.90460016972063023e-05, 2.30417297573763929e-05, -2.96589568540237556e-05, -9.51592254519715870e-05, 0.0, -6.90460016972063023e-05, 2.30417297573763929e-05, -2.96589568540237556e-05, -9.51592254519715870e-05 }) { for (int i = 0; i < BodyVector.BodyLength; i += 2) { StoreAligned(x + i, Multiply(daysPY, LoadVector128(xSource + i))); } } x = NBodyVector->Mass; var mSol = SetAllVector128(BodyVector.SolarMass); fixed(double *xSource = new[] { 0.0, 9.54791938424326609e-04, 2.85885980666130812e-04, 4.36624404335156298e-05, 5.15138902046611451e-05, 0.0, 9.54791938424326609e-04, 2.85885980666130812e-04, 4.36624404335156298e-05, 5.15138902046611451e-05 }) { for (int i = 0; i < BodyVector.BodyLength; i += 2) { StoreAligned(x + i, Multiply(mSol, LoadVector128(xSource + i))); } } *NBodyVector->Mass = BodyVector.SolarMass; *(NBodyVector->Mass + 6) = BodyVector.SolarMass; var px = SetZeroVector128 <double>(); var py = SetZeroVector128 <double>(); var pz = SetZeroVector128 <double>(); for (int i = 0; i < 6; i += 2) { var mass = LoadAlignedVector128(NBodyVector->Mass + i); px = Add(px, Multiply(LoadAlignedVector128(NBodyVector->VX + i), mass)); py = Add(py, Multiply(LoadAlignedVector128(NBodyVector->VY + i), mass)); pz = Add(pz, Multiply(LoadAlignedVector128(NBodyVector->VZ + i), mass)); } NBodyVector->OffsetMomentum(px, py, pz); }