hip_filename stringlengths 5 84 | hip_content stringlengths 79 9.69M | cuda_filename stringlengths 4 83 | cuda_content stringlengths 19 9.69M |
|---|---|---|---|
397ad7e03fefb390cfbae4a1fe48a0e6164224d7.hip | // !!! This is a file automatically generated by hipify!!!
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <hiprand/hiprand_kernel.h>
#include <stdlib.h>
#include <hip/hip_runtime.h>
#include <sys/time.h>
#include "RevealNumber.cu"
#include<chrono>
#include<iostream>
using namespace std;
using namespace std::chrono;
int blocks_[20][2] = {{8,8},{16,16},{24,24},{32,32},{1,64},{1,128},{1,192},{1,256},{1,320},{1,384},{1,448},{1,512},{1,576},{1,640},{1,704},{1,768},{1,832},{1,896},{1,960},{1,1024}};
int matrices_[7][2] = {{240,240},{496,496},{784,784},{1016,1016},{1232,1232},{1680,1680},{2024,2024}};
int main(int argc, char **argv) {
hipSetDevice(0);
char* p;int matrix_len=strtol(argv[1], &p, 10);
for(int matrix_looper=0;matrix_looper<matrix_len;matrix_looper++){
for(int block_looper=0;block_looper<20;block_looper++){
int XSIZE=matrices_[matrix_looper][0],YSIZE=matrices_[matrix_looper][1],BLOCKX=blocks_[block_looper][0],BLOCKY=blocks_[block_looper][1];
int *number = NULL;
hipMalloc(&number, XSIZE*YSIZE);
unsigned int number_size = 1;
int iXSIZE= XSIZE;
int iYSIZE= YSIZE;
while(iXSIZE%BLOCKX!=0)
{
iXSIZE++;
}
while(iYSIZE%BLOCKY!=0)
{
iYSIZE++;
}
dim3 gridBlock(iXSIZE/BLOCKX, iYSIZE/BLOCKY);
dim3 threadBlock(BLOCKX, BLOCKY);
hipFree(0);hipLaunchKernelGGL((
RevealNumber), dim3(gridBlock),dim3(threadBlock), 0, 0, number,number_size);
hipDeviceSynchronize();
for (int loop_counter = 0; loop_counter < 10; ++loop_counter) {hipLaunchKernelGGL((
RevealNumber), dim3(gridBlock),dim3(threadBlock), 0, 0, number,number_size);
}
auto start = steady_clock::now();
for (int loop_counter = 0; loop_counter < 1000; loop_counter++) {hipLaunchKernelGGL((
RevealNumber), dim3(gridBlock),dim3(threadBlock), 0, 0, number,number_size);
}
auto end = steady_clock::now();
auto usecs = duration_cast<duration<float, microseconds::period> >(end - start);
cout <<'['<<usecs.count()<<','<<'('<<BLOCKX<<','<<BLOCKY<<')' << ','<<'('<<XSIZE<<','<<YSIZE<<')'<<']' << endl;
}
}} | 397ad7e03fefb390cfbae4a1fe48a0e6164224d7.cu | #include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <curand_kernel.h>
#include <stdlib.h>
#include <cuda.h>
#include <sys/time.h>
#include "RevealNumber.cu"
#include<chrono>
#include<iostream>
using namespace std;
using namespace std::chrono;
int blocks_[20][2] = {{8,8},{16,16},{24,24},{32,32},{1,64},{1,128},{1,192},{1,256},{1,320},{1,384},{1,448},{1,512},{1,576},{1,640},{1,704},{1,768},{1,832},{1,896},{1,960},{1,1024}};
int matrices_[7][2] = {{240,240},{496,496},{784,784},{1016,1016},{1232,1232},{1680,1680},{2024,2024}};
int main(int argc, char **argv) {
cudaSetDevice(0);
char* p;int matrix_len=strtol(argv[1], &p, 10);
for(int matrix_looper=0;matrix_looper<matrix_len;matrix_looper++){
for(int block_looper=0;block_looper<20;block_looper++){
int XSIZE=matrices_[matrix_looper][0],YSIZE=matrices_[matrix_looper][1],BLOCKX=blocks_[block_looper][0],BLOCKY=blocks_[block_looper][1];
int *number = NULL;
cudaMalloc(&number, XSIZE*YSIZE);
unsigned int number_size = 1;
int iXSIZE= XSIZE;
int iYSIZE= YSIZE;
while(iXSIZE%BLOCKX!=0)
{
iXSIZE++;
}
while(iYSIZE%BLOCKY!=0)
{
iYSIZE++;
}
dim3 gridBlock(iXSIZE/BLOCKX, iYSIZE/BLOCKY);
dim3 threadBlock(BLOCKX, BLOCKY);
cudaFree(0);
RevealNumber<<<gridBlock,threadBlock>>>(number,number_size);
cudaDeviceSynchronize();
for (int loop_counter = 0; loop_counter < 10; ++loop_counter) {
RevealNumber<<<gridBlock,threadBlock>>>(number,number_size);
}
auto start = steady_clock::now();
for (int loop_counter = 0; loop_counter < 1000; loop_counter++) {
RevealNumber<<<gridBlock,threadBlock>>>(number,number_size);
}
auto end = steady_clock::now();
auto usecs = duration_cast<duration<float, microseconds::period> >(end - start);
cout <<'['<<usecs.count()<<','<<'('<<BLOCKX<<','<<BLOCKY<<')' << ','<<'('<<XSIZE<<','<<YSIZE<<')'<<']' << endl;
}
}} |
4de380f507362dbe6cf09ff9fcd79b179c6f9627.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
// for printing arrays
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
// for min
#include <algorithm>
#include "util/cuda_wrap.h"
#include "fixnum_array.h"
namespace cuFIXNUM
{
// TODO: The only device function in this file is the dispatch kernel
// mechanism, which could arguably be placed elsewhere, thereby
// allowing this file to be compiled completely for the host.
// Notes: Read programming guide Section K.3
// - Can prefetch unified memory
// - Can advise on location of unified memory
// TODO: Can I use smart pointers? unique_ptr?
// TODO: Clean this up
namespace
{
typedef std::uint8_t byte;
template <typename T>
static byte *as_byte_ptr(T *ptr)
{
return reinterpret_cast<byte *>(ptr);
}
template <typename T>
static const byte *as_byte_ptr(const T *ptr)
{
return reinterpret_cast<const byte *>(ptr);
}
// TODO: refactor from word_fixnum.
template <typename T>
T ceilquo(T n, T d)
{
return (n + d - 1) / d;
}
} // namespace
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::wrap(const byte *ptr, size_t nelts)
{
fixnum_array *a = new fixnum_array;
a->nelts = nelts;
a->ptr = (fixnum *)ptr;
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::create(size_t nelts)
{
fixnum_array *a = new fixnum_array;
a->nelts = nelts;
if (nelts > 0)
{
size_t nbytes = nelts * fixnum::BYTES;
cuda_malloc_managed(&a->ptr, nbytes);
}
return a;
}
template <typename fixnum>
template <typename T>
fixnum_array<fixnum> *
fixnum_array<fixnum>::create(size_t nelts, T init)
{
fixnum_array *a = create(nelts);
byte *p = as_byte_ptr(a->ptr);
const byte *in = as_byte_ptr(&init);
byte elt[fixnum::BYTES];
memset(elt, 0, fixnum::BYTES);
std::copy(in, in + sizeof(T), elt);
for (uint32_t i = 0; i < nelts; ++i, p += fixnum::BYTES)
fixnum::from_bytes(p, elt, fixnum::BYTES);
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::create(const byte *data, size_t total_bytes, size_t bytes_per_elt)
{
// FIXME: Should handle this error more appropriately
if (total_bytes == 0 || bytes_per_elt == 0)
return nullptr;
size_t nelts = ceilquo(total_bytes, bytes_per_elt);
fixnum_array *a = create(nelts);
byte *p = as_byte_ptr(a->ptr);
const byte *d = data;
for (size_t i = 0; i < nelts; ++i)
{
fixnum::from_bytes(p, d, bytes_per_elt);
p += fixnum::BYTES;
d += bytes_per_elt;
}
return a;
}
// TODO: This doesn't belong here.
template <typename digit>
void rotate_array(digit *out, const digit *in, int nelts, int words_per_elt, int i)
{
if (i < 0)
{
int j = -i;
i += nelts * ceilquo(j, nelts);
assert(i >= 0 && i < nelts);
i = nelts - i;
}
else if (i >= nelts)
i %= nelts;
int pivot = i * words_per_elt;
int nwords = nelts * words_per_elt;
std::copy(in, in + nwords - pivot, out + pivot);
std::copy(in + nwords - pivot, in + nwords, out);
}
// TODO: Find a way to return a wrapper that just modifies the requested indices
// on the fly, rather than copying the whole array. Hard part will be making it
// work with map/dispatch.
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::rotate(int i)
{
fixnum_array *a = create(length());
byte *p = as_byte_ptr(a->ptr);
const byte *q = as_byte_ptr(ptr);
rotate_array(p, q, nelts, fixnum::BYTES, i);
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::repeat(int ntimes)
{
fixnum_array *a = create(length() * ntimes);
byte *p = as_byte_ptr(a->ptr);
const byte *q = as_byte_ptr(ptr);
int nbytes = nelts * fixnum::BYTES;
for (int i = 0; i < ntimes; ++i, p += nbytes)
std::copy(q, q + nbytes, p);
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::rotations(int ntimes)
{
fixnum_array *a = create(nelts * ntimes);
byte *p = as_byte_ptr(a->ptr);
const byte *q = as_byte_ptr(ptr);
int nbytes = nelts * fixnum::BYTES;
for (int i = 0; i < ntimes; ++i, p += nbytes)
rotate_array(p, q, nelts, fixnum::BYTES, i);
return a;
}
template <typename fixnum>
int fixnum_array<fixnum>::set(int idx, const byte *data, size_t nbytes)
{
// FIXME: Better error handling
if (idx < 0 || idx >= nelts)
return -1;
int off = idx * fixnum::BYTES;
const byte *q = as_byte_ptr(ptr);
return fixnum::from_bytes(q + off, data, nbytes);
}
template <typename fixnum>
fixnum_array<fixnum>::~fixnum_array()
{
if (nelts > 0)
cuda_free(ptr);
}
template <typename fixnum>
int fixnum_array<fixnum>::length() const
{
return nelts;
}
template <typename fixnum>
size_t
fixnum_array<fixnum>::retrieve_into(byte *dest, size_t dest_space, int idx) const
{
if (idx < 0 || idx > nelts)
{
// FIXME: This is not the right way to handle an "index out of
// bounds" error.
return 0;
}
const byte *q = as_byte_ptr(ptr);
return fixnum::to_bytes(dest, dest_space, q + idx * fixnum::BYTES);
}
// FIXME: Can return fewer than nelts elements.
template <typename fixnum>
void fixnum_array<fixnum>::retrieve_all(byte *dest, size_t dest_space, int *dest_nelts) const
{
const byte *p = as_byte_ptr(ptr);
byte *d = dest;
int max_dest_nelts = dest_space / fixnum::BYTES;
*dest_nelts = ::min(nelts, max_dest_nelts);
for (int i = 0; i < *dest_nelts; ++i)
{
fixnum::to_bytes(d, fixnum::BYTES, p);
p += fixnum::BYTES;
d += fixnum::BYTES;
}
}
namespace
{
std::string
fixnum_as_str(const uint8_t *fn, int nbytes)
{
std::ostringstream ss;
for (int i = nbytes - 1; i >= 0; --i)
{
// These IO manipulators are forgotten after each use;
// i.e. they don't apply to the next output operation (whether
// it be in the next loop iteration or in the conditional
// below.
ss << std::setfill('0') << std::setw(2) << std::hex;
ss << static_cast<int>(fn[i]);
if (i && !(i & 3))
ss << ' ';
}
return ss.str();
}
} // namespace
template <typename fixnum>
std::ostream &
operator<<(std::ostream &os, const fixnum_array<fixnum> *fn_arr)
{
constexpr int fn_bytes = fixnum::BYTES;
constexpr size_t bufsz = 4096;
uint8_t arr[bufsz];
int nelts;
fn_arr->retrieve_all(arr, bufsz, &nelts);
os << "( ";
if (nelts < fn_arr->length())
{
os << "insufficient space to retrieve array";
}
else if (nelts > 0)
{
os << fixnum_as_str(arr, fn_bytes);
for (int i = 1; i < nelts; ++i)
os << ", " << fixnum_as_str(arr + i * fn_bytes, fn_bytes);
}
os << " )" << std::flush;
return os;
}
template <template <typename> class Func, typename fixnum, typename... Args>
__global__ void
dispatch(int nelts, Args... args)
{
// Get the slot index for the current thread.
int blk_tid_offset = blockDim.x * blockIdx.x;
int tid_in_blk = threadIdx.x;
int idx = (blk_tid_offset + tid_in_blk) / fixnum::SLOT_WIDTH;
if (idx < nelts)
{
// TODO: Find a way to load each argument into a register before passing
// it to fn, and then unpack the return values where they belong. This
// will guarantee that all operations happen on registers, rather than
// inadvertently operating on memory.
Func<fixnum> fn;
// TODO: This offset calculation is entwined with fixnum layout and so
// belongs somewhere else.
int off = idx * fixnum::layout::WIDTH + fixnum::layout::laneIdx();
// TODO: This is hiding a sin against memory aliasing / management /
// type-safety.
fn(args[off]...);
}
}
template <typename fixnum>
template <template <typename> class Func, typename... Args>
void fixnum_array<fixnum>::map(Args... args)
{
// TODO: Set this to the number of threads on a single SM on the host GPU.
constexpr int BLOCK_SIZE = 192;
// FIXME: WARPSIZE should come from slot_layout
constexpr int WARPSIZE = 32;
// BLOCK_SIZE must be a multiple of warpSize
static_assert(!(BLOCK_SIZE % WARPSIZE),
"block size must be a multiple of warpSize");
int nelts = ::min({args->length()...});
constexpr int fixnums_per_block = BLOCK_SIZE / fixnum::SLOT_WIDTH;
// FIXME: nblocks could be too big for a single kernel call to handle
int nblocks = ceilquo(nelts, fixnums_per_block);
// nblocks > 0 iff nelts > 0
if (nblocks > 0)
{
hipStream_t stream;
cuda_check(hipStreamCreate(&stream), "create stream");
// cuda_stream_attach_mem(stream, src->ptr);
// cuda_stream_attach_mem(stream, ptr);
cuda_check(hipStreamSynchronize(stream), "stream sync");
hipLaunchKernelGGL(( dispatch<Func, fixnum>), dim3(nblocks), dim3(BLOCK_SIZE), 0, stream, nelts, args->ptr...);
cuda_check(hipPeekAtLastError(), "kernel invocation/run");
cuda_check(hipStreamSynchronize(stream), "stream sync");
cuda_check(hipStreamDestroy(stream), "stream destroy");
// FIXME: Only synchronize when retrieving data from array
cuda_device_synchronize();
}
}
template <template <typename> class Func, typename fixnum, typename... Args>
__global__ void
dispatchNelts(int nelts, int realNelts, Args... args)
{
// Get the slot index for the current thread.
int blk_tid_offset = blockDim.x * blockIdx.x;
int tid_in_blk = threadIdx.x;
int idx = (blk_tid_offset + tid_in_blk) / fixnum::SLOT_WIDTH;
if (idx < nelts)
{
// TODO: Find a way to load each argument into a register before passing
// it to fn, and then unpack the return values where they belong. This
// will guarantee that all operations happen on registers, rather than
// inadvertently operating on memory.
Func<fixnum> fn;
// TODO: This is hiding a sin against memory aliasing / management /
// type-safety.
fn(realNelts, args...);
}
}
template <typename fixnum>
template <template <typename> class Func, typename... Args>
void fixnum_array<fixnum>::mapNoSync(hipStream_t stream, int realNelts, Args... args)
{
// TODO: Set this to the number of threads on a single SM on the host GPU.
constexpr int BLOCK_SIZE = 192; //96;
// FIXME: WARPSIZE should come from slot_layout
constexpr int WARPSIZE = 32;
// BLOCK_SIZE must be a multiple of warpSize
static_assert(!(BLOCK_SIZE % WARPSIZE),
"block size must be a multiple of warpSize");
int nelts = ::min({args->length()...});
constexpr int fixnums_per_block = BLOCK_SIZE / fixnum::SLOT_WIDTH;
// FIXME: nblocks could be too big for a single kernel call to handle
int nblocks = ceilquo(nelts, fixnums_per_block);
// nblocks > 0 iff nelts > 0
if (nblocks > 0)
{
hipLaunchKernelGGL(( dispatchNelts<Func, fixnum>), dim3(nblocks), dim3(BLOCK_SIZE), 0, stream, nelts, realNelts, args->ptr...);
}
}
} // End namespace cuFIXNUM
| 4de380f507362dbe6cf09ff9fcd79b179c6f9627.cu | // for printing arrays
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
// for min
#include <algorithm>
#include "util/cuda_wrap.h"
#include "fixnum_array.h"
namespace cuFIXNUM
{
// TODO: The only device function in this file is the dispatch kernel
// mechanism, which could arguably be placed elsewhere, thereby
// allowing this file to be compiled completely for the host.
// Notes: Read programming guide Section K.3
// - Can prefetch unified memory
// - Can advise on location of unified memory
// TODO: Can I use smart pointers? unique_ptr?
// TODO: Clean this up
namespace
{
typedef std::uint8_t byte;
template <typename T>
static byte *as_byte_ptr(T *ptr)
{
return reinterpret_cast<byte *>(ptr);
}
template <typename T>
static const byte *as_byte_ptr(const T *ptr)
{
return reinterpret_cast<const byte *>(ptr);
}
// TODO: refactor from word_fixnum.
template <typename T>
T ceilquo(T n, T d)
{
return (n + d - 1) / d;
}
} // namespace
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::wrap(const byte *ptr, size_t nelts)
{
fixnum_array *a = new fixnum_array;
a->nelts = nelts;
a->ptr = (fixnum *)ptr;
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::create(size_t nelts)
{
fixnum_array *a = new fixnum_array;
a->nelts = nelts;
if (nelts > 0)
{
size_t nbytes = nelts * fixnum::BYTES;
cuda_malloc_managed(&a->ptr, nbytes);
}
return a;
}
template <typename fixnum>
template <typename T>
fixnum_array<fixnum> *
fixnum_array<fixnum>::create(size_t nelts, T init)
{
fixnum_array *a = create(nelts);
byte *p = as_byte_ptr(a->ptr);
const byte *in = as_byte_ptr(&init);
byte elt[fixnum::BYTES];
memset(elt, 0, fixnum::BYTES);
std::copy(in, in + sizeof(T), elt);
for (uint32_t i = 0; i < nelts; ++i, p += fixnum::BYTES)
fixnum::from_bytes(p, elt, fixnum::BYTES);
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::create(const byte *data, size_t total_bytes, size_t bytes_per_elt)
{
// FIXME: Should handle this error more appropriately
if (total_bytes == 0 || bytes_per_elt == 0)
return nullptr;
size_t nelts = ceilquo(total_bytes, bytes_per_elt);
fixnum_array *a = create(nelts);
byte *p = as_byte_ptr(a->ptr);
const byte *d = data;
for (size_t i = 0; i < nelts; ++i)
{
fixnum::from_bytes(p, d, bytes_per_elt);
p += fixnum::BYTES;
d += bytes_per_elt;
}
return a;
}
// TODO: This doesn't belong here.
template <typename digit>
void rotate_array(digit *out, const digit *in, int nelts, int words_per_elt, int i)
{
if (i < 0)
{
int j = -i;
i += nelts * ceilquo(j, nelts);
assert(i >= 0 && i < nelts);
i = nelts - i;
}
else if (i >= nelts)
i %= nelts;
int pivot = i * words_per_elt;
int nwords = nelts * words_per_elt;
std::copy(in, in + nwords - pivot, out + pivot);
std::copy(in + nwords - pivot, in + nwords, out);
}
// TODO: Find a way to return a wrapper that just modifies the requested indices
// on the fly, rather than copying the whole array. Hard part will be making it
// work with map/dispatch.
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::rotate(int i)
{
fixnum_array *a = create(length());
byte *p = as_byte_ptr(a->ptr);
const byte *q = as_byte_ptr(ptr);
rotate_array(p, q, nelts, fixnum::BYTES, i);
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::repeat(int ntimes)
{
fixnum_array *a = create(length() * ntimes);
byte *p = as_byte_ptr(a->ptr);
const byte *q = as_byte_ptr(ptr);
int nbytes = nelts * fixnum::BYTES;
for (int i = 0; i < ntimes; ++i, p += nbytes)
std::copy(q, q + nbytes, p);
return a;
}
template <typename fixnum>
fixnum_array<fixnum> *
fixnum_array<fixnum>::rotations(int ntimes)
{
fixnum_array *a = create(nelts * ntimes);
byte *p = as_byte_ptr(a->ptr);
const byte *q = as_byte_ptr(ptr);
int nbytes = nelts * fixnum::BYTES;
for (int i = 0; i < ntimes; ++i, p += nbytes)
rotate_array(p, q, nelts, fixnum::BYTES, i);
return a;
}
template <typename fixnum>
int fixnum_array<fixnum>::set(int idx, const byte *data, size_t nbytes)
{
// FIXME: Better error handling
if (idx < 0 || idx >= nelts)
return -1;
int off = idx * fixnum::BYTES;
const byte *q = as_byte_ptr(ptr);
return fixnum::from_bytes(q + off, data, nbytes);
}
template <typename fixnum>
fixnum_array<fixnum>::~fixnum_array()
{
if (nelts > 0)
cuda_free(ptr);
}
template <typename fixnum>
int fixnum_array<fixnum>::length() const
{
return nelts;
}
template <typename fixnum>
size_t
fixnum_array<fixnum>::retrieve_into(byte *dest, size_t dest_space, int idx) const
{
if (idx < 0 || idx > nelts)
{
// FIXME: This is not the right way to handle an "index out of
// bounds" error.
return 0;
}
const byte *q = as_byte_ptr(ptr);
return fixnum::to_bytes(dest, dest_space, q + idx * fixnum::BYTES);
}
// FIXME: Can return fewer than nelts elements.
template <typename fixnum>
void fixnum_array<fixnum>::retrieve_all(byte *dest, size_t dest_space, int *dest_nelts) const
{
const byte *p = as_byte_ptr(ptr);
byte *d = dest;
int max_dest_nelts = dest_space / fixnum::BYTES;
*dest_nelts = std::min(nelts, max_dest_nelts);
for (int i = 0; i < *dest_nelts; ++i)
{
fixnum::to_bytes(d, fixnum::BYTES, p);
p += fixnum::BYTES;
d += fixnum::BYTES;
}
}
namespace
{
std::string
fixnum_as_str(const uint8_t *fn, int nbytes)
{
std::ostringstream ss;
for (int i = nbytes - 1; i >= 0; --i)
{
// These IO manipulators are forgotten after each use;
// i.e. they don't apply to the next output operation (whether
// it be in the next loop iteration or in the conditional
// below.
ss << std::setfill('0') << std::setw(2) << std::hex;
ss << static_cast<int>(fn[i]);
if (i && !(i & 3))
ss << ' ';
}
return ss.str();
}
} // namespace
template <typename fixnum>
std::ostream &
operator<<(std::ostream &os, const fixnum_array<fixnum> *fn_arr)
{
constexpr int fn_bytes = fixnum::BYTES;
constexpr size_t bufsz = 4096;
uint8_t arr[bufsz];
int nelts;
fn_arr->retrieve_all(arr, bufsz, &nelts);
os << "( ";
if (nelts < fn_arr->length())
{
os << "insufficient space to retrieve array";
}
else if (nelts > 0)
{
os << fixnum_as_str(arr, fn_bytes);
for (int i = 1; i < nelts; ++i)
os << ", " << fixnum_as_str(arr + i * fn_bytes, fn_bytes);
}
os << " )" << std::flush;
return os;
}
template <template <typename> class Func, typename fixnum, typename... Args>
__global__ void
dispatch(int nelts, Args... args)
{
// Get the slot index for the current thread.
int blk_tid_offset = blockDim.x * blockIdx.x;
int tid_in_blk = threadIdx.x;
int idx = (blk_tid_offset + tid_in_blk) / fixnum::SLOT_WIDTH;
if (idx < nelts)
{
// TODO: Find a way to load each argument into a register before passing
// it to fn, and then unpack the return values where they belong. This
// will guarantee that all operations happen on registers, rather than
// inadvertently operating on memory.
Func<fixnum> fn;
// TODO: This offset calculation is entwined with fixnum layout and so
// belongs somewhere else.
int off = idx * fixnum::layout::WIDTH + fixnum::layout::laneIdx();
// TODO: This is hiding a sin against memory aliasing / management /
// type-safety.
fn(args[off]...);
}
}
template <typename fixnum>
template <template <typename> class Func, typename... Args>
void fixnum_array<fixnum>::map(Args... args)
{
// TODO: Set this to the number of threads on a single SM on the host GPU.
constexpr int BLOCK_SIZE = 192;
// FIXME: WARPSIZE should come from slot_layout
constexpr int WARPSIZE = 32;
// BLOCK_SIZE must be a multiple of warpSize
static_assert(!(BLOCK_SIZE % WARPSIZE),
"block size must be a multiple of warpSize");
int nelts = std::min({args->length()...});
constexpr int fixnums_per_block = BLOCK_SIZE / fixnum::SLOT_WIDTH;
// FIXME: nblocks could be too big for a single kernel call to handle
int nblocks = ceilquo(nelts, fixnums_per_block);
// nblocks > 0 iff nelts > 0
if (nblocks > 0)
{
cudaStream_t stream;
cuda_check(cudaStreamCreate(&stream), "create stream");
// cuda_stream_attach_mem(stream, src->ptr);
// cuda_stream_attach_mem(stream, ptr);
cuda_check(cudaStreamSynchronize(stream), "stream sync");
dispatch<Func, fixnum><<<nblocks, BLOCK_SIZE, 0, stream>>>(nelts, args->ptr...);
cuda_check(cudaPeekAtLastError(), "kernel invocation/run");
cuda_check(cudaStreamSynchronize(stream), "stream sync");
cuda_check(cudaStreamDestroy(stream), "stream destroy");
// FIXME: Only synchronize when retrieving data from array
cuda_device_synchronize();
}
}
template <template <typename> class Func, typename fixnum, typename... Args>
__global__ void
dispatchNelts(int nelts, int realNelts, Args... args)
{
// Get the slot index for the current thread.
int blk_tid_offset = blockDim.x * blockIdx.x;
int tid_in_blk = threadIdx.x;
int idx = (blk_tid_offset + tid_in_blk) / fixnum::SLOT_WIDTH;
if (idx < nelts)
{
// TODO: Find a way to load each argument into a register before passing
// it to fn, and then unpack the return values where they belong. This
// will guarantee that all operations happen on registers, rather than
// inadvertently operating on memory.
Func<fixnum> fn;
// TODO: This is hiding a sin against memory aliasing / management /
// type-safety.
fn(realNelts, args...);
}
}
template <typename fixnum>
template <template <typename> class Func, typename... Args>
void fixnum_array<fixnum>::mapNoSync(cudaStream_t stream, int realNelts, Args... args)
{
// TODO: Set this to the number of threads on a single SM on the host GPU.
constexpr int BLOCK_SIZE = 192; //96;
// FIXME: WARPSIZE should come from slot_layout
constexpr int WARPSIZE = 32;
// BLOCK_SIZE must be a multiple of warpSize
static_assert(!(BLOCK_SIZE % WARPSIZE),
"block size must be a multiple of warpSize");
int nelts = std::min({args->length()...});
constexpr int fixnums_per_block = BLOCK_SIZE / fixnum::SLOT_WIDTH;
// FIXME: nblocks could be too big for a single kernel call to handle
int nblocks = ceilquo(nelts, fixnums_per_block);
// nblocks > 0 iff nelts > 0
if (nblocks > 0)
{
dispatchNelts<Func, fixnum><<<nblocks, BLOCK_SIZE, 0, stream>>>(nelts, realNelts, args->ptr...);
}
}
} // End namespace cuFIXNUM
|
a199a37020607c630203a24186ad35aae5e164a4.hip | // !!! This is a file automatically generated by hipify!!!
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
#include <hip/hip_runtime_api.h>
#include <device_launch_parameters.h>
#include <mma.h>
#include <common.hpp>
#include <layers/interaction_layer.hpp>
#include <type_traits>
#include <utils.hpp>
#ifndef NDEBUG
#include <iostream>
#endif
namespace HugeCTR {
namespace {
template <uint x>
struct Log2 {
static constexpr uint value = 1 + Log2<x / 2>::value;
};
template <>
struct Log2<1> {
static constexpr uint value = 0;
};
struct __align__(8) half4 {
half2 vals[2];
};
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint M_BLOCKS, uint K_BLOCKS,
uint SMEM_STRIDE, uint SMEM_STRIDE_ACC, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2,
uint TILE_DIM, uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__ void dotBasedInteractFwdKernelNonAligned(
const __half *__restrict bottom_mlp_input, const __half *__restrict emb_input,
__half *__restrict output, uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding, uint smem_elems_per_warp,
uint smem_rows_per_warp, uint output_size, uint num_row_steps, uint num_col_steps) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
int sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
int lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
extern __shared__ half shmem_dynamic[];
half *shmem = shmem_dynamic + (warp_id * smem_elems_per_warp);
// const half *sample_input = input + num_rows * num_cols * sample_id;
const half *sample_bottom_mlp_input = bottom_mlp_input + num_cols * sample_id;
const half *sample_emp_input = emb_input + (num_rows - 1) * num_cols * sample_id;
const half *sample_input = sample_bottom_mlp_input;
// for (uint i = 0; i < num_rows; ++i, sample_input += num_cols) {
for (uint i = 0; i < num_rows; ++i) {
for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
(shmem + i * SMEM_STRIDE)[idx] = sample_input[idx];
}
sample_input = (i == 0) ? sample_emp_input : (sample_input + num_cols);
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
for (int i = 0; i < num_rows; ++i) {
(shmem + i * SMEM_STRIDE)[idx] = __float2half(0);
}
}
half4 zeros;
zeros.vals[0].x = __float2half(0);
zeros.vals[0].y = __float2half(0);
zeros.vals[1].x = __float2half(0);
zeros.vals[1].y = __float2half(0);
if (lane_id < (num_cols_after_padding >> 2)) {
for (int i = num_rows; i < num_rows_after_padding; i++) {
((half4 *)(shmem + i * SMEM_STRIDE))[lane_id] = zeros;
}
}
__syncwarp();
half *gmem_output = output + output_size * sample_id;
for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
gmem_output[idx] = shmem[idx];
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[M_BLOCKS][M_BLOCKS];
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::fill_fragment(acc[i][j], 0);
}
}
for (int k_step = 0; k_step < num_col_steps; k_step++) {
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[M_BLOCKS];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::col_major>
b[M_BLOCKS];
for (int j = 0; j < M_BLOCKS; j++) {
int base_row = (j < M_BLOCKS - 1) ? j * 16 : smem_rows_per_warp - 16;
const half *tile_ptr = shmem + (base_row * SMEM_STRIDE + k_step * 16);
nvcuda::wmma::load_matrix_sync(a[j], tile_ptr, SMEM_STRIDE);
nvcuda::wmma::load_matrix_sync(b[j], tile_ptr, SMEM_STRIDE);
}
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::mma_sync(acc[i][j], a[i], b[j], acc[i][j]);
}
}
}
float *shmem_store = reinterpret_cast<float *>(shmem);
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
float *tile_ptr = shmem_store + (i * 16 * SMEM_STRIDE_ACC + j * 16);
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i][j], SMEM_STRIDE_ACC,
nvcuda::wmma::mem_row_major);
}
}
half *gmem_interact_output = gmem_output + num_cols;
int lastRowBlockOffset = M_BLOCKS * 16 - smem_rows_per_warp;
int srcLine = 0;
for (int i = 0; i < num_rows; ++i, ++srcLine) {
if (i == ((M_BLOCKS - 1) * 16)) {
srcLine += lastRowBlockOffset;
}
if (lane_id < i) {
uint offset = (i * (i - 1)) >> 1;
gmem_interact_output[offset + lane_id] =
__float2half(shmem_store[srcLine * SMEM_STRIDE_ACC + lane_id]);
}
}
// Padding
if (lane_id == 0) {
gmem_output[output_size - 1] = __float2half(0);
}
#else
#warning "dotBasedInteractFwdKernelNonAligned is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint M_BLOCKS, uint K_BLOCKS,
uint SMEM_STRIDE, uint SMEM_STRIDE_ACC, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2,
uint TILE_DIM, uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__
void dotBasedInteractFwdKernel(const __half *__restrict bottom_mlp_input,
const __half *__restrict emb_input, __half *__restrict output,
uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding,
uint smem_elems_per_warp, uint smem_rows_per_warp,
uint output_size, uint num_row_steps, uint num_col_steps) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
int sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
int lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
extern __shared__ half shmem_dynamic[];
half *shmem = shmem_dynamic + (warp_id * smem_elems_per_warp);
// const half *sample_input = input + num_rows * num_cols * sample_id;
const half *sample_bottom_mlp_input = bottom_mlp_input + num_cols * sample_id;
const half *sample_emp_input = emb_input + (num_rows - 1) * num_cols * sample_id;
const half *sample_input = sample_bottom_mlp_input;
if (lane_id < (num_cols >> 2)) {
// for (int i = 0; i < num_rows; ++i, sample_input += num_cols) {
for (int i = 0; i < num_rows; ++i) {
((float2 *)(shmem + i * SMEM_STRIDE))[lane_id] = ((float2 *)sample_input)[lane_id];
sample_input = (i == 0) ? sample_emp_input : (sample_input + num_cols);
}
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
for (int i = 0; i < num_rows; ++i) {
(shmem + i * SMEM_STRIDE)[idx] = __float2half(0);
}
}
half4 zeros;
zeros.vals[0].x = __float2half(0);
zeros.vals[0].y = __float2half(0);
zeros.vals[1].x = __float2half(0);
zeros.vals[1].y = __float2half(0);
if (lane_id < (num_cols_after_padding >> 2)) {
for (int i = num_rows; i < num_rows_after_padding; i++) {
((half4 *)(shmem + i * SMEM_STRIDE))[lane_id] = zeros;
}
}
__syncwarp();
half *gmem_output = output + output_size * sample_id;
if (lane_id < (num_cols >> 2)) {
((float2 *)gmem_output)[lane_id] = ((float2 *)shmem)[lane_id];
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[M_BLOCKS][M_BLOCKS];
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::fill_fragment(acc[i][j], 0);
}
}
for (int k_step = 0; k_step < num_col_steps; k_step++) {
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[M_BLOCKS];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::col_major>
b[M_BLOCKS];
for (int j = 0; j < M_BLOCKS; j++) {
int base_row = (j < M_BLOCKS - 1) ? j * 16 : smem_rows_per_warp - 16;
const half *tile_ptr = shmem + (base_row * SMEM_STRIDE + k_step * 16);
nvcuda::wmma::load_matrix_sync(a[j], tile_ptr, SMEM_STRIDE);
nvcuda::wmma::load_matrix_sync(b[j], tile_ptr, SMEM_STRIDE);
}
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::mma_sync(acc[i][j], a[i], b[j], acc[i][j]);
}
}
}
float *shmem_store = reinterpret_cast<float *>(shmem);
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
float *tile_ptr = shmem_store + (i * 16 * SMEM_STRIDE_ACC + j * 16);
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i][j], SMEM_STRIDE_ACC,
nvcuda::wmma::mem_row_major);
}
}
half *gmem_interact_output = gmem_output + num_cols;
int lastRowBlockOffset = M_BLOCKS * 16 - smem_rows_per_warp;
int srcLine = 0;
for (int i = 0; i < num_rows; ++i, ++srcLine) {
if (i == ((M_BLOCKS - 1) * 16)) {
srcLine += lastRowBlockOffset;
}
if (lane_id < i) {
uint offset = (i * (i - 1)) >> 1;
gmem_interact_output[offset + lane_id] =
__float2half(shmem_store[srcLine * SMEM_STRIDE_ACC + lane_id]);
}
}
// Padding
if (lane_id == 0) {
gmem_output[output_size - 1] = __float2half(0);
}
#else
#warning "dotBasedInteractFwdKernel is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint ROW_TILES_PER_STEP,
uint COL_TILES_PER_STEP, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2, uint TILE_DIM,
uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__ void dotBasedInteractBwdKernelNonAligned(
const __half *__restrict upstream_grad, half __restrict *bottom_mlp_grad,
half __restrict *emb_grad, uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding, uint sample_size,
uint interaction_ugrad_size, uint interaction_ugrad_size_with_padding,
uint interaction_ugrad_2D_size_elems, uint interaction_ugrad_2D_stride, uint input_size_elems,
uint input_stride, uint num_row_steps, uint num_col_steps, uint row_tiles_per_step,
uint shared_mem_per_warp_size_byte) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
extern __shared__ half shared_mem[];
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
uint sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
uint lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
// ">> 1" to convert to half pointer
uint smem_warp_offset = warp_id * (shared_mem_per_warp_size_byte >> 1);
half *smem_in = &shared_mem[smem_warp_offset];
half *smem_temp = &shared_mem[smem_warp_offset + input_size_elems];
float *smem_out = reinterpret_cast<float *>(smem_temp);
// Global memory pointers for the current sample
// Input
// uint gmem_input_sample_offset = sample_id * sample_size;
// const half *gmem_input = &input[gmem_input_sample_offset];
uint gmem_bottom_mlp_input_sample_offset = sample_id * num_cols;
uint gmem_emb_input_sample_offset = sample_id * (num_rows - 1) * num_cols;
const half *gmem_bottom_mlp_input = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
const half *gmem_emb_input = &emb_grad[gmem_emb_input_sample_offset];
// Interaction Gradient
// const uint &gmem_grad_sample_offset = gmem_input_sample_offset;
// half *gmem_grad = &grad[gmem_grad_sample_offset];
half *gmem_bottom_mlp_grad = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
half *gmem_emb_grad = &emb_grad[gmem_emb_input_sample_offset];
// Bottom MLP gradient
// half *gmem_mlp_grad = &bottom_mlp_grad[sample_id * num_cols];
// Upstream gradient vector
uint gmem_ugrad_sample_offset = sample_id * (num_cols + interaction_ugrad_size_with_padding);
const half *gmem_ugrad = &upstream_grad[gmem_ugrad_sample_offset];
// Upstream gradient vector for interactions
const half *gmem_ugrad_interactions = &gmem_ugrad[num_cols];
// upstream grad -> shared memory (place in input section temporarily)
#pragma unroll
for (uint idx = lane_id; idx < interaction_ugrad_size; idx += THREADS_IN_WARP) {
smem_in[idx] = gmem_ugrad_interactions[idx];
}
__syncwarp();
// Form the 2D ugrad matrix.
if (lane_id < num_rows_after_padding) {
uint ugrad_flat_index = ((lane_id * (lane_id - 1)) >> 1);
uint ugrad_offset_1 = lane_id * interaction_ugrad_2D_stride;
for (uint row = 0; row < num_rows; row++) {
half ugrad_val = __float2half(0.0f);
if (row < lane_id && lane_id < num_rows) {
ugrad_val = smem_in[ugrad_flat_index + row];
smem_temp[ugrad_offset_1 + row] = ugrad_val;
}
if (row <= lane_id && lane_id < num_rows_after_padding) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = ugrad_val;
}
}
for (uint row = num_rows; row < num_rows_after_padding; row++) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = __float2half(0.0f);
}
}
__syncwarp();
// Input -> Shared Memory
for (uint row = 0; row < num_rows; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
// const half *gmem_row_ptr = &gmem_input[row * num_cols];
const half *gmem_row_ptr =
(row == 0) ? gmem_bottom_mlp_input : &gmem_emb_input[(row - 1) * num_cols];
for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
smem_row_ptr[idx] = gmem_row_ptr[idx];
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
smem_row_ptr[idx] = __float2half(0);
}
}
#pragma unroll 2
for (uint row = num_rows; row < num_rows_after_padding; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
for (uint idx = lane_id; idx < num_cols_after_padding; idx += THREADS_IN_WARP) {
smem_row_ptr[idx] = __float2half(0);
}
}
__syncwarp();
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[ROW_TILES_PER_STEP][ROW_TILES_PER_STEP];
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
const half *tile_ptr = smem_temp + ((i * interaction_ugrad_2D_stride + j) << TILE_DIM_LOG_2);
nvcuda::wmma::load_matrix_sync(a[i][j], tile_ptr, interaction_ugrad_2D_stride);
}
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[ROW_TILES_PER_STEP];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
b[ROW_TILES_PER_STEP];
for (int col_step = 0; col_step < num_col_steps; col_step++) {
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
const half *tile_ptr = smem_in + ((i * input_stride + col_step) << TILE_DIM_LOG_2);
nvcuda::wmma::fill_fragment(acc[i], 0);
nvcuda::wmma::load_matrix_sync(b[i], tile_ptr, input_stride);
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
nvcuda::wmma::mma_sync(acc[i], a[i][j], b[j], acc[i]);
}
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
float *tile_ptr = smem_out + i * TILE_DIM * TILE_DIM;
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i], TILE_DIM, nvcuda::wmma::mem_row_major);
}
__syncwarp();
uint gmem_grad_col = (col_step << TILE_DIM_LOG_2) + lane_id;
if (gmem_grad_col < num_cols) {
for (uint i = 0; i < num_rows; i++) {
// gmem_grad[i * num_cols + gmem_grad_col] = __float2half(smem_out[(i << TILE_DIM_LOG_2) +
// lane_id]);
half *gmem_grad = (i == 0) ? gmem_bottom_mlp_grad : gmem_emb_grad;
uint idx = (i == 0) ? gmem_grad_col : ((i - 1) * num_cols + gmem_grad_col);
half val = __float2half(smem_out[(i << TILE_DIM_LOG_2) + lane_id]);
gmem_grad[idx] = (i == 0) ? (val + gmem_ugrad[idx]) : val;
}
}
}
// for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
// gmem_mlp_grad[idx] = gmem_ugrad[idx];
// }
#else
#warning "dotBasedInteractBwdKernelNonAligned is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint ROW_TILES_PER_STEP,
uint COL_TILES_PER_STEP, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2, uint TILE_DIM,
uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__
void dotBasedInteractBwdKernel(const __half *__restrict upstream_grad,
half __restrict *bottom_mlp_grad, half __restrict *emb_grad,
uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding,
uint sample_size, uint interaction_ugrad_size,
uint interaction_ugrad_size_with_padding,
uint interaction_ugrad_2D_size_elems,
uint interaction_ugrad_2D_stride, uint input_size_elems,
uint input_stride, uint num_row_steps, uint num_col_steps,
uint row_tiles_per_step, uint shared_mem_per_warp_size_byte) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
extern __shared__ half shared_mem[];
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
uint sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
uint lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
// ">> 1" to convert to half pointer
uint smem_warp_offset = warp_id * (shared_mem_per_warp_size_byte >> 1);
half *smem_in = &shared_mem[smem_warp_offset];
half *smem_temp = &shared_mem[smem_warp_offset + input_size_elems];
float *smem_out = reinterpret_cast<float *>(smem_temp);
// Global memory pointers for the current sample
// Input
// uint gmem_input_sample_offset = sample_id * sample_size;
// const half *gmem_input = &input[gmem_input_sample_offset];
uint gmem_bottom_mlp_input_sample_offset = sample_id * num_cols;
uint gmem_emb_input_sample_offset = sample_id * (num_rows - 1) * num_cols;
const half *gmem_bottom_mlp_input = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
const half *gmem_emb_input = &emb_grad[gmem_emb_input_sample_offset];
// Interaction Gradient
// const uint &gmem_grad_sample_offset = gmem_input_sample_offset;
// half *gmem_grad = &grad[gmem_grad_sample_offset];
half *gmem_bottom_mlp_grad = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
half *gmem_emb_grad = &emb_grad[gmem_emb_input_sample_offset];
// Bottom MLP gradient
// half *gmem_mlp_grad = &bottom_mlp_grad[sample_id * num_cols];
// Upstream gradient vector
uint gmem_ugrad_sample_offset = sample_id * (num_cols + interaction_ugrad_size_with_padding);
const half *gmem_ugrad = &upstream_grad[gmem_ugrad_sample_offset];
// Upstream gradient vector for interactions
const half *gmem_ugrad_interactions = &gmem_ugrad[num_cols];
// upstream grad -> shared memory (place in input section temporarily)
#pragma unroll
for (uint idx = lane_id; idx < (interaction_ugrad_size >> 3); idx += THREADS_IN_WARP) {
((float4 *)smem_in)[idx] = ((float4 *)gmem_ugrad_interactions)[idx];
}
uint offset = (interaction_ugrad_size >> 3) << 3;
for (uint idx = lane_id + offset; idx < interaction_ugrad_size; idx += THREADS_IN_WARP) {
smem_in[idx] = gmem_ugrad_interactions[idx];
}
__syncwarp();
// Form the 2D ugrad matrix.
if (lane_id < num_rows_after_padding) {
uint ugrad_flat_index = ((lane_id * (lane_id - 1)) >> 1);
uint ugrad_offset_1 = lane_id * interaction_ugrad_2D_stride;
for (uint row = 0; row < num_rows; row++) {
half ugrad_val = __float2half(0.0f);
if (row < lane_id && lane_id < num_rows) {
ugrad_val = smem_in[ugrad_flat_index + row];
smem_temp[ugrad_offset_1 + row] = ugrad_val;
}
if (row <= lane_id && lane_id < num_rows_after_padding) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = ugrad_val;
}
}
for (uint row = num_rows; row < num_rows_after_padding; row++) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = __float2half(0.0f);
}
}
__syncwarp();
// Input -> Shared Memory
if (lane_id < (num_cols >> 2)) {
for (uint row = 0; row < num_rows; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
// const half *gmem_row_ptr = &gmem_input[row * num_cols];
const half *gmem_row_ptr =
(row == 0) ? gmem_bottom_mlp_input : &gmem_emb_input[(row - 1) * num_cols];
((float2 *)smem_row_ptr)[lane_id] = ((float2 *)gmem_row_ptr)[lane_id];
}
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
for (uint row = 0; row < num_rows; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
smem_row_ptr[idx] = __float2half(0);
}
}
half4 zeros;
zeros.vals[0].x = __float2half(0);
zeros.vals[0].y = __float2half(0);
zeros.vals[1].x = __float2half(0);
zeros.vals[1].y = __float2half(0);
if (lane_id < (num_cols_after_padding >> 2)) {
#pragma unroll 2
for (uint row = num_rows; row < num_rows_after_padding; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
((half4 *)smem_row_ptr)[lane_id] = zeros;
}
}
__syncwarp();
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[ROW_TILES_PER_STEP][ROW_TILES_PER_STEP];
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
const half *tile_ptr = smem_temp + ((i * interaction_ugrad_2D_stride + j) << TILE_DIM_LOG_2);
nvcuda::wmma::load_matrix_sync(a[i][j], tile_ptr, interaction_ugrad_2D_stride);
}
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[ROW_TILES_PER_STEP];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
b[ROW_TILES_PER_STEP];
for (int col_step = 0; col_step < num_col_steps; col_step++) {
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
const half *tile_ptr = smem_in + ((i * input_stride + col_step) << TILE_DIM_LOG_2);
nvcuda::wmma::fill_fragment(acc[i], 0);
nvcuda::wmma::load_matrix_sync(b[i], tile_ptr, input_stride);
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
nvcuda::wmma::mma_sync(acc[i], a[i][j], b[j], acc[i]);
}
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
float *tile_ptr = smem_out + i * TILE_DIM * TILE_DIM;
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i], TILE_DIM, nvcuda::wmma::mem_row_major);
}
__syncwarp();
uint gmem_grad_col_base = (col_step << TILE_DIM_LOG_2);
uint gmem_grad_col = gmem_grad_col_base + lane_id;
if (gmem_grad_col < num_cols) {
if (lane_id < 8) {
((__half2 *)(gmem_bottom_mlp_grad + gmem_grad_col_base))[lane_id] =
__hadd2(__float22half2_rn(((float2 *)smem_out)[lane_id]),
((__half2 *)(gmem_ugrad + gmem_grad_col_base))[lane_id]);
}
for (uint i = 0; i < num_rows - 1; i++) {
half val = __float2half(smem_out[((i + 1) << TILE_DIM_LOG_2) + lane_id]);
gmem_emb_grad[i * num_cols + gmem_grad_col] = val;
}
}
}
#else
#warning "dotBasedInteractBwdKernel is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
inline void dotBasedInteractFwd(const void *bottom_mlp_input, const void *emb_input, void *output,
uint batch_size, uint num_rows, uint num_cols,
hipStream_t stream) {
const uint kWarpSize = 32;
const uint kWarpSizeLog2 = Log2<kWarpSize>::value;
const uint kTileDim = 16;
const uint kTileDimLog2 = Log2<kTileDim>::value;
const uint warps_per_threadblock = 4;
const uint threadblock_size = warps_per_threadblock * 32;
const uint kPaddingSize = 1;
const uint kRowTilesPerStep = 2;
const uint kColTilesPerStep = 1;
// num tiles
uint num_row_tiles = (num_rows + kTileDim - 1) >> kTileDimLog2;
uint num_col_tiles = (num_cols + kTileDim - 1) >> kTileDimLog2;
// number of rows and columns after padding
uint num_rows_after_padding = kTileDim << 1;
uint num_cols_after_padding = num_col_tiles << kTileDimLog2;
uint num_row_steps = num_row_tiles / kRowTilesPerStep;
uint num_col_steps = num_col_tiles / kColTilesPerStep;
const uint K_BLOCKS = 8;
const uint M_BLOCKS = 2;
const uint SKEW_HALF = ((K_BLOCKS % 2) == 0) ? 8 : 0;
const uint SMEM_STRIDE = (K_BLOCKS * 16 + SKEW_HALF);
// multiple of 2 to guarantee 256-bit alignment for start of the row, at least 16 to safeload a
// tile
const uint smem_rows_per_warp = M_BLOCKS << 4;
const uint smem_elems_per_warp_mat = smem_rows_per_warp * SMEM_STRIDE;
const uint SKEW_HALF_ACC = ((M_BLOCKS % 2) == 0) ? 8 : 0;
const uint SMEM_STRIDE_ACC = (M_BLOCKS * 16 + SKEW_HALF_ACC);
const uint smem_elems_per_warp_acc = M_BLOCKS * 16 * SMEM_STRIDE_ACC * 2; // output in FP32
const uint smem_elems_per_warp = (smem_elems_per_warp_mat > smem_elems_per_warp_acc)
? smem_elems_per_warp_mat
: smem_elems_per_warp_acc;
uint output_size = num_cols + (num_rows * (num_rows - 1) >> 1) + kPaddingSize;
bool float4_predicate = !((num_cols & 7) || (output_size & 7));
if (float4_predicate) {
hipLaunchKernelGGL(( dotBasedInteractFwdKernel<warps_per_threadblock, threadblock_size, M_BLOCKS, K_BLOCKS,
SMEM_STRIDE, SMEM_STRIDE_ACC, kWarpSize, kWarpSizeLog2, kTileDim,
kTileDimLog2>)
, dim3((batch_size + warps_per_threadblock - 1) / warps_per_threadblock), dim3(threadblock_size),
warps_per_threadblock * smem_elems_per_warp * sizeof(__half), stream,
(const __half *)bottom_mlp_input, (const __half *)emb_input, (half *)output, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, smem_elems_per_warp,
smem_rows_per_warp, output_size, num_row_steps, num_col_steps);
} else {
hipLaunchKernelGGL(( dotBasedInteractFwdKernelNonAligned<warps_per_threadblock, threadblock_size, M_BLOCKS, K_BLOCKS,
SMEM_STRIDE, SMEM_STRIDE_ACC, kWarpSize, kWarpSizeLog2,
kTileDim, kTileDimLog2>)
, dim3((batch_size + warps_per_threadblock - 1) / warps_per_threadblock), dim3(threadblock_size),
warps_per_threadblock * smem_elems_per_warp * sizeof(__half), stream,
(const __half *)bottom_mlp_input, (const __half *)emb_input, (half *)output, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, smem_elems_per_warp,
smem_rows_per_warp, output_size, num_row_steps, num_col_steps);
}
}
inline void dotBasedInteractBwd(void *upstream_grad, void *bottom_mlp_grad, void *emb_grad,
uint batch_size, uint num_rows, uint num_cols,
hipStream_t stream) {
const uint kWarpSize = 32;
const uint kWarpSizeLog2 = Log2<kWarpSize>::value;
const uint kTileDim = 16;
const uint kTileDimLog2 = Log2<kTileDim>::value;
const uint mem_skew_size = 8;
const uint kPaddingSize = 1;
const uint kWarpsPerBlock = 4;
const uint kWarpsPerBlockLog2 = Log2<kWarpsPerBlock>::value;
const uint kNumThreads = kWarpsPerBlock * kWarpSize;
const uint kRowTilesPerStep = 2;
const uint kColTilesPerStep = 1;
uint row_tiles_per_step = num_rows > kTileDim ? kRowTilesPerStep : 1;
// num tiles
uint num_row_tiles = (num_rows + kTileDim - 1) >> kTileDimLog2;
uint num_col_tiles = (num_cols + kTileDim - 1) >> kTileDimLog2;
// number of rows and columns after padding
uint num_rows_after_padding = kTileDim << 1;
uint num_cols_after_padding = num_col_tiles << kTileDimLog2;
// 2D ugrad size and stride
uint interaction_ugrad_2D_stride = num_rows_after_padding + mem_skew_size;
uint interaction_ugrad_2D_size_elems = num_rows_after_padding * interaction_ugrad_2D_stride;
uint interaction_ugrad_2D_size_bytes = interaction_ugrad_2D_size_elems * sizeof(half);
// 1D ugrad size
uint interaction_ugrad_size = num_rows * (num_rows - 1) >> 1;
uint interaction_ugrad_size_with_padding = interaction_ugrad_size + kPaddingSize;
// in_out place size and stride
uint input_stride = num_cols_after_padding + mem_skew_size;
uint input_size_elems = num_rows_after_padding * input_stride;
uint input_size_bytes = input_size_elems * sizeof(half);
// sample size
uint sample_size = num_rows * num_cols;
// output size
uint output_size_elems = kTileDim * kTileDim * kRowTilesPerStep * kColTilesPerStep;
uint output_size_bytes = output_size_elems * sizeof(float);
// staging area size
uint staging_area_size_bytes = output_size_bytes > interaction_ugrad_2D_size_bytes
? output_size_bytes
: interaction_ugrad_2D_size_bytes;
// Shared memory size
uint shared_mem_per_warp_size_byte = input_size_bytes + staging_area_size_bytes;
uint shared_mem_size_bytes = kWarpsPerBlock * shared_mem_per_warp_size_byte;
uint num_blocks = (batch_size + kWarpsPerBlock - 1) >> kWarpsPerBlockLog2;
uint num_row_steps = num_row_tiles / row_tiles_per_step;
uint num_col_steps = num_col_tiles / kColTilesPerStep;
bool float4_predicate = !((interaction_ugrad_size_with_padding & 7) || (num_cols & 7));
if (float4_predicate) {
hipLaunchKernelGGL(( dotBasedInteractBwdKernel<kWarpsPerBlock, kNumThreads, kRowTilesPerStep, kColTilesPerStep,
kWarpSize, kWarpSizeLog2, kTileDim, kTileDimLog2>)
, dim3(num_blocks), dim3(kNumThreads), shared_mem_size_bytes, stream,
(const half *)upstream_grad, (half *)bottom_mlp_grad, (half *)emb_grad, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, sample_size,
interaction_ugrad_size, interaction_ugrad_size_with_padding,
interaction_ugrad_2D_size_elems, interaction_ugrad_2D_stride, input_size_elems,
input_stride, num_row_steps, num_col_steps, row_tiles_per_step,
shared_mem_per_warp_size_byte);
} else {
hipLaunchKernelGGL(( dotBasedInteractBwdKernelNonAligned<kWarpsPerBlock, kNumThreads, kRowTilesPerStep,
kColTilesPerStep, kWarpSize, kWarpSizeLog2, kTileDim,
kTileDimLog2>)
, dim3(num_blocks), dim3(kNumThreads), shared_mem_size_bytes, stream,
(const half *)upstream_grad, (half *)bottom_mlp_grad, (half *)emb_grad, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, sample_size,
interaction_ugrad_size, interaction_ugrad_size_with_padding,
interaction_ugrad_2D_size_elems, interaction_ugrad_2D_stride, input_size_elems,
input_stride, num_row_steps, num_col_steps, row_tiles_per_step,
shared_mem_per_warp_size_byte);
}
}
template <typename T>
__global__ void concat_kernel(bool forward, T *out, T *in_mlp, T *in_emb, const int h,
const int out_w, const int in_w, const int n_emb) {
const int n_ins = 1 + n_emb;
if (blockIdx.x < n_ins) {
T *in = (blockIdx.x == 0) ? in_mlp : in_emb + (blockIdx.x - 1) * in_w;
for (int bid = blockIdx.y; bid < h; bid += gridDim.y) {
int in_idx_base = (blockIdx.x == 0) ? bid * in_w : bid * in_w * n_emb;
for (int tid = threadIdx.x; tid < in_w; tid += blockDim.x) {
int in_idx = in_idx_base + tid;
int out_idx = bid * out_w + blockIdx.x * in_w + tid;
if (forward) {
out[out_idx] = in[in_idx];
} else {
in[in_idx] = (blockIdx.x == 0) ? (in[in_idx] + out[out_idx]) : out[out_idx];
}
}
}
}
}
template <typename T>
__global__ void gather_concat_fprop_kernel(T *out, const T *in0, const T *mat, const int h,
const int n_ins, const int w) {
extern __shared__ T s_buf[];
for (int bid = blockIdx.x; bid < h; bid += gridDim.x) {
int g_in_idx_base = bid * n_ins * n_ins;
for (int row = threadIdx.y; row < n_ins; row += blockDim.y) {
for (int col = threadIdx.x; col < n_ins; col += blockDim.x) {
if (col > row) {
int idx_in_blk = row * n_ins + col;
int g_in_idx = g_in_idx_base + idx_in_blk;
int s_idx = (col * (col - 1) / 2) + row;
s_buf[s_idx] = mat[g_in_idx];
}
}
}
__syncthreads();
int tid_base = threadIdx.y * blockDim.x + threadIdx.x;
int out_len = w + (n_ins * (n_ins + 1) / 2 - n_ins) + 1;
int g_out_idx_base = bid * out_len;
for (int tid = tid_base; tid < out_len - 1; tid += blockDim.y * blockDim.x) {
int g_out_idx = g_out_idx_base + tid;
T value = (tid < w) ? in0[bid * w + tid] : s_buf[tid - w];
out[g_out_idx] = value;
}
__syncthreads();
}
}
template <typename T>
__global__ void transpose_and_add(const T *src, T *dst, const int h, const int n_ins) {
extern __shared__ T s_buf[];
for (int bid = blockIdx.z; bid < h; bid += gridDim.z) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
int gid = bid * n_ins * n_ins + y * n_ins + x;
int sid_n = threadIdx.y * blockDim.x + threadIdx.x;
int sid_t = threadIdx.x * blockDim.y + threadIdx.y;
if (x < n_ins && y < n_ins) {
s_buf[sid_n] = src[gid];
}
__syncthreads();
if (x < n_ins && y < n_ins) {
dst[gid] = s_buf[sid_n] + s_buf[sid_t];
}
__syncthreads();
}
}
template <typename T>
__global__ void gather_concat_bprop_kernel(const T *out, T *in0, T *mat, const int h,
const int n_ins, const int w) {
extern __shared__ T s_buf[];
for (int bid = blockIdx.x; bid < h; bid += gridDim.x) {
int tid_base = threadIdx.y * blockDim.x + threadIdx.x;
int out_len = w + (n_ins * (n_ins + 1) / 2 - n_ins) + 1;
int g_out_idx_base = bid * out_len;
for (int tid = tid_base; tid < out_len - 1; tid += blockDim.y * blockDim.x) {
int g_out_idx = g_out_idx_base + tid;
T val = out[g_out_idx];
if (tid < w) {
in0[bid * w + tid] = val;
} else {
s_buf[tid - w] = val;
}
}
__syncthreads();
int g_in_idx_base = bid * n_ins * n_ins;
for (int row = threadIdx.y; row < n_ins; row += blockDim.y) {
for (int col = threadIdx.x; col < n_ins; col += blockDim.x) {
int idx_in_blk = row * n_ins + col;
int g_in_idx = g_in_idx_base + idx_in_blk;
int s_idx = (col * (col - 1) / 2) + row;
mat[g_in_idx] = (col > row) ? s_buf[s_idx] : T(0);
}
}
__syncthreads();
}
}
} // anonymous namespace
template <typename T>
InteractionLayer<T>::InteractionLayer(
const Tensor2<T> &in_bottom_mlp_tensor, const Tensor2<T> &in_embeddings, Tensor2<T> &out_tensor,
const std::shared_ptr<GeneralBuffer2<CudaAllocator>> &blobs_buff,
const std::shared_ptr<GPUResource> &gpu_resource, bool use_mixed_precision,
bool enable_tf32_compute)
: Layer(gpu_resource),
use_mixed_precision_(use_mixed_precision),
enable_tf32_compute_(enable_tf32_compute) {
try {
auto first_in_dims = in_bottom_mlp_tensor.get_dimensions();
auto second_in_dims = in_embeddings.get_dimensions();
if (first_in_dims.size() != 2) {
CK_THROW_(Error_t::WrongInput, "Input Bottom MLP must be a 2D tensor");
}
if (second_in_dims.size() != 3) {
CK_THROW_(Error_t::WrongInput, "Input Embeddings must be a 3D tensor");
}
if (first_in_dims[0] != second_in_dims[0]) {
CK_THROW_(Error_t::WrongInput, "the input tensors' batch sizes must be the same");
}
if (first_in_dims[1] != second_in_dims[2]) {
CK_THROW_(Error_t::WrongInput, "the input tensors' widths must be the same");
}
size_t n_ins = 1 + second_in_dims[1];
if (std::is_same<T, __half>::value == false) {
size_t concat_dims_width = first_in_dims[1] + second_in_dims[1] * second_in_dims[2];
std::vector<size_t> concat_dims = {first_in_dims[0], concat_dims_width};
{
Tensor2<T> tensor;
blobs_buff->reserve(concat_dims, &tensor);
internal_tensors_.push_back(tensor);
}
{
std::vector<size_t> mat_dims = {first_in_dims[0], n_ins * n_ins};
Tensor2<T> tensor;
blobs_buff->reserve(mat_dims, &tensor);
internal_tensors_.push_back(tensor);
}
{
Tensor2<T> tensor;
blobs_buff->reserve(concat_dims, &tensor);
internal_tensors_.push_back(tensor);
}
}
int concat_len = n_ins * (n_ins + 1) / 2 - n_ins;
std::vector<size_t> out_dims = {first_in_dims[0], first_in_dims[1] + concat_len + 1};
blobs_buff->reserve(out_dims, &out_tensor);
in_tensors_.push_back(in_bottom_mlp_tensor);
in_tensors_.push_back(in_embeddings);
out_tensors_.push_back(out_tensor);
} catch (const std::runtime_error &rt_err) {
std::cerr << rt_err.what() << std::endl;
throw;
}
}
template <typename T>
InteractionLayer<T>::~InteractionLayer(){};
template <typename T>
void InteractionLayer<T>::fprop(bool is_train) {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.fprop.start", get_gpu().get_stream());
// phase 0: concat
T *concat = internal_tensors_[0].get_ptr();
T *in_mlp = get_in_tensors(is_train)[0].get_ptr();
T *in_emb = get_in_tensors(is_train)[1].get_ptr();
const int h = internal_tensors_[0].get_dimensions()[0];
const int out_w = internal_tensors_[0].get_dimensions()[1];
const int in_w = get_in_tensors(is_train)[0].get_dimensions()[1];
const int n_emb = get_in_tensors(is_train)[1].get_dimensions()[1];
const int n_ins = 1 + n_emb;
dim3 grid0(n_ins, get_gpu().get_sm_count(), 1);
dim3 block0(((in_w <= 128) ? 128 : ((in_w <= 256) ? 256 : 512)), 1, 1);
hipLaunchKernelGGL(( concat_kernel), dim3(grid0), dim3(block0), 0, get_gpu().get_stream(), true, concat, in_mlp, in_emb, h,
out_w, in_w, n_emb);
// phase 1: matmul
const int batch_count = h;
T *mat = internal_tensors_[1].get_ptr();
const int m = n_ins;
const int n = n_ins;
const int k = in_w;
float alpha = 1.0f;
float beta = 0.0f;
long long int stride_a = n * k;
long long int stride_b = k * m;
long long int stride_c = n * m;
hipDataType a_type = HIP_R_32F;
hipDataType b_type = HIP_R_32F;
hipDataType c_type = HIP_R_32F;
hipblasComputeType_t compute_type =
enable_tf32_compute_ ? CUBLAS_COMPUTE_32F_FAST_TF32 : CUBLAS_COMPUTE_32F;
hipblasGemmAlgo_t algo =
use_mixed_precision_ ? CUBLAS_GEMM_DEFAULT_TENSOR_OP : HIPBLAS_GEMM_DEFAULT;
CK_CUBLAS_THROW_(
hipblasGemmStridedBatchedEx(get_gpu().get_cublas_handle(), HIPBLAS_OP_T, HIPBLAS_OP_N, m, n, k,
&alpha, concat, a_type, k, stride_a, concat, b_type, k, stride_b,
&beta, mat, c_type, n, stride_c, batch_count, compute_type, algo));
// phase 2: gather & concat
T *in0 = get_in_tensors(is_train)[0].get_ptr();
T *gather = out_tensors_[0].get_ptr();
dim3 grid1(get_gpu().get_sm_count() * 8, 1, 1);
dim3 block1(16, 16, 1);
size_t smem_size = sizeof(T) * (n_ins * (n_ins + 1) / 2 - n_ins);
hipLaunchKernelGGL(( gather_concat_fprop_kernel), dim3(grid1), dim3(block1), smem_size, get_gpu().get_stream(), gather, in0, mat,
h, n_ins, in_w);
PROFILE_RECORD("interaction.fprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
hipDeviceSynchronize();
CK_CUDA_THROW_(hipGetLastError());
#endif
}
template <>
void InteractionLayer<__half>::fprop(bool is_train) {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.fprop.start", get_gpu().get_stream());
__half *in_mlp = get_in_tensors(is_train)[0].get_ptr();
__half *in_emb = get_in_tensors(is_train)[1].get_ptr();
__half *output = out_tensors_[0].get_ptr();
const int h = get_in_tensors(is_train)[0].get_dimensions()[0];
const int in_w = get_in_tensors(is_train)[0].get_dimensions()[1];
const int n_emb = get_in_tensors(is_train)[1].get_dimensions()[1];
const int n_ins = 1 + n_emb;
dotBasedInteractFwd(in_mlp, in_emb, output, h, n_ins, in_w, get_gpu().get_stream());
PROFILE_RECORD("interaction.fprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
hipDeviceSynchronize();
CK_CUDA_THROW_(hipGetLastError());
#endif
}
template <typename T>
void InteractionLayer<T>::bprop() {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.bprop.start", get_gpu().get_stream());
// phase 0:
T *gather = out_tensors_[0].get_ptr();
T *in0 = get_in_tensors(true)[0].get_ptr();
T *mat = internal_tensors_[1].get_ptr();
const int h = internal_tensors_[0].get_dimensions()[0];
const int n_ins = 1 + get_in_tensors(true)[1].get_dimensions()[1];
const int in_w = get_in_tensors(true)[0].get_dimensions()[1];
dim3 grid1(get_gpu().get_sm_count() * 8, 1, 1);
dim3 block1(16, 16, 1);
size_t smem_size = sizeof(T) * (n_ins * (n_ins + 1) / 2 - n_ins);
hipLaunchKernelGGL(( gather_concat_bprop_kernel), dim3(grid1), dim3(block1), smem_size, get_gpu().get_stream(), gather, in0, mat,
h, n_ins, in_w);
// phase 1:
const int batch_count = h;
T *concat = internal_tensors_[0].get_ptr();
T *concat_tmp = internal_tensors_[2].get_ptr();
const int m = n_ins;
const int n = in_w;
const int k = n_ins;
T alpha = 1.0f;
T beta = 0.0f;
long long int stride_a = n * k;
long long int stride_b = k * m;
long long int stride_c = n * m;
hipDataType a_type = HIP_R_32F;
hipDataType b_type = HIP_R_32F;
hipDataType c_type = HIP_R_32F;
hipblasComputeType_t compute_type =
enable_tf32_compute_ ? CUBLAS_COMPUTE_32F_FAST_TF32 : CUBLAS_COMPUTE_32F;
hipblasGemmAlgo_t algo =
use_mixed_precision_ ? CUBLAS_GEMM_DEFAULT_TENSOR_OP : HIPBLAS_GEMM_DEFAULT;
// mat = mat + T(mat)
{
dim3 block(32, 32, 1);
dim3 grid((n_ins + block.x - 1) / block.x, (n_ins + block.y - 1) / block.y, h);
size_t smem_size = sizeof(T) * block.x * block.y;
hipLaunchKernelGGL(( transpose_and_add), dim3(grid), dim3(block), smem_size, get_gpu().get_stream(), mat, mat, h, n_ins);
}
CK_CUBLAS_THROW_(hipblasGemmStridedBatchedEx(
get_gpu().get_cublas_handle(), HIPBLAS_OP_N, HIPBLAS_OP_N, n, m, k, &alpha, concat, a_type, n,
stride_a, mat, b_type, k, stride_b, &beta, concat_tmp, c_type, n, stride_c, batch_count,
compute_type, algo));
// phase 2:
T *in_mlp = get_in_tensors(true)[0].get_ptr();
T *in_emb = get_in_tensors(true)[1].get_ptr();
const int out_w = internal_tensors_[0].get_dimensions()[1];
const int n_emb = get_in_tensors(true)[1].get_dimensions()[1];
dim3 grid0(n_ins, get_gpu().get_sm_count(), 1);
dim3 block0(((in_w <= 128) ? 128 : ((in_w <= 256) ? 256 : 512)), 1, 1);
hipLaunchKernelGGL(( concat_kernel), dim3(grid0), dim3(block0), 0, get_gpu().get_stream(), false, concat_tmp, in_mlp, in_emb, h,
out_w, in_w, n_emb);
PROFILE_RECORD("interaction.bprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
hipDeviceSynchronize();
CK_CUDA_THROW_(hipGetLastError());
#endif
}
template <>
void InteractionLayer<__half>::bprop() {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.bprop.start", get_gpu().get_stream());
__half *up_grad = out_tensors_[0].get_ptr();
__half *mlp_grad = get_in_tensors(true)[0].get_ptr();
__half *emb_grad = get_in_tensors(true)[1].get_ptr();
const int h = get_in_tensors(true)[0].get_dimensions()[0];
const int n_emb = get_in_tensors(true)[1].get_dimensions()[1];
const int n_ins = 1 + n_emb;
const int in_w = get_in_tensors(true)[0].get_dimensions()[1];
dotBasedInteractBwd(up_grad, mlp_grad, emb_grad, h, n_ins, in_w, get_gpu().get_stream());
PROFILE_RECORD("interaction.bprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
hipDeviceSynchronize();
CK_CUDA_THROW_(hipGetLastError());
#endif
}
template class InteractionLayer<float>;
template class InteractionLayer<__half>;
} // namespace HugeCTR
| a199a37020607c630203a24186ad35aae5e164a4.cu | /*
* Copyright (c) 2020, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cuda.h>
#include <cuda_fp16.h>
#include <cuda_runtime_api.h>
#include <device_launch_parameters.h>
#include <mma.h>
#include <common.hpp>
#include <layers/interaction_layer.hpp>
#include <type_traits>
#include <utils.hpp>
#ifndef NDEBUG
#include <iostream>
#endif
namespace HugeCTR {
namespace {
template <uint x>
struct Log2 {
static constexpr uint value = 1 + Log2<x / 2>::value;
};
template <>
struct Log2<1> {
static constexpr uint value = 0;
};
struct __align__(8) half4 {
half2 vals[2];
};
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint M_BLOCKS, uint K_BLOCKS,
uint SMEM_STRIDE, uint SMEM_STRIDE_ACC, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2,
uint TILE_DIM, uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__ void dotBasedInteractFwdKernelNonAligned(
const __half *__restrict bottom_mlp_input, const __half *__restrict emb_input,
__half *__restrict output, uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding, uint smem_elems_per_warp,
uint smem_rows_per_warp, uint output_size, uint num_row_steps, uint num_col_steps) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
int sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
int lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
extern __shared__ half shmem_dynamic[];
half *shmem = shmem_dynamic + (warp_id * smem_elems_per_warp);
// const half *sample_input = input + num_rows * num_cols * sample_id;
const half *sample_bottom_mlp_input = bottom_mlp_input + num_cols * sample_id;
const half *sample_emp_input = emb_input + (num_rows - 1) * num_cols * sample_id;
const half *sample_input = sample_bottom_mlp_input;
// for (uint i = 0; i < num_rows; ++i, sample_input += num_cols) {
for (uint i = 0; i < num_rows; ++i) {
for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
(shmem + i * SMEM_STRIDE)[idx] = sample_input[idx];
}
sample_input = (i == 0) ? sample_emp_input : (sample_input + num_cols);
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
for (int i = 0; i < num_rows; ++i) {
(shmem + i * SMEM_STRIDE)[idx] = __float2half(0);
}
}
half4 zeros;
zeros.vals[0].x = __float2half(0);
zeros.vals[0].y = __float2half(0);
zeros.vals[1].x = __float2half(0);
zeros.vals[1].y = __float2half(0);
if (lane_id < (num_cols_after_padding >> 2)) {
for (int i = num_rows; i < num_rows_after_padding; i++) {
((half4 *)(shmem + i * SMEM_STRIDE))[lane_id] = zeros;
}
}
__syncwarp();
half *gmem_output = output + output_size * sample_id;
for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
gmem_output[idx] = shmem[idx];
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[M_BLOCKS][M_BLOCKS];
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::fill_fragment(acc[i][j], 0);
}
}
for (int k_step = 0; k_step < num_col_steps; k_step++) {
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[M_BLOCKS];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::col_major>
b[M_BLOCKS];
for (int j = 0; j < M_BLOCKS; j++) {
int base_row = (j < M_BLOCKS - 1) ? j * 16 : smem_rows_per_warp - 16;
const half *tile_ptr = shmem + (base_row * SMEM_STRIDE + k_step * 16);
nvcuda::wmma::load_matrix_sync(a[j], tile_ptr, SMEM_STRIDE);
nvcuda::wmma::load_matrix_sync(b[j], tile_ptr, SMEM_STRIDE);
}
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::mma_sync(acc[i][j], a[i], b[j], acc[i][j]);
}
}
}
float *shmem_store = reinterpret_cast<float *>(shmem);
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
float *tile_ptr = shmem_store + (i * 16 * SMEM_STRIDE_ACC + j * 16);
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i][j], SMEM_STRIDE_ACC,
nvcuda::wmma::mem_row_major);
}
}
half *gmem_interact_output = gmem_output + num_cols;
int lastRowBlockOffset = M_BLOCKS * 16 - smem_rows_per_warp;
int srcLine = 0;
for (int i = 0; i < num_rows; ++i, ++srcLine) {
if (i == ((M_BLOCKS - 1) * 16)) {
srcLine += lastRowBlockOffset;
}
if (lane_id < i) {
uint offset = (i * (i - 1)) >> 1;
gmem_interact_output[offset + lane_id] =
__float2half(shmem_store[srcLine * SMEM_STRIDE_ACC + lane_id]);
}
}
// Padding
if (lane_id == 0) {
gmem_output[output_size - 1] = __float2half(0);
}
#else
#warning "dotBasedInteractFwdKernelNonAligned is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint M_BLOCKS, uint K_BLOCKS,
uint SMEM_STRIDE, uint SMEM_STRIDE_ACC, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2,
uint TILE_DIM, uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__
void dotBasedInteractFwdKernel(const __half *__restrict bottom_mlp_input,
const __half *__restrict emb_input, __half *__restrict output,
uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding,
uint smem_elems_per_warp, uint smem_rows_per_warp,
uint output_size, uint num_row_steps, uint num_col_steps) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
int sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
int lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
extern __shared__ half shmem_dynamic[];
half *shmem = shmem_dynamic + (warp_id * smem_elems_per_warp);
// const half *sample_input = input + num_rows * num_cols * sample_id;
const half *sample_bottom_mlp_input = bottom_mlp_input + num_cols * sample_id;
const half *sample_emp_input = emb_input + (num_rows - 1) * num_cols * sample_id;
const half *sample_input = sample_bottom_mlp_input;
if (lane_id < (num_cols >> 2)) {
// for (int i = 0; i < num_rows; ++i, sample_input += num_cols) {
for (int i = 0; i < num_rows; ++i) {
((float2 *)(shmem + i * SMEM_STRIDE))[lane_id] = ((float2 *)sample_input)[lane_id];
sample_input = (i == 0) ? sample_emp_input : (sample_input + num_cols);
}
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
for (int i = 0; i < num_rows; ++i) {
(shmem + i * SMEM_STRIDE)[idx] = __float2half(0);
}
}
half4 zeros;
zeros.vals[0].x = __float2half(0);
zeros.vals[0].y = __float2half(0);
zeros.vals[1].x = __float2half(0);
zeros.vals[1].y = __float2half(0);
if (lane_id < (num_cols_after_padding >> 2)) {
for (int i = num_rows; i < num_rows_after_padding; i++) {
((half4 *)(shmem + i * SMEM_STRIDE))[lane_id] = zeros;
}
}
__syncwarp();
half *gmem_output = output + output_size * sample_id;
if (lane_id < (num_cols >> 2)) {
((float2 *)gmem_output)[lane_id] = ((float2 *)shmem)[lane_id];
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[M_BLOCKS][M_BLOCKS];
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::fill_fragment(acc[i][j], 0);
}
}
for (int k_step = 0; k_step < num_col_steps; k_step++) {
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[M_BLOCKS];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::col_major>
b[M_BLOCKS];
for (int j = 0; j < M_BLOCKS; j++) {
int base_row = (j < M_BLOCKS - 1) ? j * 16 : smem_rows_per_warp - 16;
const half *tile_ptr = shmem + (base_row * SMEM_STRIDE + k_step * 16);
nvcuda::wmma::load_matrix_sync(a[j], tile_ptr, SMEM_STRIDE);
nvcuda::wmma::load_matrix_sync(b[j], tile_ptr, SMEM_STRIDE);
}
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
nvcuda::wmma::mma_sync(acc[i][j], a[i], b[j], acc[i][j]);
}
}
}
float *shmem_store = reinterpret_cast<float *>(shmem);
for (int i = 0; i < M_BLOCKS; i++) {
for (int j = 0; j < M_BLOCKS; j++) {
float *tile_ptr = shmem_store + (i * 16 * SMEM_STRIDE_ACC + j * 16);
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i][j], SMEM_STRIDE_ACC,
nvcuda::wmma::mem_row_major);
}
}
half *gmem_interact_output = gmem_output + num_cols;
int lastRowBlockOffset = M_BLOCKS * 16 - smem_rows_per_warp;
int srcLine = 0;
for (int i = 0; i < num_rows; ++i, ++srcLine) {
if (i == ((M_BLOCKS - 1) * 16)) {
srcLine += lastRowBlockOffset;
}
if (lane_id < i) {
uint offset = (i * (i - 1)) >> 1;
gmem_interact_output[offset + lane_id] =
__float2half(shmem_store[srcLine * SMEM_STRIDE_ACC + lane_id]);
}
}
// Padding
if (lane_id == 0) {
gmem_output[output_size - 1] = __float2half(0);
}
#else
#warning "dotBasedInteractFwdKernel is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint ROW_TILES_PER_STEP,
uint COL_TILES_PER_STEP, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2, uint TILE_DIM,
uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__ void dotBasedInteractBwdKernelNonAligned(
const __half *__restrict upstream_grad, half __restrict *bottom_mlp_grad,
half __restrict *emb_grad, uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding, uint sample_size,
uint interaction_ugrad_size, uint interaction_ugrad_size_with_padding,
uint interaction_ugrad_2D_size_elems, uint interaction_ugrad_2D_stride, uint input_size_elems,
uint input_stride, uint num_row_steps, uint num_col_steps, uint row_tiles_per_step,
uint shared_mem_per_warp_size_byte) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
extern __shared__ half shared_mem[];
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
uint sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
uint lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
// ">> 1" to convert to half pointer
uint smem_warp_offset = warp_id * (shared_mem_per_warp_size_byte >> 1);
half *smem_in = &shared_mem[smem_warp_offset];
half *smem_temp = &shared_mem[smem_warp_offset + input_size_elems];
float *smem_out = reinterpret_cast<float *>(smem_temp);
// Global memory pointers for the current sample
// Input
// uint gmem_input_sample_offset = sample_id * sample_size;
// const half *gmem_input = &input[gmem_input_sample_offset];
uint gmem_bottom_mlp_input_sample_offset = sample_id * num_cols;
uint gmem_emb_input_sample_offset = sample_id * (num_rows - 1) * num_cols;
const half *gmem_bottom_mlp_input = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
const half *gmem_emb_input = &emb_grad[gmem_emb_input_sample_offset];
// Interaction Gradient
// const uint &gmem_grad_sample_offset = gmem_input_sample_offset;
// half *gmem_grad = &grad[gmem_grad_sample_offset];
half *gmem_bottom_mlp_grad = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
half *gmem_emb_grad = &emb_grad[gmem_emb_input_sample_offset];
// Bottom MLP gradient
// half *gmem_mlp_grad = &bottom_mlp_grad[sample_id * num_cols];
// Upstream gradient vector
uint gmem_ugrad_sample_offset = sample_id * (num_cols + interaction_ugrad_size_with_padding);
const half *gmem_ugrad = &upstream_grad[gmem_ugrad_sample_offset];
// Upstream gradient vector for interactions
const half *gmem_ugrad_interactions = &gmem_ugrad[num_cols];
// upstream grad -> shared memory (place in input section temporarily)
#pragma unroll
for (uint idx = lane_id; idx < interaction_ugrad_size; idx += THREADS_IN_WARP) {
smem_in[idx] = gmem_ugrad_interactions[idx];
}
__syncwarp();
// Form the 2D ugrad matrix.
if (lane_id < num_rows_after_padding) {
uint ugrad_flat_index = ((lane_id * (lane_id - 1)) >> 1);
uint ugrad_offset_1 = lane_id * interaction_ugrad_2D_stride;
for (uint row = 0; row < num_rows; row++) {
half ugrad_val = __float2half(0.0f);
if (row < lane_id && lane_id < num_rows) {
ugrad_val = smem_in[ugrad_flat_index + row];
smem_temp[ugrad_offset_1 + row] = ugrad_val;
}
if (row <= lane_id && lane_id < num_rows_after_padding) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = ugrad_val;
}
}
for (uint row = num_rows; row < num_rows_after_padding; row++) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = __float2half(0.0f);
}
}
__syncwarp();
// Input -> Shared Memory
for (uint row = 0; row < num_rows; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
// const half *gmem_row_ptr = &gmem_input[row * num_cols];
const half *gmem_row_ptr =
(row == 0) ? gmem_bottom_mlp_input : &gmem_emb_input[(row - 1) * num_cols];
for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
smem_row_ptr[idx] = gmem_row_ptr[idx];
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
smem_row_ptr[idx] = __float2half(0);
}
}
#pragma unroll 2
for (uint row = num_rows; row < num_rows_after_padding; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
for (uint idx = lane_id; idx < num_cols_after_padding; idx += THREADS_IN_WARP) {
smem_row_ptr[idx] = __float2half(0);
}
}
__syncwarp();
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[ROW_TILES_PER_STEP][ROW_TILES_PER_STEP];
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
const half *tile_ptr = smem_temp + ((i * interaction_ugrad_2D_stride + j) << TILE_DIM_LOG_2);
nvcuda::wmma::load_matrix_sync(a[i][j], tile_ptr, interaction_ugrad_2D_stride);
}
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[ROW_TILES_PER_STEP];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
b[ROW_TILES_PER_STEP];
for (int col_step = 0; col_step < num_col_steps; col_step++) {
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
const half *tile_ptr = smem_in + ((i * input_stride + col_step) << TILE_DIM_LOG_2);
nvcuda::wmma::fill_fragment(acc[i], 0);
nvcuda::wmma::load_matrix_sync(b[i], tile_ptr, input_stride);
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
nvcuda::wmma::mma_sync(acc[i], a[i][j], b[j], acc[i]);
}
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
float *tile_ptr = smem_out + i * TILE_DIM * TILE_DIM;
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i], TILE_DIM, nvcuda::wmma::mem_row_major);
}
__syncwarp();
uint gmem_grad_col = (col_step << TILE_DIM_LOG_2) + lane_id;
if (gmem_grad_col < num_cols) {
for (uint i = 0; i < num_rows; i++) {
// gmem_grad[i * num_cols + gmem_grad_col] = __float2half(smem_out[(i << TILE_DIM_LOG_2) +
// lane_id]);
half *gmem_grad = (i == 0) ? gmem_bottom_mlp_grad : gmem_emb_grad;
uint idx = (i == 0) ? gmem_grad_col : ((i - 1) * num_cols + gmem_grad_col);
half val = __float2half(smem_out[(i << TILE_DIM_LOG_2) + lane_id]);
gmem_grad[idx] = (i == 0) ? (val + gmem_ugrad[idx]) : val;
}
}
}
// for (uint idx = lane_id; idx < num_cols; idx += THREADS_IN_WARP) {
// gmem_mlp_grad[idx] = gmem_ugrad[idx];
// }
#else
#warning "dotBasedInteractBwdKernelNonAligned is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
template <uint WARPS_PER_BLOCK, uint THREADBLOCK_SIZE, uint ROW_TILES_PER_STEP,
uint COL_TILES_PER_STEP, uint THREADS_IN_WARP, uint THREADS_IN_WARP_LOG_2, uint TILE_DIM,
uint TILE_DIM_LOG_2>
__launch_bounds__(THREADBLOCK_SIZE) __global__
void dotBasedInteractBwdKernel(const __half *__restrict upstream_grad,
half __restrict *bottom_mlp_grad, half __restrict *emb_grad,
uint batch_size, uint num_rows, uint num_cols,
uint num_rows_after_padding, uint num_cols_after_padding,
uint sample_size, uint interaction_ugrad_size,
uint interaction_ugrad_size_with_padding,
uint interaction_ugrad_2D_size_elems,
uint interaction_ugrad_2D_stride, uint input_size_elems,
uint input_stride, uint num_row_steps, uint num_col_steps,
uint row_tiles_per_step, uint shared_mem_per_warp_size_byte) {
#if __CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__)
extern __shared__ half shared_mem[];
uint warp_id = (threadIdx.x >> THREADS_IN_WARP_LOG_2);
uint sample_id = blockIdx.x * WARPS_PER_BLOCK + warp_id;
if (sample_id >= batch_size) {
return;
}
uint lane_id = threadIdx.x & (THREADS_IN_WARP - 1);
// ">> 1" to convert to half pointer
uint smem_warp_offset = warp_id * (shared_mem_per_warp_size_byte >> 1);
half *smem_in = &shared_mem[smem_warp_offset];
half *smem_temp = &shared_mem[smem_warp_offset + input_size_elems];
float *smem_out = reinterpret_cast<float *>(smem_temp);
// Global memory pointers for the current sample
// Input
// uint gmem_input_sample_offset = sample_id * sample_size;
// const half *gmem_input = &input[gmem_input_sample_offset];
uint gmem_bottom_mlp_input_sample_offset = sample_id * num_cols;
uint gmem_emb_input_sample_offset = sample_id * (num_rows - 1) * num_cols;
const half *gmem_bottom_mlp_input = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
const half *gmem_emb_input = &emb_grad[gmem_emb_input_sample_offset];
// Interaction Gradient
// const uint &gmem_grad_sample_offset = gmem_input_sample_offset;
// half *gmem_grad = &grad[gmem_grad_sample_offset];
half *gmem_bottom_mlp_grad = &bottom_mlp_grad[gmem_bottom_mlp_input_sample_offset];
half *gmem_emb_grad = &emb_grad[gmem_emb_input_sample_offset];
// Bottom MLP gradient
// half *gmem_mlp_grad = &bottom_mlp_grad[sample_id * num_cols];
// Upstream gradient vector
uint gmem_ugrad_sample_offset = sample_id * (num_cols + interaction_ugrad_size_with_padding);
const half *gmem_ugrad = &upstream_grad[gmem_ugrad_sample_offset];
// Upstream gradient vector for interactions
const half *gmem_ugrad_interactions = &gmem_ugrad[num_cols];
// upstream grad -> shared memory (place in input section temporarily)
#pragma unroll
for (uint idx = lane_id; idx < (interaction_ugrad_size >> 3); idx += THREADS_IN_WARP) {
((float4 *)smem_in)[idx] = ((float4 *)gmem_ugrad_interactions)[idx];
}
uint offset = (interaction_ugrad_size >> 3) << 3;
for (uint idx = lane_id + offset; idx < interaction_ugrad_size; idx += THREADS_IN_WARP) {
smem_in[idx] = gmem_ugrad_interactions[idx];
}
__syncwarp();
// Form the 2D ugrad matrix.
if (lane_id < num_rows_after_padding) {
uint ugrad_flat_index = ((lane_id * (lane_id - 1)) >> 1);
uint ugrad_offset_1 = lane_id * interaction_ugrad_2D_stride;
for (uint row = 0; row < num_rows; row++) {
half ugrad_val = __float2half(0.0f);
if (row < lane_id && lane_id < num_rows) {
ugrad_val = smem_in[ugrad_flat_index + row];
smem_temp[ugrad_offset_1 + row] = ugrad_val;
}
if (row <= lane_id && lane_id < num_rows_after_padding) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = ugrad_val;
}
}
for (uint row = num_rows; row < num_rows_after_padding; row++) {
smem_temp[row * interaction_ugrad_2D_stride + lane_id] = __float2half(0.0f);
}
}
__syncwarp();
// Input -> Shared Memory
if (lane_id < (num_cols >> 2)) {
for (uint row = 0; row < num_rows; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
// const half *gmem_row_ptr = &gmem_input[row * num_cols];
const half *gmem_row_ptr =
(row == 0) ? gmem_bottom_mlp_input : &gmem_emb_input[(row - 1) * num_cols];
((float2 *)smem_row_ptr)[lane_id] = ((float2 *)gmem_row_ptr)[lane_id];
}
}
uint idx = lane_id + num_cols;
if (idx < num_cols_after_padding) {
for (uint row = 0; row < num_rows; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
smem_row_ptr[idx] = __float2half(0);
}
}
half4 zeros;
zeros.vals[0].x = __float2half(0);
zeros.vals[0].y = __float2half(0);
zeros.vals[1].x = __float2half(0);
zeros.vals[1].y = __float2half(0);
if (lane_id < (num_cols_after_padding >> 2)) {
#pragma unroll 2
for (uint row = num_rows; row < num_rows_after_padding; row++) {
half *smem_row_ptr = &smem_in[row * input_stride];
((half4 *)smem_row_ptr)[lane_id] = zeros;
}
}
__syncwarp();
nvcuda::wmma::fragment<nvcuda::wmma::matrix_a, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
a[ROW_TILES_PER_STEP][ROW_TILES_PER_STEP];
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
const half *tile_ptr = smem_temp + ((i * interaction_ugrad_2D_stride + j) << TILE_DIM_LOG_2);
nvcuda::wmma::load_matrix_sync(a[i][j], tile_ptr, interaction_ugrad_2D_stride);
}
}
nvcuda::wmma::fragment<nvcuda::wmma::accumulator, TILE_DIM, TILE_DIM, TILE_DIM, float>
acc[ROW_TILES_PER_STEP];
nvcuda::wmma::fragment<nvcuda::wmma::matrix_b, TILE_DIM, TILE_DIM, TILE_DIM, half,
nvcuda::wmma::row_major>
b[ROW_TILES_PER_STEP];
for (int col_step = 0; col_step < num_col_steps; col_step++) {
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
const half *tile_ptr = smem_in + ((i * input_stride + col_step) << TILE_DIM_LOG_2);
nvcuda::wmma::fill_fragment(acc[i], 0);
nvcuda::wmma::load_matrix_sync(b[i], tile_ptr, input_stride);
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
for (uint j = 0; j < ROW_TILES_PER_STEP; j++) {
nvcuda::wmma::mma_sync(acc[i], a[i][j], b[j], acc[i]);
}
}
for (uint i = 0; i < ROW_TILES_PER_STEP; i++) {
float *tile_ptr = smem_out + i * TILE_DIM * TILE_DIM;
nvcuda::wmma::store_matrix_sync(tile_ptr, acc[i], TILE_DIM, nvcuda::wmma::mem_row_major);
}
__syncwarp();
uint gmem_grad_col_base = (col_step << TILE_DIM_LOG_2);
uint gmem_grad_col = gmem_grad_col_base + lane_id;
if (gmem_grad_col < num_cols) {
if (lane_id < 8) {
((__half2 *)(gmem_bottom_mlp_grad + gmem_grad_col_base))[lane_id] =
__hadd2(__float22half2_rn(((float2 *)smem_out)[lane_id]),
((__half2 *)(gmem_ugrad + gmem_grad_col_base))[lane_id]);
}
for (uint i = 0; i < num_rows - 1; i++) {
half val = __float2half(smem_out[((i + 1) << TILE_DIM_LOG_2) + lane_id]);
gmem_emb_grad[i * num_cols + gmem_grad_col] = val;
}
}
}
#else
#warning "dotBasedInteractBwdKernel is not supported for SM < 70 (or __CUDA_ARCH__ < 700)"
#endif
}
inline void dotBasedInteractFwd(const void *bottom_mlp_input, const void *emb_input, void *output,
uint batch_size, uint num_rows, uint num_cols,
cudaStream_t stream) {
const uint kWarpSize = 32;
const uint kWarpSizeLog2 = Log2<kWarpSize>::value;
const uint kTileDim = 16;
const uint kTileDimLog2 = Log2<kTileDim>::value;
const uint warps_per_threadblock = 4;
const uint threadblock_size = warps_per_threadblock * 32;
const uint kPaddingSize = 1;
const uint kRowTilesPerStep = 2;
const uint kColTilesPerStep = 1;
// num tiles
uint num_row_tiles = (num_rows + kTileDim - 1) >> kTileDimLog2;
uint num_col_tiles = (num_cols + kTileDim - 1) >> kTileDimLog2;
// number of rows and columns after padding
uint num_rows_after_padding = kTileDim << 1;
uint num_cols_after_padding = num_col_tiles << kTileDimLog2;
uint num_row_steps = num_row_tiles / kRowTilesPerStep;
uint num_col_steps = num_col_tiles / kColTilesPerStep;
const uint K_BLOCKS = 8;
const uint M_BLOCKS = 2;
const uint SKEW_HALF = ((K_BLOCKS % 2) == 0) ? 8 : 0;
const uint SMEM_STRIDE = (K_BLOCKS * 16 + SKEW_HALF);
// multiple of 2 to guarantee 256-bit alignment for start of the row, at least 16 to safeload a
// tile
const uint smem_rows_per_warp = M_BLOCKS << 4;
const uint smem_elems_per_warp_mat = smem_rows_per_warp * SMEM_STRIDE;
const uint SKEW_HALF_ACC = ((M_BLOCKS % 2) == 0) ? 8 : 0;
const uint SMEM_STRIDE_ACC = (M_BLOCKS * 16 + SKEW_HALF_ACC);
const uint smem_elems_per_warp_acc = M_BLOCKS * 16 * SMEM_STRIDE_ACC * 2; // output in FP32
const uint smem_elems_per_warp = (smem_elems_per_warp_mat > smem_elems_per_warp_acc)
? smem_elems_per_warp_mat
: smem_elems_per_warp_acc;
uint output_size = num_cols + (num_rows * (num_rows - 1) >> 1) + kPaddingSize;
bool float4_predicate = !((num_cols & 7) || (output_size & 7));
if (float4_predicate) {
dotBasedInteractFwdKernel<warps_per_threadblock, threadblock_size, M_BLOCKS, K_BLOCKS,
SMEM_STRIDE, SMEM_STRIDE_ACC, kWarpSize, kWarpSizeLog2, kTileDim,
kTileDimLog2>
<<<(batch_size + warps_per_threadblock - 1) / warps_per_threadblock, threadblock_size,
warps_per_threadblock * smem_elems_per_warp * sizeof(__half), stream>>>(
(const __half *)bottom_mlp_input, (const __half *)emb_input, (half *)output, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, smem_elems_per_warp,
smem_rows_per_warp, output_size, num_row_steps, num_col_steps);
} else {
dotBasedInteractFwdKernelNonAligned<warps_per_threadblock, threadblock_size, M_BLOCKS, K_BLOCKS,
SMEM_STRIDE, SMEM_STRIDE_ACC, kWarpSize, kWarpSizeLog2,
kTileDim, kTileDimLog2>
<<<(batch_size + warps_per_threadblock - 1) / warps_per_threadblock, threadblock_size,
warps_per_threadblock * smem_elems_per_warp * sizeof(__half), stream>>>(
(const __half *)bottom_mlp_input, (const __half *)emb_input, (half *)output, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, smem_elems_per_warp,
smem_rows_per_warp, output_size, num_row_steps, num_col_steps);
}
}
inline void dotBasedInteractBwd(void *upstream_grad, void *bottom_mlp_grad, void *emb_grad,
uint batch_size, uint num_rows, uint num_cols,
cudaStream_t stream) {
const uint kWarpSize = 32;
const uint kWarpSizeLog2 = Log2<kWarpSize>::value;
const uint kTileDim = 16;
const uint kTileDimLog2 = Log2<kTileDim>::value;
const uint mem_skew_size = 8;
const uint kPaddingSize = 1;
const uint kWarpsPerBlock = 4;
const uint kWarpsPerBlockLog2 = Log2<kWarpsPerBlock>::value;
const uint kNumThreads = kWarpsPerBlock * kWarpSize;
const uint kRowTilesPerStep = 2;
const uint kColTilesPerStep = 1;
uint row_tiles_per_step = num_rows > kTileDim ? kRowTilesPerStep : 1;
// num tiles
uint num_row_tiles = (num_rows + kTileDim - 1) >> kTileDimLog2;
uint num_col_tiles = (num_cols + kTileDim - 1) >> kTileDimLog2;
// number of rows and columns after padding
uint num_rows_after_padding = kTileDim << 1;
uint num_cols_after_padding = num_col_tiles << kTileDimLog2;
// 2D ugrad size and stride
uint interaction_ugrad_2D_stride = num_rows_after_padding + mem_skew_size;
uint interaction_ugrad_2D_size_elems = num_rows_after_padding * interaction_ugrad_2D_stride;
uint interaction_ugrad_2D_size_bytes = interaction_ugrad_2D_size_elems * sizeof(half);
// 1D ugrad size
uint interaction_ugrad_size = num_rows * (num_rows - 1) >> 1;
uint interaction_ugrad_size_with_padding = interaction_ugrad_size + kPaddingSize;
// in_out place size and stride
uint input_stride = num_cols_after_padding + mem_skew_size;
uint input_size_elems = num_rows_after_padding * input_stride;
uint input_size_bytes = input_size_elems * sizeof(half);
// sample size
uint sample_size = num_rows * num_cols;
// output size
uint output_size_elems = kTileDim * kTileDim * kRowTilesPerStep * kColTilesPerStep;
uint output_size_bytes = output_size_elems * sizeof(float);
// staging area size
uint staging_area_size_bytes = output_size_bytes > interaction_ugrad_2D_size_bytes
? output_size_bytes
: interaction_ugrad_2D_size_bytes;
// Shared memory size
uint shared_mem_per_warp_size_byte = input_size_bytes + staging_area_size_bytes;
uint shared_mem_size_bytes = kWarpsPerBlock * shared_mem_per_warp_size_byte;
uint num_blocks = (batch_size + kWarpsPerBlock - 1) >> kWarpsPerBlockLog2;
uint num_row_steps = num_row_tiles / row_tiles_per_step;
uint num_col_steps = num_col_tiles / kColTilesPerStep;
bool float4_predicate = !((interaction_ugrad_size_with_padding & 7) || (num_cols & 7));
if (float4_predicate) {
dotBasedInteractBwdKernel<kWarpsPerBlock, kNumThreads, kRowTilesPerStep, kColTilesPerStep,
kWarpSize, kWarpSizeLog2, kTileDim, kTileDimLog2>
<<<num_blocks, kNumThreads, shared_mem_size_bytes, stream>>>(
(const half *)upstream_grad, (half *)bottom_mlp_grad, (half *)emb_grad, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, sample_size,
interaction_ugrad_size, interaction_ugrad_size_with_padding,
interaction_ugrad_2D_size_elems, interaction_ugrad_2D_stride, input_size_elems,
input_stride, num_row_steps, num_col_steps, row_tiles_per_step,
shared_mem_per_warp_size_byte);
} else {
dotBasedInteractBwdKernelNonAligned<kWarpsPerBlock, kNumThreads, kRowTilesPerStep,
kColTilesPerStep, kWarpSize, kWarpSizeLog2, kTileDim,
kTileDimLog2>
<<<num_blocks, kNumThreads, shared_mem_size_bytes, stream>>>(
(const half *)upstream_grad, (half *)bottom_mlp_grad, (half *)emb_grad, batch_size,
num_rows, num_cols, num_rows_after_padding, num_cols_after_padding, sample_size,
interaction_ugrad_size, interaction_ugrad_size_with_padding,
interaction_ugrad_2D_size_elems, interaction_ugrad_2D_stride, input_size_elems,
input_stride, num_row_steps, num_col_steps, row_tiles_per_step,
shared_mem_per_warp_size_byte);
}
}
template <typename T>
__global__ void concat_kernel(bool forward, T *out, T *in_mlp, T *in_emb, const int h,
const int out_w, const int in_w, const int n_emb) {
const int n_ins = 1 + n_emb;
if (blockIdx.x < n_ins) {
T *in = (blockIdx.x == 0) ? in_mlp : in_emb + (blockIdx.x - 1) * in_w;
for (int bid = blockIdx.y; bid < h; bid += gridDim.y) {
int in_idx_base = (blockIdx.x == 0) ? bid * in_w : bid * in_w * n_emb;
for (int tid = threadIdx.x; tid < in_w; tid += blockDim.x) {
int in_idx = in_idx_base + tid;
int out_idx = bid * out_w + blockIdx.x * in_w + tid;
if (forward) {
out[out_idx] = in[in_idx];
} else {
in[in_idx] = (blockIdx.x == 0) ? (in[in_idx] + out[out_idx]) : out[out_idx];
}
}
}
}
}
template <typename T>
__global__ void gather_concat_fprop_kernel(T *out, const T *in0, const T *mat, const int h,
const int n_ins, const int w) {
extern __shared__ T s_buf[];
for (int bid = blockIdx.x; bid < h; bid += gridDim.x) {
int g_in_idx_base = bid * n_ins * n_ins;
for (int row = threadIdx.y; row < n_ins; row += blockDim.y) {
for (int col = threadIdx.x; col < n_ins; col += blockDim.x) {
if (col > row) {
int idx_in_blk = row * n_ins + col;
int g_in_idx = g_in_idx_base + idx_in_blk;
int s_idx = (col * (col - 1) / 2) + row;
s_buf[s_idx] = mat[g_in_idx];
}
}
}
__syncthreads();
int tid_base = threadIdx.y * blockDim.x + threadIdx.x;
int out_len = w + (n_ins * (n_ins + 1) / 2 - n_ins) + 1;
int g_out_idx_base = bid * out_len;
for (int tid = tid_base; tid < out_len - 1; tid += blockDim.y * blockDim.x) {
int g_out_idx = g_out_idx_base + tid;
T value = (tid < w) ? in0[bid * w + tid] : s_buf[tid - w];
out[g_out_idx] = value;
}
__syncthreads();
}
}
template <typename T>
__global__ void transpose_and_add(const T *src, T *dst, const int h, const int n_ins) {
extern __shared__ T s_buf[];
for (int bid = blockIdx.z; bid < h; bid += gridDim.z) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
int gid = bid * n_ins * n_ins + y * n_ins + x;
int sid_n = threadIdx.y * blockDim.x + threadIdx.x;
int sid_t = threadIdx.x * blockDim.y + threadIdx.y;
if (x < n_ins && y < n_ins) {
s_buf[sid_n] = src[gid];
}
__syncthreads();
if (x < n_ins && y < n_ins) {
dst[gid] = s_buf[sid_n] + s_buf[sid_t];
}
__syncthreads();
}
}
template <typename T>
__global__ void gather_concat_bprop_kernel(const T *out, T *in0, T *mat, const int h,
const int n_ins, const int w) {
extern __shared__ T s_buf[];
for (int bid = blockIdx.x; bid < h; bid += gridDim.x) {
int tid_base = threadIdx.y * blockDim.x + threadIdx.x;
int out_len = w + (n_ins * (n_ins + 1) / 2 - n_ins) + 1;
int g_out_idx_base = bid * out_len;
for (int tid = tid_base; tid < out_len - 1; tid += blockDim.y * blockDim.x) {
int g_out_idx = g_out_idx_base + tid;
T val = out[g_out_idx];
if (tid < w) {
in0[bid * w + tid] = val;
} else {
s_buf[tid - w] = val;
}
}
__syncthreads();
int g_in_idx_base = bid * n_ins * n_ins;
for (int row = threadIdx.y; row < n_ins; row += blockDim.y) {
for (int col = threadIdx.x; col < n_ins; col += blockDim.x) {
int idx_in_blk = row * n_ins + col;
int g_in_idx = g_in_idx_base + idx_in_blk;
int s_idx = (col * (col - 1) / 2) + row;
mat[g_in_idx] = (col > row) ? s_buf[s_idx] : T(0);
}
}
__syncthreads();
}
}
} // anonymous namespace
template <typename T>
InteractionLayer<T>::InteractionLayer(
const Tensor2<T> &in_bottom_mlp_tensor, const Tensor2<T> &in_embeddings, Tensor2<T> &out_tensor,
const std::shared_ptr<GeneralBuffer2<CudaAllocator>> &blobs_buff,
const std::shared_ptr<GPUResource> &gpu_resource, bool use_mixed_precision,
bool enable_tf32_compute)
: Layer(gpu_resource),
use_mixed_precision_(use_mixed_precision),
enable_tf32_compute_(enable_tf32_compute) {
try {
auto first_in_dims = in_bottom_mlp_tensor.get_dimensions();
auto second_in_dims = in_embeddings.get_dimensions();
if (first_in_dims.size() != 2) {
CK_THROW_(Error_t::WrongInput, "Input Bottom MLP must be a 2D tensor");
}
if (second_in_dims.size() != 3) {
CK_THROW_(Error_t::WrongInput, "Input Embeddings must be a 3D tensor");
}
if (first_in_dims[0] != second_in_dims[0]) {
CK_THROW_(Error_t::WrongInput, "the input tensors' batch sizes must be the same");
}
if (first_in_dims[1] != second_in_dims[2]) {
CK_THROW_(Error_t::WrongInput, "the input tensors' widths must be the same");
}
size_t n_ins = 1 + second_in_dims[1];
if (std::is_same<T, __half>::value == false) {
size_t concat_dims_width = first_in_dims[1] + second_in_dims[1] * second_in_dims[2];
std::vector<size_t> concat_dims = {first_in_dims[0], concat_dims_width};
{
Tensor2<T> tensor;
blobs_buff->reserve(concat_dims, &tensor);
internal_tensors_.push_back(tensor);
}
{
std::vector<size_t> mat_dims = {first_in_dims[0], n_ins * n_ins};
Tensor2<T> tensor;
blobs_buff->reserve(mat_dims, &tensor);
internal_tensors_.push_back(tensor);
}
{
Tensor2<T> tensor;
blobs_buff->reserve(concat_dims, &tensor);
internal_tensors_.push_back(tensor);
}
}
int concat_len = n_ins * (n_ins + 1) / 2 - n_ins;
std::vector<size_t> out_dims = {first_in_dims[0], first_in_dims[1] + concat_len + 1};
blobs_buff->reserve(out_dims, &out_tensor);
in_tensors_.push_back(in_bottom_mlp_tensor);
in_tensors_.push_back(in_embeddings);
out_tensors_.push_back(out_tensor);
} catch (const std::runtime_error &rt_err) {
std::cerr << rt_err.what() << std::endl;
throw;
}
}
template <typename T>
InteractionLayer<T>::~InteractionLayer(){};
template <typename T>
void InteractionLayer<T>::fprop(bool is_train) {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.fprop.start", get_gpu().get_stream());
// phase 0: concat
T *concat = internal_tensors_[0].get_ptr();
T *in_mlp = get_in_tensors(is_train)[0].get_ptr();
T *in_emb = get_in_tensors(is_train)[1].get_ptr();
const int h = internal_tensors_[0].get_dimensions()[0];
const int out_w = internal_tensors_[0].get_dimensions()[1];
const int in_w = get_in_tensors(is_train)[0].get_dimensions()[1];
const int n_emb = get_in_tensors(is_train)[1].get_dimensions()[1];
const int n_ins = 1 + n_emb;
dim3 grid0(n_ins, get_gpu().get_sm_count(), 1);
dim3 block0(((in_w <= 128) ? 128 : ((in_w <= 256) ? 256 : 512)), 1, 1);
concat_kernel<<<grid0, block0, 0, get_gpu().get_stream()>>>(true, concat, in_mlp, in_emb, h,
out_w, in_w, n_emb);
// phase 1: matmul
const int batch_count = h;
T *mat = internal_tensors_[1].get_ptr();
const int m = n_ins;
const int n = n_ins;
const int k = in_w;
float alpha = 1.0f;
float beta = 0.0f;
long long int stride_a = n * k;
long long int stride_b = k * m;
long long int stride_c = n * m;
cudaDataType_t a_type = CUDA_R_32F;
cudaDataType_t b_type = CUDA_R_32F;
cudaDataType_t c_type = CUDA_R_32F;
cublasComputeType_t compute_type =
enable_tf32_compute_ ? CUBLAS_COMPUTE_32F_FAST_TF32 : CUBLAS_COMPUTE_32F;
cublasGemmAlgo_t algo =
use_mixed_precision_ ? CUBLAS_GEMM_DEFAULT_TENSOR_OP : CUBLAS_GEMM_DEFAULT;
CK_CUBLAS_THROW_(
cublasGemmStridedBatchedEx(get_gpu().get_cublas_handle(), CUBLAS_OP_T, CUBLAS_OP_N, m, n, k,
&alpha, concat, a_type, k, stride_a, concat, b_type, k, stride_b,
&beta, mat, c_type, n, stride_c, batch_count, compute_type, algo));
// phase 2: gather & concat
T *in0 = get_in_tensors(is_train)[0].get_ptr();
T *gather = out_tensors_[0].get_ptr();
dim3 grid1(get_gpu().get_sm_count() * 8, 1, 1);
dim3 block1(16, 16, 1);
size_t smem_size = sizeof(T) * (n_ins * (n_ins + 1) / 2 - n_ins);
gather_concat_fprop_kernel<<<grid1, block1, smem_size, get_gpu().get_stream()>>>(gather, in0, mat,
h, n_ins, in_w);
PROFILE_RECORD("interaction.fprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
cudaDeviceSynchronize();
CK_CUDA_THROW_(cudaGetLastError());
#endif
}
template <>
void InteractionLayer<__half>::fprop(bool is_train) {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.fprop.start", get_gpu().get_stream());
__half *in_mlp = get_in_tensors(is_train)[0].get_ptr();
__half *in_emb = get_in_tensors(is_train)[1].get_ptr();
__half *output = out_tensors_[0].get_ptr();
const int h = get_in_tensors(is_train)[0].get_dimensions()[0];
const int in_w = get_in_tensors(is_train)[0].get_dimensions()[1];
const int n_emb = get_in_tensors(is_train)[1].get_dimensions()[1];
const int n_ins = 1 + n_emb;
dotBasedInteractFwd(in_mlp, in_emb, output, h, n_ins, in_w, get_gpu().get_stream());
PROFILE_RECORD("interaction.fprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
cudaDeviceSynchronize();
CK_CUDA_THROW_(cudaGetLastError());
#endif
}
template <typename T>
void InteractionLayer<T>::bprop() {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.bprop.start", get_gpu().get_stream());
// phase 0:
T *gather = out_tensors_[0].get_ptr();
T *in0 = get_in_tensors(true)[0].get_ptr();
T *mat = internal_tensors_[1].get_ptr();
const int h = internal_tensors_[0].get_dimensions()[0];
const int n_ins = 1 + get_in_tensors(true)[1].get_dimensions()[1];
const int in_w = get_in_tensors(true)[0].get_dimensions()[1];
dim3 grid1(get_gpu().get_sm_count() * 8, 1, 1);
dim3 block1(16, 16, 1);
size_t smem_size = sizeof(T) * (n_ins * (n_ins + 1) / 2 - n_ins);
gather_concat_bprop_kernel<<<grid1, block1, smem_size, get_gpu().get_stream()>>>(gather, in0, mat,
h, n_ins, in_w);
// phase 1:
const int batch_count = h;
T *concat = internal_tensors_[0].get_ptr();
T *concat_tmp = internal_tensors_[2].get_ptr();
const int m = n_ins;
const int n = in_w;
const int k = n_ins;
T alpha = 1.0f;
T beta = 0.0f;
long long int stride_a = n * k;
long long int stride_b = k * m;
long long int stride_c = n * m;
cudaDataType_t a_type = CUDA_R_32F;
cudaDataType_t b_type = CUDA_R_32F;
cudaDataType_t c_type = CUDA_R_32F;
cublasComputeType_t compute_type =
enable_tf32_compute_ ? CUBLAS_COMPUTE_32F_FAST_TF32 : CUBLAS_COMPUTE_32F;
cublasGemmAlgo_t algo =
use_mixed_precision_ ? CUBLAS_GEMM_DEFAULT_TENSOR_OP : CUBLAS_GEMM_DEFAULT;
// mat = mat + T(mat)
{
dim3 block(32, 32, 1);
dim3 grid((n_ins + block.x - 1) / block.x, (n_ins + block.y - 1) / block.y, h);
size_t smem_size = sizeof(T) * block.x * block.y;
transpose_and_add<<<grid, block, smem_size, get_gpu().get_stream()>>>(mat, mat, h, n_ins);
}
CK_CUBLAS_THROW_(cublasGemmStridedBatchedEx(
get_gpu().get_cublas_handle(), CUBLAS_OP_N, CUBLAS_OP_N, n, m, k, &alpha, concat, a_type, n,
stride_a, mat, b_type, k, stride_b, &beta, concat_tmp, c_type, n, stride_c, batch_count,
compute_type, algo));
// phase 2:
T *in_mlp = get_in_tensors(true)[0].get_ptr();
T *in_emb = get_in_tensors(true)[1].get_ptr();
const int out_w = internal_tensors_[0].get_dimensions()[1];
const int n_emb = get_in_tensors(true)[1].get_dimensions()[1];
dim3 grid0(n_ins, get_gpu().get_sm_count(), 1);
dim3 block0(((in_w <= 128) ? 128 : ((in_w <= 256) ? 256 : 512)), 1, 1);
concat_kernel<<<grid0, block0, 0, get_gpu().get_stream()>>>(false, concat_tmp, in_mlp, in_emb, h,
out_w, in_w, n_emb);
PROFILE_RECORD("interaction.bprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
cudaDeviceSynchronize();
CK_CUDA_THROW_(cudaGetLastError());
#endif
}
template <>
void InteractionLayer<__half>::bprop() {
CudaDeviceContext context(get_device_id());
PROFILE_RECORD("interaction.bprop.start", get_gpu().get_stream());
__half *up_grad = out_tensors_[0].get_ptr();
__half *mlp_grad = get_in_tensors(true)[0].get_ptr();
__half *emb_grad = get_in_tensors(true)[1].get_ptr();
const int h = get_in_tensors(true)[0].get_dimensions()[0];
const int n_emb = get_in_tensors(true)[1].get_dimensions()[1];
const int n_ins = 1 + n_emb;
const int in_w = get_in_tensors(true)[0].get_dimensions()[1];
dotBasedInteractBwd(up_grad, mlp_grad, emb_grad, h, n_ins, in_w, get_gpu().get_stream());
PROFILE_RECORD("interaction.bprop.stop", get_gpu().get_stream());
#ifndef NDEBUG
cudaDeviceSynchronize();
CK_CUDA_THROW_(cudaGetLastError());
#endif
}
template class InteractionLayer<float>;
template class InteractionLayer<__half>;
} // namespace HugeCTR
|
06548180e62068073ae13afdd7afd5c092189ee0.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
(HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
the University of Michigan All rights reserved.
HOOMD-blue may contain modifications ("Contributions") provided, and to which
copyright is held, by various Contributors who have granted The Regents of the
University of Michigan the right to modify and/or distribute such Contributions.
You may redistribute, use, and create derivate works of HOOMD-blue, in source
and binary forms, provided you abide by the following conditions:
* Redistributions of source code must retain the above copyright notice, this
list of conditions, and the following disclaimer both in the code and
prominently in any materials provided with the distribution.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions, and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* All publications and presentations based on HOOMD-blue, including any reports
or published results obtained, in whole or in part, with HOOMD-blue, will
acknowledge its use according to the terms posted at the time of submission on:
http://codeblue.umich.edu/hoomd-blue/citations.html
* Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
http://codeblue.umich.edu/hoomd-blue/
* Apart from the above required attributions, neither the name of the copyright
holder nor the names of HOOMD-blue's contributors may be used to endorse or
promote products derived from this software without specific prior written
permission.
Disclaimer
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Maintainer: ndtrung
#include "QuaternionMath.h"
#include "TwoStepNPTRigidGPU.cuh"
#ifdef WIN32
#include <cassert>
#else
#include <assert.h>
#endif
/*! \file TwoStepNPTRigidGPU.cu
\brief Defines GPU kernel code for NPT integration on the GPU. Used by TwoStepNPTRigidGPU.
*/
// Flag for invalid particle index, identical to the sentinel value NO_INDEX in RigidData.h
#define INVALID_INDEX 0xffffffff
/*! Maclaurine expansion
\param x Point to take the expansion
*/
__device__ Scalar maclaurin_series(Scalar x)
{
Scalar x2, x4;
x2 = x * x;
x4 = x2 * x2;
return (Scalar(1.0) + (Scalar(1.0)/Scalar(6.0)) * x2 + (Scalar(1.0)/Scalar(120.0)) * x4 + (Scalar(1.0)/Scalar(5040.0)) * x2 * x4 + (Scalar(1.0)/Scalar(362880.0)) * x4 * x4);
}
/*! Kernel to zero virial contribution from particles from rigid bodies
\param d_virial_rigid Virial contribution from particles in rigid bodies
\param local_num Number of particles in this card
*/
extern "C" __global__ void gpu_npt_rigid_zero_virial_rigid_kernel(Scalar *d_virial_rigid,
unsigned int local_num)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x; // particle's index
if (idx < local_num)
{
d_virial_rigid[idx] = Scalar(0.0);
}
}
/*! Takes the first half-step forward for rigid bodies in the velocity-verlet NVT integration
\param rdata_com Body center of mass
\param d_rigid_group Body group
\param n_group_bodies Number of rigid bodies in my group
\param n_bodies Total umber of rigid bodies
\param box Box dimensions for periodic boundary condition handling
\param npt_rdata_dilation Volume scaling factor
\param npt_rdata_dimension System dimensionality
\param npt_rdata_new box New box sizes
*/
extern "C" __global__ void gpu_npt_rigid_remap_kernel(Scalar4 *rdata_com,
unsigned int *d_rigid_group,
unsigned int n_group_bodies,
unsigned int n_bodies,
BoxDim box,
Scalar npt_rdata_dilation,
unsigned int npt_rdata_dimension,
Scalar4 *npt_rdata_new_box)
{
unsigned int group_idx = blockIdx.x * blockDim.x + threadIdx.x;
if (group_idx >= n_group_bodies)
return;
unsigned int idx_body = d_rigid_group[group_idx];
Scalar3 curL = box.getL();
Scalar3 L;
// reset box to new size/shape
L.x = curL.x * npt_rdata_dilation;
L.y = curL.y * npt_rdata_dilation;
if (npt_rdata_dimension == 3)
L.z = curL.z * npt_rdata_dilation;
// copy and setL
BoxDim newBox = box;
newBox.setL(L);
Scalar4 com = rdata_com[idx_body];
Scalar3 f = box.makeFraction(make_scalar3(com.x, com.y, com.z));
Scalar3 pos = newBox.makeCoordinates(f);
// write out results
rdata_com[idx_body] = make_scalar4(pos.x, pos.y, pos.z, Scalar(0.0));
if (idx_body == 0)
{
*(npt_rdata_new_box) = make_scalar4(L.x, L.y, L.z, 0.0f);
}
}
#pragma mark RIGID_STEP_ONE_KERNEL
/*! Takes the first half-step forward for rigid bodies in the velocity-verlet NVT integration
\param rdata_com Body center of mass
\param rdata_vel Body velocity
\param rdata_angmom Angular momentum
\param rdata_angvel Angular velocity
\param rdata_orientation Quaternion
\param rdata_body_image Body image
\param rdata_conjqm Conjugate quaternion momentum
\param d_rigid_mass Body mass
\param d_rigid_mi Body inertia moments
\param n_group_bodies Number of rigid bodies in my group
\param d_rigid_force Body forces
\param d_rigid_torque Body torques
\param d_rigid_group Body indices
\param n_bodies Total umber of rigid bodies
\param npt_rdata_eta_dot_t0 Thermostat translational velocity
\param npt_rdata_eta_dot_r0 Thermostat rotational velocity
\param npt_rdata_epsilon_dot Barostat velocity
\param npt_rdata_partial_Ksum_t Body translational kinetic energy
\param npt_rdata_partial_Ksum_r Body rotation kinetic energy
\param npt_rdata_nf_t Translational degrees of freedom
\param npt_rdata_nf_r Translational degrees of freedom
\param npt_rdata_dimension System dimesion
\param box Box dimensions for periodic boundary condition handling
\param deltaT Timestep
*/
extern "C" __global__ void gpu_npt_rigid_step_one_body_kernel(Scalar4* rdata_com,
Scalar4* rdata_vel,
Scalar4* rdata_angmom,
Scalar4* rdata_angvel,
Scalar4* rdata_orientation,
int3* rdata_body_image,
Scalar4* rdata_conjqm,
Scalar *d_rigid_mass,
Scalar4 *d_rigid_mi,
Scalar4 *d_rigid_force,
Scalar4 *d_rigid_torque,
unsigned int *d_rigid_group,
unsigned int n_group_bodies,
unsigned int n_bodies,
Scalar npt_rdata_eta_dot_t0,
Scalar npt_rdata_eta_dot_r0,
Scalar npt_rdata_epsilon_dot,
Scalar* npt_rdata_partial_Ksum_t,
Scalar* npt_rdata_partial_Ksum_r,
unsigned int npt_rdata_nf_t,
unsigned int npt_rdata_nf_r,
unsigned int npt_rdata_dimension,
BoxDim box,
Scalar deltaT)
{
unsigned int group_idx = blockIdx.x * blockDim.x + threadIdx.x;
if (group_idx >= n_group_bodies)
return;
// do velocity verlet update
// v(t+deltaT/2) = v(t) + (1/2)a*deltaT
// r(t+deltaT) = r(t) + v(t+deltaT/2)*deltaT
Scalar body_mass;
Scalar4 moment_inertia, com, vel, orientation, ex_space, ey_space, ez_space, force, torque, conjqm;
int3 body_image;
Scalar4 mbody, tbody, fquat;
Scalar dt_half = Scalar(0.5) * deltaT;
Scalar onednft, onednfr, tmp, scale_t, scale_r, scale_v, akin_t, akin_r;
onednft = Scalar(1.0) + Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
onednfr = Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_t0 + onednft * npt_rdata_epsilon_dot);
scale_t = fast::exp(tmp);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_r0 + onednfr * npt_rdata_epsilon_dot);
scale_r = fast::exp(tmp);
tmp = dt_half * npt_rdata_epsilon_dot;
scale_v = deltaT * fast::exp(tmp) * maclaurin_series(tmp);
unsigned int idx_body = d_rigid_group[group_idx];
body_mass = d_rigid_mass[idx_body];
moment_inertia = d_rigid_mi[idx_body];
com = rdata_com[idx_body];
vel = rdata_vel[idx_body];
orientation = rdata_orientation[idx_body];
body_image = rdata_body_image[idx_body];
force = d_rigid_force[idx_body];
torque = d_rigid_torque[idx_body];
conjqm = rdata_conjqm[idx_body];
exyzFromQuaternion(orientation, ex_space, ey_space, ez_space);
// update velocity
Scalar dtfm = dt_half / body_mass;
Scalar4 vel2;
vel2.x = vel.x + dtfm * force.x;
vel2.y = vel.y + dtfm * force.y;
vel2.z = vel.z + dtfm * force.z;
vel2.x *= scale_t;
vel2.y *= scale_t;
vel2.z *= scale_t;
vel2.w = vel.w;
tmp = vel2.x * vel2.x + vel2.y * vel2.y + vel2.z * vel2.z;
akin_t = body_mass * tmp;
// update position
Scalar3 pos2;
pos2.x = com.x + vel2.x * scale_v;
pos2.y = com.y + vel2.y * scale_v;
pos2.z = com.z + vel2.z * scale_v;
// time to fix the periodic boundary conditions
box.wrap(pos2, body_image);
matrix_dot(ex_space, ey_space, ez_space, torque, tbody);
quatvec(orientation, tbody, fquat);
Scalar4 conjqm2;
conjqm2.x = conjqm.x + deltaT * fquat.x;
conjqm2.y = conjqm.y + deltaT * fquat.y;
conjqm2.z = conjqm.z + deltaT * fquat.z;
conjqm2.w = conjqm.w + deltaT * fquat.w;
conjqm2.x *= scale_r;
conjqm2.y *= scale_r;
conjqm2.z *= scale_r;
conjqm2.w *= scale_r;
// use no_squish rotate to update p and q
no_squish_rotate(3, conjqm2, orientation, moment_inertia, dt_half);
no_squish_rotate(2, conjqm2, orientation, moment_inertia, dt_half);
no_squish_rotate(1, conjqm2, orientation, moment_inertia, deltaT);
no_squish_rotate(2, conjqm2, orientation, moment_inertia, dt_half);
no_squish_rotate(3, conjqm2, orientation, moment_inertia, dt_half);
// update the exyz_space
// transform p back to angmom
// update angular velocity
Scalar4 angmom2;
exyzFromQuaternion(orientation, ex_space, ey_space, ez_space);
invquatvec(orientation, conjqm2, mbody);
transpose_dot(ex_space, ey_space, ez_space, mbody, angmom2);
angmom2.x *= Scalar(0.5);
angmom2.y *= Scalar(0.5);
angmom2.z *= Scalar(0.5);
Scalar4 angvel2;
computeAngularVelocity(angmom2, moment_inertia, ex_space, ey_space, ez_space, angvel2);
akin_r = angmom2.x * angvel2.x + angmom2.y * angvel2.y + angmom2.z * angvel2.z;
// write out the results (MEM_TRANSFER: ? bytes)
rdata_com[idx_body] = make_scalar4(pos2.x, pos2.y, pos2.z, com.w);
rdata_vel[idx_body] = vel2;
rdata_angmom[idx_body] = angmom2;
rdata_angvel[idx_body] = angvel2;
rdata_orientation[idx_body] = orientation;
rdata_body_image[idx_body] = body_image;
rdata_conjqm[idx_body] = conjqm2;
npt_rdata_partial_Ksum_t[group_idx] = akin_t;
npt_rdata_partial_Ksum_r[group_idx] = akin_r;
}
/*! \param rigid_data Rigid body data to step forward 1/2 step
\param d_group_members Device array listing the indicies of the mebers of the group to integrate
\param group_size Number of members in the group
\param d_net_force Particle net forces
\param box Box dimensions for periodic boundary condition handling
\param npt_rdata Thermostat/barostat data
\param deltaT Amount of real time to step forward in one time step
*/
hipError_t gpu_npt_rigid_step_one(const gpu_rigid_data_arrays& rigid_data,
unsigned int *d_group_members,
unsigned int group_size,
Scalar4 *d_net_force,
const BoxDim& box,
const gpu_npt_rigid_data& npt_rdata,
Scalar deltaT)
{
unsigned int n_bodies = rigid_data.n_bodies;
unsigned int n_group_bodies = rigid_data.n_group_bodies;
// setup the grid to run the kernel for rigid bodies
int block_size = 64;
int n_blocks = n_group_bodies / block_size + 1;
dim3 body_grid(n_blocks, 1, 1);
dim3 body_threads(block_size, 1, 1);
hipLaunchKernelGGL(( gpu_npt_rigid_step_one_body_kernel), dim3(body_grid), dim3(body_threads) , 0, 0, rigid_data.com,
rigid_data.vel,
rigid_data.angmom,
rigid_data.angvel,
rigid_data.orientation,
rigid_data.body_image,
rigid_data.conjqm,
rigid_data.body_mass,
rigid_data.moment_inertia,
rigid_data.force,
rigid_data.torque,
rigid_data.body_indices,
n_group_bodies,
n_bodies,
npt_rdata.eta_dot_t0,
npt_rdata.eta_dot_r0,
npt_rdata.epsilon_dot,
npt_rdata.partial_Ksum_t,
npt_rdata.partial_Ksum_r,
npt_rdata.nf_t,
npt_rdata.nf_r,
npt_rdata.dimension,
box,
deltaT);
hipLaunchKernelGGL(( gpu_npt_rigid_remap_kernel), dim3(body_grid), dim3(body_threads) , 0, 0, rigid_data.com,
rigid_data.body_indices,
n_group_bodies,
n_bodies,
box,
npt_rdata.dilation,
npt_rdata.dimension,
npt_rdata.new_box);
return hipSuccess;
}
#pragma mark RIGID_STEP_TWO_KERNEL
//! Takes the 2nd 1/2 step forward in the velocity-verlet NPT integration scheme
/*!
\param rdata_vel Body velocity
\param rdata_angmom Angular momentum
\param rdata_angvel Angular velocity
\param rdata_orientation Quaternion
\param rdata_conjqm Conjugate quaternion momentum
\param d_rigid_mass Body mass
\param d_rigid_mi Body inertia moments
\param d_rigid_force Body forces
\param d_rigid_torque Body torques
\param d_rigid_group Body indices
\param n_group_bodies Number of rigid bodies in my group
\param n_bodies Total number of rigid bodies
\param npt_rdata_eta_dot_t0 Thermostat translational part
\param npt_rdata_eta_dot_r0 Thermostat rotational part
\param npt_rdata_epsilon_dot Barostat velocity
\param npt_rdata_partial_Ksum_t Body translational kinetic energy
\param npt_rdata_partial_Ksum_r Body rotation kinetic energy
\param npt_rdata_nf_t Translational degrees of freedom
\param npt_rdata_nf_r Translational degrees of freedom
\param npt_rdata_dimension System dimesion
\param deltaT Timestep
\param box Box dimensions for periodic boundary condition handling
*/
extern "C" __global__ void gpu_npt_rigid_step_two_body_kernel(Scalar4* rdata_vel,
Scalar4* rdata_angmom,
Scalar4* rdata_angvel,
Scalar4* rdata_orientation,
Scalar4* rdata_conjqm,
Scalar *d_rigid_mass,
Scalar4 *d_rigid_mi,
Scalar4 *d_rigid_force,
Scalar4 *d_rigid_torque,
unsigned int *d_rigid_group,
unsigned int n_group_bodies,
unsigned int n_bodies,
Scalar npt_rdata_eta_dot_t0,
Scalar npt_rdata_eta_dot_r0,
Scalar npt_rdata_epsilon_dot,
Scalar* npt_rdata_partial_Ksum_t,
Scalar* npt_rdata_partial_Ksum_r,
unsigned int npt_rdata_nf_t,
unsigned int npt_rdata_nf_r,
unsigned int npt_rdata_dimension,
BoxDim box,
Scalar deltaT)
{
unsigned int group_idx = blockIdx.x * blockDim.x + threadIdx.x;
if (group_idx >= n_group_bodies)
return;
Scalar body_mass;
Scalar4 moment_inertia, vel, ex_space, ey_space, ez_space, orientation, conjqm;
Scalar4 force, torque;
Scalar4 mbody, tbody, fquat;
Scalar dt_half = Scalar(0.5) * deltaT;
Scalar onednft, onednfr, tmp, scale_t, scale_r, akin_t, akin_r;
onednft = Scalar(1.0) + Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
onednfr = Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_t0 + onednft * npt_rdata_epsilon_dot);
scale_t = exp(tmp);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_r0 + onednfr * npt_rdata_epsilon_dot);
scale_r = exp(tmp);
unsigned int idx_body = d_rigid_group[group_idx];
// Update body velocity and angmom
body_mass = d_rigid_mass[idx_body];
moment_inertia = d_rigid_mi[idx_body];
vel = rdata_vel[idx_body];
force = d_rigid_force[idx_body];
torque = d_rigid_torque[idx_body];
orientation = rdata_orientation[idx_body];
conjqm = rdata_conjqm[idx_body];
exyzFromQuaternion(orientation, ex_space, ey_space, ez_space);
Scalar dtfm = dt_half / body_mass;
// update the velocity
Scalar4 vel2;
vel2.x = scale_t * vel.x + dtfm * force.x;
vel2.y = scale_t * vel.y + dtfm * force.y;
vel2.z = scale_t * vel.z + dtfm * force.z;
vel2.w = Scalar(0.0);
tmp = vel2.x * vel2.x + vel2.y * vel2.y + vel2.z * vel2.z;
akin_t = body_mass * tmp;
// update angular momentum
matrix_dot(ex_space, ey_space, ez_space, torque, tbody);
quatvec(orientation, tbody, fquat);
Scalar4 conjqm2, angmom2;
conjqm2.x = scale_r * conjqm.x + deltaT * fquat.x;
conjqm2.y = scale_r * conjqm.y + deltaT * fquat.y;
conjqm2.z = scale_r * conjqm.z + deltaT * fquat.z;
conjqm2.w = scale_r * conjqm.w + deltaT * fquat.w;
invquatvec(orientation, conjqm2, mbody);
transpose_dot(ex_space, ey_space, ez_space, mbody, angmom2);
angmom2.x *= Scalar(0.5);
angmom2.y *= Scalar(0.5);
angmom2.z *= Scalar(0.5);
angmom2.w = Scalar(0.0);
// update angular velocity
Scalar4 angvel2;
computeAngularVelocity(angmom2, moment_inertia, ex_space, ey_space, ez_space, angvel2);
akin_r = angmom2.x * angvel2.x + angmom2.y * angvel2.y + angmom2.z * angvel2.z;
rdata_vel[idx_body] = vel2;
rdata_angmom[idx_body] = angmom2;
rdata_angvel[idx_body] = angvel2;
rdata_conjqm[idx_body] = conjqm2;
npt_rdata_partial_Ksum_t[group_idx] = akin_t;
npt_rdata_partial_Ksum_r[group_idx] = akin_r;
}
/*! \param rigid_data Rigid body data to step forward 1/2 step
\param d_group_members Device array listing the indicies of the mebers of the group to integrate
\param group_size Number of members in the group
\param d_net_force Particle net forces
\param d_net_virial Particle net virial
\param box Box dimensions for periodic boundary condition handling
\param npt_rdata Thermostat/barostat data
\param deltaT Amount of real time to step forward in one time step
*/
hipError_t gpu_npt_rigid_step_two( const gpu_rigid_data_arrays& rigid_data,
unsigned int *d_group_members,
unsigned int group_size,
Scalar4 *d_net_force,
Scalar *d_net_virial,
const BoxDim& box,
const gpu_npt_rigid_data& npt_rdata,
Scalar deltaT)
{
unsigned int n_bodies = rigid_data.n_bodies;
unsigned int n_group_bodies = rigid_data.n_group_bodies;
unsigned int block_size = 64;
unsigned int n_blocks = n_group_bodies / block_size + 1;
dim3 body_grid(n_blocks, 1, 1);
dim3 body_threads(block_size, 1, 1);
hipLaunchKernelGGL(( gpu_npt_rigid_step_two_body_kernel), dim3(body_grid), dim3(body_threads) , 0, 0, rigid_data.vel,
rigid_data.angmom,
rigid_data.angvel,
rigid_data.orientation,
rigid_data.conjqm,
rigid_data.body_mass,
rigid_data.moment_inertia,
rigid_data.force,
rigid_data.torque,
rigid_data.body_indices,
n_group_bodies,
n_bodies,
npt_rdata.eta_dot_t0,
npt_rdata.eta_dot_r0,
npt_rdata.epsilon_dot,
npt_rdata.partial_Ksum_t,
npt_rdata.partial_Ksum_r,
npt_rdata.nf_t,
npt_rdata.nf_r,
npt_rdata.dimension,
box,
deltaT);
return hipSuccess;
}
#pragma mark RIGID_KINETIC_ENERGY_REDUCTION
//! Shared memory for kinetic energy reduction
extern __shared__ Scalar npt_rigid_sdata[];
/*! Summing the kinetic energy of rigid bodies
\param npt_rdata Thermostat data for rigid bodies
*/
extern "C" __global__ void gpu_npt_rigid_reduce_ksum_kernel(gpu_npt_rigid_data npt_rdata)
{
int global_idx = blockIdx.x * blockDim.x + threadIdx.x;
Scalar* body_ke_t = npt_rigid_sdata;
Scalar* body_ke_r = &npt_rigid_sdata[blockDim.x];
Scalar Ksum_t = Scalar(0.0), Ksum_r=Scalar(0.0);
// sum up the values in the partial sum via a sliding window
for (int start = 0; start < npt_rdata.n_bodies; start += blockDim.x)
{
if (start + threadIdx.x < npt_rdata.n_bodies)
{
body_ke_t[threadIdx.x] = npt_rdata.partial_Ksum_t[start + threadIdx.x];
body_ke_r[threadIdx.x] = npt_rdata.partial_Ksum_r[start + threadIdx.x];
}
else
{
body_ke_t[threadIdx.x] = Scalar(0.0);
body_ke_r[threadIdx.x] = Scalar(0.0);
}
__syncthreads();
// reduce the sum within a block
int offset = blockDim.x >> 1;
while (offset > 0)
{
if (threadIdx.x < offset)
{
body_ke_t[threadIdx.x] += body_ke_t[threadIdx.x + offset];
body_ke_r[threadIdx.x] += body_ke_r[threadIdx.x + offset];
}
offset >>= 1;
__syncthreads();
}
// everybody sums up Ksum
Ksum_t += body_ke_t[0];
Ksum_r += body_ke_r[0];
}
__syncthreads();
if (global_idx == 0)
{
*npt_rdata.Ksum_t = Ksum_t;
*npt_rdata.Ksum_r = Ksum_r;
}
}
/*!
\param npt_rdata Thermostat/barostat data for rigid bodies
*/
hipError_t gpu_npt_rigid_reduce_ksum(const gpu_npt_rigid_data& npt_rdata)
{
// setup the grid to run the kernel
int block_size = 128;
dim3 grid( 1, 1, 1);
dim3 threads(block_size, 1, 1);
// run the kernel: double the block size to accomodate Ksum_t and Ksum_r
hipLaunchKernelGGL(( gpu_npt_rigid_reduce_ksum_kernel), dim3(grid), dim3(threads), 2 * block_size * sizeof(Scalar) , 0, npt_rdata);
return hipSuccess;
}
| 06548180e62068073ae13afdd7afd5c092189ee0.cu | /*
Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
(HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
the University of Michigan All rights reserved.
HOOMD-blue may contain modifications ("Contributions") provided, and to which
copyright is held, by various Contributors who have granted The Regents of the
University of Michigan the right to modify and/or distribute such Contributions.
You may redistribute, use, and create derivate works of HOOMD-blue, in source
and binary forms, provided you abide by the following conditions:
* Redistributions of source code must retain the above copyright notice, this
list of conditions, and the following disclaimer both in the code and
prominently in any materials provided with the distribution.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions, and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* All publications and presentations based on HOOMD-blue, including any reports
or published results obtained, in whole or in part, with HOOMD-blue, will
acknowledge its use according to the terms posted at the time of submission on:
http://codeblue.umich.edu/hoomd-blue/citations.html
* Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
http://codeblue.umich.edu/hoomd-blue/
* Apart from the above required attributions, neither the name of the copyright
holder nor the names of HOOMD-blue's contributors may be used to endorse or
promote products derived from this software without specific prior written
permission.
Disclaimer
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Maintainer: ndtrung
#include "QuaternionMath.h"
#include "TwoStepNPTRigidGPU.cuh"
#ifdef WIN32
#include <cassert>
#else
#include <assert.h>
#endif
/*! \file TwoStepNPTRigidGPU.cu
\brief Defines GPU kernel code for NPT integration on the GPU. Used by TwoStepNPTRigidGPU.
*/
// Flag for invalid particle index, identical to the sentinel value NO_INDEX in RigidData.h
#define INVALID_INDEX 0xffffffff
/*! Maclaurine expansion
\param x Point to take the expansion
*/
__device__ Scalar maclaurin_series(Scalar x)
{
Scalar x2, x4;
x2 = x * x;
x4 = x2 * x2;
return (Scalar(1.0) + (Scalar(1.0)/Scalar(6.0)) * x2 + (Scalar(1.0)/Scalar(120.0)) * x4 + (Scalar(1.0)/Scalar(5040.0)) * x2 * x4 + (Scalar(1.0)/Scalar(362880.0)) * x4 * x4);
}
/*! Kernel to zero virial contribution from particles from rigid bodies
\param d_virial_rigid Virial contribution from particles in rigid bodies
\param local_num Number of particles in this card
*/
extern "C" __global__ void gpu_npt_rigid_zero_virial_rigid_kernel(Scalar *d_virial_rigid,
unsigned int local_num)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x; // particle's index
if (idx < local_num)
{
d_virial_rigid[idx] = Scalar(0.0);
}
}
/*! Takes the first half-step forward for rigid bodies in the velocity-verlet NVT integration
\param rdata_com Body center of mass
\param d_rigid_group Body group
\param n_group_bodies Number of rigid bodies in my group
\param n_bodies Total umber of rigid bodies
\param box Box dimensions for periodic boundary condition handling
\param npt_rdata_dilation Volume scaling factor
\param npt_rdata_dimension System dimensionality
\param npt_rdata_new box New box sizes
*/
extern "C" __global__ void gpu_npt_rigid_remap_kernel(Scalar4 *rdata_com,
unsigned int *d_rigid_group,
unsigned int n_group_bodies,
unsigned int n_bodies,
BoxDim box,
Scalar npt_rdata_dilation,
unsigned int npt_rdata_dimension,
Scalar4 *npt_rdata_new_box)
{
unsigned int group_idx = blockIdx.x * blockDim.x + threadIdx.x;
if (group_idx >= n_group_bodies)
return;
unsigned int idx_body = d_rigid_group[group_idx];
Scalar3 curL = box.getL();
Scalar3 L;
// reset box to new size/shape
L.x = curL.x * npt_rdata_dilation;
L.y = curL.y * npt_rdata_dilation;
if (npt_rdata_dimension == 3)
L.z = curL.z * npt_rdata_dilation;
// copy and setL
BoxDim newBox = box;
newBox.setL(L);
Scalar4 com = rdata_com[idx_body];
Scalar3 f = box.makeFraction(make_scalar3(com.x, com.y, com.z));
Scalar3 pos = newBox.makeCoordinates(f);
// write out results
rdata_com[idx_body] = make_scalar4(pos.x, pos.y, pos.z, Scalar(0.0));
if (idx_body == 0)
{
*(npt_rdata_new_box) = make_scalar4(L.x, L.y, L.z, 0.0f);
}
}
#pragma mark RIGID_STEP_ONE_KERNEL
/*! Takes the first half-step forward for rigid bodies in the velocity-verlet NVT integration
\param rdata_com Body center of mass
\param rdata_vel Body velocity
\param rdata_angmom Angular momentum
\param rdata_angvel Angular velocity
\param rdata_orientation Quaternion
\param rdata_body_image Body image
\param rdata_conjqm Conjugate quaternion momentum
\param d_rigid_mass Body mass
\param d_rigid_mi Body inertia moments
\param n_group_bodies Number of rigid bodies in my group
\param d_rigid_force Body forces
\param d_rigid_torque Body torques
\param d_rigid_group Body indices
\param n_bodies Total umber of rigid bodies
\param npt_rdata_eta_dot_t0 Thermostat translational velocity
\param npt_rdata_eta_dot_r0 Thermostat rotational velocity
\param npt_rdata_epsilon_dot Barostat velocity
\param npt_rdata_partial_Ksum_t Body translational kinetic energy
\param npt_rdata_partial_Ksum_r Body rotation kinetic energy
\param npt_rdata_nf_t Translational degrees of freedom
\param npt_rdata_nf_r Translational degrees of freedom
\param npt_rdata_dimension System dimesion
\param box Box dimensions for periodic boundary condition handling
\param deltaT Timestep
*/
extern "C" __global__ void gpu_npt_rigid_step_one_body_kernel(Scalar4* rdata_com,
Scalar4* rdata_vel,
Scalar4* rdata_angmom,
Scalar4* rdata_angvel,
Scalar4* rdata_orientation,
int3* rdata_body_image,
Scalar4* rdata_conjqm,
Scalar *d_rigid_mass,
Scalar4 *d_rigid_mi,
Scalar4 *d_rigid_force,
Scalar4 *d_rigid_torque,
unsigned int *d_rigid_group,
unsigned int n_group_bodies,
unsigned int n_bodies,
Scalar npt_rdata_eta_dot_t0,
Scalar npt_rdata_eta_dot_r0,
Scalar npt_rdata_epsilon_dot,
Scalar* npt_rdata_partial_Ksum_t,
Scalar* npt_rdata_partial_Ksum_r,
unsigned int npt_rdata_nf_t,
unsigned int npt_rdata_nf_r,
unsigned int npt_rdata_dimension,
BoxDim box,
Scalar deltaT)
{
unsigned int group_idx = blockIdx.x * blockDim.x + threadIdx.x;
if (group_idx >= n_group_bodies)
return;
// do velocity verlet update
// v(t+deltaT/2) = v(t) + (1/2)a*deltaT
// r(t+deltaT) = r(t) + v(t+deltaT/2)*deltaT
Scalar body_mass;
Scalar4 moment_inertia, com, vel, orientation, ex_space, ey_space, ez_space, force, torque, conjqm;
int3 body_image;
Scalar4 mbody, tbody, fquat;
Scalar dt_half = Scalar(0.5) * deltaT;
Scalar onednft, onednfr, tmp, scale_t, scale_r, scale_v, akin_t, akin_r;
onednft = Scalar(1.0) + Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
onednfr = Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_t0 + onednft * npt_rdata_epsilon_dot);
scale_t = fast::exp(tmp);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_r0 + onednfr * npt_rdata_epsilon_dot);
scale_r = fast::exp(tmp);
tmp = dt_half * npt_rdata_epsilon_dot;
scale_v = deltaT * fast::exp(tmp) * maclaurin_series(tmp);
unsigned int idx_body = d_rigid_group[group_idx];
body_mass = d_rigid_mass[idx_body];
moment_inertia = d_rigid_mi[idx_body];
com = rdata_com[idx_body];
vel = rdata_vel[idx_body];
orientation = rdata_orientation[idx_body];
body_image = rdata_body_image[idx_body];
force = d_rigid_force[idx_body];
torque = d_rigid_torque[idx_body];
conjqm = rdata_conjqm[idx_body];
exyzFromQuaternion(orientation, ex_space, ey_space, ez_space);
// update velocity
Scalar dtfm = dt_half / body_mass;
Scalar4 vel2;
vel2.x = vel.x + dtfm * force.x;
vel2.y = vel.y + dtfm * force.y;
vel2.z = vel.z + dtfm * force.z;
vel2.x *= scale_t;
vel2.y *= scale_t;
vel2.z *= scale_t;
vel2.w = vel.w;
tmp = vel2.x * vel2.x + vel2.y * vel2.y + vel2.z * vel2.z;
akin_t = body_mass * tmp;
// update position
Scalar3 pos2;
pos2.x = com.x + vel2.x * scale_v;
pos2.y = com.y + vel2.y * scale_v;
pos2.z = com.z + vel2.z * scale_v;
// time to fix the periodic boundary conditions
box.wrap(pos2, body_image);
matrix_dot(ex_space, ey_space, ez_space, torque, tbody);
quatvec(orientation, tbody, fquat);
Scalar4 conjqm2;
conjqm2.x = conjqm.x + deltaT * fquat.x;
conjqm2.y = conjqm.y + deltaT * fquat.y;
conjqm2.z = conjqm.z + deltaT * fquat.z;
conjqm2.w = conjqm.w + deltaT * fquat.w;
conjqm2.x *= scale_r;
conjqm2.y *= scale_r;
conjqm2.z *= scale_r;
conjqm2.w *= scale_r;
// use no_squish rotate to update p and q
no_squish_rotate(3, conjqm2, orientation, moment_inertia, dt_half);
no_squish_rotate(2, conjqm2, orientation, moment_inertia, dt_half);
no_squish_rotate(1, conjqm2, orientation, moment_inertia, deltaT);
no_squish_rotate(2, conjqm2, orientation, moment_inertia, dt_half);
no_squish_rotate(3, conjqm2, orientation, moment_inertia, dt_half);
// update the exyz_space
// transform p back to angmom
// update angular velocity
Scalar4 angmom2;
exyzFromQuaternion(orientation, ex_space, ey_space, ez_space);
invquatvec(orientation, conjqm2, mbody);
transpose_dot(ex_space, ey_space, ez_space, mbody, angmom2);
angmom2.x *= Scalar(0.5);
angmom2.y *= Scalar(0.5);
angmom2.z *= Scalar(0.5);
Scalar4 angvel2;
computeAngularVelocity(angmom2, moment_inertia, ex_space, ey_space, ez_space, angvel2);
akin_r = angmom2.x * angvel2.x + angmom2.y * angvel2.y + angmom2.z * angvel2.z;
// write out the results (MEM_TRANSFER: ? bytes)
rdata_com[idx_body] = make_scalar4(pos2.x, pos2.y, pos2.z, com.w);
rdata_vel[idx_body] = vel2;
rdata_angmom[idx_body] = angmom2;
rdata_angvel[idx_body] = angvel2;
rdata_orientation[idx_body] = orientation;
rdata_body_image[idx_body] = body_image;
rdata_conjqm[idx_body] = conjqm2;
npt_rdata_partial_Ksum_t[group_idx] = akin_t;
npt_rdata_partial_Ksum_r[group_idx] = akin_r;
}
/*! \param rigid_data Rigid body data to step forward 1/2 step
\param d_group_members Device array listing the indicies of the mebers of the group to integrate
\param group_size Number of members in the group
\param d_net_force Particle net forces
\param box Box dimensions for periodic boundary condition handling
\param npt_rdata Thermostat/barostat data
\param deltaT Amount of real time to step forward in one time step
*/
cudaError_t gpu_npt_rigid_step_one(const gpu_rigid_data_arrays& rigid_data,
unsigned int *d_group_members,
unsigned int group_size,
Scalar4 *d_net_force,
const BoxDim& box,
const gpu_npt_rigid_data& npt_rdata,
Scalar deltaT)
{
unsigned int n_bodies = rigid_data.n_bodies;
unsigned int n_group_bodies = rigid_data.n_group_bodies;
// setup the grid to run the kernel for rigid bodies
int block_size = 64;
int n_blocks = n_group_bodies / block_size + 1;
dim3 body_grid(n_blocks, 1, 1);
dim3 body_threads(block_size, 1, 1);
gpu_npt_rigid_step_one_body_kernel<<< body_grid, body_threads >>>(rigid_data.com,
rigid_data.vel,
rigid_data.angmom,
rigid_data.angvel,
rigid_data.orientation,
rigid_data.body_image,
rigid_data.conjqm,
rigid_data.body_mass,
rigid_data.moment_inertia,
rigid_data.force,
rigid_data.torque,
rigid_data.body_indices,
n_group_bodies,
n_bodies,
npt_rdata.eta_dot_t0,
npt_rdata.eta_dot_r0,
npt_rdata.epsilon_dot,
npt_rdata.partial_Ksum_t,
npt_rdata.partial_Ksum_r,
npt_rdata.nf_t,
npt_rdata.nf_r,
npt_rdata.dimension,
box,
deltaT);
gpu_npt_rigid_remap_kernel<<< body_grid, body_threads >>>(rigid_data.com,
rigid_data.body_indices,
n_group_bodies,
n_bodies,
box,
npt_rdata.dilation,
npt_rdata.dimension,
npt_rdata.new_box);
return cudaSuccess;
}
#pragma mark RIGID_STEP_TWO_KERNEL
//! Takes the 2nd 1/2 step forward in the velocity-verlet NPT integration scheme
/*!
\param rdata_vel Body velocity
\param rdata_angmom Angular momentum
\param rdata_angvel Angular velocity
\param rdata_orientation Quaternion
\param rdata_conjqm Conjugate quaternion momentum
\param d_rigid_mass Body mass
\param d_rigid_mi Body inertia moments
\param d_rigid_force Body forces
\param d_rigid_torque Body torques
\param d_rigid_group Body indices
\param n_group_bodies Number of rigid bodies in my group
\param n_bodies Total number of rigid bodies
\param npt_rdata_eta_dot_t0 Thermostat translational part
\param npt_rdata_eta_dot_r0 Thermostat rotational part
\param npt_rdata_epsilon_dot Barostat velocity
\param npt_rdata_partial_Ksum_t Body translational kinetic energy
\param npt_rdata_partial_Ksum_r Body rotation kinetic energy
\param npt_rdata_nf_t Translational degrees of freedom
\param npt_rdata_nf_r Translational degrees of freedom
\param npt_rdata_dimension System dimesion
\param deltaT Timestep
\param box Box dimensions for periodic boundary condition handling
*/
extern "C" __global__ void gpu_npt_rigid_step_two_body_kernel(Scalar4* rdata_vel,
Scalar4* rdata_angmom,
Scalar4* rdata_angvel,
Scalar4* rdata_orientation,
Scalar4* rdata_conjqm,
Scalar *d_rigid_mass,
Scalar4 *d_rigid_mi,
Scalar4 *d_rigid_force,
Scalar4 *d_rigid_torque,
unsigned int *d_rigid_group,
unsigned int n_group_bodies,
unsigned int n_bodies,
Scalar npt_rdata_eta_dot_t0,
Scalar npt_rdata_eta_dot_r0,
Scalar npt_rdata_epsilon_dot,
Scalar* npt_rdata_partial_Ksum_t,
Scalar* npt_rdata_partial_Ksum_r,
unsigned int npt_rdata_nf_t,
unsigned int npt_rdata_nf_r,
unsigned int npt_rdata_dimension,
BoxDim box,
Scalar deltaT)
{
unsigned int group_idx = blockIdx.x * blockDim.x + threadIdx.x;
if (group_idx >= n_group_bodies)
return;
Scalar body_mass;
Scalar4 moment_inertia, vel, ex_space, ey_space, ez_space, orientation, conjqm;
Scalar4 force, torque;
Scalar4 mbody, tbody, fquat;
Scalar dt_half = Scalar(0.5) * deltaT;
Scalar onednft, onednfr, tmp, scale_t, scale_r, akin_t, akin_r;
onednft = Scalar(1.0) + Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
onednfr = Scalar(npt_rdata_dimension) / Scalar(npt_rdata_nf_t+npt_rdata_nf_r);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_t0 + onednft * npt_rdata_epsilon_dot);
scale_t = exp(tmp);
tmp = Scalar(-1.0) * dt_half * (npt_rdata_eta_dot_r0 + onednfr * npt_rdata_epsilon_dot);
scale_r = exp(tmp);
unsigned int idx_body = d_rigid_group[group_idx];
// Update body velocity and angmom
body_mass = d_rigid_mass[idx_body];
moment_inertia = d_rigid_mi[idx_body];
vel = rdata_vel[idx_body];
force = d_rigid_force[idx_body];
torque = d_rigid_torque[idx_body];
orientation = rdata_orientation[idx_body];
conjqm = rdata_conjqm[idx_body];
exyzFromQuaternion(orientation, ex_space, ey_space, ez_space);
Scalar dtfm = dt_half / body_mass;
// update the velocity
Scalar4 vel2;
vel2.x = scale_t * vel.x + dtfm * force.x;
vel2.y = scale_t * vel.y + dtfm * force.y;
vel2.z = scale_t * vel.z + dtfm * force.z;
vel2.w = Scalar(0.0);
tmp = vel2.x * vel2.x + vel2.y * vel2.y + vel2.z * vel2.z;
akin_t = body_mass * tmp;
// update angular momentum
matrix_dot(ex_space, ey_space, ez_space, torque, tbody);
quatvec(orientation, tbody, fquat);
Scalar4 conjqm2, angmom2;
conjqm2.x = scale_r * conjqm.x + deltaT * fquat.x;
conjqm2.y = scale_r * conjqm.y + deltaT * fquat.y;
conjqm2.z = scale_r * conjqm.z + deltaT * fquat.z;
conjqm2.w = scale_r * conjqm.w + deltaT * fquat.w;
invquatvec(orientation, conjqm2, mbody);
transpose_dot(ex_space, ey_space, ez_space, mbody, angmom2);
angmom2.x *= Scalar(0.5);
angmom2.y *= Scalar(0.5);
angmom2.z *= Scalar(0.5);
angmom2.w = Scalar(0.0);
// update angular velocity
Scalar4 angvel2;
computeAngularVelocity(angmom2, moment_inertia, ex_space, ey_space, ez_space, angvel2);
akin_r = angmom2.x * angvel2.x + angmom2.y * angvel2.y + angmom2.z * angvel2.z;
rdata_vel[idx_body] = vel2;
rdata_angmom[idx_body] = angmom2;
rdata_angvel[idx_body] = angvel2;
rdata_conjqm[idx_body] = conjqm2;
npt_rdata_partial_Ksum_t[group_idx] = akin_t;
npt_rdata_partial_Ksum_r[group_idx] = akin_r;
}
/*! \param rigid_data Rigid body data to step forward 1/2 step
\param d_group_members Device array listing the indicies of the mebers of the group to integrate
\param group_size Number of members in the group
\param d_net_force Particle net forces
\param d_net_virial Particle net virial
\param box Box dimensions for periodic boundary condition handling
\param npt_rdata Thermostat/barostat data
\param deltaT Amount of real time to step forward in one time step
*/
cudaError_t gpu_npt_rigid_step_two( const gpu_rigid_data_arrays& rigid_data,
unsigned int *d_group_members,
unsigned int group_size,
Scalar4 *d_net_force,
Scalar *d_net_virial,
const BoxDim& box,
const gpu_npt_rigid_data& npt_rdata,
Scalar deltaT)
{
unsigned int n_bodies = rigid_data.n_bodies;
unsigned int n_group_bodies = rigid_data.n_group_bodies;
unsigned int block_size = 64;
unsigned int n_blocks = n_group_bodies / block_size + 1;
dim3 body_grid(n_blocks, 1, 1);
dim3 body_threads(block_size, 1, 1);
gpu_npt_rigid_step_two_body_kernel<<< body_grid, body_threads >>>(rigid_data.vel,
rigid_data.angmom,
rigid_data.angvel,
rigid_data.orientation,
rigid_data.conjqm,
rigid_data.body_mass,
rigid_data.moment_inertia,
rigid_data.force,
rigid_data.torque,
rigid_data.body_indices,
n_group_bodies,
n_bodies,
npt_rdata.eta_dot_t0,
npt_rdata.eta_dot_r0,
npt_rdata.epsilon_dot,
npt_rdata.partial_Ksum_t,
npt_rdata.partial_Ksum_r,
npt_rdata.nf_t,
npt_rdata.nf_r,
npt_rdata.dimension,
box,
deltaT);
return cudaSuccess;
}
#pragma mark RIGID_KINETIC_ENERGY_REDUCTION
//! Shared memory for kinetic energy reduction
extern __shared__ Scalar npt_rigid_sdata[];
/*! Summing the kinetic energy of rigid bodies
\param npt_rdata Thermostat data for rigid bodies
*/
extern "C" __global__ void gpu_npt_rigid_reduce_ksum_kernel(gpu_npt_rigid_data npt_rdata)
{
int global_idx = blockIdx.x * blockDim.x + threadIdx.x;
Scalar* body_ke_t = npt_rigid_sdata;
Scalar* body_ke_r = &npt_rigid_sdata[blockDim.x];
Scalar Ksum_t = Scalar(0.0), Ksum_r=Scalar(0.0);
// sum up the values in the partial sum via a sliding window
for (int start = 0; start < npt_rdata.n_bodies; start += blockDim.x)
{
if (start + threadIdx.x < npt_rdata.n_bodies)
{
body_ke_t[threadIdx.x] = npt_rdata.partial_Ksum_t[start + threadIdx.x];
body_ke_r[threadIdx.x] = npt_rdata.partial_Ksum_r[start + threadIdx.x];
}
else
{
body_ke_t[threadIdx.x] = Scalar(0.0);
body_ke_r[threadIdx.x] = Scalar(0.0);
}
__syncthreads();
// reduce the sum within a block
int offset = blockDim.x >> 1;
while (offset > 0)
{
if (threadIdx.x < offset)
{
body_ke_t[threadIdx.x] += body_ke_t[threadIdx.x + offset];
body_ke_r[threadIdx.x] += body_ke_r[threadIdx.x + offset];
}
offset >>= 1;
__syncthreads();
}
// everybody sums up Ksum
Ksum_t += body_ke_t[0];
Ksum_r += body_ke_r[0];
}
__syncthreads();
if (global_idx == 0)
{
*npt_rdata.Ksum_t = Ksum_t;
*npt_rdata.Ksum_r = Ksum_r;
}
}
/*!
\param npt_rdata Thermostat/barostat data for rigid bodies
*/
cudaError_t gpu_npt_rigid_reduce_ksum(const gpu_npt_rigid_data& npt_rdata)
{
// setup the grid to run the kernel
int block_size = 128;
dim3 grid( 1, 1, 1);
dim3 threads(block_size, 1, 1);
// run the kernel: double the block size to accomodate Ksum_t and Ksum_r
gpu_npt_rigid_reduce_ksum_kernel<<< grid, threads, 2 * block_size * sizeof(Scalar) >>>(npt_rdata);
return cudaSuccess;
}
|
4a114cab06c4e41f5696ffe912d476e8e7795f7c.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*--
This File include
--*/
#include <time.h>
#include "../include/MCMPC_Controller.cuh"
void set_GPU_constant_values(const float *q, const float *r, const float *sys_pr, const float *inp_cntrnt, const float *st_cntrnt){
hipMemcpyToSymbol(d_Q, &q, DIM_Q * sizeof(float));
hipMemcpyToSymbol(d_R, &r, DIM_R * sizeof(float));
hipMemcpyToSymbol(d_param, &sys_pr, NUM_OF_SYS_PARAMETERS * sizeof(float));
hipMemcpyToSymbol(output_constraint, &st_cntrnt, NUM_OF_S_CONSTRAINT * sizeof(float));
printf("#Successful copy of parameters from host to device d_param == %f\n",sys_pr[0]);
}
void set_GPU_constant_values_2(const float *q, const float *r, const float *qf, const float *rf, const float *sys_pr, const float *inp_cntrnt, const float *st_cntrnt){
hipMemcpyToSymbol(d_Q, &q, DIM_Q * sizeof(float));
hipMemcpyToSymbol(d_R, &r, DIM_R * sizeof(float));
hipMemcpyToSymbol(d_param, &sys_pr, NUM_OF_SYS_PARAMETERS * sizeof(float));
hipMemcpyToSymbol(input_constraint, &inp_cntrnt, NUM_OF_I_CONSTRAINT * sizeof(float));
hipMemcpyToSymbol(output_constraint, &st_cntrnt, NUM_OF_S_CONSTRAINT * sizeof(float));
hipMemcpyToSymbol(d_Qf, &qf, DIM_Qf * sizeof(float));
hipMemcpyToSymbol(d_Rf, &rf, DIM_Rf * sizeof(float));
printf("#Successful copy of parameters from host to device");
}
__device__ float generate_u1(unsigned int id, hiprandState_t *state, float ave, float vr) {
float u;
hiprandState_t localState = state[id];
u = hiprand_normal(&localState) * vr + ave;
return u;
}
__global__ void MCMPC_GPU(float *h_state, SpecGPU gpu_info, hiprandState_t *devSt, DataMessanger *dvc, float *var, InputSequences *InpSeq){
unsigned int id = threadIdx.x + blockDim.x * blockIdx.x;
unsigned int random_id = id;
float U_dev[DIM_U][NUM_OF_HORIZON], Input_here[DIM_U];
float Dev_State[DIM_X], dev_Diff_State[DIM_X];
float Cost = 0;
general_copy(Dev_State, h_state, DIM_X);
for(int i = 0; i < NUM_OF_HORIZON; i++){
for(int k = 0; k < DIM_U; k++){
// U_dev[k][i] = dvc[blockIdx.x].u[k][i];
Input_here[k] = generate_u1(random_id, devSt, InpSeq[k].u[i], st_dev[k]);
random_id += k*DIM_U + i;
Input_here[k] = input_saturation(Input_here[k], input_constraint, k);
U_dev[k][i] = Input_here[k]; //
/*if(blockIdx.x == 1 && threadIdx.x == 1){
printf("RandamizedInput:%f Mean:%f\n", Input_here[k], InpSeq[k].u[i]);
}*/
}
// update predictive model by using random input
get_current_diff_state(Dev_State, Input_here, d_param, dev_Diff_State);
euler_integrator_in_thread(Dev_State, dev_Diff_State, gpu_info.RATE_OF_CYCLE);
Cost += get_stage_cost(Dev_State ,dev_Diff_State, Input_here, d_Q, d_R, output_constraint);
}
//printf("ID:%d INP: %f Cost:%f, State[0]: %f\n",id, Input_here[0], Cost, d_R[0]);
float exp_COST, S;
S = Cost / gpu_info.LAMBDA;
exp_COST = expf(-S);
thread_COST[threadIdx.x] = Cost;
thread_exp_COST[threadIdx.x] = exp_COST;
__syncthreads();
if(threadIdx.x == 0){
NO1 = 0;
for(int i = 1; i < blockDim.x; i++){
if(thread_COST[i] < thread_COST[NO1])
NO1 = i;
}
}
__syncthreads();
if(threadIdx.x == NO1){
dvc[blockIdx.x].L = thread_COST[NO1];
dvc[blockIdx.x].W = thread_exp_COST[NO1];
for(int i = 0; i < NUM_OF_HORIZON; i++){
for(int k = 0; k < DIM_U; k++){
dvc[blockIdx.x].u[k][i] = U_dev[k][i];
}
}
//printf("ID: %d Value: %f Mean: %f Cost:%f\n", id, U_dev[0][0], InpSeq[0].u[0], thread_COST[NO1]);
//dvc[blockIdx.x] = in_block;
}
}
void MCMPC_Controller(float *state, ControllerInfo &info_cont , SpecGPU gpu_info, ControllerParams param, DataMessanger *hst, DataMessanger *dvc, InputSequences *InpSeq, hiprandState_t *se, InputSequences *device_InpSeq){
if(param.NUM_CYCLES == 0){
hipMemcpyToSymbol(d_Q, &Q, DIM_Q * sizeof(float));
hipMemcpyToSymbol(d_R, &R, DIM_R * sizeof(float));
hipMemcpyToSymbol(d_param, &system_params, NUM_OF_SYS_PARAMETERS * sizeof(float));
hipMemcpyToSymbol(output_constraint, &constraint_for_state, NUM_OF_S_CONSTRAINT * sizeof(float));
hipMemcpyToSymbol(input_constraint, &constraint_for_input, NUM_OF_I_CONSTRAINT * sizeof(float));
}
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);
// InputSequences *device_InpSeq;
float *h_state;
// hipMalloc((void**)&device_InpSeq, DIM_U * sizeof(InputSequences));
hipMalloc(&h_state,DIM_X * sizeof(float));
hipMemcpy(h_state, state, DIM_X*sizeof(float), hipMemcpyHostToDevice); //
float variance[DIM_U];
float *dptr = NULL;
hipGetSymbolAddress((void**)&dptr, device_InpSeq);
//variance = (float*)malloc(DIM_U * sizeof(float));
//printf("Function: %f\n", hst[10].u[0][10]);
/* Iterate Predction Process */
for(int i = 0; i < gpu_info.ITERATIONS; i++){
switch(COOLING_PATTERN){
case 1:
for(int k = 0; k < DIM_U; k++){
variance[k] = geometric_cooling(gpu_info.INIT_VARIANCE[k], i, gpu_info.COOLING_RATES[k]);
}
break;
case 2:
for(int k = 0; k < DIM_U; k++){
variance[k] = hyperbolic_cooling(gpu_info.INIT_VARIANCE[k], i);
}
break;
default:
for(int k = 0; k < DIM_U; k++){
variance[k] = gpu_info.INIT_VARIANCE[k];
}
break;
}
//hipMemcpy(dptr, InpSeq, DIM_U * sizeof(InputSequences),hipMemcpyHostToDevice);
copy_input_sequences(InpSeq, device_InpSeq, gpu_info);
hipMemcpyToSymbol(st_dev, &variance, DIM_U*sizeof(float));
hipLaunchKernelGGL(( MCMPC_GPU), dim3(gpu_info.NUM_BLOCKS),dim3(gpu_info.TH_PER_BLS), 0, 0, h_state, gpu_info, se, dvc, variance, device_InpSeq);
hipDeviceSynchronize();
hipMemcpy(hst, dvc, gpu_info.NUM_BLOCKS * sizeof(DataMessanger),hipMemcpyDeviceToHost); //
switch(PREDICTIVE_METHOD){
case 1:
TOP1_sample_method(hst, gpu_info, InpSeq);
break;
case 2:
TOP1_sample_method(hst, gpu_info, InpSeq);
break;
default:
printf("The value of <PREDICTIVE_METHOD> in headerfile you created is invalid\n");
break;
}
//printf("Values From Function: %f CostFrom: %f TOP_Input: %f\n", hst[10].u[0][0], hst[10].L, InpSeq[0].u[0]);
}
//hst[10].u[0][10] = 1.0;
printf("Values From Function: %f\n", InpSeq[0].u[0]);
}
| 4a114cab06c4e41f5696ffe912d476e8e7795f7c.cu | /*--
This File include
--*/
#include <time.h>
#include "../include/MCMPC_Controller.cuh"
void set_GPU_constant_values(const float *q, const float *r, const float *sys_pr, const float *inp_cntrnt, const float *st_cntrnt){
cudaMemcpyToSymbol(d_Q, &q, DIM_Q * sizeof(float));
cudaMemcpyToSymbol(d_R, &r, DIM_R * sizeof(float));
cudaMemcpyToSymbol(d_param, &sys_pr, NUM_OF_SYS_PARAMETERS * sizeof(float));
cudaMemcpyToSymbol(output_constraint, &st_cntrnt, NUM_OF_S_CONSTRAINT * sizeof(float));
printf("#Successful copy of parameters from host to device d_param == %f\n",sys_pr[0]);
}
void set_GPU_constant_values_2(const float *q, const float *r, const float *qf, const float *rf, const float *sys_pr, const float *inp_cntrnt, const float *st_cntrnt){
cudaMemcpyToSymbol(d_Q, &q, DIM_Q * sizeof(float));
cudaMemcpyToSymbol(d_R, &r, DIM_R * sizeof(float));
cudaMemcpyToSymbol(d_param, &sys_pr, NUM_OF_SYS_PARAMETERS * sizeof(float));
cudaMemcpyToSymbol(input_constraint, &inp_cntrnt, NUM_OF_I_CONSTRAINT * sizeof(float));
cudaMemcpyToSymbol(output_constraint, &st_cntrnt, NUM_OF_S_CONSTRAINT * sizeof(float));
cudaMemcpyToSymbol(d_Qf, &qf, DIM_Qf * sizeof(float));
cudaMemcpyToSymbol(d_Rf, &rf, DIM_Rf * sizeof(float));
printf("#Successful copy of parameters from host to device");
}
__device__ float generate_u1(unsigned int id, curandState *state, float ave, float vr) {
float u;
curandState localState = state[id];
u = curand_normal(&localState) * vr + ave;
return u;
}
__global__ void MCMPC_GPU(float *h_state, SpecGPU gpu_info, curandState *devSt, DataMessanger *dvc, float *var, InputSequences *InpSeq){
unsigned int id = threadIdx.x + blockDim.x * blockIdx.x;
unsigned int random_id = id;
float U_dev[DIM_U][NUM_OF_HORIZON], Input_here[DIM_U];
float Dev_State[DIM_X], dev_Diff_State[DIM_X];
float Cost = 0;
general_copy(Dev_State, h_state, DIM_X);
for(int i = 0; i < NUM_OF_HORIZON; i++){
for(int k = 0; k < DIM_U; k++){
// U_dev[k][i] = dvc[blockIdx.x].u[k][i];
Input_here[k] = generate_u1(random_id, devSt, InpSeq[k].u[i], st_dev[k]);
random_id += k*DIM_U + i;
Input_here[k] = input_saturation(Input_here[k], input_constraint, k);
U_dev[k][i] = Input_here[k]; //入力を生成する関数はここ(同じファイル)に記述しないと機能しない
/*if(blockIdx.x == 1 && threadIdx.x == 1){
printf("RandamizedInput:%f Mean:%f\n", Input_here[k], InpSeq[k].u[i]);
}*/
}
// update predictive model by using random input
get_current_diff_state(Dev_State, Input_here, d_param, dev_Diff_State);
euler_integrator_in_thread(Dev_State, dev_Diff_State, gpu_info.RATE_OF_CYCLE);
Cost += get_stage_cost(Dev_State ,dev_Diff_State, Input_here, d_Q, d_R, output_constraint);
}
//printf("ID:%d INP: %f Cost:%f, State[0]: %f\n",id, Input_here[0], Cost, d_R[0]);
float exp_COST, S;
S = Cost / gpu_info.LAMBDA;
exp_COST = expf(-S);
thread_COST[threadIdx.x] = Cost;
thread_exp_COST[threadIdx.x] = exp_COST;
__syncthreads();
if(threadIdx.x == 0){
NO1 = 0;
for(int i = 1; i < blockDim.x; i++){
if(thread_COST[i] < thread_COST[NO1])
NO1 = i;
}
}
__syncthreads();
if(threadIdx.x == NO1){
dvc[blockIdx.x].L = thread_COST[NO1];
dvc[blockIdx.x].W = thread_exp_COST[NO1];
for(int i = 0; i < NUM_OF_HORIZON; i++){
for(int k = 0; k < DIM_U; k++){
dvc[blockIdx.x].u[k][i] = U_dev[k][i];
}
}
//printf("ID: %d Value: %f Mean: %f Cost:%f\n", id, U_dev[0][0], InpSeq[0].u[0], thread_COST[NO1]);
//dvc[blockIdx.x] = in_block;
}
}
void MCMPC_Controller(float *state, ControllerInfo &info_cont , SpecGPU gpu_info, ControllerParams param, DataMessanger *hst, DataMessanger *dvc, InputSequences *InpSeq, curandState *se, InputSequences *device_InpSeq){
if(param.NUM_CYCLES == 0){
cudaMemcpyToSymbol(d_Q, &Q, DIM_Q * sizeof(float));
cudaMemcpyToSymbol(d_R, &R, DIM_R * sizeof(float));
cudaMemcpyToSymbol(d_param, &system_params, NUM_OF_SYS_PARAMETERS * sizeof(float));
cudaMemcpyToSymbol(output_constraint, &constraint_for_state, NUM_OF_S_CONSTRAINT * sizeof(float));
cudaMemcpyToSymbol(input_constraint, &constraint_for_input, NUM_OF_I_CONSTRAINT * sizeof(float));
}
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
// InputSequences *device_InpSeq;
float *h_state;
// cudaMalloc((void**)&device_InpSeq, DIM_U * sizeof(InputSequences));
cudaMalloc(&h_state,DIM_X * sizeof(float));
cudaMemcpy(h_state, state, DIM_X*sizeof(float), cudaMemcpyHostToDevice); //状態量をデバイスで使用する変数にコピー
float variance[DIM_U];
float *dptr = NULL;
cudaGetSymbolAddress((void**)&dptr, device_InpSeq);
//variance = (float*)malloc(DIM_U * sizeof(float));
//printf("Function: %f\n", hst[10].u[0][10]);
/* Iterate Predction Process */
for(int i = 0; i < gpu_info.ITERATIONS; i++){
switch(COOLING_PATTERN){
case 1:
for(int k = 0; k < DIM_U; k++){
variance[k] = geometric_cooling(gpu_info.INIT_VARIANCE[k], i, gpu_info.COOLING_RATES[k]);
}
break;
case 2:
for(int k = 0; k < DIM_U; k++){
variance[k] = hyperbolic_cooling(gpu_info.INIT_VARIANCE[k], i);
}
break;
default:
for(int k = 0; k < DIM_U; k++){
variance[k] = gpu_info.INIT_VARIANCE[k];
}
break;
}
//cudaMemcpy(dptr, InpSeq, DIM_U * sizeof(InputSequences),cudaMemcpyHostToDevice);
copy_input_sequences(InpSeq, device_InpSeq, gpu_info);
cudaMemcpyToSymbol(st_dev, &variance, DIM_U*sizeof(float));
MCMPC_GPU<<<gpu_info.NUM_BLOCKS,gpu_info.TH_PER_BLS>>>(h_state, gpu_info, se, dvc, variance, device_InpSeq);
cudaDeviceSynchronize();
cudaMemcpy(hst, dvc, gpu_info.NUM_BLOCKS * sizeof(DataMessanger),cudaMemcpyDeviceToHost); //ここでコピーしても記述されない
switch(PREDICTIVE_METHOD){
case 1:
TOP1_sample_method(hst, gpu_info, InpSeq);
break;
case 2:
TOP1_sample_method(hst, gpu_info, InpSeq);
break;
default:
printf("The value of <PREDICTIVE_METHOD> in headerfile you created is invalid\n");
break;
}
//printf("Values From Function: %f CostFrom: %f TOP_Input: %f\n", hst[10].u[0][0], hst[10].L, InpSeq[0].u[0]);
}
//hst[10].u[0][10] = 1.0;
printf("Values From Function: %f\n", InpSeq[0].u[0]);
}
|
e084034b8fa859d55fc3034f30eee0cbd82f348a.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/perception/lidar/lib/detector/cnn_segmentation/feature_generator.h"
#include "modules/perception/base/common.h"
namespace apollo {
namespace perception {
namespace lidar {
#define CUDA_KERNEL_LOOP(i, n) \
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < (n); \
i += blockDim.x * gridDim.x)
#if __CUDA_ARCH__ < 600
__device__ double atomicAdd(double* address, double val) {
unsigned long long int* address_as_ull = (unsigned long long int*)address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__double_as_longlong(val + __longlong_as_double(assumed)));
// Note: uses integer comparison to avoid hang in case of NaN
// (since NaN != NaN)
} while (assumed != old);
return __longlong_as_double(old);
}
#endif
__device__ float atomicAdd(float* address, float val) {
int* address_as_ull = reinterpret_cast<int*>(address);
int old = *address_as_ull, assumed;
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__float_as_int(val + __int_as_float(assumed)));
// Note: uses integer comparison to avoid hang in case of NaN
// (since NaN != NaN)
} while (assumed != old);
return __int_as_float(old);
}
__device__ double atomic_exch(double* addr, double val) {
unsigned long long int* m_addr = (unsigned long long int*)addr;
unsigned long long int old_val = 0;
old_val = atomicExch(m_addr, __double_as_longlong(val));
return __longlong_as_double(old_val);
}
__device__ float atomic_exch(float* addr, float val) {
return atomicExch(addr, (val));
}
// __device__ void atomicMax(double* max_height_addr, double pz) {
// double old_pz = *max_height_addr;
// do {
// old_pz = atomic_exch(max_height_addr, (pz));
// if (pz < old_pz) {
// pz = old_pz;
// }
// } while (pz > (*max_height_addr));
// }
__device__ void atomicMax(float* max_height_addr, float pz) {
float old_pz = *max_height_addr;
do {
old_pz = atomic_exch(max_height_addr, (pz));
if (pz < old_pz) {
pz = old_pz;
}
} while (pz > (*max_height_addr));
}
template <typename Dtype>
__global__ void MapKernel(const int n, const base::PointF* pc,
Dtype* max_height_data, Dtype* mean_height_data,
Dtype* mean_intensity_data, Dtype* count_data,
int* point2grid) {
CUDA_KERNEL_LOOP(i, n) {
int idx = point2grid[i];
if (idx == -1) {
continue;
}
Dtype pz = pc[i].z;
Dtype pi = pc[i].intensity / 255.0;
atomicMax(&max_height_data[idx], pz);
atomicAdd(&mean_height_data[idx], pz);
if (mean_intensity_data != nullptr) {
atomicAdd(&mean_intensity_data[idx], pi);
}
atomicAdd(&count_data[idx], (Dtype)1);
}
}
template <typename Dtype>
__global__ void AverageKernel(const int n, Dtype* count_data,
Dtype* max_height_data, Dtype* mean_height_data,
Dtype* mean_intensity_data, Dtype* nonempty_data,
Dtype* log_table, const int max_log_num) {
CUDA_KERNEL_LOOP(i, n) {
if (count_data[i] < 1e-6) {
max_height_data[i] = 0;
} else {
mean_height_data[i] /= count_data[i];
if (mean_intensity_data != nullptr) {
mean_intensity_data[i] /= count_data[i];
}
nonempty_data[i] = Dtype(1.0);
}
int count = static_cast<int>(count_data[i]);
if (count < max_log_num) {
count_data[i] = log_table[count];
} else {
count_data[i] = log(1.0 + count);
}
}
}
template <typename Dtype>
__global__ void TopIntensityKernel(const int n, Dtype* top_intensity,
base::PointF* pc, Dtype* max_height_data,
int* point2grid) {
if (top_intensity == nullptr) {
return;
}
CUDA_KERNEL_LOOP(i, n) {
int idx = point2grid[i];
if (idx == -1) {
continue;
}
Dtype pz = pc[i].z;
Dtype pi = pc[i].intensity / 255.0;
if (pz == max_height_data[idx]) {
top_intensity[idx] = pi;
}
}
}
template <typename Dtype>
__global__ void SetKernel(const int n, const Dtype alpha, Dtype* y) {
CUDA_KERNEL_LOOP(i, n) { y[i] = alpha; }
}
void FeatureGenerator::GenerateGPU(const base::PointFCloudPtr& pc_ptr,
const std::vector<int>& point2grid) {
// fill initial value for feature blob
int map_size = width_ * height_;
int block_size = (map_size + kGPUThreadSize - 1) / kGPUThreadSize;
hipLaunchKernelGGL(( SetKernel<float>)
, dim3(block_size), dim3(kGPUThreadSize), 0, 0, map_size, -5.f, max_height_data_);
BASE_CUDA_CHECK(hipMemset(mean_height_data_, 0.f, sizeof(float) * map_size));
BASE_CUDA_CHECK(hipMemset(count_data_, 0.f, sizeof(float) * map_size));
BASE_CUDA_CHECK(hipMemset(nonempty_data_, 0.f, sizeof(float) * map_size));
if (use_intensity_feature_) {
BASE_CUDA_CHECK(
hipMemset(top_intensity_data_, 0.f, sizeof(float) * map_size));
BASE_CUDA_CHECK(
hipMemset(mean_intensity_data_, 0.f, sizeof(float) * map_size));
}
// copy cloud data and point2grid from CPU to GPU memory
size_t cloud_size = pc_ptr->size();
if (cloud_size > pc_gpu_size_) {
// cloud data
BASE_CUDA_CHECK(hipFree(pc_gpu_));
BASE_CUDA_CHECK(hipMalloc(reinterpret_cast<void**>(&pc_gpu_),
cloud_size * sizeof(base::PointF)));
pc_gpu_size_ = cloud_size;
// point2grid
BASE_CUDA_CHECK(hipFree(point2grid_gpu_));
BASE_CUDA_CHECK(hipMalloc(reinterpret_cast<void**>(&point2grid_gpu_),
cloud_size * sizeof(int)));
}
BASE_CUDA_CHECK(hipMemcpy(pc_gpu_, &(pc_ptr->front()),
sizeof(base::PointF) * cloud_size,
hipMemcpyHostToDevice));
BASE_CUDA_CHECK(hipMemcpy(point2grid_gpu_, point2grid.data(),
sizeof(int) * cloud_size, hipMemcpyHostToDevice));
// compute features
// float inv_res_x = 0.5 * width_ / range_;
// float inv_res_y = 0.5 * height_ / range_;
{
int block_size = (cloud_size + kGPUThreadSize - 1) / kGPUThreadSize;
hipLaunchKernelGGL(( MapKernel<float>), dim3(block_size), dim3(kGPUThreadSize), 0, 0,
cloud_size, pc_gpu_, max_height_data_, mean_height_data_,
mean_intensity_data_, count_data_, point2grid_gpu_);
hipLaunchKernelGGL(( TopIntensityKernel<float>), dim3(block_size), dim3(kGPUThreadSize), 0, 0,
cloud_size, top_intensity_data_, pc_gpu_, max_height_data_,
point2grid_gpu_);
}
{
int block_size = (map_size + kGPUThreadSize - 1) / kGPUThreadSize;
float* log_table = log_blob_->mutable_gpu_data() + log_blob_->offset(0, 0);
hipLaunchKernelGGL(( AverageKernel<float>), dim3(block_size), dim3(kGPUThreadSize), 0, 0,
map_size, count_data_, max_height_data_, mean_height_data_,
mean_intensity_data_, nonempty_data_, log_table, kMaxLogNum);
}
}
void FeatureGenerator::ReleaseGPUMemory() {
if (pc_gpu_ != nullptr) {
BASE_CUDA_CHECK(hipFree(pc_gpu_));
}
if (point2grid_gpu_ != nullptr) {
BASE_CUDA_CHECK(hipFree(point2grid_gpu_));
}
}
} // namespace lidar
} // namespace perception
} // namespace apollo
| e084034b8fa859d55fc3034f30eee0cbd82f348a.cu | /******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/perception/lidar/lib/detector/cnn_segmentation/feature_generator.h"
#include "modules/perception/base/common.h"
namespace apollo {
namespace perception {
namespace lidar {
#define CUDA_KERNEL_LOOP(i, n) \
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < (n); \
i += blockDim.x * gridDim.x)
#if __CUDA_ARCH__ < 600
__device__ double atomicAdd(double* address, double val) {
unsigned long long int* address_as_ull = (unsigned long long int*)address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__double_as_longlong(val + __longlong_as_double(assumed)));
// Note: uses integer comparison to avoid hang in case of NaN
// (since NaN != NaN)
} while (assumed != old);
return __longlong_as_double(old);
}
#endif
__device__ float atomicAdd(float* address, float val) {
int* address_as_ull = reinterpret_cast<int*>(address);
int old = *address_as_ull, assumed;
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__float_as_int(val + __int_as_float(assumed)));
// Note: uses integer comparison to avoid hang in case of NaN
// (since NaN != NaN)
} while (assumed != old);
return __int_as_float(old);
}
__device__ double atomic_exch(double* addr, double val) {
unsigned long long int* m_addr = (unsigned long long int*)addr;
unsigned long long int old_val = 0;
old_val = atomicExch(m_addr, __double_as_longlong(val));
return __longlong_as_double(old_val);
}
__device__ float atomic_exch(float* addr, float val) {
return atomicExch(addr, (val));
}
// __device__ void atomicMax(double* max_height_addr, double pz) {
// double old_pz = *max_height_addr;
// do {
// old_pz = atomic_exch(max_height_addr, (pz));
// if (pz < old_pz) {
// pz = old_pz;
// }
// } while (pz > (*max_height_addr));
// }
__device__ void atomicMax(float* max_height_addr, float pz) {
float old_pz = *max_height_addr;
do {
old_pz = atomic_exch(max_height_addr, (pz));
if (pz < old_pz) {
pz = old_pz;
}
} while (pz > (*max_height_addr));
}
template <typename Dtype>
__global__ void MapKernel(const int n, const base::PointF* pc,
Dtype* max_height_data, Dtype* mean_height_data,
Dtype* mean_intensity_data, Dtype* count_data,
int* point2grid) {
CUDA_KERNEL_LOOP(i, n) {
int idx = point2grid[i];
if (idx == -1) {
continue;
}
Dtype pz = pc[i].z;
Dtype pi = pc[i].intensity / 255.0;
atomicMax(&max_height_data[idx], pz);
atomicAdd(&mean_height_data[idx], pz);
if (mean_intensity_data != nullptr) {
atomicAdd(&mean_intensity_data[idx], pi);
}
atomicAdd(&count_data[idx], (Dtype)1);
}
}
template <typename Dtype>
__global__ void AverageKernel(const int n, Dtype* count_data,
Dtype* max_height_data, Dtype* mean_height_data,
Dtype* mean_intensity_data, Dtype* nonempty_data,
Dtype* log_table, const int max_log_num) {
CUDA_KERNEL_LOOP(i, n) {
if (count_data[i] < 1e-6) {
max_height_data[i] = 0;
} else {
mean_height_data[i] /= count_data[i];
if (mean_intensity_data != nullptr) {
mean_intensity_data[i] /= count_data[i];
}
nonempty_data[i] = Dtype(1.0);
}
int count = static_cast<int>(count_data[i]);
if (count < max_log_num) {
count_data[i] = log_table[count];
} else {
count_data[i] = log(1.0 + count);
}
}
}
template <typename Dtype>
__global__ void TopIntensityKernel(const int n, Dtype* top_intensity,
base::PointF* pc, Dtype* max_height_data,
int* point2grid) {
if (top_intensity == nullptr) {
return;
}
CUDA_KERNEL_LOOP(i, n) {
int idx = point2grid[i];
if (idx == -1) {
continue;
}
Dtype pz = pc[i].z;
Dtype pi = pc[i].intensity / 255.0;
if (pz == max_height_data[idx]) {
top_intensity[idx] = pi;
}
}
}
template <typename Dtype>
__global__ void SetKernel(const int n, const Dtype alpha, Dtype* y) {
CUDA_KERNEL_LOOP(i, n) { y[i] = alpha; }
}
void FeatureGenerator::GenerateGPU(const base::PointFCloudPtr& pc_ptr,
const std::vector<int>& point2grid) {
// fill initial value for feature blob
int map_size = width_ * height_;
int block_size = (map_size + kGPUThreadSize - 1) / kGPUThreadSize;
SetKernel<float>
<<<block_size, kGPUThreadSize>>>(map_size, -5.f, max_height_data_);
BASE_CUDA_CHECK(cudaMemset(mean_height_data_, 0.f, sizeof(float) * map_size));
BASE_CUDA_CHECK(cudaMemset(count_data_, 0.f, sizeof(float) * map_size));
BASE_CUDA_CHECK(cudaMemset(nonempty_data_, 0.f, sizeof(float) * map_size));
if (use_intensity_feature_) {
BASE_CUDA_CHECK(
cudaMemset(top_intensity_data_, 0.f, sizeof(float) * map_size));
BASE_CUDA_CHECK(
cudaMemset(mean_intensity_data_, 0.f, sizeof(float) * map_size));
}
// copy cloud data and point2grid from CPU to GPU memory
size_t cloud_size = pc_ptr->size();
if (cloud_size > pc_gpu_size_) {
// cloud data
BASE_CUDA_CHECK(cudaFree(pc_gpu_));
BASE_CUDA_CHECK(cudaMalloc(reinterpret_cast<void**>(&pc_gpu_),
cloud_size * sizeof(base::PointF)));
pc_gpu_size_ = cloud_size;
// point2grid
BASE_CUDA_CHECK(cudaFree(point2grid_gpu_));
BASE_CUDA_CHECK(cudaMalloc(reinterpret_cast<void**>(&point2grid_gpu_),
cloud_size * sizeof(int)));
}
BASE_CUDA_CHECK(cudaMemcpy(pc_gpu_, &(pc_ptr->front()),
sizeof(base::PointF) * cloud_size,
cudaMemcpyHostToDevice));
BASE_CUDA_CHECK(cudaMemcpy(point2grid_gpu_, point2grid.data(),
sizeof(int) * cloud_size, cudaMemcpyHostToDevice));
// compute features
// float inv_res_x = 0.5 * width_ / range_;
// float inv_res_y = 0.5 * height_ / range_;
{
int block_size = (cloud_size + kGPUThreadSize - 1) / kGPUThreadSize;
MapKernel<float><<<block_size, kGPUThreadSize>>>(
cloud_size, pc_gpu_, max_height_data_, mean_height_data_,
mean_intensity_data_, count_data_, point2grid_gpu_);
TopIntensityKernel<float><<<block_size, kGPUThreadSize>>>(
cloud_size, top_intensity_data_, pc_gpu_, max_height_data_,
point2grid_gpu_);
}
{
int block_size = (map_size + kGPUThreadSize - 1) / kGPUThreadSize;
float* log_table = log_blob_->mutable_gpu_data() + log_blob_->offset(0, 0);
AverageKernel<float><<<block_size, kGPUThreadSize>>>(
map_size, count_data_, max_height_data_, mean_height_data_,
mean_intensity_data_, nonempty_data_, log_table, kMaxLogNum);
}
}
void FeatureGenerator::ReleaseGPUMemory() {
if (pc_gpu_ != nullptr) {
BASE_CUDA_CHECK(cudaFree(pc_gpu_));
}
if (point2grid_gpu_ != nullptr) {
BASE_CUDA_CHECK(cudaFree(point2grid_gpu_));
}
}
} // namespace lidar
} // namespace perception
} // namespace apollo
|
a1423f105c7da46f748e64c944a837f686a99706.hip | // !!! This is a file automatically generated by hipify!!!
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test_utils.h"
#include <gtest/gtest.h>
#include <matrix/reverse.cuh>
#include <memory>
#include <raft/random/rng.cuh>
#include <raft/util/cudart_utils.hpp>
#include <rmm/device_uvector.hpp>
namespace MLCommon {
namespace Matrix {
template <typename T>
struct ReverseInputs {
T tolerance;
int nrows, ncols;
bool rowMajor, alongRows;
unsigned long long seed;
};
template <typename T>
class ReverseTest : public ::testing::TestWithParam<ReverseInputs<T>> {
protected:
ReverseTest() : in(0, stream), out(0, stream) {}
void SetUp() override
{
RAFT_CUDA_TRY(hipStreamCreate(&stream));
params = ::testing::TestWithParam<ReverseInputs<T>>::GetParam();
raft::random::Rng r(params.seed);
int len = params.nrows * params.ncols;
in.resize(len, stream);
out.resize(len, stream);
r.uniform(in.data(), len, T(-1.0), T(1.0), stream);
// applying reverse twice should yield the same output!
// this will in turn also verify the inplace mode of reverse method
reverse(
out.data(), in.data(), params.nrows, params.ncols, params.rowMajor, params.alongRows, stream);
reverse(out.data(),
out.data(),
params.nrows,
params.ncols,
params.rowMajor,
params.alongRows,
stream);
}
void TearDown() override { RAFT_CUDA_TRY(hipStreamDestroy(stream)); }
protected:
ReverseInputs<T> params;
rmm::device_uvector<T> in, out;
hipStream_t stream = 0;
};
const std::vector<ReverseInputs<float>> inputsf = {{0.000001f, 32, 32, false, false, 1234ULL},
{0.000001f, 32, 32, false, true, 1234ULL},
{0.000001f, 32, 32, true, false, 1234ULL},
{0.000001f, 32, 32, true, true, 1234ULL},
{0.000001f, 41, 41, false, false, 1234ULL},
{0.000001f, 41, 41, false, true, 1234ULL},
{0.000001f, 41, 41, true, false, 1234ULL},
{0.000001f, 41, 41, true, true, 1234ULL}};
typedef ReverseTest<float> ReverseTestF;
TEST_P(ReverseTestF, Result)
{
ASSERT_TRUE(devArrMatch(in.data(),
out.data(),
params.nrows,
params.ncols,
raft::CompareApprox<float>(params.tolerance)));
}
INSTANTIATE_TEST_CASE_P(ReverseTests, ReverseTestF, ::testing::ValuesIn(inputsf));
typedef ReverseTest<double> ReverseTestD;
const std::vector<ReverseInputs<double>> inputsd = {{0.000001, 32, 32, false, false, 1234ULL},
{0.000001, 32, 32, false, true, 1234ULL},
{0.000001, 32, 32, true, false, 1234ULL},
{0.000001, 32, 32, true, true, 1234ULL},
{0.000001, 41, 41, false, false, 1234ULL},
{0.000001, 41, 41, false, true, 1234ULL},
{0.000001, 41, 41, true, false, 1234ULL},
{0.000001, 41, 41, true, true, 1234ULL}};
TEST_P(ReverseTestD, Result)
{
ASSERT_TRUE(devArrMatch(in.data(),
out.data(),
params.nrows,
params.ncols,
raft::CompareApprox<double>(params.tolerance)));
}
INSTANTIATE_TEST_CASE_P(ReverseTests, ReverseTestD, ::testing::ValuesIn(inputsd));
} // end namespace Matrix
} // end namespace MLCommon
| a1423f105c7da46f748e64c944a837f686a99706.cu | /*
* Copyright (c) 2018-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test_utils.h"
#include <gtest/gtest.h>
#include <matrix/reverse.cuh>
#include <memory>
#include <raft/random/rng.cuh>
#include <raft/util/cudart_utils.hpp>
#include <rmm/device_uvector.hpp>
namespace MLCommon {
namespace Matrix {
template <typename T>
struct ReverseInputs {
T tolerance;
int nrows, ncols;
bool rowMajor, alongRows;
unsigned long long seed;
};
template <typename T>
class ReverseTest : public ::testing::TestWithParam<ReverseInputs<T>> {
protected:
ReverseTest() : in(0, stream), out(0, stream) {}
void SetUp() override
{
RAFT_CUDA_TRY(cudaStreamCreate(&stream));
params = ::testing::TestWithParam<ReverseInputs<T>>::GetParam();
raft::random::Rng r(params.seed);
int len = params.nrows * params.ncols;
in.resize(len, stream);
out.resize(len, stream);
r.uniform(in.data(), len, T(-1.0), T(1.0), stream);
// applying reverse twice should yield the same output!
// this will in turn also verify the inplace mode of reverse method
reverse(
out.data(), in.data(), params.nrows, params.ncols, params.rowMajor, params.alongRows, stream);
reverse(out.data(),
out.data(),
params.nrows,
params.ncols,
params.rowMajor,
params.alongRows,
stream);
}
void TearDown() override { RAFT_CUDA_TRY(cudaStreamDestroy(stream)); }
protected:
ReverseInputs<T> params;
rmm::device_uvector<T> in, out;
cudaStream_t stream = 0;
};
const std::vector<ReverseInputs<float>> inputsf = {{0.000001f, 32, 32, false, false, 1234ULL},
{0.000001f, 32, 32, false, true, 1234ULL},
{0.000001f, 32, 32, true, false, 1234ULL},
{0.000001f, 32, 32, true, true, 1234ULL},
{0.000001f, 41, 41, false, false, 1234ULL},
{0.000001f, 41, 41, false, true, 1234ULL},
{0.000001f, 41, 41, true, false, 1234ULL},
{0.000001f, 41, 41, true, true, 1234ULL}};
typedef ReverseTest<float> ReverseTestF;
TEST_P(ReverseTestF, Result)
{
ASSERT_TRUE(devArrMatch(in.data(),
out.data(),
params.nrows,
params.ncols,
raft::CompareApprox<float>(params.tolerance)));
}
INSTANTIATE_TEST_CASE_P(ReverseTests, ReverseTestF, ::testing::ValuesIn(inputsf));
typedef ReverseTest<double> ReverseTestD;
const std::vector<ReverseInputs<double>> inputsd = {{0.000001, 32, 32, false, false, 1234ULL},
{0.000001, 32, 32, false, true, 1234ULL},
{0.000001, 32, 32, true, false, 1234ULL},
{0.000001, 32, 32, true, true, 1234ULL},
{0.000001, 41, 41, false, false, 1234ULL},
{0.000001, 41, 41, false, true, 1234ULL},
{0.000001, 41, 41, true, false, 1234ULL},
{0.000001, 41, 41, true, true, 1234ULL}};
TEST_P(ReverseTestD, Result)
{
ASSERT_TRUE(devArrMatch(in.data(),
out.data(),
params.nrows,
params.ncols,
raft::CompareApprox<double>(params.tolerance)));
}
INSTANTIATE_TEST_CASE_P(ReverseTests, ReverseTestD, ::testing::ValuesIn(inputsd));
} // end namespace Matrix
} // end namespace MLCommon
|
ea98eb9b5c2fef1a84deb416c929dc507ede6976.hip | // !!! This is a file automatically generated by hipify!!!
// ----------------------------------------------------------------
// Gunrock -- Fast and Efficient GPU Graph Library
// ----------------------------------------------------------------
// This source code is distributed under the terms of LICENSE.TXT
// in the root directory of this source distribution.
// ----------------------------------------------------------------
/**
* @file
* test_cc.cu
*
* @brief Simple test driver program for connected component.
*/
#include <stdio.h>
#include <string>
#include <deque>
#include <vector>
#include <iostream>
// Utilities and correctness-checking
#include <gunrock/util/test_utils.cuh>
// CC includes
#include <gunrock/app/cc/cc_enactor.cuh>
#include <gunrock/app/cc/cc_problem.cuh>
#include <gunrock/app/cc/cc_functor.cuh>
// Operator includes
#include <gunrock/oprtr/advance/kernel.cuh>
#include <gunrock/oprtr/filter/kernel.cuh>
// Boost includes for CPU CC reference algorithms
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
using namespace gunrock;
using namespace gunrock::app;
using namespace gunrock::util;
using namespace gunrock::oprtr;
using namespace gunrock::app::cc;
/******************************************************************************
* Defines, constants, globals
******************************************************************************/
template <typename VertexId, typename SizeT>
struct CcList
{
VertexId root;
SizeT histogram;
CcList(VertexId root, SizeT histogram) :
root(root), histogram(histogram) {}
};
template<typename CcList>
bool CCCompare(
CcList elem1,
CcList elem2)
{
return elem1.histogram > elem2.histogram;
}
/******************************************************************************
* Housekeeping Routines
******************************************************************************/
void Usage()
{
printf(
"test <graph-type> [graph-type-arguments]\n"
"Graph type and graph type arguments:\n"
" market <matrix-market-file-name>\n"
" Reads a Matrix-Market coordinate-formatted graph of\n"
" directed/undirected edges from STDIN (or from the\n"
" optionally-specified file).\n"
" rmat (default: rmat_scale = 10, a = 0.57, b = c = 0.19)\n"
" Generate R-MAT graph as input\n"
" --rmat_scale=<vertex-scale>\n"
" --rmat_nodes=<number-nodes>\n"
" --rmat_edgefactor=<edge-factor>\n"
" --rmat_edges=<number-edges>\n"
" --rmat_a=<factor> --rmat_b=<factor> --rmat_c=<factor>\n"
" --rmat_seed=<seed>\n"
" rgg (default: rgg_scale = 10, rgg_thfactor = 0.55)\n"
" Generate Random Geometry Graph as input\n"
" --rgg_scale=<vertex-scale>\n"
" --rgg_nodes=<number-nodes>\n"
" --rgg_thfactor=<threshold-factor>\n"
" --rgg_threshold=<threshold>\n"
" --rgg_vmultipiler=<vmultipiler>\n"
" --rgg_seed=<seed>\n\n"
"Optional arguments:\n"
"[--device=<device_index>] Set GPU(s) for testing (Default: 0).\n"
"[--instrumented] Keep kernels statics [Default: Disable].\n"
" total_queued, search_depth and barrier duty.\n"
" (a relative indicator of load imbalance.)\n"
"[--quick] Skip the CPU reference validation process.\n"
"[--disable-size-check] Disable frontier queue size check.\n"
"[--grid-size=<grid size>] Maximum allowed grid size setting.\n"
"[--queue-sizing=<factor>] Allocates a frontier queue sized at: \n"
" (graph-edges * <factor>). (Default: 1.0)\n"
"[--in-sizing=<in/out_queue_scale_factor>]\n"
" Allocates a frontier queue sized at: \n"
" (graph-edges * <factor>). (Default: 1.0)\n"
"[--v] Print verbose per iteration debug info.\n"
"[--iteration-num=<num>] Number of runs to perform the test.\n"
"[--partition-method=<random|biasrandom|clustered|metis>]\n"
" Choose partitioner (Default use random).\n"
"[--quiet] No output (unless --json is specified).\n"
"[--json] Output JSON-format statistics to STDOUT.\n"
"[--jsonfile=<name>] Output JSON-format statistics to file <name>\n"
"[--jsondir=<dir>] Output JSON-format statistics to <dir>/name,\n"
" where name is auto-generated.\n"
);
}
/**
* @brief Displays the CC result (i.e., number of components)
*
* @tparam VertexId
* @tparam SizeT
*
* @param[in] comp_ids Host-side vector to store computed component id for each node
* @param[in] nodes Number of nodes in the graph
* @param[in] num_components Number of connected components in the graph
* @param[in] roots Host-side vector stores the root for each node in the graph
* @param[in] histogram Histogram of connected component ids
*/
template<typename VertexId, typename SizeT>
void DisplaySolution(
VertexId *comp_ids,
SizeT nodes,
SizeT num_components,
VertexId *roots,
SizeT *histogram)
{
typedef CcList<VertexId, SizeT> CcListType;
//printf("Number of components: %d\n", num_components);
if (nodes <= 40)
{
printf("[");
for (VertexId i = 0; i < nodes; ++i)
{
PrintValue(i);
printf(":");
PrintValue(comp_ids[i]);
printf(",");
printf(" ");
}
printf("]\n");
}
else
{
//sort the components by size
CcListType *cclist =
(CcListType*)malloc(sizeof(CcListType) * num_components);
for (SizeT i = 0; i < num_components; ++i)
{
cclist[i].root = roots[i];
cclist[i].histogram = histogram[i];
}
std::stable_sort(
cclist, cclist + num_components, CCCompare<CcListType>);
// Print out at most top 10 largest components
SizeT top = (num_components < 10) ? num_components : 10;
printf("Top %lld largest components:\n", (long long)top);
for (SizeT i = 0; i < top; ++i)
{
printf("CC ID: %lld, CC Root: %lld, CC Size: %lld\n",
(long long)i, (long long)cclist[i].root, (long long)cclist[i].histogram);
}
free(cclist);
}
}
/******************************************************************************
* CC Testing Routines
*****************************************************************************/
/**
* @brief CPU-based reference CC algorithm using Boost Graph Library
*
* @tparam VertexId
* @tparam SizeT
*
* @param[in] graph Reference to the CSR graph we process on
* @param[out] labels Host-side vector to store the component id for each node in the graph
* @param[in] quiet Don't print out anything to stdout
*
* \return Number of connected components in the graph
*/
template <
typename VertexId,
typename SizeT,
typename Value >
unsigned int ReferenceCC(
const Csr<VertexId, SizeT, Value> &graph,
VertexId *labels,
bool quiet = false)
{
using namespace boost;
SizeT *row_offsets = graph.row_offsets;
VertexId *column_indices = graph.column_indices;
SizeT num_nodes = graph.nodes;
typedef adjacency_list <vecS, vecS, undirectedS> Graph;
Graph G;
for (int i = 0; i < num_nodes; ++i)
{
for (int j = row_offsets[i]; j < row_offsets[i + 1]; ++j)
{
add_edge(i, column_indices[j], G);
}
}
CpuTimer cpu_timer;
cpu_timer.Start();
SizeT num_components = connected_components(G, &labels[0]);
cpu_timer.Stop();
float elapsed = cpu_timer.ElapsedMillis();
if (!quiet) { printf("CPU CC finished in %lf msec.\n", elapsed); }
return num_components;
}
/**
* @brief Convert component IDs.
*
* @tparam VertexId
* @tparam SizeT
*
* @param[in] labels
* @param[in] num_nodes
* @param[in] num_components
*/
template <
typename VertexId,
typename SizeT >
void ConvertIDs(
VertexId *labels,
SizeT num_nodes,
SizeT num_components)
{
VertexId *min_nodes = new VertexId[num_nodes];
for (int cc = 0; cc < num_nodes; cc++)
min_nodes[cc] = num_nodes;
for (int node = 0; node < num_nodes; node++)
if (min_nodes[labels[node]] > node) min_nodes[labels[node]] = node;
for (int node = 0; node < num_nodes; node++)
labels[node] = min_nodes[labels[node]];
delete[] min_nodes; min_nodes = NULL;
}
/**
* @brief RunTests entry
*
* @tparam VertexId
* @tparam Value
* @tparam SizeT
*
* @param[in] info Pointer to info contains parameters and statistics.
*
* \return hipError_t object which indicates the success of
* all CUDA function calls.
*/
template <
typename VertexId,
typename SizeT,
typename Value>
hipError_t RunTests(Info<VertexId, SizeT, Value> *info)
{
typedef CCProblem < VertexId,
SizeT,
Value> Problem; // use double buffer for advance and filter
typedef CCEnactor < Problem>
//INSTRUMENT,
//DEBUG,
//SIZE_CHECK >
Enactor;
// parse configurations from mObject info
Csr<VertexId, SizeT, Value> *graph = info->csr_ptr;
int max_grid_size = info->info["max_grid_size" ].get_int ();
int num_gpus = info->info["num_gpus" ].get_int ();
double max_queue_sizing = info->info["max_queue_sizing" ].get_real ();
double max_queue_sizing1 = info->info["max_queue_sizing1" ].get_real ();
double max_in_sizing = info->info["max_in_sizing" ].get_real ();
std::string partition_method = info->info["partition_method" ].get_str ();
double partition_factor = info->info["partition_factor" ].get_real ();
int partition_seed = info->info["partition_seed" ].get_int ();
bool quiet_mode = info->info["quiet_mode" ].get_bool ();
bool quick_mode = info->info["quick_mode" ].get_bool ();
bool stream_from_host = info->info["stream_from_host" ].get_bool ();
std::string traversal_mode = info->info["traversal_mode" ].get_str ();
bool instrument = info->info["instrument" ].get_bool ();
bool debug = info->info["debug_mode" ].get_bool ();
bool size_check = info->info["size_check" ].get_bool ();
int iterations = info->info["num_iteration" ].get_int();
int communicate_latency = info->info["communicate_latency"].get_int ();
float communicate_multipy = info->info["communicate_multipy"].get_real();
int expand_latency = info->info["expand_latency" ].get_int ();
int subqueue_latency = info->info["subqueue_latency" ].get_int ();
int fullqueue_latency = info->info["fullqueue_latency" ].get_int ();
int makeout_latency = info->info["makeout_latency" ].get_int ();
if (max_queue_sizing < 0) max_queue_sizing = 1.0;
if (max_in_sizing < 0) max_in_sizing = 1.1;
if (communicate_multipy > 1) max_in_sizing *= communicate_multipy;
CpuTimer cpu_timer;
hipError_t retval;
cpu_timer.Start();
json_spirit::mArray device_list = info->info["device_list"].get_array();
int* gpu_idx = new int[num_gpus];
for (int i = 0; i < num_gpus; i++) gpu_idx[i] = device_list[i].get_int();
// TODO: remove after merge mgpu-cq
ContextPtr *context = (ContextPtr*) info->context;
hipStream_t *streams = (hipStream_t*)info->streams;
// Allocate host-side array (for both reference and GPU-computed results)
VertexId *reference_component_ids = new VertexId[graph->nodes];
VertexId *h_component_ids = new VertexId[graph->nodes];
VertexId *reference_check = (quick_mode) ? NULL : reference_component_ids;
SizeT ref_num_components = 0;
//printf("0: node %d: %d -> %d, node %d: %d -> %d\n", 131070, graph->row_offsets[131070], graph->row_offsets[131071], 131071, graph->row_offsets[131071], graph->row_offsets[131072]);
//for (int edge = 0; edge < graph->edges; edge ++)
//{
// if (graph->column_indices[edge] == 131070 || graph->column_indices[edge] == 131071)
// printf("edge %d: -> %d\n", edge, graph->column_indices[edge]);
//}
//util::cpu_mt::PrintCPUArray("row_offsets", graph->row_offsets, graph->nodes+1);
//util::cpu_mt::PrintCPUArray("colunm_indices", graph->column_indices, graph->edges);
size_t *org_size = new size_t[num_gpus];
for (int gpu = 0; gpu < num_gpus; gpu++)
{
size_t dummy;
if (retval = util::SetDevice(gpu_idx[gpu])) return retval;
hipMemGetInfo(&(org_size[gpu]), &dummy);
}
Problem* problem = new Problem; // allocate problem on GPU
if (retval = util::GRError(problem->Init(
stream_from_host,
graph,
NULL,
num_gpus,
gpu_idx,
partition_method,
streams,
max_queue_sizing,
max_in_sizing,
partition_factor,
partition_seed),
"CC Problem Initialization Failed", __FILE__, __LINE__))
return retval;
Enactor* enactor = new Enactor(
num_gpus, gpu_idx, instrument, debug, size_check); // enactor map
if (retval = util::GRError(enactor->Init(
context, problem, traversal_mode, max_grid_size),
"CC Enactor Init failed", __FILE__, __LINE__))
return retval;
enactor -> communicate_latency = communicate_latency;
enactor -> communicate_multipy = communicate_multipy;
enactor -> expand_latency = expand_latency;
enactor -> subqueue_latency = subqueue_latency;
enactor -> fullqueue_latency = fullqueue_latency;
enactor -> makeout_latency = makeout_latency;
if (retval = util::SetDevice(gpu_idx[0])) return retval;
if (retval = util::latency::Test(
streams[0], problem -> data_slices[0] -> latency_data,
communicate_latency,
communicate_multipy,
expand_latency,
subqueue_latency,
fullqueue_latency,
makeout_latency)) return retval;
cpu_timer.Stop();
info -> info["preprocess_time"] = cpu_timer.ElapsedMillis();
// compute reference CPU CC
if (!quick_mode)
{
if (!quiet_mode) { printf("Computing reference value ...\n"); }
ref_num_components = ReferenceCC(*graph, reference_check, quiet_mode);
if (!quiet_mode) { printf("\n"); }
}
// perform CC
double total_elapsed = 0.0;
double single_elapsed = 0.0;
double max_elapsed = 0.0;
double min_elapsed = 1e10;
json_spirit::mArray process_times;
if (!quiet_mode) printf("Using traversal mode %s\n", traversal_mode.c_str());
for (SizeT iter = 0; iter < iterations; ++iter)
{
if (retval = util::GRError(problem->Reset(
enactor->GetFrontierType(), max_queue_sizing),
"CC Problem Data Reset Failed", __FILE__, __LINE__))
return retval;
if (retval = util::GRError(enactor->Reset(),
"CC Enactor Reset failed", __FILE__, __LINE__))
return retval;
if (!quiet_mode)
{
printf("_________________________\n"); fflush(stdout);
}
cpu_timer.Start();
if (retval = util::GRError(enactor->Enact(traversal_mode),
"CC Problem Enact Failed", __FILE__, __LINE__))
return retval;
cpu_timer.Stop();
single_elapsed = cpu_timer.ElapsedMillis();
total_elapsed += single_elapsed;
process_times.push_back(single_elapsed);
if (single_elapsed > max_elapsed) max_elapsed = single_elapsed;
if (single_elapsed < min_elapsed) min_elapsed = single_elapsed;
if (!quiet_mode)
{
printf("-------------------------\n"
"iteration %lld elapsed: %lf ms\n",
(long long)iter, single_elapsed);
fflush(stdout);
}
}
total_elapsed /= iterations;
info -> info["process_times"] = process_times;
info -> info["min_process_time"] = min_elapsed;
info -> info["max_process_time"] = max_elapsed;
cpu_timer.Start();
// copy out results
if (retval = util::GRError(problem->Extract(h_component_ids),
"CC Problem Data Extraction Failed", __FILE__, __LINE__))
return retval;
// validity
if (!quick_mode)
{
if (ref_num_components == problem->num_components)
{
if (!quiet_mode)
{
printf("CORRECT. Component Count: %lld\n", (long long)ref_num_components);
}
}
else
{
if (!quiet_mode)
{
printf(
"INCORRECT. Ref Component Count: %lld, "
"GPU Computed Component Count: %lld\n",
(long long)ref_num_components, (long long)problem->num_components);
}
}
}
else
{
if (!quiet_mode)
{
printf("Component Count: %lld\n", (long long) problem->num_components);
}
}
if (!quick_mode)
{
ConvertIDs<VertexId, SizeT>(reference_check, graph->nodes, ref_num_components);
ConvertIDs<VertexId, SizeT>(h_component_ids, graph->nodes, problem->num_components);
if (!quiet_mode)
{
printf("Label Validity: ");
}
SizeT error_num = CompareResults(
h_component_ids, reference_check, graph->nodes, true, quiet_mode);
if (error_num > 0)
{
if (!quiet_mode) { printf("%lld errors occurred.\n", (long long)error_num); }
}
else
{
if (!quiet_mode) { printf("\n"); }
}
}
//if (ref_num_components == csr_problem->num_components)
{
// Compute size and root of each component
VertexId *h_roots = new VertexId[problem->num_components];
SizeT *h_histograms = new SizeT [problem->num_components];
//printf("num_components = %d\n", problem->num_components);
problem->ComputeCCHistogram(h_component_ids, h_roots, h_histograms);
//printf("num_components = %d\n", problem->num_components);
if (!quiet_mode)
{
// Display Solution
DisplaySolution(h_component_ids, graph->nodes,
problem->num_components, h_roots, h_histograms);
}
if (h_roots ) {delete[] h_roots ; h_roots = NULL;}
if (h_histograms) {delete[] h_histograms; h_histograms = NULL;}
}
info->ComputeCommonStats( // compute running statistics
enactor->enactor_stats.GetPointer(), total_elapsed, h_component_ids, true);
if (!quiet_mode)
{
printf("\n\tMemory Usage(B)\t");
for (int gpu = 0; gpu < num_gpus; gpu++)
if (num_gpus > 1)
{
if (gpu != 0) printf(" #keys%d\t #ins%d,0\t #ins%d,1", gpu, gpu, gpu);
else printf(" $keys%d", gpu);
}
else printf(" #keys%d", gpu);
if (num_gpus > 1) printf(" #keys%d", num_gpus);
printf("\n");
double max_key_sizing = 0, max_in_sizing_ = 0;
for (int gpu = 0; gpu < num_gpus; gpu++)
{
size_t gpu_free, dummy;
hipSetDevice(gpu_idx[gpu]);
hipMemGetInfo(&gpu_free, &dummy);
printf("GPU_%d\t %ld", gpu_idx[gpu], org_size[gpu] - gpu_free);
for (int i = 0; i < num_gpus; i++)
{
SizeT x = problem->data_slices[gpu]->frontier_queues[i].keys[0].GetSize();
printf("\t %lld", (long long)x);
double factor = 1.0 * x / (num_gpus > 1 ? problem->graph_slices[gpu]->in_counter[i] : problem->graph_slices[gpu]->nodes);
if (factor > max_key_sizing) max_key_sizing = factor;
if (num_gpus > 1 && i != 0 )
for (int t = 0; t < 2; t++)
{
x = problem->data_slices[gpu][0].keys_in[t][i].GetSize();
printf("\t %lld", (long long)x);
factor = 1.0 * x / problem->graph_slices[gpu]->in_counter[i];
if (factor > max_in_sizing_) max_in_sizing_ = factor;
}
}
if (num_gpus > 1) printf("\t %lld", (long long)problem->data_slices[gpu]->frontier_queues[num_gpus].keys[0].GetSize());
printf("\n");
}
printf("\t key_sizing =\t %lf", max_key_sizing);
if (num_gpus > 1) printf("\t in_sizing =\t %lf", max_in_sizing_);
printf("\n");
}
// Cleanup
if (org_size ) {delete[] org_size ; org_size = NULL;}
if (problem ) {delete problem ; problem = NULL;}
if (enactor ) {delete enactor ; enactor = NULL;}
if (reference_component_ids) {delete[] reference_component_ids; reference_component_ids = NULL;}
if (h_component_ids ) {delete[] h_component_ids ; h_component_ids = NULL;}
cpu_timer.Stop();
info->info["postprocess_time"] = cpu_timer.ElapsedMillis();
return retval;
}
/******************************************************************************
* Main
******************************************************************************/
template <
typename VertexId, // use int as the vertex identifier
typename SizeT , // use int as the graph size type
typename Value > // use int as the value type
int main_(CommandLineArgs *args)
{
CpuTimer cpu_timer, cpu_timer2;
cpu_timer.Start();
Csr <VertexId, SizeT, Value> csr(false); // graph we process on
Info<VertexId, SizeT, Value> *info = new Info<VertexId, SizeT, Value>;
// graph construction or generation related parameters
info->info["undirected"] = true; // require undirected input graph
cpu_timer2.Start();
info->Init("CC", *args, csr); // initialize Info structure
graphio::RemoveStandaloneNodes<VertexId, SizeT, Value>(
&csr, args->CheckCmdLineFlag("quiet"));
cpu_timer2.Stop();
info->info["load_time"] = cpu_timer2.ElapsedMillis();
RunTests<VertexId, SizeT, Value>(info); // run test
cpu_timer.Stop();
info->info["total_time"] = cpu_timer.ElapsedMillis();
if (!(info->info["quiet_mode"].get_bool()))
{
info->DisplayStats(); // display collected statistics
}
info->CollectInfo(); // collected all the info and put into JSON mObject
return 0;
}
template <
typename VertexId, // the vertex identifier type, usually int or long long
typename SizeT > // the size tyep, usually int or long long
int main_Value(CommandLineArgs *args)
{
// if (args -> CheckCmdLineFlag("64bit-Value"))
// return main_<VertexId, SizeT, long long>(args);
// else
// return main_<VertexId, SizeT, int >(args);
return main_<VertexId, SizeT, VertexId>(args); // Value = VertexId for CC
}
template <
typename VertexId>
int main_SizeT(CommandLineArgs *args)
{
// disabled to reduce compile time
if (args -> CheckCmdLineFlag("64bit-SizeT"))
return main_Value<VertexId, long long>(args);
else
return main_Value<VertexId, int >(args);
}
int main_VertexId(CommandLineArgs *args)
{
// disabled, because oprtr::filter::KernelPolicy::SmemStorage is too large for 64bit VertexId
//if (args -> CheckCmdLineFlag("64bit-VertexId"))
// return main_SizeT<long long>(args);
//else
return main_SizeT<int >(args);
}
int main(int argc, char** argv)
{
CommandLineArgs args(argc, argv);
int graph_args = argc - args.ParsedArgc() - 1;
if (argc < 2 || graph_args < 1 || args.CheckCmdLineFlag("help"))
{
Usage();
return 1;
}
return main_VertexId(&args);
}
// Leave this at the end of the file
// Local Variables:
// mode:c++
// c-file-style: "NVIDIA"
// End:
| ea98eb9b5c2fef1a84deb416c929dc507ede6976.cu | // ----------------------------------------------------------------
// Gunrock -- Fast and Efficient GPU Graph Library
// ----------------------------------------------------------------
// This source code is distributed under the terms of LICENSE.TXT
// in the root directory of this source distribution.
// ----------------------------------------------------------------
/**
* @file
* test_cc.cu
*
* @brief Simple test driver program for connected component.
*/
#include <stdio.h>
#include <string>
#include <deque>
#include <vector>
#include <iostream>
// Utilities and correctness-checking
#include <gunrock/util/test_utils.cuh>
// CC includes
#include <gunrock/app/cc/cc_enactor.cuh>
#include <gunrock/app/cc/cc_problem.cuh>
#include <gunrock/app/cc/cc_functor.cuh>
// Operator includes
#include <gunrock/oprtr/advance/kernel.cuh>
#include <gunrock/oprtr/filter/kernel.cuh>
// Boost includes for CPU CC reference algorithms
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
using namespace gunrock;
using namespace gunrock::app;
using namespace gunrock::util;
using namespace gunrock::oprtr;
using namespace gunrock::app::cc;
/******************************************************************************
* Defines, constants, globals
******************************************************************************/
template <typename VertexId, typename SizeT>
struct CcList
{
VertexId root;
SizeT histogram;
CcList(VertexId root, SizeT histogram) :
root(root), histogram(histogram) {}
};
template<typename CcList>
bool CCCompare(
CcList elem1,
CcList elem2)
{
return elem1.histogram > elem2.histogram;
}
/******************************************************************************
* Housekeeping Routines
******************************************************************************/
void Usage()
{
printf(
"test <graph-type> [graph-type-arguments]\n"
"Graph type and graph type arguments:\n"
" market <matrix-market-file-name>\n"
" Reads a Matrix-Market coordinate-formatted graph of\n"
" directed/undirected edges from STDIN (or from the\n"
" optionally-specified file).\n"
" rmat (default: rmat_scale = 10, a = 0.57, b = c = 0.19)\n"
" Generate R-MAT graph as input\n"
" --rmat_scale=<vertex-scale>\n"
" --rmat_nodes=<number-nodes>\n"
" --rmat_edgefactor=<edge-factor>\n"
" --rmat_edges=<number-edges>\n"
" --rmat_a=<factor> --rmat_b=<factor> --rmat_c=<factor>\n"
" --rmat_seed=<seed>\n"
" rgg (default: rgg_scale = 10, rgg_thfactor = 0.55)\n"
" Generate Random Geometry Graph as input\n"
" --rgg_scale=<vertex-scale>\n"
" --rgg_nodes=<number-nodes>\n"
" --rgg_thfactor=<threshold-factor>\n"
" --rgg_threshold=<threshold>\n"
" --rgg_vmultipiler=<vmultipiler>\n"
" --rgg_seed=<seed>\n\n"
"Optional arguments:\n"
"[--device=<device_index>] Set GPU(s) for testing (Default: 0).\n"
"[--instrumented] Keep kernels statics [Default: Disable].\n"
" total_queued, search_depth and barrier duty.\n"
" (a relative indicator of load imbalance.)\n"
"[--quick] Skip the CPU reference validation process.\n"
"[--disable-size-check] Disable frontier queue size check.\n"
"[--grid-size=<grid size>] Maximum allowed grid size setting.\n"
"[--queue-sizing=<factor>] Allocates a frontier queue sized at: \n"
" (graph-edges * <factor>). (Default: 1.0)\n"
"[--in-sizing=<in/out_queue_scale_factor>]\n"
" Allocates a frontier queue sized at: \n"
" (graph-edges * <factor>). (Default: 1.0)\n"
"[--v] Print verbose per iteration debug info.\n"
"[--iteration-num=<num>] Number of runs to perform the test.\n"
"[--partition-method=<random|biasrandom|clustered|metis>]\n"
" Choose partitioner (Default use random).\n"
"[--quiet] No output (unless --json is specified).\n"
"[--json] Output JSON-format statistics to STDOUT.\n"
"[--jsonfile=<name>] Output JSON-format statistics to file <name>\n"
"[--jsondir=<dir>] Output JSON-format statistics to <dir>/name,\n"
" where name is auto-generated.\n"
);
}
/**
* @brief Displays the CC result (i.e., number of components)
*
* @tparam VertexId
* @tparam SizeT
*
* @param[in] comp_ids Host-side vector to store computed component id for each node
* @param[in] nodes Number of nodes in the graph
* @param[in] num_components Number of connected components in the graph
* @param[in] roots Host-side vector stores the root for each node in the graph
* @param[in] histogram Histogram of connected component ids
*/
template<typename VertexId, typename SizeT>
void DisplaySolution(
VertexId *comp_ids,
SizeT nodes,
SizeT num_components,
VertexId *roots,
SizeT *histogram)
{
typedef CcList<VertexId, SizeT> CcListType;
//printf("Number of components: %d\n", num_components);
if (nodes <= 40)
{
printf("[");
for (VertexId i = 0; i < nodes; ++i)
{
PrintValue(i);
printf(":");
PrintValue(comp_ids[i]);
printf(",");
printf(" ");
}
printf("]\n");
}
else
{
//sort the components by size
CcListType *cclist =
(CcListType*)malloc(sizeof(CcListType) * num_components);
for (SizeT i = 0; i < num_components; ++i)
{
cclist[i].root = roots[i];
cclist[i].histogram = histogram[i];
}
std::stable_sort(
cclist, cclist + num_components, CCCompare<CcListType>);
// Print out at most top 10 largest components
SizeT top = (num_components < 10) ? num_components : 10;
printf("Top %lld largest components:\n", (long long)top);
for (SizeT i = 0; i < top; ++i)
{
printf("CC ID: %lld, CC Root: %lld, CC Size: %lld\n",
(long long)i, (long long)cclist[i].root, (long long)cclist[i].histogram);
}
free(cclist);
}
}
/******************************************************************************
* CC Testing Routines
*****************************************************************************/
/**
* @brief CPU-based reference CC algorithm using Boost Graph Library
*
* @tparam VertexId
* @tparam SizeT
*
* @param[in] graph Reference to the CSR graph we process on
* @param[out] labels Host-side vector to store the component id for each node in the graph
* @param[in] quiet Don't print out anything to stdout
*
* \return Number of connected components in the graph
*/
template <
typename VertexId,
typename SizeT,
typename Value >
unsigned int ReferenceCC(
const Csr<VertexId, SizeT, Value> &graph,
VertexId *labels,
bool quiet = false)
{
using namespace boost;
SizeT *row_offsets = graph.row_offsets;
VertexId *column_indices = graph.column_indices;
SizeT num_nodes = graph.nodes;
typedef adjacency_list <vecS, vecS, undirectedS> Graph;
Graph G;
for (int i = 0; i < num_nodes; ++i)
{
for (int j = row_offsets[i]; j < row_offsets[i + 1]; ++j)
{
add_edge(i, column_indices[j], G);
}
}
CpuTimer cpu_timer;
cpu_timer.Start();
SizeT num_components = connected_components(G, &labels[0]);
cpu_timer.Stop();
float elapsed = cpu_timer.ElapsedMillis();
if (!quiet) { printf("CPU CC finished in %lf msec.\n", elapsed); }
return num_components;
}
/**
* @brief Convert component IDs.
*
* @tparam VertexId
* @tparam SizeT
*
* @param[in] labels
* @param[in] num_nodes
* @param[in] num_components
*/
template <
typename VertexId,
typename SizeT >
void ConvertIDs(
VertexId *labels,
SizeT num_nodes,
SizeT num_components)
{
VertexId *min_nodes = new VertexId[num_nodes];
for (int cc = 0; cc < num_nodes; cc++)
min_nodes[cc] = num_nodes;
for (int node = 0; node < num_nodes; node++)
if (min_nodes[labels[node]] > node) min_nodes[labels[node]] = node;
for (int node = 0; node < num_nodes; node++)
labels[node] = min_nodes[labels[node]];
delete[] min_nodes; min_nodes = NULL;
}
/**
* @brief RunTests entry
*
* @tparam VertexId
* @tparam Value
* @tparam SizeT
*
* @param[in] info Pointer to info contains parameters and statistics.
*
* \return cudaError_t object which indicates the success of
* all CUDA function calls.
*/
template <
typename VertexId,
typename SizeT,
typename Value>
cudaError_t RunTests(Info<VertexId, SizeT, Value> *info)
{
typedef CCProblem < VertexId,
SizeT,
Value> Problem; // use double buffer for advance and filter
typedef CCEnactor < Problem>
//INSTRUMENT,
//DEBUG,
//SIZE_CHECK >
Enactor;
// parse configurations from mObject info
Csr<VertexId, SizeT, Value> *graph = info->csr_ptr;
int max_grid_size = info->info["max_grid_size" ].get_int ();
int num_gpus = info->info["num_gpus" ].get_int ();
double max_queue_sizing = info->info["max_queue_sizing" ].get_real ();
double max_queue_sizing1 = info->info["max_queue_sizing1" ].get_real ();
double max_in_sizing = info->info["max_in_sizing" ].get_real ();
std::string partition_method = info->info["partition_method" ].get_str ();
double partition_factor = info->info["partition_factor" ].get_real ();
int partition_seed = info->info["partition_seed" ].get_int ();
bool quiet_mode = info->info["quiet_mode" ].get_bool ();
bool quick_mode = info->info["quick_mode" ].get_bool ();
bool stream_from_host = info->info["stream_from_host" ].get_bool ();
std::string traversal_mode = info->info["traversal_mode" ].get_str ();
bool instrument = info->info["instrument" ].get_bool ();
bool debug = info->info["debug_mode" ].get_bool ();
bool size_check = info->info["size_check" ].get_bool ();
int iterations = info->info["num_iteration" ].get_int();
int communicate_latency = info->info["communicate_latency"].get_int ();
float communicate_multipy = info->info["communicate_multipy"].get_real();
int expand_latency = info->info["expand_latency" ].get_int ();
int subqueue_latency = info->info["subqueue_latency" ].get_int ();
int fullqueue_latency = info->info["fullqueue_latency" ].get_int ();
int makeout_latency = info->info["makeout_latency" ].get_int ();
if (max_queue_sizing < 0) max_queue_sizing = 1.0;
if (max_in_sizing < 0) max_in_sizing = 1.1;
if (communicate_multipy > 1) max_in_sizing *= communicate_multipy;
CpuTimer cpu_timer;
cudaError_t retval;
cpu_timer.Start();
json_spirit::mArray device_list = info->info["device_list"].get_array();
int* gpu_idx = new int[num_gpus];
for (int i = 0; i < num_gpus; i++) gpu_idx[i] = device_list[i].get_int();
// TODO: remove after merge mgpu-cq
ContextPtr *context = (ContextPtr*) info->context;
cudaStream_t *streams = (cudaStream_t*)info->streams;
// Allocate host-side array (for both reference and GPU-computed results)
VertexId *reference_component_ids = new VertexId[graph->nodes];
VertexId *h_component_ids = new VertexId[graph->nodes];
VertexId *reference_check = (quick_mode) ? NULL : reference_component_ids;
SizeT ref_num_components = 0;
//printf("0: node %d: %d -> %d, node %d: %d -> %d\n", 131070, graph->row_offsets[131070], graph->row_offsets[131071], 131071, graph->row_offsets[131071], graph->row_offsets[131072]);
//for (int edge = 0; edge < graph->edges; edge ++)
//{
// if (graph->column_indices[edge] == 131070 || graph->column_indices[edge] == 131071)
// printf("edge %d: -> %d\n", edge, graph->column_indices[edge]);
//}
//util::cpu_mt::PrintCPUArray("row_offsets", graph->row_offsets, graph->nodes+1);
//util::cpu_mt::PrintCPUArray("colunm_indices", graph->column_indices, graph->edges);
size_t *org_size = new size_t[num_gpus];
for (int gpu = 0; gpu < num_gpus; gpu++)
{
size_t dummy;
if (retval = util::SetDevice(gpu_idx[gpu])) return retval;
cudaMemGetInfo(&(org_size[gpu]), &dummy);
}
Problem* problem = new Problem; // allocate problem on GPU
if (retval = util::GRError(problem->Init(
stream_from_host,
graph,
NULL,
num_gpus,
gpu_idx,
partition_method,
streams,
max_queue_sizing,
max_in_sizing,
partition_factor,
partition_seed),
"CC Problem Initialization Failed", __FILE__, __LINE__))
return retval;
Enactor* enactor = new Enactor(
num_gpus, gpu_idx, instrument, debug, size_check); // enactor map
if (retval = util::GRError(enactor->Init(
context, problem, traversal_mode, max_grid_size),
"CC Enactor Init failed", __FILE__, __LINE__))
return retval;
enactor -> communicate_latency = communicate_latency;
enactor -> communicate_multipy = communicate_multipy;
enactor -> expand_latency = expand_latency;
enactor -> subqueue_latency = subqueue_latency;
enactor -> fullqueue_latency = fullqueue_latency;
enactor -> makeout_latency = makeout_latency;
if (retval = util::SetDevice(gpu_idx[0])) return retval;
if (retval = util::latency::Test(
streams[0], problem -> data_slices[0] -> latency_data,
communicate_latency,
communicate_multipy,
expand_latency,
subqueue_latency,
fullqueue_latency,
makeout_latency)) return retval;
cpu_timer.Stop();
info -> info["preprocess_time"] = cpu_timer.ElapsedMillis();
// compute reference CPU CC
if (!quick_mode)
{
if (!quiet_mode) { printf("Computing reference value ...\n"); }
ref_num_components = ReferenceCC(*graph, reference_check, quiet_mode);
if (!quiet_mode) { printf("\n"); }
}
// perform CC
double total_elapsed = 0.0;
double single_elapsed = 0.0;
double max_elapsed = 0.0;
double min_elapsed = 1e10;
json_spirit::mArray process_times;
if (!quiet_mode) printf("Using traversal mode %s\n", traversal_mode.c_str());
for (SizeT iter = 0; iter < iterations; ++iter)
{
if (retval = util::GRError(problem->Reset(
enactor->GetFrontierType(), max_queue_sizing),
"CC Problem Data Reset Failed", __FILE__, __LINE__))
return retval;
if (retval = util::GRError(enactor->Reset(),
"CC Enactor Reset failed", __FILE__, __LINE__))
return retval;
if (!quiet_mode)
{
printf("_________________________\n"); fflush(stdout);
}
cpu_timer.Start();
if (retval = util::GRError(enactor->Enact(traversal_mode),
"CC Problem Enact Failed", __FILE__, __LINE__))
return retval;
cpu_timer.Stop();
single_elapsed = cpu_timer.ElapsedMillis();
total_elapsed += single_elapsed;
process_times.push_back(single_elapsed);
if (single_elapsed > max_elapsed) max_elapsed = single_elapsed;
if (single_elapsed < min_elapsed) min_elapsed = single_elapsed;
if (!quiet_mode)
{
printf("-------------------------\n"
"iteration %lld elapsed: %lf ms\n",
(long long)iter, single_elapsed);
fflush(stdout);
}
}
total_elapsed /= iterations;
info -> info["process_times"] = process_times;
info -> info["min_process_time"] = min_elapsed;
info -> info["max_process_time"] = max_elapsed;
cpu_timer.Start();
// copy out results
if (retval = util::GRError(problem->Extract(h_component_ids),
"CC Problem Data Extraction Failed", __FILE__, __LINE__))
return retval;
// validity
if (!quick_mode)
{
if (ref_num_components == problem->num_components)
{
if (!quiet_mode)
{
printf("CORRECT. Component Count: %lld\n", (long long)ref_num_components);
}
}
else
{
if (!quiet_mode)
{
printf(
"INCORRECT. Ref Component Count: %lld, "
"GPU Computed Component Count: %lld\n",
(long long)ref_num_components, (long long)problem->num_components);
}
}
}
else
{
if (!quiet_mode)
{
printf("Component Count: %lld\n", (long long) problem->num_components);
}
}
if (!quick_mode)
{
ConvertIDs<VertexId, SizeT>(reference_check, graph->nodes, ref_num_components);
ConvertIDs<VertexId, SizeT>(h_component_ids, graph->nodes, problem->num_components);
if (!quiet_mode)
{
printf("Label Validity: ");
}
SizeT error_num = CompareResults(
h_component_ids, reference_check, graph->nodes, true, quiet_mode);
if (error_num > 0)
{
if (!quiet_mode) { printf("%lld errors occurred.\n", (long long)error_num); }
}
else
{
if (!quiet_mode) { printf("\n"); }
}
}
//if (ref_num_components == csr_problem->num_components)
{
// Compute size and root of each component
VertexId *h_roots = new VertexId[problem->num_components];
SizeT *h_histograms = new SizeT [problem->num_components];
//printf("num_components = %d\n", problem->num_components);
problem->ComputeCCHistogram(h_component_ids, h_roots, h_histograms);
//printf("num_components = %d\n", problem->num_components);
if (!quiet_mode)
{
// Display Solution
DisplaySolution(h_component_ids, graph->nodes,
problem->num_components, h_roots, h_histograms);
}
if (h_roots ) {delete[] h_roots ; h_roots = NULL;}
if (h_histograms) {delete[] h_histograms; h_histograms = NULL;}
}
info->ComputeCommonStats( // compute running statistics
enactor->enactor_stats.GetPointer(), total_elapsed, h_component_ids, true);
if (!quiet_mode)
{
printf("\n\tMemory Usage(B)\t");
for (int gpu = 0; gpu < num_gpus; gpu++)
if (num_gpus > 1)
{
if (gpu != 0) printf(" #keys%d\t #ins%d,0\t #ins%d,1", gpu, gpu, gpu);
else printf(" $keys%d", gpu);
}
else printf(" #keys%d", gpu);
if (num_gpus > 1) printf(" #keys%d", num_gpus);
printf("\n");
double max_key_sizing = 0, max_in_sizing_ = 0;
for (int gpu = 0; gpu < num_gpus; gpu++)
{
size_t gpu_free, dummy;
cudaSetDevice(gpu_idx[gpu]);
cudaMemGetInfo(&gpu_free, &dummy);
printf("GPU_%d\t %ld", gpu_idx[gpu], org_size[gpu] - gpu_free);
for (int i = 0; i < num_gpus; i++)
{
SizeT x = problem->data_slices[gpu]->frontier_queues[i].keys[0].GetSize();
printf("\t %lld", (long long)x);
double factor = 1.0 * x / (num_gpus > 1 ? problem->graph_slices[gpu]->in_counter[i] : problem->graph_slices[gpu]->nodes);
if (factor > max_key_sizing) max_key_sizing = factor;
if (num_gpus > 1 && i != 0 )
for (int t = 0; t < 2; t++)
{
x = problem->data_slices[gpu][0].keys_in[t][i].GetSize();
printf("\t %lld", (long long)x);
factor = 1.0 * x / problem->graph_slices[gpu]->in_counter[i];
if (factor > max_in_sizing_) max_in_sizing_ = factor;
}
}
if (num_gpus > 1) printf("\t %lld", (long long)problem->data_slices[gpu]->frontier_queues[num_gpus].keys[0].GetSize());
printf("\n");
}
printf("\t key_sizing =\t %lf", max_key_sizing);
if (num_gpus > 1) printf("\t in_sizing =\t %lf", max_in_sizing_);
printf("\n");
}
// Cleanup
if (org_size ) {delete[] org_size ; org_size = NULL;}
if (problem ) {delete problem ; problem = NULL;}
if (enactor ) {delete enactor ; enactor = NULL;}
if (reference_component_ids) {delete[] reference_component_ids; reference_component_ids = NULL;}
if (h_component_ids ) {delete[] h_component_ids ; h_component_ids = NULL;}
cpu_timer.Stop();
info->info["postprocess_time"] = cpu_timer.ElapsedMillis();
return retval;
}
/******************************************************************************
* Main
******************************************************************************/
template <
typename VertexId, // use int as the vertex identifier
typename SizeT , // use int as the graph size type
typename Value > // use int as the value type
int main_(CommandLineArgs *args)
{
CpuTimer cpu_timer, cpu_timer2;
cpu_timer.Start();
Csr <VertexId, SizeT, Value> csr(false); // graph we process on
Info<VertexId, SizeT, Value> *info = new Info<VertexId, SizeT, Value>;
// graph construction or generation related parameters
info->info["undirected"] = true; // require undirected input graph
cpu_timer2.Start();
info->Init("CC", *args, csr); // initialize Info structure
graphio::RemoveStandaloneNodes<VertexId, SizeT, Value>(
&csr, args->CheckCmdLineFlag("quiet"));
cpu_timer2.Stop();
info->info["load_time"] = cpu_timer2.ElapsedMillis();
RunTests<VertexId, SizeT, Value>(info); // run test
cpu_timer.Stop();
info->info["total_time"] = cpu_timer.ElapsedMillis();
if (!(info->info["quiet_mode"].get_bool()))
{
info->DisplayStats(); // display collected statistics
}
info->CollectInfo(); // collected all the info and put into JSON mObject
return 0;
}
template <
typename VertexId, // the vertex identifier type, usually int or long long
typename SizeT > // the size tyep, usually int or long long
int main_Value(CommandLineArgs *args)
{
// if (args -> CheckCmdLineFlag("64bit-Value"))
// return main_<VertexId, SizeT, long long>(args);
// else
// return main_<VertexId, SizeT, int >(args);
return main_<VertexId, SizeT, VertexId>(args); // Value = VertexId for CC
}
template <
typename VertexId>
int main_SizeT(CommandLineArgs *args)
{
// disabled to reduce compile time
if (args -> CheckCmdLineFlag("64bit-SizeT"))
return main_Value<VertexId, long long>(args);
else
return main_Value<VertexId, int >(args);
}
int main_VertexId(CommandLineArgs *args)
{
// disabled, because oprtr::filter::KernelPolicy::SmemStorage is too large for 64bit VertexId
//if (args -> CheckCmdLineFlag("64bit-VertexId"))
// return main_SizeT<long long>(args);
//else
return main_SizeT<int >(args);
}
int main(int argc, char** argv)
{
CommandLineArgs args(argc, argv);
int graph_args = argc - args.ParsedArgc() - 1;
if (argc < 2 || graph_args < 1 || args.CheckCmdLineFlag("help"))
{
Usage();
return 1;
}
return main_VertexId(&args);
}
// Leave this at the end of the file
// Local Variables:
// mode:c++
// c-file-style: "NVIDIA"
// End:
|
80b253a1b109cbdd1156ffad5a7928473c5904d6.hip | // !!! This is a file automatically generated by hipify!!!
#include<math.h>
/* using updated (v2) interfaces to cublas */
#include <hip/hip_runtime.h>
#include<hipsparse.h>
#include<cusparse_v2.h>
#include<rocblas.h>
#include <helper_functions.h> // helper for shared functions common to cuda samples
#include <helper_cuda.h> // helper function cuda error checking and initialization
#include"header.h"
void solve_matrix_gpu(double **A, double *b, int N, node *no){
//PreConditoned
double *TempDiagonal;
TempDiagonal = (double *)malloc(3 * N*sizeof(double));
for (int i = 0; i < N + N + N; i++){
TempDiagonal[i] = A[i][i];
}
for (int i = 0; i < N + N + N; i++){
for (int j = 0; j < N + N + N; j++){
A[i][j] = A[i][j] / sqrt(TempDiagonal[i]);
A[i][j] = A[i][j] / sqrt(TempDiagonal[j]);
}
b[i] = b[i] / sqrt(TempDiagonal[i]);
}
//
double *hA,*hx,*hb,*hr,*hp,*HostTempVector;
hA = (double *)malloc(sizeof(double)*(9 * N*N));
hb = (double *)malloc(sizeof(double)*(N + N + N));
hx = (double *)malloc(sizeof(double)*(N + N + N));
hr = (double *)malloc(sizeof(double)*(N + N + N));
hp = (double *)malloc(sizeof(double)*(N + N + N));
HostTempVector = (double *)malloc(sizeof(double)*(N + N + N));
for (int i = 0; i < N + N + N; i++){
hp[i] = 0;
hr[i] = 0;
hp[i] = 0;
hx[i] = 0;
hb[i] = 0;
HostTempVector[i] = 0;
}
//
for (int i = 0; i < N + N+ N; i++){
for (int j = 0; j < N + N + N; j++){
hA[i * 3 * N + j] = A[i][j];
}
}
for (int i = 0; i < N; i++){
hx[i + i + i] = no[i].xd[0];
hx[i + i + i + 1] = no[i].xd[1];
hx[i + i + i + 2] = no[i].xd[2];
}
for (int i = 0; i < N+N+N; i++){
hb[i] = b[i];
}
hipsparseHandle_t cusparseHandle = 0;
hipsparseMatDescr_t descr = 0;
hipsparseCreate(&cusparseHandle);
//
double *dA, *db, *dx, *dr, *dp, *TempVector;
double CorrectionCoefficientA = 0; //1
double CorrectionCoefficientB = 0; //2
int *npr;
hipMalloc((void**)&dA, sizeof(double)* 9 * N*N);
hipMalloc((void**)&db, sizeof(double)* 3 * N);
hipMalloc((void**)&dx, sizeof(double)* 3 * N);
hipMalloc((void**)&dr, sizeof(double)* 3 * N);
hipMalloc((void**)&dp, sizeof(double)* 3 * N);
hipMalloc((void**)&npr, sizeof(int)* 9 * N*N);
hipMalloc((void**)&TempVector, sizeof(double)* 3 * N);
/*Create CUSPARSE context*/
hipsparseCreateMatDescr(&descr);
hipsparseSetMatType(descr, HIPSPARSE_MATRIX_TYPE_GENERAL);
hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO);
/*Create CUBLAS context*/
hipblasHandle_t cublasHandle = 0;
hipblasStatus_t cublasStatus;
cublasStatus = hipblasCreate(&cublasHandle);
//
hipMemcpy(dA, hA, sizeof(double)*(9 * N*N), hipMemcpyHostToDevice);
hipMemcpy(db, hb, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(dx, hx, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(dp, hp, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(dr, hr, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(TempVector, HostTempVector, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
int total;
hipsparseDnnz(cusparseHandle, HIPSPARSE_DIRECTION_ROW, 3 * N, 3 * N, descr, dA, 3 * N, npr, &total);
double *csrV_A;
int *csrC_A;
int *csrR_A;
hipMalloc((void**)&csrV_A, sizeof(double)*total);
hipMalloc((void**)&csrR_A, sizeof(int)* 3 * N + 1);
hipMalloc((void**)&csrC_A, sizeof(int)*total);
hipsparseDdense2csr(cusparseHandle, 3 * N, 3 * N, descr, dA, 3 * N, npr, csrV_A, csrR_A, csrC_A);
double *h_csrV_A;
h_csrV_A = (double *)malloc(sizeof(double)*total);
int *h_csrC_A;
h_csrC_A = (int *)malloc(sizeof(int)* total);
int *h_csrR_A;
h_csrR_A = (int *)malloc(sizeof(int)* 3 * N + 1);
hipMemcpy(h_csrV_A, csrV_A, sizeof(double)*total, hipMemcpyDeviceToHost);
hipMemcpy(h_csrC_A, csrC_A, sizeof(int)*total, hipMemcpyDeviceToHost);
hipMemcpy(h_csrR_A, csrR_A, sizeof(int)*(N + N + N), hipMemcpyDeviceToHost);
printf("total=%d\n", total);
FILE *fp_V,*fp_C,*fp_R;
errno_t errorV, errorC, errorR;
char fnameV[] = "gpuV";
char fnameC[] = "gpuC";
char fnameR[] = "gpuR";
if (errorV = fopen_s(&fp_V, fnameV, "w") != 0){
printf("\n file open failed \n");
}
if (errorC = fopen_s(&fp_C, fnameC, "w") != 0){
printf("\n file open failed \n");
}
if (errorR = fopen_s(&fp_R, fnameR, "w") != 0){
printf("\n file open failed \n");
}
for (int i = 0; i < total; i++){
fprintf(fp_V, "%19.15f\n", h_csrV_A[i]);
fprintf(fp_C, "%d\n", h_csrC_A[i]);
}
for (int i = 0; i < N + N + N + 1; i++){
fprintf(fp_R, "%d\n", h_csrR_A[i]);
}
fclose(fp_V);
fclose(fp_C);
fclose(fp_R);
double alpha = -1.0;
double beta = 1.0;
hipblasDcopy(cublasHandle, N + N + N, db, 1, TempVector, 1);
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dx, &beta, db);
hipblasDcopy(cublasHandle, N + N + N, db, 1, dr, 1);
hipblasDcopy(cublasHandle, N + N + N, TempVector, 1, db, 1);
hipblasDcopy(cublasHandle, N + N + N, dr, 1, dp, 1);
double ResidualError = 0;
hipblasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
printf("iteration:\t%d\tresidual error:\t%1.20f\n", 0, ResidualError);
int Iteration = 1;
double error[1000000] = {};
error[0] = ResidualError;
clock_t start, end;
start = clock();
while (1){
double Denominator = 0.0f; //
double Numerator = 0.0f; //
hipblasDdot(cublasHandle, N + N + N, dp, 1, dr, 1, &Numerator);
alpha = 1.0;
beta = 0.0f;
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, TempVector);
hipblasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientA = Numerator / Denominator;
hipblasDaxpy(cublasHandle, N + N + N, &CorrectionCoefficientA, dp, 1, dx, 1);
alpha = -CorrectionCoefficientA;
beta = 1;
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, dr);
hipblasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
Iteration++;
error[Iteration] = ResidualError;
//if (ResidualError < EPS*EPS){
// double stability = fabs(error[Iteration] - error[Iteration - 1000]);
// if (stability < EPS*EPS / 10){
// break; //EPS
// }
//}
if (ResidualError == 0)break;
alpha = 1.0f;
beta = 0.0f;
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, TempVector);
hipblasDdot(cublasHandle, N + N + N, dr, 1, TempVector, 1, &Numerator);
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, TempVector);
hipblasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientB = -Numerator / Denominator;
hipblasDscal(cublasHandle, N + N + N, &CorrectionCoefficientB, dp, 1);
CorrectionCoefficientB = 1;
hipblasDaxpy(cublasHandle, N + N + N,&CorrectionCoefficientB , dr, 1, dp, 1);
}
end = clock();
printf("-CG%d\n", end - start);
hipMemcpy(hx, dx, sizeof(double)*(N + N + N), hipMemcpyDeviceToHost);
for (int i = 0; i < N + N + N; i++){
b[i] = hx[i] / sqrt(TempDiagonal[i]);
}
}
void solve_matrix_gpu_CSR(double *CSR_Kval,int *CSR_col,int *CSR_row, double *b, int N, node *no,int RealNumberOfValues){
//Precondtioned
double *TempDiagonal;
TempDiagonal = (double *)malloc(3 * N*sizeof(double));
for (int i = 0; i < N + N + N; i++){
for (int j = CSR_row[i]; j < CSR_row[i+1]; j++){
if (CSR_col[j] == i)TempDiagonal[i] = CSR_Kval[j];
}
}
//PreConditoned
//double *TempDiagonal;
//TempDiagonal = (double *)malloc(3 * N*sizeof(double));
//for (int i = 0; i < N + N + N; i++){
// TempDiagonal[i] = A[i][i];
//}
//for (int i = 0; i < N + N + N; i++){
// for (int j = 0; j < N + N + N; j++){
// A[i][j] = A[i][j] / sqrt(TempDiagonal[i]);
// A[i][j] = A[i][j] / sqrt(TempDiagonal[j]);
// }
// b[i] = b[i] / sqrt(TempDiagonal[i]);
//}
//
//
double *h_CSR_Kval,*hx,*hb,*hr,*hp,*HostTempVector;
int *h_CSR_col, *h_CSR_row;
h_CSR_Kval = (double *)malloc(sizeof(double)*(RealNumberOfValues));
h_CSR_col = (int *)malloc(sizeof(int)*(RealNumberOfValues));
h_CSR_row = (int *)malloc(sizeof(int)*(N + N + N));
hb = (double *)malloc(sizeof(double)*(N + N + N));
for (int i = 0; i < RealNumberOfValues; i++){
h_CSR_Kval[i] = CSR_Kval[i];
}
//
for (int i = 0; i < N + N + N; i++){
for (int j = CSR_row[i]; j < CSR_row[i + 1]; j++){
h_CSR_Kval[j] = h_CSR_Kval[j] / sqrt(TempDiagonal[i]);
h_CSR_Kval[j] = h_CSR_Kval[j] / sqrt(TempDiagonal[CSR_col[j]]);
}
}
for (int i = 0; i < RealNumberOfValues; i++){
h_CSR_col[i] = CSR_col[i];
}
for (int i = 0; i < N + N + N ; i++){
h_CSR_row[i] = CSR_row[i];
}
for (int i = 0; i < N + N + N; i++){
hb[i] = b[i] / sqrt(TempDiagonal[i]);
}
FILE *fp_V, *fp_C, *fp_R;
errno_t errorV, errorC, errorR;
char fnameV[] = "cpuV";
char fnameC[] = "cpuC";
char fnameR[] = "cpuR";
if (errorV = fopen_s(&fp_V, fnameV, "w") != 0){
printf("\n file open failed \n");
}
if (errorC = fopen_s(&fp_C, fnameC, "w") != 0){
printf("\n file open failed \n");
}
if (errorR = fopen_s(&fp_R, fnameR, "w") != 0){
printf("\n file open failed \n");
}
for (int i = 0; i < RealNumberOfValues; i++){
fprintf(fp_V, "%19.15f\n", h_CSR_Kval[i]);
fprintf(fp_C, "%d\n", h_CSR_col[i]);
}
for (int i = 0; i < N + N + N; i++){
fprintf(fp_R, "%d\n", h_CSR_row[i]);
}
fclose(fp_V);
fclose(fp_C);
fclose(fp_R);
hx = (double *)malloc(sizeof(double)*(N + N + N));
hr = (double *)malloc(sizeof(double)*(N + N + N));
hp = (double *)malloc(sizeof(double)*(N + N + N));
HostTempVector = (double *)malloc(sizeof(double)*(N + N + N));
for (int i = 0; i < N + N + N; i++){
hp[i] = 0;
hr[i] = 0;
hx[i] = 0;
HostTempVector[i] = 0;
}
//
//for (int i = 0; i < N; i++){
// hx[i + i + i] = no[i].xd[0];
// hx[i + i + i + 1] = no[i].xd[1];
// hx[i + i + i + 2] = no[i].xd[2];
//}
hipsparseHandle_t cusparseHandle = 0;
hipsparseMatDescr_t descr = 0;
hipsparseCreate(&cusparseHandle);
//
double *d_CSR_Kval,*db, *dx, *dr, *dp, *TempVector;
int *d_CSR_col, *d_CSR_row;
double CorrectionCoefficientA = 0; //1
double CorrectionCoefficientB = 0; //2
int *npr;
hipMalloc((void**)&d_CSR_Kval, sizeof(double)*RealNumberOfValues);
hipMalloc((void**)&d_CSR_col, sizeof(int)*RealNumberOfValues);
hipMalloc((void**)&d_CSR_row, sizeof(int)*(N + N + N )+1);
hipMalloc((void**)&db, sizeof(double)* 3 * N);
hipMalloc((void**)&dx, sizeof(double)* 3 * N);
hipMalloc((void**)&dr, sizeof(double)* 3 * N);
hipMalloc((void**)&dp, sizeof(double)* 3 * N);
hipMalloc((void**)&npr, sizeof(int)* 9 * N*N);
hipMalloc((void**)&TempVector, sizeof(double)* 3 * N);
/*Create CUSPARSE context*/
hipsparseCreateMatDescr(&descr);
hipsparseSetMatType(descr, HIPSPARSE_MATRIX_TYPE_GENERAL);
hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO);
/*Create CUBLAS context*/
hipblasHandle_t cublasHandle = 0;
hipblasStatus_t cublasStatus;
cublasStatus = hipblasCreate(&cublasHandle);
//
hipMemcpy(d_CSR_Kval, h_CSR_Kval, sizeof(double)*RealNumberOfValues, hipMemcpyHostToDevice);
hipMemcpy(d_CSR_col, h_CSR_col, sizeof(int)*RealNumberOfValues, hipMemcpyHostToDevice);
hipMemcpy(d_CSR_row, h_CSR_row, sizeof(int)*(N + N + N ), hipMemcpyHostToDevice);
hipMemcpy(db, hb, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(dx, hx, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(dp, hp, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(dr, hr, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
hipMemcpy(TempVector, HostTempVector, sizeof(double)*(N + N + N), hipMemcpyHostToDevice);
int total=RealNumberOfValues;
//double *csrV_A;
//int *csrC_A;
//int *csrR_A;
//hipMalloc((void**)&csrV_A, sizeof(double)*total);
//hipMalloc((void**)&csrR_A, sizeof(int)* 3 * N + 1);
//hipMalloc((void**)&csrC_A, sizeof(int)*total);
double alpha = -1.0;
double beta = 1.0;
hipblasDcopy(cublasHandle, N + N + N, db, 1, TempVector, 1);
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dx, &beta, db);
hipblasDcopy(cublasHandle, N + N + N, db, 1, dr, 1);
hipblasDcopy(cublasHandle, N + N + N, TempVector, 1, db, 1);
hipblasDcopy(cublasHandle, N + N + N, dr, 1, dp, 1);
double ResidualError = 0;
hipblasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
//printf("iteration:\t%d\tresidual error:\t%1.20f\n", 0, ResidualError);
int Iteration = 1;
double error[1000000] = {};
error[0] = ResidualError;
clock_t start, end;
start = clock();
while (1){
double Denominator = 0.0f; //
double Numerator = 0.0f; //
hipblasDdot(cublasHandle, N + N + N, dp, 1, dr, 1, &Numerator);
alpha = 1.0;
beta = 0.0f;
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, TempVector);
hipblasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientA = Numerator / Denominator;
hipblasDaxpy(cublasHandle, N + N + N, &CorrectionCoefficientA, dp, 1, dx, 1);
alpha = -CorrectionCoefficientA;
beta = 1;
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, dr);
hipblasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
Iteration++;
error[Iteration] = ResidualError;
printf("iteration:\t%d\tresidual error:\t%1.20f\n", Iteration, error[Iteration]);
//if (ResidualError < EPS*EPS){
// double stability = fabs(error[Iteration] - error[Iteration - 1000]);
// if (stability < EPS*EPS / 10){
// break; //EPS
// }
//}
if (ResidualError <= 1e-15f*1e-15f)break;
alpha = 1.0f;
beta = 0.0f;
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, TempVector);
hipblasDdot(cublasHandle, N + N + N, dr, 1, TempVector, 1, &Numerator);
hipsparseDcsrmv(cusparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, TempVector);
hipblasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientB = -Numerator / Denominator;
hipblasDscal(cublasHandle, N + N + N, &CorrectionCoefficientB, dp, 1);
CorrectionCoefficientB = 1;
hipblasDaxpy(cublasHandle, N + N + N,&CorrectionCoefficientB , dr, 1, dp, 1);
}
end = clock();
printf("-CG%d\n", end - start);
hipMemcpy(hx, dx, sizeof(double)*(N + N + N), hipMemcpyDeviceToHost);
for (int i = 0; i < N; i++){
no[i].xd[0] = hx[3*i] / sqrt(TempDiagonal[3*i]);
no[i].xd[1] = hx[3*i+1] / sqrt(TempDiagonal[3*i+1]);
no[i].xd[2] = hx[3*i+2] / sqrt(TempDiagonal[3*i+2]);
}
}
| 80b253a1b109cbdd1156ffad5a7928473c5904d6.cu |
#include<math.h>
/* using updated (v2) interfaces to cublas */
#include <cuda_runtime.h>
#include<cusparse.h>
#include<cusparse_v2.h>
#include<cublas_v2.h>
#include <helper_functions.h> // helper for shared functions common to cuda samples
#include <helper_cuda.h> // helper function cuda error checking and initialization
#include"header.h"
void solve_matrix_gpu(double **A, double *b, int N, node *no){
//PreConditoned
double *TempDiagonal;
TempDiagonal = (double *)malloc(3 * N*sizeof(double));
for (int i = 0; i < N + N + N; i++){
TempDiagonal[i] = A[i][i];
}
for (int i = 0; i < N + N + N; i++){
for (int j = 0; j < N + N + N; j++){
A[i][j] = A[i][j] / sqrt(TempDiagonal[i]);
A[i][j] = A[i][j] / sqrt(TempDiagonal[j]);
}
b[i] = b[i] / sqrt(TempDiagonal[i]);
}
//ホスト側のメモリを確保
double *hA,*hx,*hb,*hr,*hp,*HostTempVector;
hA = (double *)malloc(sizeof(double)*(9 * N*N));
hb = (double *)malloc(sizeof(double)*(N + N + N));
hx = (double *)malloc(sizeof(double)*(N + N + N));
hr = (double *)malloc(sizeof(double)*(N + N + N));
hp = (double *)malloc(sizeof(double)*(N + N + N));
HostTempVector = (double *)malloc(sizeof(double)*(N + N + N));
for (int i = 0; i < N + N + N; i++){
hp[i] = 0;
hr[i] = 0;
hp[i] = 0;
hx[i] = 0;
hb[i] = 0;
HostTempVector[i] = 0;
}
//データをコピー
for (int i = 0; i < N + N+ N; i++){
for (int j = 0; j < N + N + N; j++){
hA[i * 3 * N + j] = A[i][j];
}
}
for (int i = 0; i < N; i++){
hx[i + i + i] = no[i].xd[0];
hx[i + i + i + 1] = no[i].xd[1];
hx[i + i + i + 2] = no[i].xd[2];
}
for (int i = 0; i < N+N+N; i++){
hb[i] = b[i];
}
cusparseHandle_t cusparseHandle = 0;
cusparseMatDescr_t descr = 0;
cusparseCreate(&cusparseHandle);
//デバイス側のメモリを確保
double *dA, *db, *dx, *dr, *dp, *TempVector;
double CorrectionCoefficientA = 0; //修正係数1
double CorrectionCoefficientB = 0; //修正係数2
int *npr;
cudaMalloc((void**)&dA, sizeof(double)* 9 * N*N);
cudaMalloc((void**)&db, sizeof(double)* 3 * N);
cudaMalloc((void**)&dx, sizeof(double)* 3 * N);
cudaMalloc((void**)&dr, sizeof(double)* 3 * N);
cudaMalloc((void**)&dp, sizeof(double)* 3 * N);
cudaMalloc((void**)&npr, sizeof(int)* 9 * N*N);
cudaMalloc((void**)&TempVector, sizeof(double)* 3 * N);
/*Create CUSPARSE context*/
cusparseCreateMatDescr(&descr);
cusparseSetMatType(descr, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(descr, CUSPARSE_INDEX_BASE_ZERO);
/*Create CUBLAS context*/
cublasHandle_t cublasHandle = 0;
cublasStatus_t cublasStatus;
cublasStatus = cublasCreate(&cublasHandle);
//初期値を転送
cudaMemcpy(dA, hA, sizeof(double)*(9 * N*N), cudaMemcpyHostToDevice);
cudaMemcpy(db, hb, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(dx, hx, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(dp, hp, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(dr, hr, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(TempVector, HostTempVector, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
int total;
cusparseDnnz(cusparseHandle, CUSPARSE_DIRECTION_ROW, 3 * N, 3 * N, descr, dA, 3 * N, npr, &total);
double *csrV_A;
int *csrC_A;
int *csrR_A;
cudaMalloc((void**)&csrV_A, sizeof(double)*total);
cudaMalloc((void**)&csrR_A, sizeof(int)* 3 * N + 1);
cudaMalloc((void**)&csrC_A, sizeof(int)*total);
cusparseDdense2csr(cusparseHandle, 3 * N, 3 * N, descr, dA, 3 * N, npr, csrV_A, csrR_A, csrC_A);
double *h_csrV_A;
h_csrV_A = (double *)malloc(sizeof(double)*total);
int *h_csrC_A;
h_csrC_A = (int *)malloc(sizeof(int)* total);
int *h_csrR_A;
h_csrR_A = (int *)malloc(sizeof(int)* 3 * N + 1);
cudaMemcpy(h_csrV_A, csrV_A, sizeof(double)*total, cudaMemcpyDeviceToHost);
cudaMemcpy(h_csrC_A, csrC_A, sizeof(int)*total, cudaMemcpyDeviceToHost);
cudaMemcpy(h_csrR_A, csrR_A, sizeof(int)*(N + N + N), cudaMemcpyDeviceToHost);
printf("total=%d\n", total);
FILE *fp_V,*fp_C,*fp_R;
errno_t errorV, errorC, errorR;
char fnameV[] = "gpuV";
char fnameC[] = "gpuC";
char fnameR[] = "gpuR";
if (errorV = fopen_s(&fp_V, fnameV, "w") != 0){
printf("\n file open failed \n");
}
if (errorC = fopen_s(&fp_C, fnameC, "w") != 0){
printf("\n file open failed \n");
}
if (errorR = fopen_s(&fp_R, fnameR, "w") != 0){
printf("\n file open failed \n");
}
for (int i = 0; i < total; i++){
fprintf(fp_V, "%19.15f\n", h_csrV_A[i]);
fprintf(fp_C, "%d\n", h_csrC_A[i]);
}
for (int i = 0; i < N + N + N + 1; i++){
fprintf(fp_R, "%d\n", h_csrR_A[i]);
}
fclose(fp_V);
fclose(fp_C);
fclose(fp_R);
double alpha = -1.0;
double beta = 1.0;
cublasDcopy(cublasHandle, N + N + N, db, 1, TempVector, 1);
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dx, &beta, db);
cublasDcopy(cublasHandle, N + N + N, db, 1, dr, 1);
cublasDcopy(cublasHandle, N + N + N, TempVector, 1, db, 1);
cublasDcopy(cublasHandle, N + N + N, dr, 1, dp, 1);
double ResidualError = 0;
cublasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
printf("iteration:\t%d\tresidual error:\t%1.20f\n", 0, ResidualError);
int Iteration = 1;
double error[1000000] = {};
error[0] = ResidualError;
clock_t start, end;
start = clock();
while (1){
double Denominator = 0.0f; //分母
double Numerator = 0.0f; //分子
cublasDdot(cublasHandle, N + N + N, dp, 1, dr, 1, &Numerator);
alpha = 1.0;
beta = 0.0f;
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, TempVector);
cublasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientA = Numerator / Denominator;
cublasDaxpy(cublasHandle, N + N + N, &CorrectionCoefficientA, dp, 1, dx, 1);
alpha = -CorrectionCoefficientA;
beta = 1;
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, dr);
cublasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
Iteration++;
error[Iteration] = ResidualError;
//if (ResidualError < EPS*EPS){
// double stability = fabs(error[Iteration] - error[Iteration - 1000]);
// if (stability < EPS*EPS / 10){
// break; //EPSの判断
// }
//}
if (ResidualError == 0)break;
alpha = 1.0f;
beta = 0.0f;
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, TempVector);
cublasDdot(cublasHandle, N + N + N, dr, 1, TempVector, 1, &Numerator);
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, csrV_A, csrR_A, csrC_A, dp, &beta, TempVector);
cublasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientB = -Numerator / Denominator;
cublasDscal(cublasHandle, N + N + N, &CorrectionCoefficientB, dp, 1);
CorrectionCoefficientB = 1;
cublasDaxpy(cublasHandle, N + N + N,&CorrectionCoefficientB , dr, 1, dp, 1);
}
end = clock();
printf("処理時間-CG %d\n", end - start);
cudaMemcpy(hx, dx, sizeof(double)*(N + N + N), cudaMemcpyDeviceToHost);
for (int i = 0; i < N + N + N; i++){
b[i] = hx[i] / sqrt(TempDiagonal[i]);
}
}
void solve_matrix_gpu_CSR(double *CSR_Kval,int *CSR_col,int *CSR_row, double *b, int N, node *no,int RealNumberOfValues){
//Precondtioned
double *TempDiagonal;
TempDiagonal = (double *)malloc(3 * N*sizeof(double));
for (int i = 0; i < N + N + N; i++){
for (int j = CSR_row[i]; j < CSR_row[i+1]; j++){
if (CSR_col[j] == i)TempDiagonal[i] = CSR_Kval[j];
}
}
//PreConditoned
//double *TempDiagonal;
//TempDiagonal = (double *)malloc(3 * N*sizeof(double));
//for (int i = 0; i < N + N + N; i++){
// TempDiagonal[i] = A[i][i];
//}
//for (int i = 0; i < N + N + N; i++){
// for (int j = 0; j < N + N + N; j++){
// A[i][j] = A[i][j] / sqrt(TempDiagonal[i]);
// A[i][j] = A[i][j] / sqrt(TempDiagonal[j]);
// }
// b[i] = b[i] / sqrt(TempDiagonal[i]);
//}
//
//ホスト側のメモリを確保
double *h_CSR_Kval,*hx,*hb,*hr,*hp,*HostTempVector;
int *h_CSR_col, *h_CSR_row;
h_CSR_Kval = (double *)malloc(sizeof(double)*(RealNumberOfValues));
h_CSR_col = (int *)malloc(sizeof(int)*(RealNumberOfValues));
h_CSR_row = (int *)malloc(sizeof(int)*(N + N + N));
hb = (double *)malloc(sizeof(double)*(N + N + N));
for (int i = 0; i < RealNumberOfValues; i++){
h_CSR_Kval[i] = CSR_Kval[i];
}
//対角スケーリング
for (int i = 0; i < N + N + N; i++){
for (int j = CSR_row[i]; j < CSR_row[i + 1]; j++){
h_CSR_Kval[j] = h_CSR_Kval[j] / sqrt(TempDiagonal[i]);
h_CSR_Kval[j] = h_CSR_Kval[j] / sqrt(TempDiagonal[CSR_col[j]]);
}
}
for (int i = 0; i < RealNumberOfValues; i++){
h_CSR_col[i] = CSR_col[i];
}
for (int i = 0; i < N + N + N ; i++){
h_CSR_row[i] = CSR_row[i];
}
for (int i = 0; i < N + N + N; i++){
hb[i] = b[i] / sqrt(TempDiagonal[i]);
}
FILE *fp_V, *fp_C, *fp_R;
errno_t errorV, errorC, errorR;
char fnameV[] = "cpuV";
char fnameC[] = "cpuC";
char fnameR[] = "cpuR";
if (errorV = fopen_s(&fp_V, fnameV, "w") != 0){
printf("\n file open failed \n");
}
if (errorC = fopen_s(&fp_C, fnameC, "w") != 0){
printf("\n file open failed \n");
}
if (errorR = fopen_s(&fp_R, fnameR, "w") != 0){
printf("\n file open failed \n");
}
for (int i = 0; i < RealNumberOfValues; i++){
fprintf(fp_V, "%19.15f\n", h_CSR_Kval[i]);
fprintf(fp_C, "%d\n", h_CSR_col[i]);
}
for (int i = 0; i < N + N + N; i++){
fprintf(fp_R, "%d\n", h_CSR_row[i]);
}
fclose(fp_V);
fclose(fp_C);
fclose(fp_R);
hx = (double *)malloc(sizeof(double)*(N + N + N));
hr = (double *)malloc(sizeof(double)*(N + N + N));
hp = (double *)malloc(sizeof(double)*(N + N + N));
HostTempVector = (double *)malloc(sizeof(double)*(N + N + N));
for (int i = 0; i < N + N + N; i++){
hp[i] = 0;
hr[i] = 0;
hx[i] = 0;
HostTempVector[i] = 0;
}
//データをコピー
//for (int i = 0; i < N; i++){
// hx[i + i + i] = no[i].xd[0];
// hx[i + i + i + 1] = no[i].xd[1];
// hx[i + i + i + 2] = no[i].xd[2];
//}
cusparseHandle_t cusparseHandle = 0;
cusparseMatDescr_t descr = 0;
cusparseCreate(&cusparseHandle);
//デバイス側のメモリを確保
double *d_CSR_Kval,*db, *dx, *dr, *dp, *TempVector;
int *d_CSR_col, *d_CSR_row;
double CorrectionCoefficientA = 0; //修正係数1
double CorrectionCoefficientB = 0; //修正係数2
int *npr;
cudaMalloc((void**)&d_CSR_Kval, sizeof(double)*RealNumberOfValues);
cudaMalloc((void**)&d_CSR_col, sizeof(int)*RealNumberOfValues);
cudaMalloc((void**)&d_CSR_row, sizeof(int)*(N + N + N )+1);
cudaMalloc((void**)&db, sizeof(double)* 3 * N);
cudaMalloc((void**)&dx, sizeof(double)* 3 * N);
cudaMalloc((void**)&dr, sizeof(double)* 3 * N);
cudaMalloc((void**)&dp, sizeof(double)* 3 * N);
cudaMalloc((void**)&npr, sizeof(int)* 9 * N*N);
cudaMalloc((void**)&TempVector, sizeof(double)* 3 * N);
/*Create CUSPARSE context*/
cusparseCreateMatDescr(&descr);
cusparseSetMatType(descr, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(descr, CUSPARSE_INDEX_BASE_ZERO);
/*Create CUBLAS context*/
cublasHandle_t cublasHandle = 0;
cublasStatus_t cublasStatus;
cublasStatus = cublasCreate(&cublasHandle);
//初期値を転送
cudaMemcpy(d_CSR_Kval, h_CSR_Kval, sizeof(double)*RealNumberOfValues, cudaMemcpyHostToDevice);
cudaMemcpy(d_CSR_col, h_CSR_col, sizeof(int)*RealNumberOfValues, cudaMemcpyHostToDevice);
cudaMemcpy(d_CSR_row, h_CSR_row, sizeof(int)*(N + N + N ), cudaMemcpyHostToDevice);
cudaMemcpy(db, hb, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(dx, hx, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(dp, hp, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(dr, hr, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
cudaMemcpy(TempVector, HostTempVector, sizeof(double)*(N + N + N), cudaMemcpyHostToDevice);
int total=RealNumberOfValues;
//double *csrV_A;
//int *csrC_A;
//int *csrR_A;
//cudaMalloc((void**)&csrV_A, sizeof(double)*total);
//cudaMalloc((void**)&csrR_A, sizeof(int)* 3 * N + 1);
//cudaMalloc((void**)&csrC_A, sizeof(int)*total);
double alpha = -1.0;
double beta = 1.0;
cublasDcopy(cublasHandle, N + N + N, db, 1, TempVector, 1);
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dx, &beta, db);
cublasDcopy(cublasHandle, N + N + N, db, 1, dr, 1);
cublasDcopy(cublasHandle, N + N + N, TempVector, 1, db, 1);
cublasDcopy(cublasHandle, N + N + N, dr, 1, dp, 1);
double ResidualError = 0;
cublasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
//printf("iteration:\t%d\tresidual error:\t%1.20f\n", 0, ResidualError);
int Iteration = 1;
double error[1000000] = {};
error[0] = ResidualError;
clock_t start, end;
start = clock();
while (1){
double Denominator = 0.0f; //分母
double Numerator = 0.0f; //分子
cublasDdot(cublasHandle, N + N + N, dp, 1, dr, 1, &Numerator);
alpha = 1.0;
beta = 0.0f;
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, TempVector);
cublasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientA = Numerator / Denominator;
cublasDaxpy(cublasHandle, N + N + N, &CorrectionCoefficientA, dp, 1, dx, 1);
alpha = -CorrectionCoefficientA;
beta = 1;
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, dr);
cublasDdot(cublasHandle, N + N + N, dr, 1, dr, 1, &ResidualError);
Iteration++;
error[Iteration] = ResidualError;
printf("iteration:\t%d\tresidual error:\t%1.20f\n", Iteration, error[Iteration]);
//if (ResidualError < EPS*EPS){
// double stability = fabs(error[Iteration] - error[Iteration - 1000]);
// if (stability < EPS*EPS / 10){
// break; //EPSの判断
// }
//}
if (ResidualError <= 1e-15f*1e-15f)break;
alpha = 1.0f;
beta = 0.0f;
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, TempVector);
cublasDdot(cublasHandle, N + N + N, dr, 1, TempVector, 1, &Numerator);
cusparseDcsrmv(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, 3 * N, 3 * N, total, &alpha, descr, d_CSR_Kval, d_CSR_row, d_CSR_col, dp, &beta, TempVector);
cublasDdot(cublasHandle, N + N + N, dp, 1, TempVector, 1, &Denominator);
CorrectionCoefficientB = -Numerator / Denominator;
cublasDscal(cublasHandle, N + N + N, &CorrectionCoefficientB, dp, 1);
CorrectionCoefficientB = 1;
cublasDaxpy(cublasHandle, N + N + N,&CorrectionCoefficientB , dr, 1, dp, 1);
}
end = clock();
printf("処理時間-CG %d\n", end - start);
cudaMemcpy(hx, dx, sizeof(double)*(N + N + N), cudaMemcpyDeviceToHost);
for (int i = 0; i < N; i++){
no[i].xd[0] = hx[3*i] / sqrt(TempDiagonal[3*i]);
no[i].xd[1] = hx[3*i+1] / sqrt(TempDiagonal[3*i+1]);
no[i].xd[2] = hx[3*i+2] / sqrt(TempDiagonal[3*i+2]);
}
}
|
b725d3432fecd13e3bc24f9b3202825e1b6a879b.hip | // !!! This is a file automatically generated by hipify!!!
/*
* Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA Corporation is strictly prohibited.
*
*/
#include <hip/hip_runtime.h>
#include <hip/hip_runtime.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
inline __device__ float sigmoidGPU(const float& x) { return 1.0f / (1.0f + __expf(-x)); }
__global__ void gpuYoloLayerV3(const float* input, float* output, const uint gridSize, const uint numOutputClasses,
const uint numBBoxes)
{
uint x_id = blockIdx.x * blockDim.x + threadIdx.x;
uint y_id = blockIdx.y * blockDim.y + threadIdx.y;
uint z_id = blockIdx.z * blockDim.z + threadIdx.z;
if ((x_id >= gridSize) || (y_id >= gridSize) || (z_id >= numBBoxes))
{
return;
}
const int numGridCells = gridSize * gridSize;
const int bbindex = y_id * gridSize + x_id;
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]
= __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]
= __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]);
for (uint i = 0; i < numOutputClasses; ++i)
{
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]);
}
}
hipError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize,
const uint& numOutputClasses, const uint& numBBoxes,
uint64_t outputSize, hipStream_t stream);
hipError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize,
const uint& numOutputClasses, const uint& numBBoxes,
uint64_t outputSize, hipStream_t stream)
{
dim3 threads_per_block(16, 16, 4);
dim3 number_of_blocks((gridSize / threads_per_block.x) + 1,
(gridSize / threads_per_block.y) + 1,
(numBBoxes / threads_per_block.z) + 1);
for (unsigned int batch = 0; batch < batchSize; ++batch)
{
hipLaunchKernelGGL(( gpuYoloLayerV3), dim3(number_of_blocks), dim3(threads_per_block), 0, stream,
reinterpret_cast<const float*>(input) + (batch * outputSize),
reinterpret_cast<float*>(output) + (batch * outputSize), gridSize, numOutputClasses,
numBBoxes);
}
return hipGetLastError();
}
| b725d3432fecd13e3bc24f9b3202825e1b6a879b.cu | /*
* Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA Corporation is strictly prohibited.
*
*/
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
inline __device__ float sigmoidGPU(const float& x) { return 1.0f / (1.0f + __expf(-x)); }
__global__ void gpuYoloLayerV3(const float* input, float* output, const uint gridSize, const uint numOutputClasses,
const uint numBBoxes)
{
uint x_id = blockIdx.x * blockDim.x + threadIdx.x;
uint y_id = blockIdx.y * blockDim.y + threadIdx.y;
uint z_id = blockIdx.z * blockDim.z + threadIdx.z;
if ((x_id >= gridSize) || (y_id >= gridSize) || (z_id >= numBBoxes))
{
return;
}
const int numGridCells = gridSize * gridSize;
const int bbindex = y_id * gridSize + x_id;
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]
= __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]
= __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]);
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]);
for (uint i = 0; i < numOutputClasses; ++i)
{
output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]
= sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]);
}
}
cudaError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize,
const uint& numOutputClasses, const uint& numBBoxes,
uint64_t outputSize, cudaStream_t stream);
cudaError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize,
const uint& numOutputClasses, const uint& numBBoxes,
uint64_t outputSize, cudaStream_t stream)
{
dim3 threads_per_block(16, 16, 4);
dim3 number_of_blocks((gridSize / threads_per_block.x) + 1,
(gridSize / threads_per_block.y) + 1,
(numBBoxes / threads_per_block.z) + 1);
for (unsigned int batch = 0; batch < batchSize; ++batch)
{
gpuYoloLayerV3<<<number_of_blocks, threads_per_block, 0, stream>>>(
reinterpret_cast<const float*>(input) + (batch * outputSize),
reinterpret_cast<float*>(output) + (batch * outputSize), gridSize, numOutputClasses,
numBBoxes);
}
return cudaGetLastError();
}
|
3e8e8cfad78a32d5f8c933a0509cc4d0cb767a84.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__device__ void init_render_buffer(int64_t* render_buffer, const uint32_t qw_count) {
const uint32_t start = blockIdx.x * blockDim.x + threadIdx.x;
const uint32_t step = blockDim.x * gridDim.x;
for (uint32_t i = start; i < qw_count; i += step) {
render_buffer[i] = EMPTY_KEY_64;
}
}
__global__ void init_render_buffer_wrapper(int64_t* render_buffer, const uint32_t qw_count) {
init_render_buffer(render_buffer, qw_count);
} | 3e8e8cfad78a32d5f8c933a0509cc4d0cb767a84.cu | #include "includes.h"
__device__ void init_render_buffer(int64_t* render_buffer, const uint32_t qw_count) {
const uint32_t start = blockIdx.x * blockDim.x + threadIdx.x;
const uint32_t step = blockDim.x * gridDim.x;
for (uint32_t i = start; i < qw_count; i += step) {
render_buffer[i] = EMPTY_KEY_64;
}
}
__global__ void init_render_buffer_wrapper(int64_t* render_buffer, const uint32_t qw_count) {
init_render_buffer(render_buffer, qw_count);
} |
9fd48a4a19289fc39a2de22498da5dceecfe5fc2.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <iostream>
#define N 128
#define BLOCK_SIZE 16
#define BASE_TYPE float
__device__ __constant__ BASE_TYPE ash[N];
__device__ __constant__ BASE_TYPE bsh[N];
__global__ void scalMult( BASE_TYPE *C)
{
BASE_TYPE sum = 0.0;
__syncthreads();
if (threadIdx.x == 0)
{
sum = 0.0;
for (int j = 0; j < blockDim.x; j++)
sum += ash[j] * bsh[j];
C[blockIdx.x] = sum;
}
}
int main()
{
BASE_TYPE *dev_a, *dev_b, *dev_c;
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);
size_t size = N * sizeof(BASE_TYPE);
BASE_TYPE *host_a = (BASE_TYPE *)malloc(size);
BASE_TYPE *host_b = (BASE_TYPE *)malloc(size);
BASE_TYPE *host_c = (BASE_TYPE *)malloc(size);
for (int i = 0; i<N; i++)
{
host_a[i] = 5;
host_b[i] = 5;
}
hipMalloc((void**)&dev_a, size);
hipMalloc((void**)&dev_b, size);
hipMalloc((void**)&dev_c, size);
hipMemcpyToSymbol(ash, host_a, size,0, hipMemcpyHostToDevice);
hipMemcpyToSymbol(bsh, host_b, size,0, hipMemcpyHostToDevice);
hipEventRecord(start, 0);
scalMult << <BLOCK_SIZE, N / BLOCK_SIZE >> >(dev_c);
hipEventRecord(stop, 0); hipEventSynchronize(stop);
float KernelTime;
hipEventElapsedTime(&KernelTime, start, stop);
printf("KernelTime: %.2f milliseconds\n", KernelTime);
hipMemcpy(host_c, dev_c, size, hipMemcpyDeviceToHost);
BASE_TYPE S = 0;
for (int i = 0; i < N; i++)
{
S = S + host_c[i];
}
printf("<a,b>on GPU = %f\n", S);
float S1 = 0.0;
for (int i = 0; i < N; i++)
{
S1 += host_a[i]*host_b[i];
}
printf("<a,b> on CPU = %f\n", S1);
hipFree(dev_a);
hipFree(dev_b);
hipFree(dev_c);
getchar();
return 0;
}
| 9fd48a4a19289fc39a2de22498da5dceecfe5fc2.cu |
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <iostream>
#define N 128
#define BLOCK_SIZE 16
#define BASE_TYPE float
__device__ __constant__ BASE_TYPE ash[N];
__device__ __constant__ BASE_TYPE bsh[N];
__global__ void scalMult( BASE_TYPE *C)
{
BASE_TYPE sum = 0.0;
__syncthreads();
if (threadIdx.x == 0)
{
sum = 0.0;
for (int j = 0; j < blockDim.x; j++)
sum += ash[j] * bsh[j];
C[blockIdx.x] = sum;
}
}
int main()
{
BASE_TYPE *dev_a, *dev_b, *dev_c;
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
size_t size = N * sizeof(BASE_TYPE);
BASE_TYPE *host_a = (BASE_TYPE *)malloc(size);
BASE_TYPE *host_b = (BASE_TYPE *)malloc(size);
BASE_TYPE *host_c = (BASE_TYPE *)malloc(size);
for (int i = 0; i<N; i++)
{
host_a[i] = 5;
host_b[i] = 5;
}
cudaMalloc((void**)&dev_a, size);
cudaMalloc((void**)&dev_b, size);
cudaMalloc((void**)&dev_c, size);
cudaMemcpyToSymbol(ash, host_a, size,0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(bsh, host_b, size,0, cudaMemcpyHostToDevice);
cudaEventRecord(start, 0);
scalMult << <BLOCK_SIZE, N / BLOCK_SIZE >> >(dev_c);
cudaEventRecord(stop, 0); cudaEventSynchronize(stop);
float KernelTime;
cudaEventElapsedTime(&KernelTime, start, stop);
printf("KernelTime: %.2f milliseconds\n", KernelTime);
cudaMemcpy(host_c, dev_c, size, cudaMemcpyDeviceToHost);
BASE_TYPE S = 0;
for (int i = 0; i < N; i++)
{
S = S + host_c[i];
}
printf("<a,b>on GPU = %f\n", S);
float S1 = 0.0;
for (int i = 0; i < N; i++)
{
S1 += host_a[i]*host_b[i];
}
printf("<a,b> on CPU = %f\n", S1);
cudaFree(dev_a);
cudaFree(dev_b);
cudaFree(dev_c);
getchar();
return 0;
}
|
57144b92160c049cceceb74eeb4426cb4f166c36.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* Copyright 2010 Pawel Baran.
*
*/
#ifndef _SCAN_WORKEFFICIENT_KERNEL_H_
#define _SCAN_WORKEFFICIENT_KERNEL_H_
#include "elem.h"
#define MAX_REGISTERS_PER_THREAD 4
#define NORMAL 0
#define PIVOTS 1
#define KEYS 2
#define SEG_FLAGS 3
/*
__device__ float is_sorted(const float* keys,int n){
int thid=threadIdx.x;
int offset=1;
extern __shared__ float temp[];
temp[2*thid]=(keys[2*thid]>keys[2*thid+1])?1:0;
__syncthreads();
temp[2*thid+1]=((2*thid+2)<n && keys[2*thid+1]>keys[2*thid+2])?1:0;
for(int d=n>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
temp[bi]+=temp[ai];
}
offset<<=1;
}
__syncthreads();
int res=!temp[n-1];
__syncthreads();
temp[2*thid]=0;
temp[2*thid+1]=0;
__syncthreads();
return res;
}
__device__ void segmented_prescan(float* keys,float* seg_flags,int n){
int thid=threadIdx.x;
extern __shared__ float shared[];
float* f=(float*) &shared[0];
float* data=(float*) &shared[n];
int offset=1;
f[2*thid]=seg_flags[2*thid];
f[2*thid+1]=seg_flags[2*thid+1];
data[2*thid]=keys[2*thid];
data[2*thid+1]=keys[2*thid+1];
for(int d=n>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
if(!f[bi])
data[bi]+=data[ai];
f[bi]=f[bi] || f[ai];
}
offset<<=1;
}
__syncthreads();
if(thid==0) data[n-1]=0;
for(int d=1;d<n;d<<=1){
offset>>=1;
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
float t=data[ai];
data[ai]=data[bi];
if(f[ai+1])
data[bi]=0;
else if(f[ai])
data[bi]=t;
else
data[bi]+=t;
f[ai]=0;
}
}
__syncthreads();
// little correction ;-)
if(thid==(n/2-1) && !seg_flags[n-1])
keys[n-1]=data[n-2]+keys[2*thid];
else if(!seg_flags[2*thid+1])
keys[2*thid+1]=data[2*thid+1];
else
keys[2*thid+1]=0;
keys[2*thid]=data[2*thid];
}
__device__ void seg_copy(float *f,float *pivots,float *keys,float *seg_flags,unsigned int n)
{
// from arguments only f and pivots modified
int thid=threadIdx.x;
pivots[2*thid]=(seg_flags[2*thid])?keys[2*thid]:0;
pivots[2*thid+1]=(seg_flags[2*thid+1])?keys[2*thid+1]:0;
__syncthreads();
segmented_prescan(pivots,seg_flags,n);
__syncthreads();
if(seg_flags[2*thid]) pivots[2*thid]=keys[2*thid];
if(seg_flags[2*thid+1]) pivots[2*thid+1]=keys[2*thid+1];
float di=keys[2*thid]-pivots[2*thid];
f[2*thid]=(di<0)?0:1;
di=keys[2*thid+1]-pivots[2*thid+1];
f[2*thid+1]=(di<0)?0:1;
}
__device__ void ake_offsets(float* offsets,float* seg_flags,int n){
int thid=threadIdx.x;
offsets[2*thid]=(seg_flags[2*thid])?2*thid:0;
offsets[2*thid+1]=(seg_flags[2*thid+1])?2*thid+1:0;
__syncthreads();
segmented_prescan(offsets,seg_flags,n);
__syncthreads();
if(seg_flags[2*thid]) offsets[2*thid]=2*thid;
if(seg_flags[2*thid+1]) offsets[2*thid+1]=2*thid+1;
}
__device__ void make_idown(float *idown,float* seg_flags,float* f,int n){
int thid=threadIdx.x;
idown[2*thid]=(f[2*thid])?0:1;
idown[2*thid+1]=(f[2*thid+1])?0:1;
__syncthreads();
segmented_prescan(idown,seg_flags,n);
}
__device__ void make_iup1(float* iup_half,float* seg_flags,int n){
int thid=threadIdx.x;
iup_half[2*thid]=1;
iup_half[2*thid+1]=1;
__syncthreads();
segmented_prescan(iup_half,seg_flags,n);
}
__device__ void make_iup2(float *iup,float* seg_flags,float* f,int n){
int thid=threadIdx.x;
// reverse and negate
float temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
iup[2*thid]=f[2*thid];
iup[2*thid+1]=f[2*thid+1];
__syncthreads();
segmented_prescan(iup,seg_flags,n);
__syncthreads();
// reverse and negate
temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
temp=iup[thid];
iup[thid]=iup[n-1-thid];
iup[n-1-thid]=temp;
__syncthreads();
}
__device__ void make_iup(float *iup,float* iup_half,float* seg_flags,float* f,int n){
int thid=threadIdx.x;
iup_half[2*thid]=1;
iup_half[2*thid+1]=1;
__syncthreads();
segmented_prescan(iup_half,seg_flags,n);
__syncthreads();
// reverse and negate
float temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
iup[2*thid]=f[2*thid];
iup[2*thid+1]=f[2*thid+1];
__syncthreads();
segmented_prescan(iup,seg_flags,n);
__syncthreads();
// reverse and negate
temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
temp=iup[thid];
iup[thid]=iup[n-1-thid];
iup[n-1-thid]=temp;
__syncthreads();
iup[2*thid]+=iup_half[2*thid];
iup[2*thid+1]+=iup_half[2*thid+1];
}
__device__ void segmented_prescan2(float* keys,float* seg_flags,int n){
int thid=threadIdx.x;
extern __shared__ float shared[];
float* f=(float*) &shared[0];
float* data=(float*) &shared[n];
int offset=1;
f[2*thid]=seg_flags[2*thid];
f[2*thid+1]=seg_flags[2*thid+1];
data[2*thid]=keys[2*thid];
data[2*thid+1]=keys[2*thid+1];
for(int d=n>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
if(!f[bi]) data[bi]+=data[ai];
if(f[bi] || f[ai]) f[bi]=1;
else f[bi]=0;
}
offset<<=1;
}
keys[2*thid]=data[2*thid];
keys[2*thid+1]=data[2*thid+1];
return;
if(thid==0) data[n-1]=0;
__syncthreads();
for(int d=1;d<n;d<<=1){
offset>>=1;
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
float t=data[ai];
data[ai]=data[bi];
if(f[ai]) data[bi]=t;
else data[bi]+=t;
if(f[ai] || f[bi]) f[bi]=1;
else f[bi]=0;
__syncthreads();
}
break;
}
__syncthreads();
keys[2*thid]=data[2*thid];
if(thid==(n/2-1) && !seg_flags[n-1])
keys[n-1]=data[n-2];
else
keys[2*thid+1]=data[2*thid+1];
__syncthreads();
}*/
__device__ void segmented_scan_down(int* val,int* f,int* f2,int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
int offset=threads_num;
for(int d=1;d<=threads_num;d<<=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
int t=val[ai];
val[ai]=val[bi];
if((f2==NULL && f[ai+1]) || (f2!=NULL && f2[ai]))
val[bi]=0;
else if(f[ai])
val[bi]=0+t;
else
val[bi]+=t;
f[ai]=0;
}
offset>>=1;
}
}
__device__ void segmented_scan_up(int* val,int* f,int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
int offset=1;
for(int d=threads_num;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
if(!f[bi]){
val[bi]+=val[ai];
f[bi]=f[ai];
}
}
offset<<=1;
}
}
__global__ void accumulate_sum_of_sums2(sum* g_sums, int thread_elems_num, int offset){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
int* f2=(int*)&absolute_shared[2*threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[offset*(begin2+i+1)-1].seg_flag;
f2[begin2+i]=g_sums[offset*(begin2+i+1)-1].next_seg_flag;
val[begin2+i]=g_sums[offset*(begin2+i+1)-1].val;
}
if(thid==threads_num-1)
val[threads_num*thread_elems_num-1]=0;
__syncthreads();
segmented_scan_down(val,f,f2,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[offset*(begin2+i+1)-1].seg_flag=f[begin2+i];
g_sums[offset*(begin2+i+1)-1].val=val[begin2+i];
}
}
__global__ void accumulate_sums2(sum* g_sums, int thread_elems_num,short one_block){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
int* f2=(int*)&absolute_shared[2*threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[begin+i].seg_flag;
f2[begin2+i]=g_sums[begin+i].next_seg_flag;
val[begin2+i]=g_sums[begin+i].val;
}
if(thid==threads_num-1 && one_block)
val[threads_num*thread_elems_num-1]=0;
__syncthreads();
__syncthreads();
segmented_scan_down(val,f,f2,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[begin+i].seg_flag=f[begin2+i];
g_sums[begin+i].val=val[begin2+i];
}
}
__global__ void accumulate_sum_of_sums(sum* g_sums, int thread_elems_num, int offset){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[offset*(begin2+i+1)-1].seg_flag;
val[begin2+i]=g_sums[offset*(begin2+i+1)-1].val;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[offset*(begin2+i+1)-1].seg_flag=f[begin2+i];
g_sums[offset*(begin2+i+1)-1].val=val[begin2+i];
}
}
__global__ void accumulate_sums(sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[begin+i].seg_flag;
val[begin2+i]=g_sums[begin+i].val;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[begin+i].seg_flag=f[begin2+i];
g_sums[begin+i].val=val[begin2+i];
}
}
__global__ void make_idowns2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].idown;
}
__syncthreads();
// zrzut z sumy blokw:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2)
g_elems[begin+i].idown=0;
else
g_elems[begin+i].idown=val[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].idown=1-g_elems[begin+thread_elems_num-2].pivot+g_elems[begin+thread_elems_num-2].idown;
}
__global__ void make_iup2s2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2,int num_blocks){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=(num_blocks-1-bid)*n+(threads_num-1-thid)*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+thread_elems_num-1-i].seg_flag;
val[begin2+i]=g_elems[begin+thread_elems_num-1-i].iup2;
}
__syncthreads();
// zrzut z sumy blokw:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(i>0 && g_elems[begin+thread_elems_num-i].seg_flag2)
g_elems[begin+thread_elems_num-1-i].iup2=0;
else
g_elems[begin+thread_elems_num-1-i].iup2=val[begin2+i];
g_elems[begin+thread_elems_num-1-i].seg_flag=f[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1)
g_elems[0].iup2=(g_elems[1].seg_flag2)?0:1-g_elems[1].pivot+g_elems[1].iup2;
// g_elems[0].iup2=117-g_elems[1].pivot+g_elems[1].iup2;
if(thid==0 && bid==0)
g_elems[num_blocks*threads_num*thread_elems_num-1].iup2=0;
/*
*/
}
__global__ void make_iup1s2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].iup1;
}
__syncthreads();
// zrzut z sumy blokw:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2)
g_elems[begin+i].iup1=0;
else
g_elems[begin+i].iup1=val[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].iup1=1+g_elems[begin+thread_elems_num-2].iup1;
}
__global__ void make_offsets2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].offset;
}
__syncthreads();
__syncthreads();
// zrzut z sumy blokw:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2)
g_elems[begin+i].offset=begin+i;
else
g_elems[begin+i].offset=val[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].offset=g_elems[begin+thread_elems_num-2].offset;
}
__global__ void make_pivots2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].pivot;
}
__syncthreads();
// zrzut z sumy blokw:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2){
val[begin2+i]=g_elems[begin+i].val;
g_elems[begin+i].pivot=1;//g_elems[begin+i].val;//1;
}else
g_elems[begin+i].pivot=val[begin2+i]<=g_elems[begin+i].val;
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].pivot=val[begin2+thread_elems_num-2]<=g_elems[begin+thread_elems_num-1].val;
/* ze starego projektu:
// little correction ;-)
if(thid==(n/2-1) && !seg_flags[n-1])
keys[n-1]=data[n-2]+keys[2*thid];
else if(!seg_flags[2*thid+1])
keys[2*thid+1]=data[2*thid+1];
else
keys[2*thid+1]=0;
keys[2*thid]=data[2*thid];
*/
}
__global__ void make_offsets(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
if(f[begin2+i])
val[begin2+i]=begin+i;
else
val[begin2+i]=0;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].seg_flag=f[begin2+i];
g_elems[begin+i].offset=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
__global__ void make_idowns(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
if(g_elems[begin+i].pivot)
val[begin2+i]=0;
else
val[begin2+i]=1;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].pivot2=f[begin2+i];
g_elems[begin+i].idown=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
__global__ void make_iup2s(elem *g_elems, sum* g_sums, int thread_elems_num, int num_blocks){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=(num_blocks-1-bid)*n+(threads_num-1-thid)*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
if(thid==0 && bid==0 && i==0)
f[0]=1;
else
f[begin2+i]=g_elems[begin+thread_elems_num-i].seg_flag2;
// f[begin2+i]=g_elems[begin+thread_elems_num-1-i].seg_flag2;
val[begin2+i]=1-g_elems[begin+thread_elems_num-1-i].pivot;
}
/*
__syncthreads();
if(thid==0){
if(bid==0)
f[0]=1;
if(bid==num_blocks-1)
f[n-1]=0;
}
*/
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin-i-1+thread_elems_num].seg_flag=f[begin2+i];
g_elems[begin-i-1+thread_elems_num].iup2=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
__global__ void move_elems3(elem* g_elems,int thread_elems_num,int num_elements){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].val=g_elems[begin+i].pivot2;
if(g_elems[begin+i].seg_flag && begin+i<num_elements-1)
g_elems[begin+i+1].seg_flag2=1;
}
}
__global__ void move_elems2(elem* g_elems,int thread_elems_num,int num_elements){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].val=g_elems[begin+i].pivot2;
if(g_elems[begin+i].seg_flag)
g_elems[begin+i].seg_flag2=1;
}
}
__global__ void move_elems1(elem* g_elems,int thread_elems_num,int num_elements){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
for(int i=0;i<thread_elems_num;++i){
int ind=g_elems[begin+i].offset+(g_elems[begin+i].pivot?g_elems[begin+i].iup1+g_elems[begin+i].iup2:g_elems[begin+i].idown);
g_elems[ind].pivot2=g_elems[begin+i].val;
g_elems[ind].seg_flag=g_elems[begin+i].seg_flag2;
}
}
__global__ void make_iup1s(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
val[begin2+i]=1;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].seg_flag=f[begin2+i];
g_elems[begin+i].iup1=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
// n_real - number of elements to be sorted
// n - number of elements to be sorted in each block
__global__ void make_pivots(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
if(f[begin2+i])
val[begin2+i]=g_elems[begin+i].val;
else
val[begin2+i]=0;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].seg_flag=f[begin2+i];
g_elems[begin+i].pivot=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
// n_real - number of elements to be sorted
// n - number of elements to be sorted in each block
//__global__ void quicksort_kernel(elem *g_elems, int n_real,int n,int num_blocks){
__global__ void check_order(elem *g_elems, sum* g_sums, int n_real,int n,int num_blocks,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int thread_elems_num=n/threads_num; // number of elements in ech thread
const int begin=bid*n+thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
f[thid]=0;
int predecessor=g_elems[begin].val;
int current;
for(int i=1;i<=thread_elems_num;++i){
if(thid==threads_num-1 && i==thread_elems_num && bid==num_blocks-1)
current=INT_MAX;
else
current=g_elems[begin+i].val;
if(predecessor>current){
f[thid]=1;
}else
predecessor=current;
}
int offset=1;
for(int d=threads_num>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
f[bi]|=f[ai];
}
offset<<=1;
}
__syncthreads();
if(thid==0)
g_sums[bid].val=f[threads_num-1];
g_sums[bid].seg_flag=0;
}
__global__ void check_order2(sum* g_sums,int num_blocks){
const int bid=blockIdx.x; // given block's number
if(bid>=num_blocks){
g_sums[bid].val=0;
g_sums[bid].seg_flag=0;
}
}
// g_elems[begin]=is_sorted2();
/*
int i,i1,i2,f1,f2;
float temp1,temp2;
extern __shared__ float absolute_shared[];
float* shared=(float*) &absolute_shared[2*n];
float* data=(float*) &shared[0];
float* seg_flags=(float*) &shared[n];
float* f=(float*) &shared[2*n];
float* pivots=(float*) &shared[3*n];
float* offsets=(float*) &shared[3*n]; // 3*n sic!
float* idown=(float*) &shared[3*n];
float* iup=(float*) &shared[3*n];
float* iup_half=(float*) &shared[3*n];
// data initialization
if(2*thid>n-n_real-1){
data[2*thid]=g_idata[2*thid-n+n_real];
seg_flags[2*thid]=0;
}else{
data[2*thid]=0; // min from input
seg_flags[2*thid]=1;
}
if(2*thid+1>n-n_real-1){
data[2*thid+1]=g_idata[2*thid+1-n+n_real];
seg_flags[2*thid+1]=0;
}else{
data[2*thid+1]=0;
seg_flags[2*thid+1]=1;
}
// seg_flags initialization
if(2*thid==n-n_real)
seg_flags[2*thid]=1;
else if(2*thid+1==n-n_real)
seg_flags[2*thid+1]=1;
__syncthreads();
i=0;
while(!is_sorted(data,n) && i<n){
++i;
__syncthreads();
seg_copy(f,pivots,data,seg_flags,n);
__syncthreads();
ake_offsets(offsets,seg_flags,n);
__syncthreads();
float offset1=offsets[2*thid];
float offset2=offsets[2*thid+1];
__syncthreads();
make_idown(idown,seg_flags,f,n);
float idown1=idown[2*thid];
float idown2=idown[2*thid+1];
__syncthreads();
make_iup1(iup_half,seg_flags,n);
__syncthreads();
float iup1=iup_half[2*thid];
float iup2=iup_half[2*thid+1];
__syncthreads();
make_iup2(iup,seg_flags,f,n);
__syncthreads();
iup1+=iup[2*thid];
iup2+=iup[2*thid+1];
__syncthreads();
temp1=data[2*thid];
temp2=data[2*thid+1];
i1=(f[2*thid])?iup1:idown1;
i1+=offset1;
i2=(f[2*thid+1])?iup2:idown2;
i2+=offset2;
__syncthreads();
data[i1]=temp1;
data[i2]=temp2;
__syncthreads();
f1=seg_flags[2*thid];
f2=seg_flags[2*thid+1];
__syncthreads();
if(!seg_flags[i1] && f1) seg_flags[i1]=1;
if(!seg_flags[i2] && f2) seg_flags[i2]=1;
__syncthreads();
if(f1 && i1+1<n && !seg_flags[i1+1]) seg_flags[i1+1]=1;
if(f2 && i2+1<n && !seg_flags[i2+1]) seg_flags[i2+1]=1;
__syncthreads();
}
if(2*thid>n-n_real-1)
g_odata[2*thid-n+n_real]=data[2*thid];
if(2*thid+1>n-n_real-1)
g_odata[2*thid+1-n+n_real]=data[2*thid+1];
// g_odata[2*thid]=data[2*thid];
// g_odata[2*thid+1]=data[2*thid+1];
*/
#endif // #ifndef _SCAN_WORKEFFICIENT_KERNEL_H_
| 57144b92160c049cceceb74eeb4426cb4f166c36.cu | /*
* Copyright 2010 Pawel Baran.
*
*/
#ifndef _SCAN_WORKEFFICIENT_KERNEL_H_
#define _SCAN_WORKEFFICIENT_KERNEL_H_
#include "elem.h"
#define MAX_REGISTERS_PER_THREAD 4
#define NORMAL 0
#define PIVOTS 1
#define KEYS 2
#define SEG_FLAGS 3
/*
__device__ float is_sorted(const float* keys,int n){
int thid=threadIdx.x;
int offset=1;
extern __shared__ float temp[];
temp[2*thid]=(keys[2*thid]>keys[2*thid+1])?1:0;
__syncthreads();
temp[2*thid+1]=((2*thid+2)<n && keys[2*thid+1]>keys[2*thid+2])?1:0;
for(int d=n>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
temp[bi]+=temp[ai];
}
offset<<=1;
}
__syncthreads();
int res=!temp[n-1];
__syncthreads();
temp[2*thid]=0;
temp[2*thid+1]=0;
__syncthreads();
return res;
}
__device__ void segmented_prescan(float* keys,float* seg_flags,int n){
int thid=threadIdx.x;
extern __shared__ float shared[];
float* f=(float*) &shared[0];
float* data=(float*) &shared[n];
int offset=1;
f[2*thid]=seg_flags[2*thid];
f[2*thid+1]=seg_flags[2*thid+1];
data[2*thid]=keys[2*thid];
data[2*thid+1]=keys[2*thid+1];
for(int d=n>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
if(!f[bi])
data[bi]+=data[ai];
f[bi]=f[bi] || f[ai];
}
offset<<=1;
}
__syncthreads();
if(thid==0) data[n-1]=0;
for(int d=1;d<n;d<<=1){
offset>>=1;
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
float t=data[ai];
data[ai]=data[bi];
if(f[ai+1])
data[bi]=0;
else if(f[ai])
data[bi]=t;
else
data[bi]+=t;
f[ai]=0;
}
}
__syncthreads();
// little correction ;-)
if(thid==(n/2-1) && !seg_flags[n-1])
keys[n-1]=data[n-2]+keys[2*thid];
else if(!seg_flags[2*thid+1])
keys[2*thid+1]=data[2*thid+1];
else
keys[2*thid+1]=0;
keys[2*thid]=data[2*thid];
}
__device__ void seg_copy(float *f,float *pivots,float *keys,float *seg_flags,unsigned int n)
{
// from arguments only f and pivots modified
int thid=threadIdx.x;
pivots[2*thid]=(seg_flags[2*thid])?keys[2*thid]:0;
pivots[2*thid+1]=(seg_flags[2*thid+1])?keys[2*thid+1]:0;
__syncthreads();
segmented_prescan(pivots,seg_flags,n);
__syncthreads();
if(seg_flags[2*thid]) pivots[2*thid]=keys[2*thid];
if(seg_flags[2*thid+1]) pivots[2*thid+1]=keys[2*thid+1];
float di=keys[2*thid]-pivots[2*thid];
f[2*thid]=(di<0)?0:1;
di=keys[2*thid+1]-pivots[2*thid+1];
f[2*thid+1]=(di<0)?0:1;
}
__device__ void ake_offsets(float* offsets,float* seg_flags,int n){
int thid=threadIdx.x;
offsets[2*thid]=(seg_flags[2*thid])?2*thid:0;
offsets[2*thid+1]=(seg_flags[2*thid+1])?2*thid+1:0;
__syncthreads();
segmented_prescan(offsets,seg_flags,n);
__syncthreads();
if(seg_flags[2*thid]) offsets[2*thid]=2*thid;
if(seg_flags[2*thid+1]) offsets[2*thid+1]=2*thid+1;
}
__device__ void make_idown(float *idown,float* seg_flags,float* f,int n){
int thid=threadIdx.x;
idown[2*thid]=(f[2*thid])?0:1;
idown[2*thid+1]=(f[2*thid+1])?0:1;
__syncthreads();
segmented_prescan(idown,seg_flags,n);
}
__device__ void make_iup1(float* iup_half,float* seg_flags,int n){
int thid=threadIdx.x;
iup_half[2*thid]=1;
iup_half[2*thid+1]=1;
__syncthreads();
segmented_prescan(iup_half,seg_flags,n);
}
__device__ void make_iup2(float *iup,float* seg_flags,float* f,int n){
int thid=threadIdx.x;
// reverse and negate
float temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
iup[2*thid]=f[2*thid];
iup[2*thid+1]=f[2*thid+1];
__syncthreads();
segmented_prescan(iup,seg_flags,n);
__syncthreads();
// reverse and negate
temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
temp=iup[thid];
iup[thid]=iup[n-1-thid];
iup[n-1-thid]=temp;
__syncthreads();
}
__device__ void make_iup(float *iup,float* iup_half,float* seg_flags,float* f,int n){
int thid=threadIdx.x;
iup_half[2*thid]=1;
iup_half[2*thid+1]=1;
__syncthreads();
segmented_prescan(iup_half,seg_flags,n);
__syncthreads();
// reverse and negate
float temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
iup[2*thid]=f[2*thid];
iup[2*thid+1]=f[2*thid+1];
__syncthreads();
segmented_prescan(iup,seg_flags,n);
__syncthreads();
// reverse and negate
temp=f[thid];
f[thid]=(f[n-thid-1])?0:1;
f[n-thid-1]=temp?0:1;
if(thid>0){
temp=seg_flags[thid];
seg_flags[thid]=seg_flags[n-thid];
seg_flags[n-thid]=temp;
}
__syncthreads();
temp=iup[thid];
iup[thid]=iup[n-1-thid];
iup[n-1-thid]=temp;
__syncthreads();
iup[2*thid]+=iup_half[2*thid];
iup[2*thid+1]+=iup_half[2*thid+1];
}
__device__ void segmented_prescan2(float* keys,float* seg_flags,int n){
int thid=threadIdx.x;
extern __shared__ float shared[];
float* f=(float*) &shared[0];
float* data=(float*) &shared[n];
int offset=1;
f[2*thid]=seg_flags[2*thid];
f[2*thid+1]=seg_flags[2*thid+1];
data[2*thid]=keys[2*thid];
data[2*thid+1]=keys[2*thid+1];
for(int d=n>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
if(!f[bi]) data[bi]+=data[ai];
if(f[bi] || f[ai]) f[bi]=1;
else f[bi]=0;
}
offset<<=1;
}
keys[2*thid]=data[2*thid];
keys[2*thid+1]=data[2*thid+1];
return;
if(thid==0) data[n-1]=0;
__syncthreads();
for(int d=1;d<n;d<<=1){
offset>>=1;
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
float t=data[ai];
data[ai]=data[bi];
if(f[ai]) data[bi]=t;
else data[bi]+=t;
if(f[ai] || f[bi]) f[bi]=1;
else f[bi]=0;
__syncthreads();
}
break;
}
__syncthreads();
keys[2*thid]=data[2*thid];
if(thid==(n/2-1) && !seg_flags[n-1])
keys[n-1]=data[n-2];
else
keys[2*thid+1]=data[2*thid+1];
__syncthreads();
}*/
__device__ void segmented_scan_down(int* val,int* f,int* f2,int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
int offset=threads_num;
for(int d=1;d<=threads_num;d<<=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
int t=val[ai];
val[ai]=val[bi];
if((f2==NULL && f[ai+1]) || (f2!=NULL && f2[ai]))
val[bi]=0;
else if(f[ai])
val[bi]=0+t;
else
val[bi]+=t;
f[ai]=0;
}
offset>>=1;
}
}
__device__ void segmented_scan_up(int* val,int* f,int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
int offset=1;
for(int d=threads_num;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
if(!f[bi]){
val[bi]+=val[ai];
f[bi]=f[ai];
}
}
offset<<=1;
}
}
__global__ void accumulate_sum_of_sums2(sum* g_sums, int thread_elems_num, int offset){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
int* f2=(int*)&absolute_shared[2*threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[offset*(begin2+i+1)-1].seg_flag;
f2[begin2+i]=g_sums[offset*(begin2+i+1)-1].next_seg_flag;
val[begin2+i]=g_sums[offset*(begin2+i+1)-1].val;
}
if(thid==threads_num-1)
val[threads_num*thread_elems_num-1]=0;
__syncthreads();
segmented_scan_down(val,f,f2,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[offset*(begin2+i+1)-1].seg_flag=f[begin2+i];
g_sums[offset*(begin2+i+1)-1].val=val[begin2+i];
}
}
__global__ void accumulate_sums2(sum* g_sums, int thread_elems_num,short one_block){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
int* f2=(int*)&absolute_shared[2*threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[begin+i].seg_flag;
f2[begin2+i]=g_sums[begin+i].next_seg_flag;
val[begin2+i]=g_sums[begin+i].val;
}
if(thid==threads_num-1 && one_block)
val[threads_num*thread_elems_num-1]=0;
__syncthreads();
__syncthreads();
segmented_scan_down(val,f,f2,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[begin+i].seg_flag=f[begin2+i];
g_sums[begin+i].val=val[begin2+i];
}
}
__global__ void accumulate_sum_of_sums(sum* g_sums, int thread_elems_num, int offset){
const int threads_num=blockDim.x; // number of threads in each block
const int thid=threadIdx.x; // thread's number in given block
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[offset*(begin2+i+1)-1].seg_flag;
val[begin2+i]=g_sums[offset*(begin2+i+1)-1].val;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[offset*(begin2+i+1)-1].seg_flag=f[begin2+i];
g_sums[offset*(begin2+i+1)-1].val=val[begin2+i];
}
}
__global__ void accumulate_sums(sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_sums[begin+i].seg_flag;
val[begin2+i]=g_sums[begin+i].val;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_sums[begin+i].seg_flag=f[begin2+i];
g_sums[begin+i].val=val[begin2+i];
}
}
__global__ void make_idowns2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].idown;
}
__syncthreads();
// zrzut z sumy bloków:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2)
g_elems[begin+i].idown=0;
else
g_elems[begin+i].idown=val[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].idown=1-g_elems[begin+thread_elems_num-2].pivot+g_elems[begin+thread_elems_num-2].idown;
}
__global__ void make_iup2s2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2,int num_blocks){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=(num_blocks-1-bid)*n+(threads_num-1-thid)*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+thread_elems_num-1-i].seg_flag;
val[begin2+i]=g_elems[begin+thread_elems_num-1-i].iup2;
}
__syncthreads();
// zrzut z sumy bloków:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(i>0 && g_elems[begin+thread_elems_num-i].seg_flag2)
g_elems[begin+thread_elems_num-1-i].iup2=0;
else
g_elems[begin+thread_elems_num-1-i].iup2=val[begin2+i];
g_elems[begin+thread_elems_num-1-i].seg_flag=f[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1)
g_elems[0].iup2=(g_elems[1].seg_flag2)?0:1-g_elems[1].pivot+g_elems[1].iup2;
// g_elems[0].iup2=117-g_elems[1].pivot+g_elems[1].iup2;
if(thid==0 && bid==0)
g_elems[num_blocks*threads_num*thread_elems_num-1].iup2=0;
/*
*/
}
__global__ void make_iup1s2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].iup1;
}
__syncthreads();
// zrzut z sumy bloków:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2)
g_elems[begin+i].iup1=0;
else
g_elems[begin+i].iup1=val[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].iup1=1+g_elems[begin+thread_elems_num-2].iup1;
}
__global__ void make_offsets2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].offset;
}
__syncthreads();
__syncthreads();
// zrzut z sumy bloków:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2)
g_elems[begin+i].offset=begin+i;
else
g_elems[begin+i].offset=val[begin2+i];
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].offset=g_elems[begin+thread_elems_num-2].offset;
}
__global__ void make_pivots2(elem *g_elems, sum* g_sums, int thread_elems_num,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag;
val[begin2+i]=g_elems[begin+i].pivot;
}
__syncthreads();
// zrzut z sumy bloków:
if(thid==0){
f[n-1]=g_sums[bid].seg_flag;
val[n-1]=g_sums[bid].val;
}
__syncthreads();
segmented_scan_down(val,f,NULL,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
if(g_elems[begin+i].seg_flag2){
val[begin2+i]=g_elems[begin+i].val;
g_elems[begin+i].pivot=1;//g_elems[begin+i].val;//1;
}else
g_elems[begin+i].pivot=val[begin2+i]<=g_elems[begin+i].val;
}
__syncthreads();
if(thid==threads_num-1 && bid==num_blocks2-1 && !g_elems[begin+thread_elems_num-1].seg_flag2)
g_elems[begin+thread_elems_num-1].pivot=val[begin2+thread_elems_num-2]<=g_elems[begin+thread_elems_num-1].val;
/* ze starego projektu:
// little correction ;-)
if(thid==(n/2-1) && !seg_flags[n-1])
keys[n-1]=data[n-2]+keys[2*thid];
else if(!seg_flags[2*thid+1])
keys[2*thid+1]=data[2*thid+1];
else
keys[2*thid+1]=0;
keys[2*thid]=data[2*thid];
*/
}
__global__ void make_offsets(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
if(f[begin2+i])
val[begin2+i]=begin+i;
else
val[begin2+i]=0;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].seg_flag=f[begin2+i];
g_elems[begin+i].offset=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
__global__ void make_idowns(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
if(g_elems[begin+i].pivot)
val[begin2+i]=0;
else
val[begin2+i]=1;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].pivot2=f[begin2+i];
g_elems[begin+i].idown=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
__global__ void make_iup2s(elem *g_elems, sum* g_sums, int thread_elems_num, int num_blocks){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=(num_blocks-1-bid)*n+(threads_num-1-thid)*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
if(thid==0 && bid==0 && i==0)
f[0]=1;
else
f[begin2+i]=g_elems[begin+thread_elems_num-i].seg_flag2;
// f[begin2+i]=g_elems[begin+thread_elems_num-1-i].seg_flag2;
val[begin2+i]=1-g_elems[begin+thread_elems_num-1-i].pivot;
}
/*
__syncthreads();
if(thid==0){
if(bid==0)
f[0]=1;
if(bid==num_blocks-1)
f[n-1]=0;
}
*/
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin-i-1+thread_elems_num].seg_flag=f[begin2+i];
g_elems[begin-i-1+thread_elems_num].iup2=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
__global__ void move_elems3(elem* g_elems,int thread_elems_num,int num_elements){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].val=g_elems[begin+i].pivot2;
if(g_elems[begin+i].seg_flag && begin+i<num_elements-1)
g_elems[begin+i+1].seg_flag2=1;
}
}
__global__ void move_elems2(elem* g_elems,int thread_elems_num,int num_elements){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].val=g_elems[begin+i].pivot2;
if(g_elems[begin+i].seg_flag)
g_elems[begin+i].seg_flag2=1;
}
}
__global__ void move_elems1(elem* g_elems,int thread_elems_num,int num_elements){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
for(int i=0;i<thread_elems_num;++i){
int ind=g_elems[begin+i].offset+(g_elems[begin+i].pivot?g_elems[begin+i].iup1+g_elems[begin+i].iup2:g_elems[begin+i].idown);
g_elems[ind].pivot2=g_elems[begin+i].val;
g_elems[ind].seg_flag=g_elems[begin+i].seg_flag2;
}
}
__global__ void make_iup1s(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
val[begin2+i]=1;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].seg_flag=f[begin2+i];
g_elems[begin+i].iup1=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
// n_real - number of elements to be sorted
// n - number of elements to be sorted in each block
__global__ void make_pivots(elem *g_elems, sum* g_sums, int thread_elems_num){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int n=threads_num*thread_elems_num;
const int begin=bid*n+thid*thread_elems_num;
const int begin2=thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
int* val=(int*)&absolute_shared[threads_num*thread_elems_num];
for(int i=0;i<thread_elems_num;++i){
f[begin2+i]=g_elems[begin+i].seg_flag2;
if(f[begin2+i])
val[begin2+i]=g_elems[begin+i].val;
else
val[begin2+i]=0;
}
__syncthreads();
segmented_scan_up(val,f,thread_elems_num);
__syncthreads();
for(int i=0;i<thread_elems_num;++i){
g_elems[begin+i].seg_flag=f[begin2+i];
g_elems[begin+i].pivot=val[begin2+i];
}
if(thid==0){ // do sprawdzenia!
g_sums[bid].val=val[n-1];
g_sums[bid].seg_flag=f[n-1];
if(bid>0)
g_sums[bid-1].next_seg_flag=f[0];
else
g_sums[0].next_seg_flag=0;
}
}
// n_real - number of elements to be sorted
// n - number of elements to be sorted in each block
//__global__ void quicksort_kernel(elem *g_elems, int n_real,int n,int num_blocks){
__global__ void check_order(elem *g_elems, sum* g_sums, int n_real,int n,int num_blocks,int num_blocks2){
const int threads_num=blockDim.x; // number of threads in each block
const int bid=blockIdx.x; // given block's number
const int thid=threadIdx.x; // thread's number in given block
const int thread_elems_num=n/threads_num; // number of elements in ech thread
const int begin=bid*n+thid*thread_elems_num;
extern __shared__ int absolute_shared[];
int* f=(int*)&absolute_shared[0];
f[thid]=0;
int predecessor=g_elems[begin].val;
int current;
for(int i=1;i<=thread_elems_num;++i){
if(thid==threads_num-1 && i==thread_elems_num && bid==num_blocks-1)
current=INT_MAX;
else
current=g_elems[begin+i].val;
if(predecessor>current){
f[thid]=1;
}else
predecessor=current;
}
int offset=1;
for(int d=threads_num>>1;d>0;d>>=1){
__syncthreads();
if(thid<d){
int ai=offset*(2*thid+1)-1;
int bi=offset*(2*thid+2)-1;
f[bi]|=f[ai];
}
offset<<=1;
}
__syncthreads();
if(thid==0)
g_sums[bid].val=f[threads_num-1];
g_sums[bid].seg_flag=0;
}
__global__ void check_order2(sum* g_sums,int num_blocks){
const int bid=blockIdx.x; // given block's number
if(bid>=num_blocks){
g_sums[bid].val=0;
g_sums[bid].seg_flag=0;
}
}
// g_elems[begin]=is_sorted2();
/*
int i,i1,i2,f1,f2;
float temp1,temp2;
extern __shared__ float absolute_shared[];
float* shared=(float*) &absolute_shared[2*n];
float* data=(float*) &shared[0];
float* seg_flags=(float*) &shared[n];
float* f=(float*) &shared[2*n];
float* pivots=(float*) &shared[3*n];
float* offsets=(float*) &shared[3*n]; // 3*n sic!
float* idown=(float*) &shared[3*n];
float* iup=(float*) &shared[3*n];
float* iup_half=(float*) &shared[3*n];
// data initialization
if(2*thid>n-n_real-1){
data[2*thid]=g_idata[2*thid-n+n_real];
seg_flags[2*thid]=0;
}else{
data[2*thid]=0; // min from input
seg_flags[2*thid]=1;
}
if(2*thid+1>n-n_real-1){
data[2*thid+1]=g_idata[2*thid+1-n+n_real];
seg_flags[2*thid+1]=0;
}else{
data[2*thid+1]=0;
seg_flags[2*thid+1]=1;
}
// seg_flags initialization
if(2*thid==n-n_real)
seg_flags[2*thid]=1;
else if(2*thid+1==n-n_real)
seg_flags[2*thid+1]=1;
__syncthreads();
i=0;
while(!is_sorted(data,n) && i<n){
++i;
__syncthreads();
seg_copy(f,pivots,data,seg_flags,n);
__syncthreads();
ake_offsets(offsets,seg_flags,n);
__syncthreads();
float offset1=offsets[2*thid];
float offset2=offsets[2*thid+1];
__syncthreads();
make_idown(idown,seg_flags,f,n);
float idown1=idown[2*thid];
float idown2=idown[2*thid+1];
__syncthreads();
make_iup1(iup_half,seg_flags,n);
__syncthreads();
float iup1=iup_half[2*thid];
float iup2=iup_half[2*thid+1];
__syncthreads();
make_iup2(iup,seg_flags,f,n);
__syncthreads();
iup1+=iup[2*thid];
iup2+=iup[2*thid+1];
__syncthreads();
temp1=data[2*thid];
temp2=data[2*thid+1];
i1=(f[2*thid])?iup1:idown1;
i1+=offset1;
i2=(f[2*thid+1])?iup2:idown2;
i2+=offset2;
__syncthreads();
data[i1]=temp1;
data[i2]=temp2;
__syncthreads();
f1=seg_flags[2*thid];
f2=seg_flags[2*thid+1];
__syncthreads();
if(!seg_flags[i1] && f1) seg_flags[i1]=1;
if(!seg_flags[i2] && f2) seg_flags[i2]=1;
__syncthreads();
if(f1 && i1+1<n && !seg_flags[i1+1]) seg_flags[i1+1]=1;
if(f2 && i2+1<n && !seg_flags[i2+1]) seg_flags[i2+1]=1;
__syncthreads();
}
if(2*thid>n-n_real-1)
g_odata[2*thid-n+n_real]=data[2*thid];
if(2*thid+1>n-n_real-1)
g_odata[2*thid+1-n+n_real]=data[2*thid+1];
// g_odata[2*thid]=data[2*thid];
// g_odata[2*thid+1]=data[2*thid+1];
*/
#endif // #ifndef _SCAN_WORKEFFICIENT_KERNEL_H_
|
272016e41e952e3aa50b919db49a592c0f983565.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
//
// ConvSingleInputExecution.cpp
// MNN
//
// Created by MNN on 2020/08/22.
// Copyright 2018, Alibaba Group Holding Limited
//
#include "ConvSingleInputExecution.hpp"
namespace MNN {
namespace CUDA {
template <typename T>
__global__ void Pad(const size_t size, const T* input, const int old_height,
const int old_width, const int padded_height, const int padded_width, const int pad_top,
const int pad_left, float pad_value, T* output) {
T pad_value_ = static_cast<T>(pad_value);
for (size_t pos = blockIdx.x * blockDim.x + threadIdx.x; pos < (size); pos += blockDim.x * gridDim.x) {
int block_num = pos / (padded_width*padded_height);
int left = pos % (padded_width*padded_height);
const int padded_w = left % padded_width;
const int padded_h = left / padded_width % padded_height;
if (padded_h - pad_top < 0 || padded_w - pad_left < 0 || padded_h - pad_top >= old_height ||
padded_w - pad_left >= old_width) {
output[pos] = pad_value_;
} else {
output[pos] = input[(block_num * old_height + padded_h - pad_top) * old_width + padded_w - pad_left];
}
}
return;
}
ConvSingleInputExecution::ConvSingleInputExecution(Backend* backend, const MNN::Op* op) : Execution(backend), mOp(op) {
//MNN_PRINT("cuda convSingleInput onInit in\n");
auto conv = op->main_as_Convolution2D();
auto common = conv->common();
mKernelInfo.groups = common->group();
mKernelInfo.kernelX = common->kernelX();
mKernelInfo.kernelY = common->kernelY();
mKernelInfo.padMode = common->padMode();
mKernelInfo.padX = common->padX();
mKernelInfo.padY = common->padY();
if (nullptr != common->pads()) {
mKernelInfo.padX = common->pads()->data()[1];
mKernelInfo.padY = common->pads()->data()[0];
}
pad_left_ = mKernelInfo.padX;
pad_right_ = mKernelInfo.padX;
pad_top_ = mKernelInfo.padY;
pad_bottom_ = mKernelInfo.padY;
mKernelInfo.strideX = common->strideX();
mKernelInfo.strideY = common->strideY();
mKernelInfo.dilateX = common->dilateX();
mKernelInfo.dilateY = common->dilateY();
mKernelInfo.activationType = common->relu() ? 1 : (common->relu6() ? 2 : 0);
use_relu_ = (mKernelInfo.activationType == 1);
use_relu6_ = (mKernelInfo.activationType == 2);
cudnn_handle_ = nullptr;
input_desc_ = nullptr;
output_desc_ = nullptr;
filter_desc_ = nullptr;
conv_desc_ = nullptr;
padded_desc_ = nullptr;
cudnn_data_type_ = CUDNN_DATA_FLOAT;
cudnn_data_type_len_ = 0;
auto runtime = static_cast<CUDABackend*>(backend)->getCUDARuntime();
cudnn_handle_ = runtime->cudnn_handle();
cudnn_check(cudnnCreateTensorDescriptor(&input_desc_));
cudnn_check(cudnnCreateTensorDescriptor(&output_desc_));
cudnn_check(cudnnCreateTensorDescriptor(&padded_desc_));
cudnn_check(cudnnCreateTensorDescriptor(&bias_desc_));
cudnn_check(cudnnCreateFilterDescriptor(&filter_desc_));
cudnn_check(cudnnCreateConvolutionDescriptor(&conv_desc_));
cudnn_check(cudnnCreateActivationDescriptor(&act_desc_));
//weight host->device
const float* filterDataPtr = nullptr;
int weightSize = 0;
std::shared_ptr<ConvolutionCommon::Int8Common> quanCommon;
ConvolutionCommon::getConvParameters(&quanCommon, conv, &filterDataPtr, &weightSize);
weightTensor.reset(Tensor::createDevice<float>({weightSize}));
backend->onAcquireBuffer(weightTensor.get(), Backend::STATIC);
mFilter = (void *)weightTensor.get()->buffer().device;
cuda_check(hipMemcpy(mFilter, filterDataPtr, weightSize*sizeof(float), hipMemcpyHostToDevice));
if(conv->bias()->size() != 0) {
int biasSize = conv->bias()->size();
biasTensor.reset(Tensor::createDevice<float>({biasSize}));
backend->onAcquireBuffer(biasTensor.get(), Backend::STATIC);
mBias = (void *)biasTensor.get()->buffer().device;
cuda_check(hipMemcpy(mBias, conv->bias()->data(), conv->bias()->size()*sizeof(float), hipMemcpyHostToDevice));
int bias_size = conv->bias()->size();
int dim_bias[] = {1, bias_size, 1, 1};
int stride_bias[] = {bias_size, 1, 1, 1};
if(cudnn_data_type_ == CUDNN_DATA_FLOAT) {
cudnn_check(cudnnSetTensorNdDescriptor(bias_desc_, CUDNN_DATA_FLOAT, 4, dim_bias, stride_bias));
}
else if(cudnn_data_type_ == CUDNN_DATA_HALF) {
cudnn_check(cudnnSetTensorNdDescriptor(bias_desc_, CUDNN_DATA_HALF, 4, dim_bias, stride_bias));
} else {
MNN_PRINT("only supports fp32/fp16 data type!!!\n");
}
use_bias_ = true;
}
mKernelInfo.kernelN = common->outputCount();
mKernelInfo.kernelC = weightSize / (mKernelInfo.kernelN * mKernelInfo.kernelY * mKernelInfo.kernelX);
std::vector<int> filter_shape = {mKernelInfo.kernelN, mKernelInfo.kernelC, mKernelInfo.kernelY, mKernelInfo.kernelX};
cudnn_check(cudnnSetFilter4dDescriptor(filter_desc_, cudnn_data_type_, CUDNN_TENSOR_NCHW, filter_shape[0],
filter_shape[1], filter_shape[2], filter_shape[3]));
cudnn_check(cudnnSetConvolution2dDescriptor(conv_desc_, 0, 0, mKernelInfo.strideY, mKernelInfo.strideX,
mKernelInfo.dilateY, mKernelInfo.dilateX, CUDNN_CROSS_CORRELATION, CUDNN_DATA_FLOAT));
if (cudnn_data_type_ == CUDNN_DATA_HALF) {
cudnn_check(cudnnSetConvolutionMathType(conv_desc_, CUDNN_TENSOR_OP_MATH));
}
//set group num
cudnn_check(cudnnSetConvolutionGroupCount(conv_desc_, mKernelInfo.groups));
}
ConvSingleInputExecution::~ConvSingleInputExecution() {
cudnn_check(cudnnDestroyConvolutionDescriptor(conv_desc_));
cudnn_check(cudnnDestroyFilterDescriptor(filter_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(padded_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(output_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(input_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(bias_desc_));
cudnn_check(cudnnDestroyActivationDescriptor(act_desc_));
if (nullptr != weightTensor) {
backend()->onReleaseBuffer(weightTensor.get(), Backend::STATIC);
}
if(use_bias_ && nullptr != biasTensor) {
backend()->onReleaseBuffer(biasTensor.get(), Backend::STATIC);
}
if(workspace_size_!=0 && nullptr != workspaceTensor) {
backend()->onReleaseBuffer(workspaceTensor.get(), Backend::STATIC);
}
}
ErrorCode ConvSingleInputExecution::onResize(const std::vector<Tensor*> &inputs, const std::vector<Tensor*> &outputs) {
// prepare
//MNN_PRINT("cuda convSingleInput onResize in, pad:%d\n", mKernelInfo.padX);
auto input = inputs[0], output = outputs[0];
mIOInfo.iw = input->width();
mIOInfo.ih = input->height();
mIOInfo.ic = input->channel();
mIOInfo.ib = input->batch();
mIOInfo.ow = output->width();
mIOInfo.oh = output->height();
mIOInfo.oc = output->channel();
mIOInfo.ob = output->batch();
mKernelInfo.kernelN = output->channel();
mKernelInfo.kernelC = input->channel() / mKernelInfo.groups;
if(mIOInfo.iw==0) {
mIOInfo.iw = 1;
}
if(mIOInfo.ih==0) {
mIOInfo.ih = 1;
}
if(mIOInfo.ic==0) {
mIOInfo.ic = 1;
}
if(mIOInfo.ib==0) {
mIOInfo.ib = 1;
}
if(mIOInfo.ow==0) {
mIOInfo.ow = 1;
}
if(mIOInfo.oh==0) {
mIOInfo.oh = 1;
}
if(mIOInfo.oc==0) {
mIOInfo.oc = 1;
}
if(mIOInfo.ob==0) {
mIOInfo.ob = 1;
}
std::vector<int> in_shape = {mIOInfo.ib, mIOInfo.ic, mIOInfo.ih, mIOInfo.iw};
std::vector<int> output_shape = {mIOInfo.ob, mIOInfo.oc, mIOInfo.oh, mIOInfo.ow};
// printf("filter:%d %d %d %d\n", filter_shape[0], filter_shape[1], filter_shape[2], filter_shape[3]);
// printf("input:%d %d %d %d\n", in_shape[0], in_shape[1], in_shape[2], in_shape[3]);
// printf("output:%d %d %d %d\n", output_shape[0], output_shape[1], output_shape[2], output_shape[3]);
cudnn_check(cudnnSetTensor4dDescriptor(input_desc_, CUDNN_TENSOR_NCHW, cudnn_data_type_, in_shape[0],
in_shape[1], in_shape[2], in_shape[3]));
cudnn_check(cudnnSetTensor4dDescriptor(output_desc_, CUDNN_TENSOR_NCHW, cudnn_data_type_, output_shape[0],
output_shape[1], output_shape[2], output_shape[3]));
cudnnTensorDescriptor_t input_descriptor_real = nullptr;
if (mKernelInfo.padMode == PadMode_SAME) {
int kernelWidthSize = (mKernelInfo.kernelX - 1) * mKernelInfo.dilateX + 1;
int kernelHeightSize = (mKernelInfo.kernelY - 1) * mKernelInfo.dilateY + 1;
int pw = (mIOInfo.ow - 1) * mKernelInfo.strideX + kernelWidthSize - mIOInfo.iw;
int ph = (mIOInfo.oh - 1) * mKernelInfo.strideY + kernelHeightSize - mIOInfo.ih;
pad_left_ = pw/2;
pad_right_ = pw - pad_left_;
pad_top_ = ph/2;
pad_bottom_ = ph - pad_top_;
} else {
if (mKernelInfo.padMode == PadMode_VALID) {
pad_left_ = 0;
pad_right_ = 0;
pad_top_ = 0;
pad_bottom_ = 0;
}
}
use_pad_ = (pad_left_!=0 || pad_right_!=0 || pad_top_!=0 || pad_bottom_!=0 ) ? true : false;
if(use_pad_) {
int totalSize = in_shape[0]*in_shape[1]*(in_shape[2]+pad_top_+pad_bottom_)*(in_shape[3]+pad_left_+pad_right_);
padTensor.reset(Tensor::createDevice<float>({totalSize}));
backend()->onAcquireBuffer(padTensor.get(), Backend::DYNAMIC);
mPadPtr = (void *)padTensor.get()->buffer().device;
//dynamic memory release
backend()->onReleaseBuffer(padTensor.get(), Backend::DYNAMIC);
cudnn_check(cudnnSetTensor4dDescriptor(padded_desc_, CUDNN_TENSOR_NCHW, cudnn_data_type_, in_shape[0], in_shape[1],
in_shape[2] + +pad_top_+pad_bottom_, in_shape[3] + pad_left_+pad_right_));
}
input_descriptor_real = use_pad_ ? padded_desc_ : input_desc_;
// algorithm
constexpr int requested_algo_count = 1;
int returned_algo_count;
cudnnConvolutionFwdAlgoPerf_t perf_results;
cudnn_check(cudnnGetConvolutionForwardAlgorithm_v7(cudnn_handle_, input_descriptor_real, filter_desc_, conv_desc_,
output_desc_, requested_algo_count, &returned_algo_count, &perf_results));
conv_algorithm_ = perf_results.algo;
// workspace
cudnn_check(cudnnGetConvolutionForwardWorkspaceSize(cudnn_handle_, input_descriptor_real, filter_desc_, conv_desc_, output_desc_,
conv_algorithm_, &workspace_size_));
if (workspace_size_ != 0) {
int workspaceSize = workspace_size_;
workspaceTensor.reset(Tensor::createDevice<float>({workspaceSize}));
//cudnn not support workspace memory reuse
backend()->onAcquireBuffer(workspaceTensor.get(), Backend::STATIC);
mWorkSpace = (void *)workspaceTensor.get()->buffer().device;
}
if(use_relu_) {
cudnn_check(cudnnSetActivationDescriptor(act_desc_, CUDNN_ACTIVATION_RELU, CUDNN_NOT_PROPAGATE_NAN, 0.0));
} else if(use_relu6_) {
cudnn_check(cudnnSetActivationDescriptor(act_desc_, CUDNN_ACTIVATION_CLIPPED_RELU, CUDNN_NOT_PROPAGATE_NAN, 6.0));
} else {
//do nothing
}
//MNN_PRINT("cuda convSingleInput onResize out\n");
return NO_ERROR;
}
ErrorCode ConvSingleInputExecution::onExecute(const std::vector<Tensor*> &inputs, const std::vector<Tensor*> &outputs) {
//MNN_PRINT("cuda convSingleInput onExecute in, inputsize:%d %d\n", (int)inputs.size(), workspace_size_);
MNN_ASSERT(inputs.size() == 1);
MNN_ASSERT(outputs.size() == 1);
auto runtime = static_cast<CUDABackend*>(backend())->getCUDARuntime();
const void *input_addr = (const void*)inputs[0]->deviceId();
const void *filter_addr = mFilter;
const void *bias_addr = mBias;
void *output_addr = (void*)outputs[0]->deviceId();
void *workspace_addr = nullptr;
if (workspace_size_ != 0) {
workspace_addr = mWorkSpace;
}
const float alpha = 1;
const float beta = 0;
if(use_pad_) {
std::vector<int> in_shape = {mIOInfo.ib, mIOInfo.ic, mIOInfo.ih, mIOInfo.iw};
int size = in_shape[0] * in_shape[1] * (in_shape[2]+pad_top_+pad_bottom_) * (in_shape[3]+pad_left_+pad_right_);
int block_num = runtime->blocks_num(size);
int threads_num = runtime->threads_num();
hipLaunchKernelGGL(( Pad), dim3(block_num), dim3(threads_num), 0, 0, size, (float*)input_addr, in_shape[2], in_shape[3],
in_shape[2]+pad_top_+pad_bottom_, in_shape[3]+pad_left_+pad_right_, pad_top_, pad_left_, 0.0, (float*)mPadPtr);
cudnn_check(cudnnConvolutionForward(cudnn_handle_, &alpha, padded_desc_, mPadPtr, filter_desc_, filter_addr, conv_desc_,
conv_algorithm_, workspace_addr, workspace_size_, &beta, output_desc_, output_addr));
}
else {
cudnn_check(cudnnConvolutionForward(cudnn_handle_, &alpha, input_desc_, input_addr, filter_desc_, filter_addr, conv_desc_,
conv_algorithm_, workspace_addr, workspace_size_, &beta, output_desc_, output_addr));
}
if(use_bias_) {
cudnn_check(cudnnAddTensor(cudnn_handle_, &alpha, bias_desc_, bias_addr, &alpha, output_desc_, output_addr));
}
if(use_relu_ || use_relu6_) {
cudnn_check(cudnnActivationForward(cudnn_handle_, act_desc_, &alpha, output_desc_, output_addr, &beta, output_desc_, output_addr));
}
return NO_ERROR;
}
class CUDAConvolutionCreator : public CUDABackend::Creator {
public:
virtual Execution* onCreate(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
const MNN::Op* op, Backend* backend) const override {
if (nullptr != op->main_as_Convolution2D()->quanParameter()) {
auto quan = op->main_as_Convolution2D()->quanParameter();
if (1 == quan->type() || 2 == quan->type()) {
MNN_PRINT("cuda conv quant type 1 or 2 not support\n");
return nullptr;
}
}
if(inputs.size() == 3) {
MNN_PRINT("conv inputs size:3 not support\n");
return nullptr;
} else if(inputs.size() == 1) {
return new ConvSingleInputExecution(backend, op);
} else {
MNN_PRINT("conv inputs size:%d not support", (int)inputs.size());
return nullptr;
}
}
};
CUDACreatorRegister<CUDAConvolutionCreator> __ConvExecution(OpType_Convolution);
}// namespace CUDA
}// namespace MNN | 272016e41e952e3aa50b919db49a592c0f983565.cu | //
// ConvSingleInputExecution.cpp
// MNN
//
// Created by MNN on 2020/08/22.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include "ConvSingleInputExecution.hpp"
namespace MNN {
namespace CUDA {
template <typename T>
__global__ void Pad(const size_t size, const T* input, const int old_height,
const int old_width, const int padded_height, const int padded_width, const int pad_top,
const int pad_left, float pad_value, T* output) {
T pad_value_ = static_cast<T>(pad_value);
for (size_t pos = blockIdx.x * blockDim.x + threadIdx.x; pos < (size); pos += blockDim.x * gridDim.x) {
int block_num = pos / (padded_width*padded_height);
int left = pos % (padded_width*padded_height);
const int padded_w = left % padded_width;
const int padded_h = left / padded_width % padded_height;
if (padded_h - pad_top < 0 || padded_w - pad_left < 0 || padded_h - pad_top >= old_height ||
padded_w - pad_left >= old_width) {
output[pos] = pad_value_;
} else {
output[pos] = input[(block_num * old_height + padded_h - pad_top) * old_width + padded_w - pad_left];
}
}
return;
}
ConvSingleInputExecution::ConvSingleInputExecution(Backend* backend, const MNN::Op* op) : Execution(backend), mOp(op) {
//MNN_PRINT("cuda convSingleInput onInit in\n");
auto conv = op->main_as_Convolution2D();
auto common = conv->common();
mKernelInfo.groups = common->group();
mKernelInfo.kernelX = common->kernelX();
mKernelInfo.kernelY = common->kernelY();
mKernelInfo.padMode = common->padMode();
mKernelInfo.padX = common->padX();
mKernelInfo.padY = common->padY();
if (nullptr != common->pads()) {
mKernelInfo.padX = common->pads()->data()[1];
mKernelInfo.padY = common->pads()->data()[0];
}
pad_left_ = mKernelInfo.padX;
pad_right_ = mKernelInfo.padX;
pad_top_ = mKernelInfo.padY;
pad_bottom_ = mKernelInfo.padY;
mKernelInfo.strideX = common->strideX();
mKernelInfo.strideY = common->strideY();
mKernelInfo.dilateX = common->dilateX();
mKernelInfo.dilateY = common->dilateY();
mKernelInfo.activationType = common->relu() ? 1 : (common->relu6() ? 2 : 0);
use_relu_ = (mKernelInfo.activationType == 1);
use_relu6_ = (mKernelInfo.activationType == 2);
cudnn_handle_ = nullptr;
input_desc_ = nullptr;
output_desc_ = nullptr;
filter_desc_ = nullptr;
conv_desc_ = nullptr;
padded_desc_ = nullptr;
cudnn_data_type_ = CUDNN_DATA_FLOAT;
cudnn_data_type_len_ = 0;
auto runtime = static_cast<CUDABackend*>(backend)->getCUDARuntime();
cudnn_handle_ = runtime->cudnn_handle();
cudnn_check(cudnnCreateTensorDescriptor(&input_desc_));
cudnn_check(cudnnCreateTensorDescriptor(&output_desc_));
cudnn_check(cudnnCreateTensorDescriptor(&padded_desc_));
cudnn_check(cudnnCreateTensorDescriptor(&bias_desc_));
cudnn_check(cudnnCreateFilterDescriptor(&filter_desc_));
cudnn_check(cudnnCreateConvolutionDescriptor(&conv_desc_));
cudnn_check(cudnnCreateActivationDescriptor(&act_desc_));
//weight host->device
const float* filterDataPtr = nullptr;
int weightSize = 0;
std::shared_ptr<ConvolutionCommon::Int8Common> quanCommon;
ConvolutionCommon::getConvParameters(&quanCommon, conv, &filterDataPtr, &weightSize);
weightTensor.reset(Tensor::createDevice<float>({weightSize}));
backend->onAcquireBuffer(weightTensor.get(), Backend::STATIC);
mFilter = (void *)weightTensor.get()->buffer().device;
cuda_check(cudaMemcpy(mFilter, filterDataPtr, weightSize*sizeof(float), cudaMemcpyHostToDevice));
if(conv->bias()->size() != 0) {
int biasSize = conv->bias()->size();
biasTensor.reset(Tensor::createDevice<float>({biasSize}));
backend->onAcquireBuffer(biasTensor.get(), Backend::STATIC);
mBias = (void *)biasTensor.get()->buffer().device;
cuda_check(cudaMemcpy(mBias, conv->bias()->data(), conv->bias()->size()*sizeof(float), cudaMemcpyHostToDevice));
int bias_size = conv->bias()->size();
int dim_bias[] = {1, bias_size, 1, 1};
int stride_bias[] = {bias_size, 1, 1, 1};
if(cudnn_data_type_ == CUDNN_DATA_FLOAT) {
cudnn_check(cudnnSetTensorNdDescriptor(bias_desc_, CUDNN_DATA_FLOAT, 4, dim_bias, stride_bias));
}
else if(cudnn_data_type_ == CUDNN_DATA_HALF) {
cudnn_check(cudnnSetTensorNdDescriptor(bias_desc_, CUDNN_DATA_HALF, 4, dim_bias, stride_bias));
} else {
MNN_PRINT("only supports fp32/fp16 data type!!!\n");
}
use_bias_ = true;
}
mKernelInfo.kernelN = common->outputCount();
mKernelInfo.kernelC = weightSize / (mKernelInfo.kernelN * mKernelInfo.kernelY * mKernelInfo.kernelX);
std::vector<int> filter_shape = {mKernelInfo.kernelN, mKernelInfo.kernelC, mKernelInfo.kernelY, mKernelInfo.kernelX};
cudnn_check(cudnnSetFilter4dDescriptor(filter_desc_, cudnn_data_type_, CUDNN_TENSOR_NCHW, filter_shape[0],
filter_shape[1], filter_shape[2], filter_shape[3]));
cudnn_check(cudnnSetConvolution2dDescriptor(conv_desc_, 0, 0, mKernelInfo.strideY, mKernelInfo.strideX,
mKernelInfo.dilateY, mKernelInfo.dilateX, CUDNN_CROSS_CORRELATION, CUDNN_DATA_FLOAT));
if (cudnn_data_type_ == CUDNN_DATA_HALF) {
cudnn_check(cudnnSetConvolutionMathType(conv_desc_, CUDNN_TENSOR_OP_MATH));
}
//set group num
cudnn_check(cudnnSetConvolutionGroupCount(conv_desc_, mKernelInfo.groups));
}
ConvSingleInputExecution::~ConvSingleInputExecution() {
cudnn_check(cudnnDestroyConvolutionDescriptor(conv_desc_));
cudnn_check(cudnnDestroyFilterDescriptor(filter_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(padded_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(output_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(input_desc_));
cudnn_check(cudnnDestroyTensorDescriptor(bias_desc_));
cudnn_check(cudnnDestroyActivationDescriptor(act_desc_));
if (nullptr != weightTensor) {
backend()->onReleaseBuffer(weightTensor.get(), Backend::STATIC);
}
if(use_bias_ && nullptr != biasTensor) {
backend()->onReleaseBuffer(biasTensor.get(), Backend::STATIC);
}
if(workspace_size_!=0 && nullptr != workspaceTensor) {
backend()->onReleaseBuffer(workspaceTensor.get(), Backend::STATIC);
}
}
ErrorCode ConvSingleInputExecution::onResize(const std::vector<Tensor*> &inputs, const std::vector<Tensor*> &outputs) {
// prepare
//MNN_PRINT("cuda convSingleInput onResize in, pad:%d\n", mKernelInfo.padX);
auto input = inputs[0], output = outputs[0];
mIOInfo.iw = input->width();
mIOInfo.ih = input->height();
mIOInfo.ic = input->channel();
mIOInfo.ib = input->batch();
mIOInfo.ow = output->width();
mIOInfo.oh = output->height();
mIOInfo.oc = output->channel();
mIOInfo.ob = output->batch();
mKernelInfo.kernelN = output->channel();
mKernelInfo.kernelC = input->channel() / mKernelInfo.groups;
if(mIOInfo.iw==0) {
mIOInfo.iw = 1;
}
if(mIOInfo.ih==0) {
mIOInfo.ih = 1;
}
if(mIOInfo.ic==0) {
mIOInfo.ic = 1;
}
if(mIOInfo.ib==0) {
mIOInfo.ib = 1;
}
if(mIOInfo.ow==0) {
mIOInfo.ow = 1;
}
if(mIOInfo.oh==0) {
mIOInfo.oh = 1;
}
if(mIOInfo.oc==0) {
mIOInfo.oc = 1;
}
if(mIOInfo.ob==0) {
mIOInfo.ob = 1;
}
std::vector<int> in_shape = {mIOInfo.ib, mIOInfo.ic, mIOInfo.ih, mIOInfo.iw};
std::vector<int> output_shape = {mIOInfo.ob, mIOInfo.oc, mIOInfo.oh, mIOInfo.ow};
// printf("filter:%d %d %d %d\n", filter_shape[0], filter_shape[1], filter_shape[2], filter_shape[3]);
// printf("input:%d %d %d %d\n", in_shape[0], in_shape[1], in_shape[2], in_shape[3]);
// printf("output:%d %d %d %d\n", output_shape[0], output_shape[1], output_shape[2], output_shape[3]);
cudnn_check(cudnnSetTensor4dDescriptor(input_desc_, CUDNN_TENSOR_NCHW, cudnn_data_type_, in_shape[0],
in_shape[1], in_shape[2], in_shape[3]));
cudnn_check(cudnnSetTensor4dDescriptor(output_desc_, CUDNN_TENSOR_NCHW, cudnn_data_type_, output_shape[0],
output_shape[1], output_shape[2], output_shape[3]));
cudnnTensorDescriptor_t input_descriptor_real = nullptr;
if (mKernelInfo.padMode == PadMode_SAME) {
int kernelWidthSize = (mKernelInfo.kernelX - 1) * mKernelInfo.dilateX + 1;
int kernelHeightSize = (mKernelInfo.kernelY - 1) * mKernelInfo.dilateY + 1;
int pw = (mIOInfo.ow - 1) * mKernelInfo.strideX + kernelWidthSize - mIOInfo.iw;
int ph = (mIOInfo.oh - 1) * mKernelInfo.strideY + kernelHeightSize - mIOInfo.ih;
pad_left_ = pw/2;
pad_right_ = pw - pad_left_;
pad_top_ = ph/2;
pad_bottom_ = ph - pad_top_;
} else {
if (mKernelInfo.padMode == PadMode_VALID) {
pad_left_ = 0;
pad_right_ = 0;
pad_top_ = 0;
pad_bottom_ = 0;
}
}
use_pad_ = (pad_left_!=0 || pad_right_!=0 || pad_top_!=0 || pad_bottom_!=0 ) ? true : false;
if(use_pad_) {
int totalSize = in_shape[0]*in_shape[1]*(in_shape[2]+pad_top_+pad_bottom_)*(in_shape[3]+pad_left_+pad_right_);
padTensor.reset(Tensor::createDevice<float>({totalSize}));
backend()->onAcquireBuffer(padTensor.get(), Backend::DYNAMIC);
mPadPtr = (void *)padTensor.get()->buffer().device;
//dynamic memory release
backend()->onReleaseBuffer(padTensor.get(), Backend::DYNAMIC);
cudnn_check(cudnnSetTensor4dDescriptor(padded_desc_, CUDNN_TENSOR_NCHW, cudnn_data_type_, in_shape[0], in_shape[1],
in_shape[2] + +pad_top_+pad_bottom_, in_shape[3] + pad_left_+pad_right_));
}
input_descriptor_real = use_pad_ ? padded_desc_ : input_desc_;
// algorithm
constexpr int requested_algo_count = 1;
int returned_algo_count;
cudnnConvolutionFwdAlgoPerf_t perf_results;
cudnn_check(cudnnGetConvolutionForwardAlgorithm_v7(cudnn_handle_, input_descriptor_real, filter_desc_, conv_desc_,
output_desc_, requested_algo_count, &returned_algo_count, &perf_results));
conv_algorithm_ = perf_results.algo;
// workspace
cudnn_check(cudnnGetConvolutionForwardWorkspaceSize(cudnn_handle_, input_descriptor_real, filter_desc_, conv_desc_, output_desc_,
conv_algorithm_, &workspace_size_));
if (workspace_size_ != 0) {
int workspaceSize = workspace_size_;
workspaceTensor.reset(Tensor::createDevice<float>({workspaceSize}));
//cudnn not support workspace memory reuse
backend()->onAcquireBuffer(workspaceTensor.get(), Backend::STATIC);
mWorkSpace = (void *)workspaceTensor.get()->buffer().device;
}
if(use_relu_) {
cudnn_check(cudnnSetActivationDescriptor(act_desc_, CUDNN_ACTIVATION_RELU, CUDNN_NOT_PROPAGATE_NAN, 0.0));
} else if(use_relu6_) {
cudnn_check(cudnnSetActivationDescriptor(act_desc_, CUDNN_ACTIVATION_CLIPPED_RELU, CUDNN_NOT_PROPAGATE_NAN, 6.0));
} else {
//do nothing
}
//MNN_PRINT("cuda convSingleInput onResize out\n");
return NO_ERROR;
}
ErrorCode ConvSingleInputExecution::onExecute(const std::vector<Tensor*> &inputs, const std::vector<Tensor*> &outputs) {
//MNN_PRINT("cuda convSingleInput onExecute in, inputsize:%d %d\n", (int)inputs.size(), workspace_size_);
MNN_ASSERT(inputs.size() == 1);
MNN_ASSERT(outputs.size() == 1);
auto runtime = static_cast<CUDABackend*>(backend())->getCUDARuntime();
const void *input_addr = (const void*)inputs[0]->deviceId();
const void *filter_addr = mFilter;
const void *bias_addr = mBias;
void *output_addr = (void*)outputs[0]->deviceId();
void *workspace_addr = nullptr;
if (workspace_size_ != 0) {
workspace_addr = mWorkSpace;
}
const float alpha = 1;
const float beta = 0;
if(use_pad_) {
std::vector<int> in_shape = {mIOInfo.ib, mIOInfo.ic, mIOInfo.ih, mIOInfo.iw};
int size = in_shape[0] * in_shape[1] * (in_shape[2]+pad_top_+pad_bottom_) * (in_shape[3]+pad_left_+pad_right_);
int block_num = runtime->blocks_num(size);
int threads_num = runtime->threads_num();
Pad<<<block_num, threads_num>>>(size, (float*)input_addr, in_shape[2], in_shape[3],
in_shape[2]+pad_top_+pad_bottom_, in_shape[3]+pad_left_+pad_right_, pad_top_, pad_left_, 0.0, (float*)mPadPtr);
cudnn_check(cudnnConvolutionForward(cudnn_handle_, &alpha, padded_desc_, mPadPtr, filter_desc_, filter_addr, conv_desc_,
conv_algorithm_, workspace_addr, workspace_size_, &beta, output_desc_, output_addr));
}
else {
cudnn_check(cudnnConvolutionForward(cudnn_handle_, &alpha, input_desc_, input_addr, filter_desc_, filter_addr, conv_desc_,
conv_algorithm_, workspace_addr, workspace_size_, &beta, output_desc_, output_addr));
}
if(use_bias_) {
cudnn_check(cudnnAddTensor(cudnn_handle_, &alpha, bias_desc_, bias_addr, &alpha, output_desc_, output_addr));
}
if(use_relu_ || use_relu6_) {
cudnn_check(cudnnActivationForward(cudnn_handle_, act_desc_, &alpha, output_desc_, output_addr, &beta, output_desc_, output_addr));
}
return NO_ERROR;
}
class CUDAConvolutionCreator : public CUDABackend::Creator {
public:
virtual Execution* onCreate(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
const MNN::Op* op, Backend* backend) const override {
if (nullptr != op->main_as_Convolution2D()->quanParameter()) {
auto quan = op->main_as_Convolution2D()->quanParameter();
if (1 == quan->type() || 2 == quan->type()) {
MNN_PRINT("cuda conv quant type 1 or 2 not support\n");
return nullptr;
}
}
if(inputs.size() == 3) {
MNN_PRINT("conv inputs size:3 not support\n");
return nullptr;
} else if(inputs.size() == 1) {
return new ConvSingleInputExecution(backend, op);
} else {
MNN_PRINT("conv inputs size:%d not support", (int)inputs.size());
return nullptr;
}
}
};
CUDACreatorRegister<CUDAConvolutionCreator> __ConvExecution(OpType_Convolution);
}// namespace CUDA
}// namespace MNN |
09d1a709c5a2bbaa458d04243178f083d468300e.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
#define NX 100 // No. of cells in x direction
#define NY 100 // No. of cells in y direction
#define NZ 100 // No. of cells in z direction
#define N (NX*NY*NZ) // N = total number of cells in domain
#define L 100 // L = length of domain (m)
#define H 100 // H = Height of domain (m)
#define W 100 // W = Width of domain (m)
#define DX (L/NX) // DX, DY, DZ = grid spacing in x,y,z.
#define DY (H/NY)
#define DZ (W/NZ)
#define DT 0.001 // Time step (seconds)
#define R (1.0) // Dimensionless specific gas constant
#define GAMA (7.0/5.0) // Ratio of specific heats
#define CV (R/(GAMA-1.0)) // Cv
#define CP (CV + R) // Cp
//#define DEBUG_VALUE
float *dens; //density
float *temperature; //temperature
float *xv; //velocity in x
float *yv; //velocity in y
float *zv; //velocity in z
float *press; //pressure
float *d_dens; //density
float *d_temperature; //temperature
float *d_xv; //velocity in x
float *d_yv; //velocity in y
float *d_zv; //velocity in z
float *d_press; //pressure
float *U;
float *U_new;
float *E;
float *F;
float *G;
float *FF;
float *FB;
float *FR;
float *FL;
float *FU;
float *FD;
float *h_body;
float *d_body;
int total_cells = 0; // A counter for computed cells
__global__ void GPUTimeStepFunction(float *a, float *b, int *body){
} | 09d1a709c5a2bbaa458d04243178f083d468300e.cu | #include "includes.h"
#define NX 100 // No. of cells in x direction
#define NY 100 // No. of cells in y direction
#define NZ 100 // No. of cells in z direction
#define N (NX*NY*NZ) // N = total number of cells in domain
#define L 100 // L = length of domain (m)
#define H 100 // H = Height of domain (m)
#define W 100 // W = Width of domain (m)
#define DX (L/NX) // DX, DY, DZ = grid spacing in x,y,z.
#define DY (H/NY)
#define DZ (W/NZ)
#define DT 0.001 // Time step (seconds)
#define R (1.0) // Dimensionless specific gas constant
#define GAMA (7.0/5.0) // Ratio of specific heats
#define CV (R/(GAMA-1.0)) // Cv
#define CP (CV + R) // Cp
//#define DEBUG_VALUE
float *dens; //density
float *temperature; //temperature
float *xv; //velocity in x
float *yv; //velocity in y
float *zv; //velocity in z
float *press; //pressure
float *d_dens; //density
float *d_temperature; //temperature
float *d_xv; //velocity in x
float *d_yv; //velocity in y
float *d_zv; //velocity in z
float *d_press; //pressure
float *U;
float *U_new;
float *E;
float *F;
float *G;
float *FF;
float *FB;
float *FR;
float *FL;
float *FU;
float *FD;
float *h_body;
float *d_body;
int total_cells = 0; // A counter for computed cells
__global__ void GPUTimeStepFunction(float *a, float *b, int *body){
} |
7638d425b08c9897d78fbdd2cd6c09c5649c9ffb.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/* Filename: main.cu **************************************************************************** /
*
* INPUT:
* -Particulas.in:
* cantParticles
* type x y z Vx Vy Vz q ; where
* dt ; (x,y,z) = posicin respecto de algn (0,0,0)
* temp0 ; (Vx,Vy,Vz) = Velocidades iniciales
* tempi ; q = carga
* tautp ; dt = delta_tiempo
* ; temp0 = temperatura target
* ; tempi = temperatura inicial (No se usa an)
* ; tautp = factor de correccin de velocidades
*
*
*
* -TablaCoeficientesLennard
* type sigma epsilon mass min max ; donde min y max indican de qu valor
* ; a qu valor hay que densificar las muestras
* ; (NO ESTA IMPLEMENTADO AUN)
*
* ALGORITMO:
* 1-Levantar Coeficientes
* 2-Armar matriz de lennard para cant_samples_r muestras
* Para cada tipo de partcula:
* Calcular en funcion de los coeficientes el potencial para cant_samples_r valores r
* 3-Levantar partculas
* Ordenar y armar ndices
* Para cada iteracin de MD:
* 4-Calcular distancias:
* Cada partcula contra todas las otras
* Armar matriz de distancias
* 5-Calcular las derivadas respecto de r para cada par de partculas
* 6-Calcular fuerza para cada particula:
* Cada partcula contra todas las otras: matriz 3D
* Obtener fuerza resultante para cada partcula: vector 3D
* 7-Calcular nuevas posiciones: vector 3D
*
***************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <sys/time.h>
/** **************************************************************** **/
/** ************* DEFAULT GLOBAL VARIABLES VALUES ****************** **/
#define BLOCK_SIZE_X 32
#define BLOCK_SIZE_Y 16
#define BLOCK_SIZE (BLOCK_SIZE_X*BLOCK_SIZE_Y)
#define TEXTURE_MEM_SIZE 65000
#define DIF_FINITAS_DELTA 4
/** Variables fsicas **/
#define CANT_TYPES 37
#define MAx 15
#define MIn 0.3
#define DIST (MAx - MIn)
#define DELTA_TIEMPO 0.001
#define TEMP 100
#define TAO 0.1
#define BOX_MAX 999 // distancia mxima del 0 para cada coordenada
// Determinamos un cubo de volumen = (2*BOX_MAX) ^3
/** Filenames **/
char* lennardTableFileName = "Input_Mache/TablaCoeficientesLennard";
char* particlesFileName = "Input_Mache/particles.in";
char* debugOutputFilename = "Output_Mache/debug.out";
char* outputFilename = "Output_Mache/results.out";
char* crdFilename = "Output_Mache/mdcrd";
char* timeFilename = "Output_Mache/times.out";
using namespace std;
// streamsize ss = cout.precision();
/** **************************************************************** **/
/** ******************** GLOBAL VARIABLES ************************** **/
texture <float, hipTextureType2D,hipReadModeElementType> texRef;
double delta_tiempo = DELTA_TIEMPO;
double temp0 = TEMP;
double tempi;
double tautp = TAO;
double Boltzmann_cte = 0.0019872041;
double box_max_x = BOX_MAX;
double box_max_y = BOX_MAX;
double box_max_z = BOX_MAX;
bool box = true;
double cut = 12;
int cant_steps = 1;
int cant_types = CANT_TYPES;
bool derivative = false;
bool analytic = false;
bool results = false;
bool amberResults = false;
bool coordenates = false;
/** **************************************************************** **/
/** ************************* DEVICE ******************************* **/
__global__
void lennard_Kernel(float* LJ_POT, double* EPS, double* SIG,
double e, double s, double var, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
/* Variables */
double sig12 = (double) (s + SIG[y])/2;
double eps12 = (double) sqrt(e * EPS[y]);
double r = (double) MIn+x*var;
/* Resultado */
LJ_POT[y*width +x] = (float) 4.0*eps12*( pow((sig12/r),12) - pow((sig12/r),6));
}
/** **************************************************************** **/
__global__
void derivatives_lennard_Kernel(float* dLJ_POT, double* EPS, double* SIG,
double e, double s, double var, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
/* Variables */
double sig12 = (double) (s + SIG[y])/2;
double eps12 = (double) sqrt(e * EPS[y]);
double r = (double) MIn+x*var;
/* Resultado */
dLJ_POT[y*width +x] = (float) 24.0*eps12*( pow(sig12,6)/ pow(r,7) - 2 * pow(sig12,12)/ pow(r,13));
}
/** **************************************************************** **/
__global__
void close_distances_kernel(double* X, double* Y, double* Z, double* R,
double* position_x, double* position_y, double* position_z,
double box_x, double box_y, double box_z, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int j = blockIdx.y * blockDim.y + threadIdx.y;
if(i >= width || j >= height) {return;}
unsigned int pos = j*width+i;
double _X = position_x[i] - position_x[j];
double _Y = position_y[i] - position_y[j];
double _Z = position_z[i] - position_z[j];
_X = _X - box_x * round((double) _X/box_x);
_Y = _Y - box_y * round((double) _Y/box_y);
_Z = _Z - box_z * round((double) _Z/box_z);
X[pos] = _X;
Y[pos] = _Y;
Z[pos] = _Z;
R[pos] = (double) sqrt( _X*_X + _Y*_Y + _Z*_Z );
}
/** **************************************************************** **/
__global__
void distances_kernel(double* R, double* X, double* Y, double* Z,
double* x1, double* y1, double* z1, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
double x_ = x1[x] - x1[y];
double y_ = y1[x] - y1[y];
double z_ = z1[x] - z1[y];
X[y*width+x] = x_;
Y[y*width+x] = y_;
Z[y*width+x] = z_;
R[y*width+x] = (double) sqrt( x_*x_ + y_*y_ + z_*z_ );
}
/** **************************************************************** **/
__global__
void derivative_E_r(double* dEr, double* r, double cut, int* item_to_type,
int cant_samples_r, int cant_types, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {dEr[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partcula correspondiente */
/** type of particles **/
float t_o_p_1 = (float) item_to_type[y] * cant_types; //this one decides which subMatrix to use
float t_o_p_2 = (float) item_to_type[x] + 0.5 + t_o_p_1; //this one decides which row on these
/** Convierto r a subndice de matriz de lennard-jones **/
/** r = (MAX-MIN) * X / N + MIN **/
/** x = (r-MIN) * N / (MAX-MIN) **/
float index_x = (float)((double) (r[y*width+x] - MIn) * (double) cant_samples_r / DIST + 0.5); // convert r to x
double E_r_up = (double) tex2D( texRef, index_x + DIF_FINITAS_DELTA, t_o_p_2 );
double E_r_dwn = (double) tex2D( texRef, index_x - DIF_FINITAS_DELTA, t_o_p_2 );
double r_dif = DIST * 2 * (DIF_FINITAS_DELTA) / cant_samples_r;
dEr[y*width+x] = (E_r_up - E_r_dwn) / (r_dif);
}
/** **************************************************************** **/
__global__
void direct_derivative_E_r(double* dEr, double* r, double cut, int* item_to_type,
int cant_samples_r, int cant_types, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {dEr[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partcula correspondiente */
/** type of particles **/
float t_o_p_1 = (float) item_to_type[y] * cant_types; //this one decides which subMatrix to use
float t_o_p_2 = (float) item_to_type[x] + 0.5 + t_o_p_1; //this one decides which row on these
/** Convierto r a subndice de matriz de lennard-jones **/
/** r = (MAX-MIN) * X / N + MIN **/
/** x = (r-MIN) * N / (MAX-MIN) **/
float index_x = (float)((double) (r[y*width+x] - MIn) * (double) cant_samples_r / DIST + 0.5); // convert r to x
dEr[y*width+x] = (double) tex2D( texRef, index_x, t_o_p_2 );
}
/** **************************************************************** **/
__global__
void E_r(double* Er, double* r, double cut, int* item_to_type,
int cant_samples_r, int cant_types, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {Er[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partcula correspondiente */
/** type of particles **/
float t_o_p_1 = (float) item_to_type[y]; //this one decides which subMatrix to use
float t_o_p_2 = (float) item_to_type[x]; //this one decides which row on these
float row = t_o_p_2 + 0.5 + (t_o_p_1* cant_types);
/** Convierto r a subndice de matriz de lennard-jones **/
/** r = (MAX-MIN) * X / N + MIN **/
/** x = (r-MIN) * N / (MAX-MIN) **/
float index_x = (float)((double) (r[y*width+x] - MIn) * (double) cant_samples_r / DIST + 0.5); // convert r to x
Er[y*width+x] = (double) tex2D( texRef, index_x, row );
}
/* ***************************************************************** **/
/** +ANALYTIC */
/** **************************************************************** **/
__global__
void derivative_E_r_analytic(double* dEr, double* r, double cut, int* item_to_type, int cant_samples_r,
double* EPS, double* SIG, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {dEr[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partcula correspondiente */
/** type of particle 2 **/
int type_i = item_to_type[x];
int type_j = item_to_type[y];
double sig12 = (double) (SIG[type_i] + SIG[type_j])/2;
double eps12 = (double) sqrt(EPS[type_i] * EPS[type_j]);
dEr[y*width+x] = (double) 24.0*eps12*( pow(sig12,6)/ pow(r[y*width+x],7) - 2 * pow(sig12,12)/ pow(r[y*width+x],13));
}
__global__
void E_r_analytic(double* Er, double* r, double cut, int* item_to_type, int cant_samples_r,
double* EPS, double* SIG, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {Er[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partcula correspondiente */
/** type of particle 2 **/
int type_i = item_to_type[x];
int type_j = item_to_type[y];
double sig12 = (double) (SIG[type_i] + SIG[type_j])/2;
double eps12 = (double) sqrt(EPS[type_i] * EPS[type_j]);
Er[y*width+x] = (double) 4.0*eps12*( pow((sig12/r[y*width+x]),12) - pow((sig12/r[y*width+x]),6));
}
/** **************************************************************** **/
/** -ANALYTIC */
/* ***************************************************************** **/
/** **************************************************************** **/
/* Fx = dE(r) / dr * (x1-x2) / r */
__global__
void Parcial_Forces_Kernel(double* force, double* dEr, double* dif, double* r, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
if(x == y) {force[y*width+x] = 0; return;}
force[y*width+x] = dEr[y*width+x] * dif[y*width+x] / r[y*width+x];
}
/** **************************************************************** **/
__global__
void Resultant_Forces_Kernel(double* result, double* forces, int cant)
{
/* Elemento del vector a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
if(x >= cant) {return;}
int i = 0;
double tmp = 0;
int row = x*cant;
for(; i < cant; i++){
tmp += forces[row + i];
}
result[x] = tmp;
}
/** **************************************************************** **/
/* V(t + Dt/2) = V(t - Dt/2) + [ F(t) * Dt ] / m */
__global__
void Resultant_Velocities_Kernel(double* velocity, double* old_velocity, double* force, double* m,
int* item_to_type, double delta_tiempo, int cant_particles)
{
/* Elemento de la matriz a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i >= cant_particles) {return;}
double Vt = old_velocity[i];
int type = item_to_type[i];
double dtx = delta_tiempo*20.455;
/* Result */
velocity[i] = Vt + ( (force[i]*dtx) / m[type] );
}
/** **************************************************************** **/
/* P(t + Dt) = P(t) + V(t + Dt/2) * Dt */
__global__
void Resultant_Positions_Kernel(double* positions, double* velocity, double delta_tiempo, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i >= cant) {return;}
double dtx = delta_tiempo*20.455;
positions[i] = positions[i] + (velocity[i] * dtx);
}
/** **************************************************************** **/
/* -BOX_MAX 0 BOX_MAX */
/* |-----------------|-----------------| */
__global__
void Adjustin_Positions_Kernel(double* position, double box_max, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i >= cant) {return;}
double pos = position[i] - box_max;
if(pos > 0){
position[i] = -box_max + fmod(pos, (double) (2*box_max));
}
if(pos < -2*box_max){
position[i] = box_max + fmod(pos, (double) (2*box_max));
}
}
/** **************************************************************** **/
/* Ek = |v|^2 * m / 2 */
/* Ek_x = (v_x)^2 * m / 2 */
__global__
void Kinetic_Energy_Kernel(double* kE, double* vold, double* v, double* m, int* item_to_type, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i>= cant) {return;}
double vi = vold[i] + v[i];
int type = item_to_type[i];
kE[i] = vi * vi * m[type] / 8;
}
/** **************************************************************** **/
__global__
void Total_Kinetic_Energy_Kernel(double* kE, double* Ke_x, double* Ke_y, double* Ke_z, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i>= cant) {return;}
kE[i] = Ke_x[i] + Ke_y[i] + Ke_z[i];
}
/** **************************************************************** **/
__global__
void Corrected_Velocities_Kernel(double* vold, double* v, double lambda, int cant){
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i>= cant) {return;}
vold[i] = v[i] * lambda;
}
/** **************************************************************** **/
/** *************************** HOST ******************************* **/
int main( int argc, char* argv[] )
{
for(uint i = 0; i < argc; i++){
if(strcmp(argv[i], "-t") == 0){
/* outputTimeFilename */
timeFilename = argv[i+1];
}
if(strcmp(argv[i], "-a") == 0){
/* ANALYTIC mode */
analytic = true;
}
if(strcmp(argv[i], "-d") == 0){
/* DERIVATIVE mode */
derivative = true;
}
if(strcmp(argv[i], "-r") == 0){
/* RESULTS or TIMER mode */
results = true;
amberResults = true;
}
if(strcmp(argv[i], "-ar") == 0){
/* RESULTS or TIMER mode */
amberResults = true;
}
if(strcmp(argv[i], "-c") == 0){
/* PRINT mdcrd file */
coordenates = true;
}
}
if (derivative)
cout << "Derivative" << endl;
if (analytic)
cout << "Analytic" << endl;
if(results){
cout << "DEBUG mode ON" << endl;
}
if(amberResults){
cout << "AMBER results ON" << endl;
}
fstream out;
fstream crd;
if(results or amberResults){
/* Output file */
out.open(outputFilename,fstream::out);
streamsize ss = out.precision();
out << setprecision(20);
}
if(coordenates){
/* CRD output file */
crd.open(crdFilename,fstream::out);
crd << setprecision(3);
crd.setf( std::ios::fixed, std:: ios::floatfield );
crd << " POS(x) POS(y) POS(z)" << endl;
}
struct timeval tv1, tv2;
fstream taim;
if(!results){ //timer mode ON
/* Time output file */
taim.open(timeFilename, fstream::app | fstream::out);
taim << setprecision(20);
}
/* Levantamos Coeficientes de Lennard */
ifstream table (lennardTableFileName);
table >> cant_types;
/**Variables y memoria*/
size_t cant_types_size = cant_types * sizeof(double);
vector<string> h_type;
h_type.resize(cant_types);
double* h_sigma = (double*) ( malloc(cant_types_size));
double* h_epsilon = (double*) ( malloc(cant_types_size));
double* h_mass = (double*) ( malloc(cant_types_size));
/**Levantamos datos*/
for(int j = 0; j<cant_types ; j++){
table >> h_type[j];
table >> h_sigma[j];
table >> h_epsilon[j];
table >> h_mass[j];
}
table.close();
/* Armamos matrices de lennard */
/**Variables y memoria**/
int cant_samples_r = TEXTURE_MEM_SIZE/(sizeof(float)); // cant of original sample values (mximo permitido por mem de textura)
double var = DIST / ((double) cant_samples_r); // variation of r
size_t cant_samples_r_size = cant_samples_r * sizeof(float);
float* h_dLJPot;
float* h_LJPot;
if(derivative)
h_dLJPot = (float*) malloc(cant_samples_r_size*cant_types*cant_types); // #samples * #particles * #particles (*float)
else
h_LJPot = (float*) malloc(cant_samples_r_size*cant_types*cant_types); // #samples * #particles * #particles (*float)
int width = cant_samples_r;
int height = cant_types;
dim3 dimBlock(BLOCK_SIZE_X,BLOCK_SIZE_Y);
dim3 dimGrid( (int) ceil((double)width / (double)dimBlock.x), (int) ceil((double)height / (double)dimBlock.y) );
double* d_EPS;
double* d_SIG;
float* d_LJPot;
float* d_dLJPot;
hipMalloc(&d_EPS, cant_types_size);
hipMalloc(&d_SIG, cant_types_size);
hipMemcpy(d_EPS, h_epsilon, cant_types_size, hipMemcpyHostToDevice);
hipMemcpy(d_SIG, h_sigma, cant_types_size, hipMemcpyHostToDevice);
if(derivative)
hipMalloc(&d_dLJPot, cant_samples_r_size * cant_types);
else
hipMalloc(&d_LJPot, cant_samples_r_size * cant_types);
/** Rellenamos datos con CUDA **/
if(derivative) {
for(int a = 0; a<cant_types; a++){
hipLaunchKernelGGL(( derivatives_lennard_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_dLJPot, d_EPS, d_SIG, h_epsilon[a], h_sigma[a], var, width, height);
hipMemcpy( (float*) &(h_dLJPot[(a*cant_samples_r*cant_types)]), d_dLJPot, cant_types * cant_samples_r_size, hipMemcpyDeviceToHost);
}
} else {
for(int a = 0; a<cant_types; a++){
hipLaunchKernelGGL(( lennard_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_LJPot, d_EPS, d_SIG, h_epsilon[a], h_sigma[a], var, width, height);
hipMemcpy( (float*) &(h_LJPot[(a*cant_samples_r*cant_types)]), d_LJPot, cant_types * cant_samples_r_size, hipMemcpyDeviceToHost);
}
}
/** Liberamos memoria de CUDA **/
hipFree(&d_EPS);
hipFree(&d_SIG);
hipFree(&d_LJPot);
if(results){
/** DEBUG **/
if(derivative)
out << " derivative LENNARD " << endl;
else
out << " LENNARD " << endl;
for(int a = 0; a<cant_types; a++){
out << " Type = " << h_type[a] << endl << " ";
for(int i = 0; i<cant_types; i++){
for(int j = 0; j<cant_samples_r; j+= cant_samples_r/8){
if(derivative)
out << h_dLJPot[(a*cant_types*cant_samples_r)+(i*cant_samples_r)+j] << ", ";
else
out << h_LJPot[(a*cant_types*cant_samples_r)+(i*cant_samples_r)+j] << ", ";
}
out << endl << " ";
}
out << "***********************************************************************************" << endl;
}
/** DEBUG **/
}
/*Levantamos partculas*/
fstream particles;
particles.open(particlesFileName);
/** Variables y memoria **/
uint cant_particles;
double* h_position_x;
double* h_position_y;
double* h_position_z;
double* h_velocity_x;
double* h_velocity_y;
double* h_velocity_z;
double* h_velocity_old_x;
double* h_velocity_old_y;
double* h_velocity_old_z;
double* h_chargue;
double h_box_x;
double h_box_y;
double h_box_z;
double h_box_alpha;
double h_box_beta;
double h_box_gamma;
vector<string> h_particle_type;
particles >> cant_particles;
size_t cant_particles_size = cant_particles * sizeof(double);
h_position_x = (double*)malloc(cant_particles_size);
h_position_y = (double*)malloc(cant_particles_size);
h_position_z = (double*)malloc(cant_particles_size);
h_velocity_x = (double*)malloc(cant_particles_size);
h_velocity_y = (double*)malloc(cant_particles_size);
h_velocity_z = (double*)malloc(cant_particles_size);
h_velocity_old_x = (double*)malloc(cant_particles_size);
h_velocity_old_y = (double*)malloc(cant_particles_size);
h_velocity_old_z = (double*)malloc(cant_particles_size);
h_chargue = (double*)malloc(cant_particles_size);
h_particle_type.resize(cant_particles);
/** Guardamos datos **/
for(uint i = 0; i < cant_particles ; i++) {
particles >> h_particle_type[i];
particles >> h_position_x[i];
particles >> h_position_y[i];
particles >> h_position_z[i];
particles >> h_velocity_old_x[i];
particles >> h_velocity_old_y[i];
particles >> h_velocity_old_z[i];
particles >> h_chargue[i];
}
/** Perioricidad **/
//TODO: por ahora usamos cubo,
//situamos el cero en el centro del mismo
//Recibimos en orden x, y, z
particles >> box;
if(box){
cout << " Levantamos caja" << endl;
particles >> h_box_x;
particles >> h_box_y;
particles >> h_box_z;
particles >> h_box_alpha;
particles >> h_box_beta;
particles >> h_box_gamma;
if( h_box_alpha != 90 or h_box_beta != 90 or h_box_gamma != 90){
cout << " Se forzaron los angulos para que sea un CUBO: " << endl;
}
box_max_x = h_box_x/2;
box_max_y = h_box_y/2;
box_max_z = h_box_z/2;
}
/** Parametros **/
particles >> cant_steps;
particles >> delta_tiempo;
particles >> temp0;
particles >> tempi;
particles >> tautp;
particles >> cut;
particles.close();
// if(results){
// /** DEBUG **/
// out << " INITIAL VALUES" << endl;
// for(int i = 0; i<cant_particles; i++){
// out << " Type: " << h_particle_type[i] << " | Pos: (" << h_position_x[i] << " , " << h_position_y[i] << " , " << h_position_z[i] << ")";
// out << " | Vel: (" << h_velocity_old_x[i] << " , " << h_velocity_old_y[i] << " , " << h_velocity_old_z[i] << ")" << endl;
// }
// out << endl;
//
// /** DEBUG **/
// }
if(results){
// /** DEBUG **/
// out << " CANT of TYPES" << endl;
// for(int i = 0; i < h_type.size(); i++){
// out << " " << h_type[i] << " " << cant_of_typ[i] << endl;
// }
// out << endl;
/** DEBUG **/
}
/* Armamos estructura de items para saber de qu tipo
/* es la partcula en la que estamos en CUDA */
/** h_particle_type = H H H H H K K K K K O O O O O O O O O ... **/
/** h_item_particle = 1 1 1 1 1 3 3 3 3 3 9 9 9 9 9 9 9 9 9 ... **/
int * h_item_particle = (int*)malloc(cant_particles * sizeof(int));
int * d_item_particle;
hipMalloc(&d_item_particle, cant_particles * sizeof(int));
/** Convertimos anotamos type de la partcula como un int que sera el index dentro de h_type **/
for(int i = 0; i< cant_particles; i++){
for(int j = 0; j< h_type.size(); j++){
if(h_type[j] == h_particle_type[i]){
h_item_particle[i] = j;
break;
}
}
}
hipMemcpy(d_item_particle, h_item_particle, cant_particles * sizeof(int), hipMemcpyHostToDevice);
// if(results){
// /** DEBUG **/
// out << " ITEM to TYPE" << endl;
// for(int i = 0; i < cant_particles; i++){
// out << " Particle[" << i << "] | Type: " << h_type[h_item_particle[i]] << " (index :" << h_item_particle[i] << ") " << endl;
// }
// out << endl;
// /** DEBUG **/
// }
/* ************************************************ */
/* MANEJO DE MEMORIA EN EL DISPOSITIVO GPU */
/* ************************************************ */
/** Variables **/
size_t s_size = cant_particles_size * cant_particles;
/** Positions **/
double* d_position_x;
double* d_position_y;
double* d_position_z;
hipMalloc(&d_position_x, cant_particles_size);
hipMalloc(&d_position_y, cant_particles_size);
hipMalloc(&d_position_z, cant_particles_size);
hipMemcpy(d_position_x, h_position_x, cant_particles_size, hipMemcpyHostToDevice);
hipMemcpy(d_position_y, h_position_y, cant_particles_size, hipMemcpyHostToDevice);
hipMemcpy(d_position_z, h_position_z, cant_particles_size, hipMemcpyHostToDevice);
/** Positions **/
double* d_pos_close_x;
double* d_pos_close_y;
double* d_pos_close_z;
hipMalloc(&d_pos_close_x, cant_particles_size);
hipMalloc(&d_pos_close_y, cant_particles_size);
hipMalloc(&d_pos_close_z, cant_particles_size);
/** Particle's mass **/
double* d_mass;
hipMalloc(&d_mass, cant_types_size);
hipMemcpy(d_mass, h_mass, cant_types_size, hipMemcpyHostToDevice);
/** Velocities **/
double* d_velocity_x;
double* d_velocity_y;
double* d_velocity_z;
double* d_velocity_old_x;
double* d_velocity_old_y;
double* d_velocity_old_z;
hipMalloc(&d_velocity_x, cant_particles_size);
hipMalloc(&d_velocity_y, cant_particles_size);
hipMalloc(&d_velocity_z, cant_particles_size);
hipMalloc(&d_velocity_old_x, cant_particles_size);
hipMalloc(&d_velocity_old_y, cant_particles_size);
hipMalloc(&d_velocity_old_z, cant_particles_size);
hipMemcpy(d_velocity_old_x, h_velocity_old_x, cant_particles_size, hipMemcpyHostToDevice);
hipMemcpy(d_velocity_old_y, h_velocity_old_y, cant_particles_size, hipMemcpyHostToDevice);
hipMemcpy(d_velocity_old_z, h_velocity_old_z, cant_particles_size, hipMemcpyHostToDevice);
/** Distances **/
double* d_distance_x;
double* d_distance_y;
double* d_distance_z;
double* d_distance_r;
hipMalloc(&d_distance_x, s_size);
hipMalloc(&d_distance_y, s_size);
hipMalloc(&d_distance_z, s_size);
hipMalloc(&d_distance_r, s_size);
/** Derivatives **/
double* d_dEr;
hipMalloc(&d_dEr, s_size);
/** VDWAALS **/
double* d_Er;
hipMalloc(&d_Er, s_size);
/** Forces **/
double* d_Force_x;
double* d_Force_y;
double* d_Force_z;
hipMalloc(&d_Force_x, s_size);
hipMalloc(&d_Force_y, s_size);
hipMalloc(&d_Force_z, s_size);
double* d_Force_x_resultant;
double* d_Force_y_resultant;
double* d_Force_z_resultant;
hipMalloc(&d_Force_x_resultant, cant_particles_size);
hipMalloc(&d_Force_y_resultant, cant_particles_size);
hipMalloc(&d_Force_z_resultant, cant_particles_size);
/** Kinetic Energy **/
double* d_kinetic_energy;
double* d_kinetic_energy_x;
double* d_kinetic_energy_y;
double* d_kinetic_energy_z;
hipMalloc(&d_kinetic_energy, cant_particles_size);
hipMalloc(&d_kinetic_energy_x, cant_particles_size);
hipMalloc(&d_kinetic_energy_y, cant_particles_size);
hipMalloc(&d_kinetic_energy_z, cant_particles_size);
/* ************************************************ */
/* MANEJO DE MEMORIA EN EL HOST */
/* ************************************************ */
/** Distances **/
double (*h_distance_x)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_distance_y)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_distance_z)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_distance_r)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
/** Forces **/
double (*h_Force_x)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_Force_y)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_Force_z)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double* h_Force_x_resultant = (double*)malloc(cant_particles_size);
double* h_Force_y_resultant = (double*)malloc(cant_particles_size);
double* h_Force_z_resultant = (double*)malloc(cant_particles_size);
/** Kinetic Energy **/
double* h_kinetic_energy = (double*)malloc(cant_particles_size);
double* h_kinetic_energy_x = (double*)malloc(cant_particles_size);
double* h_kinetic_energy_y = (double*)malloc(cant_particles_size);
double* h_kinetic_energy_z = (double*)malloc(cant_particles_size);
/* ************************************************ */
/* Calculamos ENERGIA CINETICA deseada */
/* ************************************************ */
/* Ek = Kb * T (3N - Nc) / 2 */
double Nc = 5;
double factor_conv_T_Ek = 2 / (Boltzmann_cte * (3 *cant_particles - Nc) );
if(amberResults){
double kinetic_Energy = Boltzmann_cte * temp0 * (3*cant_particles - Nc) / 2;
/** DEBUG **/
out << " THEORETICAL VALUES:" << endl << endl;
out << " * Kb = " << Boltzmann_cte << endl << endl;
out << " * Temperature = " << temp0 << endl << endl;
out << " * Kinetic Energy = " << kinetic_Energy << endl << endl;
out << " * Factor_conv_T_Ek = " << factor_conv_T_Ek << endl << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Seteamos la memoria de TEXTURA */
/* ************************************************ */
hipArray* cuLennard_i;
// if(!analytic){
/** Usamos texturas **/
hipChannelFormatDesc channelDesc = hipCreateChannelDesc( 32, 0, 0, 0, hipChannelFormatKindFloat );
hipMallocArray(&cuLennard_i, &channelDesc, cant_samples_r, cant_types*cant_types); //width x height
texRef.addressMode[0] = hipAddressModeClamp;
texRef.filterMode = hipFilterModeLinear; //hipFilterModePoint; // //Tipo de interpolacin
if(derivative) {
hipMemcpyToArray(cuLennard_i, 0, 0, h_dLJPot, cant_types * cant_types * cant_samples_r_size, hipMemcpyHostToDevice);
} else {
hipMemcpyToArray(cuLennard_i, 0, 0, h_LJPot, cant_types * cant_types * cant_samples_r_size, hipMemcpyHostToDevice);
}
/** Bindeamos la textura **/
hipBindTextureToArray(texRef, cuLennard_i, channelDesc);
// }
if(amberResults){
out << endl << " ESTARTIN DE PROGRAM" << endl;
out << " Amaunt of itereishons = " << cant_steps << endl << endl;
}
if(!results){ //timer mode ON
/** Esperamos a que termine de bindear la textura **/
hipDeviceSynchronize();
/** Arrancamos medicion del tiempo **/
gettimeofday(&tv1, NULL);
}
for(int step = 0; step < cant_steps; step++){
/* ********************************************************************************************************** */
/* ****************************************** INICIO Iteracion DM ******************************************* */
/* ********************************************************************************************************** */
if(amberResults){
out << "/* ************************************************************************************************ */" << endl;
out << "/* ************************************* INICIO Iteracion " << step << " ************************************ */" << endl;
out << "/* ************************************************************************************************ */" << endl;
}
dimBlock.x = BLOCK_SIZE_X;
dimBlock.y = BLOCK_SIZE_Y;
/* ************************************************ */
/* Calculamos Matriz de Distancias entre partculas */
/* ************************************************ */
/**Variables y memoria*/
width = cant_particles;
height = cant_particles;
dimGrid.x = ceil((double)width / (double)dimBlock.x);
dimGrid.y = ceil((double)height / (double)dimBlock.y);
/**Rellenamos datos**/
hipLaunchKernelGGL(( close_distances_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_distance_x, d_distance_y, d_distance_z, d_distance_r,
d_position_x, d_position_y, d_position_z,
h_box_x, h_box_y, h_box_z, width, height);
// distances_kernel<<<dimGrid, dimBlock>>>(d_distance_r, d_distance_x, d_distance_y, d_distance_z,
// d_position_x, d_position_y, d_position_z, width, height);
if(results){
/** DEBUG **/
hipMemcpy(h_distance_r, d_distance_r, s_size, hipMemcpyDeviceToHost);
hipMemcpy(h_distance_x, d_distance_x, s_size, hipMemcpyDeviceToHost);
hipMemcpy(h_distance_y, d_distance_y, s_size, hipMemcpyDeviceToHost);
hipMemcpy(h_distance_z, d_distance_z, s_size, hipMemcpyDeviceToHost);
out << " DISTANCES" << endl << " ";
double (*matriz)[cant_particles] = (double (*)[cant_particles]) h_distance_r;
for(int i = 0; i<cant_particles; i+= cant_particles/8){
out << " " << i << " | ";
for(int j = 0; j<cant_particles; j+= cant_particles/8){
out << matriz[i][j] << "\t";
}
out << endl << " ";
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Derivadas */
/* ************************************************ */
/** Variables y memoria **/
width = cant_particles;
height = cant_particles;
dimGrid.x = ceil((double)width / (double)dimBlock.x);
dimGrid.y = ceil((double)height / (double)dimBlock.y);
if(analytic){
hipLaunchKernelGGL(( derivative_E_r_analytic), dim3(dimGrid), dim3(dimBlock), 0, 0, d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
if(amberResults){
/** Calculo la energia E(r) para debug **/
hipLaunchKernelGGL(( E_r_analytic), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Er, d_distance_r, cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
}
} else {
/** Calculo de la derivada dE(r)/dr usando diferencias finitas **/
if(derivative){
// derivative_E_r_analytic<<<dimGrid, dimBlock>>>(d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
hipLaunchKernelGGL(( direct_derivative_E_r), dim3(dimGrid), dim3(dimBlock), 0, 0, d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, cant_types, width, height);
} else {
// derivative_E_r_analytic<<<dimGrid, dimBlock>>>(d_dEr, d_distance_r, d_cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
hipLaunchKernelGGL(( derivative_E_r), dim3(dimGrid), dim3(dimBlock), 0, 0, d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, cant_types, width, height);
if(amberResults){
/** Calculo la energia E(r) para debug **/
hipLaunchKernelGGL(( E_r), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Er, d_distance_r, cut, d_item_particle, cant_samples_r, cant_types, width, height);
}
}
}
if(amberResults){
if(!derivative){
/** DEBUG **/
out << " Lennard-Jones" << endl << " ";
double vdwaals = 0;
double (*h_Er)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
hipMemcpy(h_Er, d_Er, s_size, hipMemcpyDeviceToHost);
for(int i = 0; i<cant_particles; i++){
// out << " " << i << " | ";
for(int j = 0; j<cant_particles; j++){
// out << h_Er[i][j] << "\t";
if(i<=j)
vdwaals += h_Er[i][j];
}
// out << endl << " ";
}
// out << endl;
out << " VDWAALS = " << vdwaals << endl << endl;
free(h_Er);
/** DEBUG **/
}
}
if(results){
/** DEBUG **/
out << " DERIVATIVES" << endl << " ";
double (*h_dEr)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
hipMemcpy(h_dEr, d_dEr, s_size, hipMemcpyDeviceToHost);
for(int i = 0; i<cant_particles; i+= cant_particles/8){
out << " " << i << " | ";
for(int j = 0; j<cant_particles; j+= cant_particles/8){
out << h_dEr[i][j] << "\t";
}
out << endl << " ";
}
out << endl;
free(h_dEr);
/** DEBUG **/
}
if(results){
/** DEBUG **/
hipMemcpy(h_velocity_old_x, d_velocity_old_x, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_velocity_old_y, d_velocity_old_y, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_velocity_old_z, d_velocity_old_z, cant_particles_size, hipMemcpyDeviceToHost);
out << " OLD VELOCITIES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_velocity_old_x[i] << " , " << h_velocity_old_y[i] << " , " << h_velocity_old_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos FUERZAS resultantes */
/* ************************************************ */
/* Fx = dE(r) / dr * (x1-x2) / r *
* Fy = dE(r) / dr * (y1-y2) / r *
* Fz = dE(r) / dr * (z1-z2) / r */
/* Calculo de vectores parciales */
/**Variables y memoria*/
width = cant_particles;
height = cant_particles;
dimGrid.x = ceil((double)width / (double)dimBlock.x);
dimGrid.y = ceil((double)height / (double)dimBlock.y);
/** Calculo del vector F **/
hipLaunchKernelGGL(( Parcial_Forces_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Force_x, d_dEr, d_distance_x, d_distance_r, width, height);
hipLaunchKernelGGL(( Parcial_Forces_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Force_y, d_dEr, d_distance_y, d_distance_r, width, height);
hipLaunchKernelGGL(( Parcial_Forces_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Force_z, d_dEr, d_distance_z, d_distance_r, width, height);
if(results){
/** DEBUG **/
hipMemcpy(h_Force_x, d_Force_x, s_size, hipMemcpyDeviceToHost);
hipMemcpy(h_Force_y, d_Force_y, s_size, hipMemcpyDeviceToHost);
hipMemcpy(h_Force_z, d_Force_z, s_size, hipMemcpyDeviceToHost);
out << " FORCES" << endl << " ";
for(int i = 0; i<cant_particles; i++){
for(int j = 0; j<cant_particles; j++){
out << "(" << h_Force_x[i][j] << " , " << h_Force_y[i][j] << " , " << h_Force_z[i][j] << ")\t";
}
out << endl << " ";
}
out << endl;
/** DEBUG **/
}
/* Calculo del vector F */
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
hipLaunchKernelGGL(( Resultant_Forces_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Force_x_resultant, d_Force_x, cant_particles);
hipLaunchKernelGGL(( Resultant_Forces_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Force_y_resultant, d_Force_y, cant_particles);
hipLaunchKernelGGL(( Resultant_Forces_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_Force_z_resultant, d_Force_z, cant_particles);
if(results){
/** DEBUG **/
hipMemcpy(h_Force_x_resultant, d_Force_x_resultant, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_Force_y_resultant, d_Force_y_resultant, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_Force_z_resultant, d_Force_z_resultant, cant_particles_size, hipMemcpyDeviceToHost);
out << " RESULTANT FORCES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_Force_x_resultant[i] << " , " << h_Force_y_resultant[i] << " , " << h_Force_z_resultant[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos VELOCIDADES Resultantes */
/* ************************************************ */
/* V(t + Dt/2) = V(t - Dt/2) + [ F(t) * Dt ] / m */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Piso las velocidades acumuladas al tiempo t con las nuevas de t+Dt */
hipLaunchKernelGGL(( Resultant_Velocities_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_velocity_x, d_velocity_old_x, d_Force_x_resultant, d_mass, d_item_particle, delta_tiempo, cant_particles);
hipLaunchKernelGGL(( Resultant_Velocities_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_velocity_y, d_velocity_old_y, d_Force_y_resultant, d_mass, d_item_particle, delta_tiempo, cant_particles);
hipLaunchKernelGGL(( Resultant_Velocities_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_velocity_z, d_velocity_old_z, d_Force_z_resultant, d_mass, d_item_particle, delta_tiempo, cant_particles);
if(results){
/** DEBUG **/
hipMemcpy(h_velocity_x, d_velocity_x, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_velocity_y, d_velocity_y, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_velocity_z, d_velocity_z, cant_particles_size, hipMemcpyDeviceToHost);
out << " RESULTANT VELOCITIES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_velocity_x[i] << " , " << h_velocity_y[i] << " , " << h_velocity_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos POSICIONES Resultantes */
/* ************************************************ */
/* P(t + Dt) = P(t) + V(t + Dt/2) * Dt */
/* (TODO: ajustar condiciones de perioricidad */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
hipLaunchKernelGGL(( Resultant_Positions_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_position_x, d_velocity_x, delta_tiempo, cant_particles);
hipLaunchKernelGGL(( Resultant_Positions_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_position_y, d_velocity_y, delta_tiempo, cant_particles);
hipLaunchKernelGGL(( Resultant_Positions_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_position_z, d_velocity_z, delta_tiempo, cant_particles);
if(results){
/** DEBUG **/
hipMemcpy(h_position_x, d_position_x, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_position_y, d_position_y, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_position_z, d_position_z, cant_particles_size, hipMemcpyDeviceToHost);
out << " RESULTANT POSITIONS" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_particle_type[i] << " (" << h_position_x[i] << " , " << h_position_y[i] << " , " << h_position_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos POSICIONES con PERIORICIDAD */
/* ************************************************ */
/* P(t + Dt) = P(t) + V(t + Dt/2) * Dt */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
hipLaunchKernelGGL(( Adjustin_Positions_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_position_x, box_max_x, cant_particles);
hipLaunchKernelGGL(( Adjustin_Positions_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_position_y, box_max_y, cant_particles);
hipLaunchKernelGGL(( Adjustin_Positions_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_position_z, box_max_z, cant_particles);
if(coordenates){
/** DEBUG **/
hipMemcpy(h_position_x, d_position_x, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_position_y, d_position_y, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_position_z, d_position_z, cant_particles_size, hipMemcpyDeviceToHost);
if(results){
out << " RESULTANT POSITIONS in the CUBE" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_particle_type[i] << " (" << h_position_x[i] << " , " << h_position_y[i] << " , " << h_position_z[i] << ")" << endl;
}
out << endl;
}
for(int i = 0; i<cant_particles; i+=2){
crd << " " << h_position_x[i] << " " << h_position_y[i] << " " << h_position_z[i];
if(i+1 < cant_particles){
crd << " " << h_position_x[i+1] << " " << h_position_y[i+1] << " " << h_position_z[i+1] << endl;
} else
crd << endl;
}
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Ek de cada partcula */
/* ************************************************ */
/* Ek = |vp|^2 * m / 2 con vp = (vold+v)/2 */
/* Ek_x = (v_x)^2 * m / 2 */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Calculamos la energa cintica para las tres coordenadas de cada partcula **/
/** Puede hacerse directamente as, sin calcular mdulo por propiedades algebraicas **/
hipLaunchKernelGGL(( Kinetic_Energy_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_kinetic_energy_x, d_velocity_old_x, d_velocity_x, d_mass, d_item_particle, cant_particles);
hipLaunchKernelGGL(( Kinetic_Energy_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_kinetic_energy_y, d_velocity_old_y, d_velocity_y, d_mass, d_item_particle, cant_particles);
hipLaunchKernelGGL(( Kinetic_Energy_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_kinetic_energy_z, d_velocity_old_z, d_velocity_z, d_mass, d_item_particle, cant_particles);
if(results){
/** DEBUG **/
hipMemcpy(h_kinetic_energy_x, d_kinetic_energy_x, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_kinetic_energy_y, d_kinetic_energy_y, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_kinetic_energy_z, d_kinetic_energy_z, cant_particles_size, hipMemcpyDeviceToHost);
out << " KINETIC ENERGY" << endl;
for(int i = 0; i<cant_particles; i++){
out << " " << i << " | ";
out << i+1 << ": (" << h_kinetic_energy_x[i] << " , " << h_kinetic_energy_y[i] << " , " << h_kinetic_energy_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Ek Resultante */
/* ************************************************ */
/* Ek_TOT = sum (Ek_i) */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Calculamos la Energa cintica total de cada partcula **/
hipLaunchKernelGGL(( Total_Kinetic_Energy_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_kinetic_energy, d_kinetic_energy_x, d_kinetic_energy_y, d_kinetic_energy_z, cant_particles);
/* */
/** Calculamos la Energa cintica total del sistema **/
hipMemcpy(h_kinetic_energy, d_kinetic_energy, cant_particles_size, hipMemcpyDeviceToHost);
double Ek_TOT = 0;
for(int i = 0; i<cant_particles; i++){
Ek_TOT += h_kinetic_energy[i];
}
if(results){
/** DEBUG **/
out << " KINETIC ENERGY" << endl;
for(int i = 0; i<cant_particles; i++){
out << " " << i << " | ";
out << " " << h_kinetic_energy[i] << endl;
}
out << endl;
/** DEBUG **/
}
if(amberResults){
out << " Total Kinetic Energy(t) = " << Ek_TOT << endl << endl;
}
/* ************************************************ */
/* Calculamos Temperatura Resultante */
/* ************************************************ */
/* T(t) = 2*Ek_TOT / (Kb*(3N-Nc)) */
double Temp_TOT = Ek_TOT * factor_conv_T_Ek;
if(amberResults){
/** DEBUG **/
out << " Temp(t) = " << Temp_TOT << endl << endl;
/** DEBUG **/
}
/* *********************************************** */
/* Calculamos Factor de Correccion */
/* *********************************************** */
/* lambda = sqrt( 1 + 2 * dt / tautp * (T/T(t) -1) ) */
double lambda = sqrt( 1 + delta_tiempo / tautp * (temp0/Temp_TOT -1) );
if(amberResults){
/** DEBUG **/
out << " lambda(t) = " << lambda << endl << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Velocidades Corregidas */
/* ************************************************ */
/* vi = lambda * vi */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Piso las velocidades acumuladas al tiempo t+Dt con las nuevas de t+Dt corregidas */
hipLaunchKernelGGL(( Corrected_Velocities_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_velocity_old_x, d_velocity_x, lambda, cant_particles);
hipLaunchKernelGGL(( Corrected_Velocities_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_velocity_old_y, d_velocity_y, lambda, cant_particles);
hipLaunchKernelGGL(( Corrected_Velocities_Kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, d_velocity_old_z, d_velocity_z, lambda, cant_particles);
if(results){
/** DEBUG **/
hipMemcpy(h_velocity_x, d_velocity_old_x, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_velocity_y, d_velocity_old_y, cant_particles_size, hipMemcpyDeviceToHost);
hipMemcpy(h_velocity_z, d_velocity_old_z, cant_particles_size, hipMemcpyDeviceToHost);
out << " CORRECTED RESULTANT VELOCITIES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i << ": (" << h_velocity_x[i] << " , " << h_velocity_y[i] << " , " << h_velocity_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
dimBlock.x = BLOCK_SIZE_X;
dimBlock.y = BLOCK_SIZE_Y;
/* ********************************************************************************************************** */
/* ******************************************* FIN Iteracion DM ********************************************* */
/* ********************************************************************************************************** */
}
if(!results){ //timer mode ON
gettimeofday(&tv2, NULL);
taim << cant_steps << " " << (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec) << endl;
}
// if(!analytic){
/** Unbindeamos Textura y liberamos memoria **/
hipUnbindTexture(texRef);
hipFreeArray(cuLennard_i);
// }
if(results or amberResults){
out.close();
}
if(coordenates){
crd.close();
}
/* ************************************************ */
/* Liberamos memoria en Dispositivo */
/* ************************************************ */
hipFree(&d_item_particle);
/** Positions **/
hipFree(&d_position_x);
hipFree(&d_position_y);
hipFree(&d_position_z);
/** Distances **/
hipFree(&d_distance_x);
hipFree(&d_distance_y);
hipFree(&d_distance_z);
hipFree(&d_distance_r);
/** Particle's mass **/
hipFree(d_mass);
/** Velocities **/
hipFree(d_velocity_x);
hipFree(d_velocity_y);
hipFree(d_velocity_z);
/** Derivatives **/
hipFree(&d_dEr);
/** Forces **/
hipFree(&d_Force_x);
hipFree(&d_Force_y);
hipFree(&d_Force_z);
hipFree(d_Force_x_resultant);
hipFree(d_Force_y_resultant);
hipFree(d_Force_z_resultant);
/** Kinetic Energy **/
hipFree(d_kinetic_energy);
hipFree(d_kinetic_energy_x);
hipFree(d_kinetic_energy_y);
hipFree(d_kinetic_energy_z);
/* ************************************************ */
/* Liberamos memoria en Host */
/* ************************************************ */
free(h_sigma);
free(h_epsilon);
free(h_mass);
/** Matriz de Lennard Jones **/
if(derivative)
free(h_dLJPot);
else
free(h_LJPot);
free(h_item_particle);
/** Positions **/
free(h_position_x);
free(h_position_y);
free(h_position_z);
/** Distances **/
free(h_distance_x);
free(h_distance_y);
free(h_distance_z);
free(h_distance_r);
/** Velocities **/
free(h_velocity_x);
free(h_velocity_y);
free(h_velocity_z);
/** Chargue **/
free(h_chargue);
/** Forces **/
free(h_Force_x);
free(h_Force_y);
free(h_Force_z);
free(h_Force_x_resultant);
free(h_Force_y_resultant);
free(h_Force_z_resultant);
/** Kinetic Energy **/
free(h_kinetic_energy);
free(h_kinetic_energy_x);
free(h_kinetic_energy_y);
free(h_kinetic_energy_z);
return 0;
}
| 7638d425b08c9897d78fbdd2cd6c09c5649c9ffb.cu | /* Filename: main.cu **************************************************************************** /
*
* INPUT:
* -Particulas.in:
* cantParticles
* type x y z Vx Vy Vz q ; where
* dt ; (x,y,z) = posición respecto de algún (0,0,0)
* temp0 ; (Vx,Vy,Vz) = Velocidades iniciales
* tempi ; q = carga
* tautp ; dt = delta_tiempo
* ; temp0 = temperatura target
* ; tempi = temperatura inicial (No se usa aún)
* ; tautp = factor de corrección de velocidades
*
*
*
* -TablaCoeficientesLennard
* type sigma epsilon mass min max ; donde min y max indican de qué valor
* ; a qué valor hay que densificar las muestras
* ; (NO ESTA IMPLEMENTADO AUN)
*
* ALGORITMO:
* 1-Levantar Coeficientes
* 2-Armar matriz de lennard para cant_samples_r muestras
* Para cada tipo de partícula:
* Calcular en funcion de los coeficientes el potencial para cant_samples_r valores r
* 3-Levantar partículas
* Ordenar y armar índices
* Para cada iteración de MD:
* 4-Calcular distancias:
* Cada partícula contra todas las otras
* Armar matriz de distancias
* 5-Calcular las derivadas respecto de r para cada par de partículas
* 6-Calcular fuerza para cada particula:
* Cada partícula contra todas las otras: matriz 3D
* Obtener fuerza resultante para cada partícula: vector 3D
* 7-Calcular nuevas posiciones: vector 3D
*
***************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <sys/time.h>
/** **************************************************************** **/
/** ************* DEFAULT GLOBAL VARIABLES VALUES ****************** **/
#define BLOCK_SIZE_X 32
#define BLOCK_SIZE_Y 16
#define BLOCK_SIZE (BLOCK_SIZE_X*BLOCK_SIZE_Y)
#define TEXTURE_MEM_SIZE 65000
#define DIF_FINITAS_DELTA 4
/** Variables físicas **/
#define CANT_TYPES 37
#define MAx 15
#define MIn 0.3
#define DIST (MAx - MIn)
#define DELTA_TIEMPO 0.001
#define TEMP 100
#define TAO 0.1
#define BOX_MAX 999 // distancia máxima del 0 para cada coordenada
// Determinamos un cubo de volumen = (2*BOX_MAX) ^3
/** Filenames **/
char* lennardTableFileName = "Input_Mache/TablaCoeficientesLennard";
char* particlesFileName = "Input_Mache/particles.in";
char* debugOutputFilename = "Output_Mache/debug.out";
char* outputFilename = "Output_Mache/results.out";
char* crdFilename = "Output_Mache/mdcrd";
char* timeFilename = "Output_Mache/times.out";
using namespace std;
// streamsize ss = cout.precision();
/** **************************************************************** **/
/** ******************** GLOBAL VARIABLES ************************** **/
texture <float, cudaTextureType2D,cudaReadModeElementType> texRef;
double delta_tiempo = DELTA_TIEMPO;
double temp0 = TEMP;
double tempi;
double tautp = TAO;
double Boltzmann_cte = 0.0019872041;
double box_max_x = BOX_MAX;
double box_max_y = BOX_MAX;
double box_max_z = BOX_MAX;
bool box = true;
double cut = 12;
int cant_steps = 1;
int cant_types = CANT_TYPES;
bool derivative = false;
bool analytic = false;
bool results = false;
bool amberResults = false;
bool coordenates = false;
/** **************************************************************** **/
/** ************************* DEVICE ******************************* **/
__global__
void lennard_Kernel(float* LJ_POT, double* EPS, double* SIG,
double e, double s, double var, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
/* Variables */
double sig12 = (double) (s + SIG[y])/2;
double eps12 = (double) sqrt(e * EPS[y]);
double r = (double) MIn+x*var;
/* Resultado */
LJ_POT[y*width +x] = (float) 4.0*eps12*( pow((sig12/r),12) - pow((sig12/r),6));
}
/** **************************************************************** **/
__global__
void derivatives_lennard_Kernel(float* dLJ_POT, double* EPS, double* SIG,
double e, double s, double var, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
/* Variables */
double sig12 = (double) (s + SIG[y])/2;
double eps12 = (double) sqrt(e * EPS[y]);
double r = (double) MIn+x*var;
/* Resultado */
dLJ_POT[y*width +x] = (float) 24.0*eps12*( pow(sig12,6)/ pow(r,7) - 2 * pow(sig12,12)/ pow(r,13));
}
/** **************************************************************** **/
__global__
void close_distances_kernel(double* X, double* Y, double* Z, double* R,
double* position_x, double* position_y, double* position_z,
double box_x, double box_y, double box_z, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int j = blockIdx.y * blockDim.y + threadIdx.y;
if(i >= width || j >= height) {return;}
unsigned int pos = j*width+i;
double _X = position_x[i] - position_x[j];
double _Y = position_y[i] - position_y[j];
double _Z = position_z[i] - position_z[j];
_X = _X - box_x * round((double) _X/box_x);
_Y = _Y - box_y * round((double) _Y/box_y);
_Z = _Z - box_z * round((double) _Z/box_z);
X[pos] = _X;
Y[pos] = _Y;
Z[pos] = _Z;
R[pos] = (double) sqrt( _X*_X + _Y*_Y + _Z*_Z );
}
/** **************************************************************** **/
__global__
void distances_kernel(double* R, double* X, double* Y, double* Z,
double* x1, double* y1, double* z1, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
double x_ = x1[x] - x1[y];
double y_ = y1[x] - y1[y];
double z_ = z1[x] - z1[y];
X[y*width+x] = x_;
Y[y*width+x] = y_;
Z[y*width+x] = z_;
R[y*width+x] = (double) sqrt( x_*x_ + y_*y_ + z_*z_ );
}
/** **************************************************************** **/
__global__
void derivative_E_r(double* dEr, double* r, double cut, int* item_to_type,
int cant_samples_r, int cant_types, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {dEr[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partícula correspondiente */
/** type of particles **/
float t_o_p_1 = (float) item_to_type[y] * cant_types; //this one decides which subMatrix to use
float t_o_p_2 = (float) item_to_type[x] + 0.5 + t_o_p_1; //this one decides which row on these
/** Convierto r a subíndice de matriz de lennard-jones **/
/** r = (MAX-MIN) * X / N + MIN **/
/** x = (r-MIN) * N / (MAX-MIN) **/
float index_x = (float)((double) (r[y*width+x] - MIn) * (double) cant_samples_r / DIST + 0.5); // convert r to x
double E_r_up = (double) tex2D( texRef, index_x + DIF_FINITAS_DELTA, t_o_p_2 );
double E_r_dwn = (double) tex2D( texRef, index_x - DIF_FINITAS_DELTA, t_o_p_2 );
double r_dif = DIST * 2 * (DIF_FINITAS_DELTA) / cant_samples_r;
dEr[y*width+x] = (E_r_up - E_r_dwn) / (r_dif);
}
/** **************************************************************** **/
__global__
void direct_derivative_E_r(double* dEr, double* r, double cut, int* item_to_type,
int cant_samples_r, int cant_types, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {dEr[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partícula correspondiente */
/** type of particles **/
float t_o_p_1 = (float) item_to_type[y] * cant_types; //this one decides which subMatrix to use
float t_o_p_2 = (float) item_to_type[x] + 0.5 + t_o_p_1; //this one decides which row on these
/** Convierto r a subíndice de matriz de lennard-jones **/
/** r = (MAX-MIN) * X / N + MIN **/
/** x = (r-MIN) * N / (MAX-MIN) **/
float index_x = (float)((double) (r[y*width+x] - MIn) * (double) cant_samples_r / DIST + 0.5); // convert r to x
dEr[y*width+x] = (double) tex2D( texRef, index_x, t_o_p_2 );
}
/** **************************************************************** **/
__global__
void E_r(double* Er, double* r, double cut, int* item_to_type,
int cant_samples_r, int cant_types, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {Er[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partícula correspondiente */
/** type of particles **/
float t_o_p_1 = (float) item_to_type[y]; //this one decides which subMatrix to use
float t_o_p_2 = (float) item_to_type[x]; //this one decides which row on these
float row = t_o_p_2 + 0.5 + (t_o_p_1* cant_types);
/** Convierto r a subíndice de matriz de lennard-jones **/
/** r = (MAX-MIN) * X / N + MIN **/
/** x = (r-MIN) * N / (MAX-MIN) **/
float index_x = (float)((double) (r[y*width+x] - MIn) * (double) cant_samples_r / DIST + 0.5); // convert r to x
Er[y*width+x] = (double) tex2D( texRef, index_x, row );
}
/* ***************************************************************** **/
/** +ANALYTIC */
/** **************************************************************** **/
__global__
void derivative_E_r_analytic(double* dEr, double* r, double cut, int* item_to_type, int cant_samples_r,
double* EPS, double* SIG, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {dEr[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partícula correspondiente */
/** type of particle 2 **/
int type_i = item_to_type[x];
int type_j = item_to_type[y];
double sig12 = (double) (SIG[type_i] + SIG[type_j])/2;
double eps12 = (double) sqrt(EPS[type_i] * EPS[type_j]);
dEr[y*width+x] = (double) 24.0*eps12*( pow(sig12,6)/ pow(r[y*width+x],7) - 2 * pow(sig12,12)/ pow(r[y*width+x],13));
}
__global__
void E_r_analytic(double* Er, double* r, double cut, int* item_to_type, int cant_samples_r,
double* EPS, double* SIG, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; /** particula 2 **/
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y; /** particula 1 **/
/* Dentro del bloque correspondiente */
if(x >= width || y >= height) {return;}
if(x == y || r[y*width+x] >= cut) {Er[y*width+x] = 0; return;}
/* valor del Potencial para la distancia r,
* para el tipo de partícula correspondiente */
/** type of particle 2 **/
int type_i = item_to_type[x];
int type_j = item_to_type[y];
double sig12 = (double) (SIG[type_i] + SIG[type_j])/2;
double eps12 = (double) sqrt(EPS[type_i] * EPS[type_j]);
Er[y*width+x] = (double) 4.0*eps12*( pow((sig12/r[y*width+x]),12) - pow((sig12/r[y*width+x]),6));
}
/** **************************************************************** **/
/** -ANALYTIC */
/* ***************************************************************** **/
/** **************************************************************** **/
/* Fx = dE(r) / dr * (x1-x2) / r */
__global__
void Parcial_Forces_Kernel(double* force, double* dEr, double* dif, double* r, int width, int height)
{
/* Elemento de la matriz a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x >= width || y >= height) {return;}
if(x == y) {force[y*width+x] = 0; return;}
force[y*width+x] = dEr[y*width+x] * dif[y*width+x] / r[y*width+x];
}
/** **************************************************************** **/
__global__
void Resultant_Forces_Kernel(double* result, double* forces, int cant)
{
/* Elemento del vector a calcular */
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
if(x >= cant) {return;}
int i = 0;
double tmp = 0;
int row = x*cant;
for(; i < cant; i++){
tmp += forces[row + i];
}
result[x] = tmp;
}
/** **************************************************************** **/
/* V(t + Dt/2) = V(t - Dt/2) + [ F(t) * Dt ] / m */
__global__
void Resultant_Velocities_Kernel(double* velocity, double* old_velocity, double* force, double* m,
int* item_to_type, double delta_tiempo, int cant_particles)
{
/* Elemento de la matriz a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i >= cant_particles) {return;}
double Vt = old_velocity[i];
int type = item_to_type[i];
double dtx = delta_tiempo*20.455;
/* Result */
velocity[i] = Vt + ( (force[i]*dtx) / m[type] );
}
/** **************************************************************** **/
/* P(t + Dt) = P(t) + V(t + Dt/2) * Dt */
__global__
void Resultant_Positions_Kernel(double* positions, double* velocity, double delta_tiempo, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i >= cant) {return;}
double dtx = delta_tiempo*20.455;
positions[i] = positions[i] + (velocity[i] * dtx);
}
/** **************************************************************** **/
/* -BOX_MAX 0 BOX_MAX */
/* |-----------------|-----------------| */
__global__
void Adjustin_Positions_Kernel(double* position, double box_max, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i >= cant) {return;}
double pos = position[i] - box_max;
if(pos > 0){
position[i] = -box_max + fmod(pos, (double) (2*box_max));
}
if(pos < -2*box_max){
position[i] = box_max + fmod(pos, (double) (2*box_max));
}
}
/** **************************************************************** **/
/* Ek = |v|^2 * m / 2 */
/* Ek_x = (v_x)^2 * m / 2 */
__global__
void Kinetic_Energy_Kernel(double* kE, double* vold, double* v, double* m, int* item_to_type, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i>= cant) {return;}
double vi = vold[i] + v[i];
int type = item_to_type[i];
kE[i] = vi * vi * m[type] / 8;
}
/** **************************************************************** **/
__global__
void Total_Kinetic_Energy_Kernel(double* kE, double* Ke_x, double* Ke_y, double* Ke_z, int cant)
{
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i>= cant) {return;}
kE[i] = Ke_x[i] + Ke_y[i] + Ke_z[i];
}
/** **************************************************************** **/
__global__
void Corrected_Velocities_Kernel(double* vold, double* v, double lambda, int cant){
/* Elemento del vector a calcular */
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if(i>= cant) {return;}
vold[i] = v[i] * lambda;
}
/** **************************************************************** **/
/** *************************** HOST ******************************* **/
int main( int argc, char* argv[] )
{
for(uint i = 0; i < argc; i++){
if(strcmp(argv[i], "-t") == 0){
/* outputTimeFilename */
timeFilename = argv[i+1];
}
if(strcmp(argv[i], "-a") == 0){
/* ANALYTIC mode */
analytic = true;
}
if(strcmp(argv[i], "-d") == 0){
/* DERIVATIVE mode */
derivative = true;
}
if(strcmp(argv[i], "-r") == 0){
/* RESULTS or TIMER mode */
results = true;
amberResults = true;
}
if(strcmp(argv[i], "-ar") == 0){
/* RESULTS or TIMER mode */
amberResults = true;
}
if(strcmp(argv[i], "-c") == 0){
/* PRINT mdcrd file */
coordenates = true;
}
}
if (derivative)
cout << "Derivative" << endl;
if (analytic)
cout << "Analytic" << endl;
if(results){
cout << "DEBUG mode ON" << endl;
}
if(amberResults){
cout << "AMBER results ON" << endl;
}
fstream out;
fstream crd;
if(results or amberResults){
/* Output file */
out.open(outputFilename,fstream::out);
streamsize ss = out.precision();
out << setprecision(20);
}
if(coordenates){
/* CRD output file */
crd.open(crdFilename,fstream::out);
crd << setprecision(3);
crd.setf( std::ios::fixed, std:: ios::floatfield );
crd << " POS(x) POS(y) POS(z)" << endl;
}
struct timeval tv1, tv2;
fstream taim;
if(!results){ //timer mode ON
/* Time output file */
taim.open(timeFilename, fstream::app | fstream::out);
taim << setprecision(20);
}
/* Levantamos Coeficientes de Lennard */
ifstream table (lennardTableFileName);
table >> cant_types;
/**Variables y memoria*/
size_t cant_types_size = cant_types * sizeof(double);
vector<string> h_type;
h_type.resize(cant_types);
double* h_sigma = (double*) ( malloc(cant_types_size));
double* h_epsilon = (double*) ( malloc(cant_types_size));
double* h_mass = (double*) ( malloc(cant_types_size));
/**Levantamos datos*/
for(int j = 0; j<cant_types ; j++){
table >> h_type[j];
table >> h_sigma[j];
table >> h_epsilon[j];
table >> h_mass[j];
}
table.close();
/* Armamos matrices de lennard */
/**Variables y memoria**/
int cant_samples_r = TEXTURE_MEM_SIZE/(sizeof(float)); // cant of original sample values (máximo permitido por mem de textura)
double var = DIST / ((double) cant_samples_r); // variation of r
size_t cant_samples_r_size = cant_samples_r * sizeof(float);
float* h_dLJPot;
float* h_LJPot;
if(derivative)
h_dLJPot = (float*) malloc(cant_samples_r_size*cant_types*cant_types); // #samples * #particles * #particles (*float)
else
h_LJPot = (float*) malloc(cant_samples_r_size*cant_types*cant_types); // #samples * #particles * #particles (*float)
int width = cant_samples_r;
int height = cant_types;
dim3 dimBlock(BLOCK_SIZE_X,BLOCK_SIZE_Y);
dim3 dimGrid( (int) ceil((double)width / (double)dimBlock.x), (int) ceil((double)height / (double)dimBlock.y) );
double* d_EPS;
double* d_SIG;
float* d_LJPot;
float* d_dLJPot;
cudaMalloc(&d_EPS, cant_types_size);
cudaMalloc(&d_SIG, cant_types_size);
cudaMemcpy(d_EPS, h_epsilon, cant_types_size, cudaMemcpyHostToDevice);
cudaMemcpy(d_SIG, h_sigma, cant_types_size, cudaMemcpyHostToDevice);
if(derivative)
cudaMalloc(&d_dLJPot, cant_samples_r_size * cant_types);
else
cudaMalloc(&d_LJPot, cant_samples_r_size * cant_types);
/** Rellenamos datos con CUDA **/
if(derivative) {
for(int a = 0; a<cant_types; a++){
derivatives_lennard_Kernel<<<dimGrid, dimBlock>>>(d_dLJPot, d_EPS, d_SIG, h_epsilon[a], h_sigma[a], var, width, height);
cudaMemcpy( (float*) &(h_dLJPot[(a*cant_samples_r*cant_types)]), d_dLJPot, cant_types * cant_samples_r_size, cudaMemcpyDeviceToHost);
}
} else {
for(int a = 0; a<cant_types; a++){
lennard_Kernel<<<dimGrid, dimBlock>>>(d_LJPot, d_EPS, d_SIG, h_epsilon[a], h_sigma[a], var, width, height);
cudaMemcpy( (float*) &(h_LJPot[(a*cant_samples_r*cant_types)]), d_LJPot, cant_types * cant_samples_r_size, cudaMemcpyDeviceToHost);
}
}
/** Liberamos memoria de CUDA **/
cudaFree(&d_EPS);
cudaFree(&d_SIG);
cudaFree(&d_LJPot);
if(results){
/** DEBUG **/
if(derivative)
out << " derivative LENNARD " << endl;
else
out << " LENNARD " << endl;
for(int a = 0; a<cant_types; a++){
out << " Type = " << h_type[a] << endl << " ";
for(int i = 0; i<cant_types; i++){
for(int j = 0; j<cant_samples_r; j+= cant_samples_r/8){
if(derivative)
out << h_dLJPot[(a*cant_types*cant_samples_r)+(i*cant_samples_r)+j] << ", ";
else
out << h_LJPot[(a*cant_types*cant_samples_r)+(i*cant_samples_r)+j] << ", ";
}
out << endl << " ";
}
out << "***********************************************************************************" << endl;
}
/** DEBUG **/
}
/*Levantamos partículas*/
fstream particles;
particles.open(particlesFileName);
/** Variables y memoria **/
uint cant_particles;
double* h_position_x;
double* h_position_y;
double* h_position_z;
double* h_velocity_x;
double* h_velocity_y;
double* h_velocity_z;
double* h_velocity_old_x;
double* h_velocity_old_y;
double* h_velocity_old_z;
double* h_chargue;
double h_box_x;
double h_box_y;
double h_box_z;
double h_box_alpha;
double h_box_beta;
double h_box_gamma;
vector<string> h_particle_type;
particles >> cant_particles;
size_t cant_particles_size = cant_particles * sizeof(double);
h_position_x = (double*)malloc(cant_particles_size);
h_position_y = (double*)malloc(cant_particles_size);
h_position_z = (double*)malloc(cant_particles_size);
h_velocity_x = (double*)malloc(cant_particles_size);
h_velocity_y = (double*)malloc(cant_particles_size);
h_velocity_z = (double*)malloc(cant_particles_size);
h_velocity_old_x = (double*)malloc(cant_particles_size);
h_velocity_old_y = (double*)malloc(cant_particles_size);
h_velocity_old_z = (double*)malloc(cant_particles_size);
h_chargue = (double*)malloc(cant_particles_size);
h_particle_type.resize(cant_particles);
/** Guardamos datos **/
for(uint i = 0; i < cant_particles ; i++) {
particles >> h_particle_type[i];
particles >> h_position_x[i];
particles >> h_position_y[i];
particles >> h_position_z[i];
particles >> h_velocity_old_x[i];
particles >> h_velocity_old_y[i];
particles >> h_velocity_old_z[i];
particles >> h_chargue[i];
}
/** Perioricidad **/
//TODO: por ahora usamos cubo,
//situamos el cero en el centro del mismo
//Recibimos en orden x, y, z
particles >> box;
if(box){
cout << " Levantamos caja" << endl;
particles >> h_box_x;
particles >> h_box_y;
particles >> h_box_z;
particles >> h_box_alpha;
particles >> h_box_beta;
particles >> h_box_gamma;
if( h_box_alpha != 90 or h_box_beta != 90 or h_box_gamma != 90){
cout << " Se forzaron los angulos para que sea un CUBO: " << endl;
}
box_max_x = h_box_x/2;
box_max_y = h_box_y/2;
box_max_z = h_box_z/2;
}
/** Parametros **/
particles >> cant_steps;
particles >> delta_tiempo;
particles >> temp0;
particles >> tempi;
particles >> tautp;
particles >> cut;
particles.close();
// if(results){
// /** DEBUG **/
// out << " INITIAL VALUES" << endl;
// for(int i = 0; i<cant_particles; i++){
// out << " Type: " << h_particle_type[i] << " | Pos: (" << h_position_x[i] << " , " << h_position_y[i] << " , " << h_position_z[i] << ")";
// out << " | Vel: (" << h_velocity_old_x[i] << " , " << h_velocity_old_y[i] << " , " << h_velocity_old_z[i] << ")" << endl;
// }
// out << endl;
//
// /** DEBUG **/
// }
if(results){
// /** DEBUG **/
// out << " CANT of TYPES" << endl;
// for(int i = 0; i < h_type.size(); i++){
// out << " " << h_type[i] << " " << cant_of_typ[i] << endl;
// }
// out << endl;
/** DEBUG **/
}
/* Armamos estructura de items para saber de qué tipo
/* es la partícula en la que estamos en CUDA */
/** h_particle_type = H H H H H K K K K K O O O O O O O O O ... **/
/** h_item_particle = 1 1 1 1 1 3 3 3 3 3 9 9 9 9 9 9 9 9 9 ... **/
int * h_item_particle = (int*)malloc(cant_particles * sizeof(int));
int * d_item_particle;
cudaMalloc(&d_item_particle, cant_particles * sizeof(int));
/** Convertimos anotamos type de la partícula como un int que sería el index dentro de h_type **/
for(int i = 0; i< cant_particles; i++){
for(int j = 0; j< h_type.size(); j++){
if(h_type[j] == h_particle_type[i]){
h_item_particle[i] = j;
break;
}
}
}
cudaMemcpy(d_item_particle, h_item_particle, cant_particles * sizeof(int), cudaMemcpyHostToDevice);
// if(results){
// /** DEBUG **/
// out << " ITEM to TYPE" << endl;
// for(int i = 0; i < cant_particles; i++){
// out << " Particle[" << i << "] | Type: " << h_type[h_item_particle[i]] << " (index :" << h_item_particle[i] << ") " << endl;
// }
// out << endl;
// /** DEBUG **/
// }
/* ************************************************ */
/* MANEJO DE MEMORIA EN EL DISPOSITIVO GPU */
/* ************************************************ */
/** Variables **/
size_t s_size = cant_particles_size * cant_particles;
/** Positions **/
double* d_position_x;
double* d_position_y;
double* d_position_z;
cudaMalloc(&d_position_x, cant_particles_size);
cudaMalloc(&d_position_y, cant_particles_size);
cudaMalloc(&d_position_z, cant_particles_size);
cudaMemcpy(d_position_x, h_position_x, cant_particles_size, cudaMemcpyHostToDevice);
cudaMemcpy(d_position_y, h_position_y, cant_particles_size, cudaMemcpyHostToDevice);
cudaMemcpy(d_position_z, h_position_z, cant_particles_size, cudaMemcpyHostToDevice);
/** Positions **/
double* d_pos_close_x;
double* d_pos_close_y;
double* d_pos_close_z;
cudaMalloc(&d_pos_close_x, cant_particles_size);
cudaMalloc(&d_pos_close_y, cant_particles_size);
cudaMalloc(&d_pos_close_z, cant_particles_size);
/** Particle's mass **/
double* d_mass;
cudaMalloc(&d_mass, cant_types_size);
cudaMemcpy(d_mass, h_mass, cant_types_size, cudaMemcpyHostToDevice);
/** Velocities **/
double* d_velocity_x;
double* d_velocity_y;
double* d_velocity_z;
double* d_velocity_old_x;
double* d_velocity_old_y;
double* d_velocity_old_z;
cudaMalloc(&d_velocity_x, cant_particles_size);
cudaMalloc(&d_velocity_y, cant_particles_size);
cudaMalloc(&d_velocity_z, cant_particles_size);
cudaMalloc(&d_velocity_old_x, cant_particles_size);
cudaMalloc(&d_velocity_old_y, cant_particles_size);
cudaMalloc(&d_velocity_old_z, cant_particles_size);
cudaMemcpy(d_velocity_old_x, h_velocity_old_x, cant_particles_size, cudaMemcpyHostToDevice);
cudaMemcpy(d_velocity_old_y, h_velocity_old_y, cant_particles_size, cudaMemcpyHostToDevice);
cudaMemcpy(d_velocity_old_z, h_velocity_old_z, cant_particles_size, cudaMemcpyHostToDevice);
/** Distances **/
double* d_distance_x;
double* d_distance_y;
double* d_distance_z;
double* d_distance_r;
cudaMalloc(&d_distance_x, s_size);
cudaMalloc(&d_distance_y, s_size);
cudaMalloc(&d_distance_z, s_size);
cudaMalloc(&d_distance_r, s_size);
/** Derivatives **/
double* d_dEr;
cudaMalloc(&d_dEr, s_size);
/** VDWAALS **/
double* d_Er;
cudaMalloc(&d_Er, s_size);
/** Forces **/
double* d_Force_x;
double* d_Force_y;
double* d_Force_z;
cudaMalloc(&d_Force_x, s_size);
cudaMalloc(&d_Force_y, s_size);
cudaMalloc(&d_Force_z, s_size);
double* d_Force_x_resultant;
double* d_Force_y_resultant;
double* d_Force_z_resultant;
cudaMalloc(&d_Force_x_resultant, cant_particles_size);
cudaMalloc(&d_Force_y_resultant, cant_particles_size);
cudaMalloc(&d_Force_z_resultant, cant_particles_size);
/** Kinetic Energy **/
double* d_kinetic_energy;
double* d_kinetic_energy_x;
double* d_kinetic_energy_y;
double* d_kinetic_energy_z;
cudaMalloc(&d_kinetic_energy, cant_particles_size);
cudaMalloc(&d_kinetic_energy_x, cant_particles_size);
cudaMalloc(&d_kinetic_energy_y, cant_particles_size);
cudaMalloc(&d_kinetic_energy_z, cant_particles_size);
/* ************************************************ */
/* MANEJO DE MEMORIA EN EL HOST */
/* ************************************************ */
/** Distances **/
double (*h_distance_x)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_distance_y)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_distance_z)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_distance_r)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
/** Forces **/
double (*h_Force_x)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_Force_y)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double (*h_Force_z)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
double* h_Force_x_resultant = (double*)malloc(cant_particles_size);
double* h_Force_y_resultant = (double*)malloc(cant_particles_size);
double* h_Force_z_resultant = (double*)malloc(cant_particles_size);
/** Kinetic Energy **/
double* h_kinetic_energy = (double*)malloc(cant_particles_size);
double* h_kinetic_energy_x = (double*)malloc(cant_particles_size);
double* h_kinetic_energy_y = (double*)malloc(cant_particles_size);
double* h_kinetic_energy_z = (double*)malloc(cant_particles_size);
/* ************************************************ */
/* Calculamos ENERGIA CINETICA deseada */
/* ************************************************ */
/* Ek = Kb * T (3N - Nc) / 2 */
double Nc = 5;
double factor_conv_T_Ek = 2 / (Boltzmann_cte * (3 *cant_particles - Nc) );
if(amberResults){
double kinetic_Energy = Boltzmann_cte * temp0 * (3*cant_particles - Nc) / 2;
/** DEBUG **/
out << " THEORETICAL VALUES:" << endl << endl;
out << " * Kb = " << Boltzmann_cte << endl << endl;
out << " * Temperature = " << temp0 << endl << endl;
out << " * Kinetic Energy = " << kinetic_Energy << endl << endl;
out << " * Factor_conv_T_Ek = " << factor_conv_T_Ek << endl << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Seteamos la memoria de TEXTURA */
/* ************************************************ */
cudaArray* cuLennard_i;
// if(!analytic){
/** Usamos texturas **/
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc( 32, 0, 0, 0, cudaChannelFormatKindFloat );
cudaMallocArray(&cuLennard_i, &channelDesc, cant_samples_r, cant_types*cant_types); //width x height
texRef.addressMode[0] = cudaAddressModeClamp;
texRef.filterMode = cudaFilterModeLinear; //cudaFilterModePoint; // //Tipo de interpolación
if(derivative) {
cudaMemcpyToArray(cuLennard_i, 0, 0, h_dLJPot, cant_types * cant_types * cant_samples_r_size, cudaMemcpyHostToDevice);
} else {
cudaMemcpyToArray(cuLennard_i, 0, 0, h_LJPot, cant_types * cant_types * cant_samples_r_size, cudaMemcpyHostToDevice);
}
/** Bindeamos la textura **/
cudaBindTextureToArray(texRef, cuLennard_i, channelDesc);
// }
if(amberResults){
out << endl << " ESTARTIN DE PROGRAM" << endl;
out << " Amaunt of itereishons = " << cant_steps << endl << endl;
}
if(!results){ //timer mode ON
/** Esperamos a que termine de bindear la textura **/
cudaDeviceSynchronize();
/** Arrancamos medicion del tiempo **/
gettimeofday(&tv1, NULL);
}
for(int step = 0; step < cant_steps; step++){
/* ********************************************************************************************************** */
/* ****************************************** INICIO Iteracion DM ******************************************* */
/* ********************************************************************************************************** */
if(amberResults){
out << "/* ************************************************************************************************ */" << endl;
out << "/* ************************************* INICIO Iteracion " << step << " ************************************ */" << endl;
out << "/* ************************************************************************************************ */" << endl;
}
dimBlock.x = BLOCK_SIZE_X;
dimBlock.y = BLOCK_SIZE_Y;
/* ************************************************ */
/* Calculamos Matriz de Distancias entre partículas */
/* ************************************************ */
/**Variables y memoria*/
width = cant_particles;
height = cant_particles;
dimGrid.x = ceil((double)width / (double)dimBlock.x);
dimGrid.y = ceil((double)height / (double)dimBlock.y);
/**Rellenamos datos**/
close_distances_kernel<<<dimGrid, dimBlock>>>(d_distance_x, d_distance_y, d_distance_z, d_distance_r,
d_position_x, d_position_y, d_position_z,
h_box_x, h_box_y, h_box_z, width, height);
// distances_kernel<<<dimGrid, dimBlock>>>(d_distance_r, d_distance_x, d_distance_y, d_distance_z,
// d_position_x, d_position_y, d_position_z, width, height);
if(results){
/** DEBUG **/
cudaMemcpy(h_distance_r, d_distance_r, s_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_distance_x, d_distance_x, s_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_distance_y, d_distance_y, s_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_distance_z, d_distance_z, s_size, cudaMemcpyDeviceToHost);
out << " DISTANCES" << endl << " ";
double (*matriz)[cant_particles] = (double (*)[cant_particles]) h_distance_r;
for(int i = 0; i<cant_particles; i+= cant_particles/8){
out << " " << i << " | ";
for(int j = 0; j<cant_particles; j+= cant_particles/8){
out << matriz[i][j] << "\t";
}
out << endl << " ";
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Derivadas */
/* ************************************************ */
/** Variables y memoria **/
width = cant_particles;
height = cant_particles;
dimGrid.x = ceil((double)width / (double)dimBlock.x);
dimGrid.y = ceil((double)height / (double)dimBlock.y);
if(analytic){
derivative_E_r_analytic<<<dimGrid, dimBlock>>>(d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
if(amberResults){
/** Calculo la energia E(r) para debug **/
E_r_analytic<<<dimGrid, dimBlock>>>(d_Er, d_distance_r, cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
}
} else {
/** Calculo de la derivada dE(r)/dr usando diferencias finitas **/
if(derivative){
// derivative_E_r_analytic<<<dimGrid, dimBlock>>>(d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
direct_derivative_E_r<<<dimGrid, dimBlock>>>(d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, cant_types, width, height);
} else {
// derivative_E_r_analytic<<<dimGrid, dimBlock>>>(d_dEr, d_distance_r, d_cut, d_item_particle, cant_samples_r, d_EPS, d_SIG, width, height);
derivative_E_r<<<dimGrid, dimBlock>>>(d_dEr, d_distance_r, cut, d_item_particle, cant_samples_r, cant_types, width, height);
if(amberResults){
/** Calculo la energia E(r) para debug **/
E_r<<<dimGrid, dimBlock>>>(d_Er, d_distance_r, cut, d_item_particle, cant_samples_r, cant_types, width, height);
}
}
}
if(amberResults){
if(!derivative){
/** DEBUG **/
out << " Lennard-Jones" << endl << " ";
double vdwaals = 0;
double (*h_Er)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
cudaMemcpy(h_Er, d_Er, s_size, cudaMemcpyDeviceToHost);
for(int i = 0; i<cant_particles; i++){
// out << " " << i << " | ";
for(int j = 0; j<cant_particles; j++){
// out << h_Er[i][j] << "\t";
if(i<=j)
vdwaals += h_Er[i][j];
}
// out << endl << " ";
}
// out << endl;
out << " VDWAALS = " << vdwaals << endl << endl;
free(h_Er);
/** DEBUG **/
}
}
if(results){
/** DEBUG **/
out << " DERIVATIVES" << endl << " ";
double (*h_dEr)[cant_particles] = (double (*)[cant_particles]) ( malloc(s_size));
cudaMemcpy(h_dEr, d_dEr, s_size, cudaMemcpyDeviceToHost);
for(int i = 0; i<cant_particles; i+= cant_particles/8){
out << " " << i << " | ";
for(int j = 0; j<cant_particles; j+= cant_particles/8){
out << h_dEr[i][j] << "\t";
}
out << endl << " ";
}
out << endl;
free(h_dEr);
/** DEBUG **/
}
if(results){
/** DEBUG **/
cudaMemcpy(h_velocity_old_x, d_velocity_old_x, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_velocity_old_y, d_velocity_old_y, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_velocity_old_z, d_velocity_old_z, cant_particles_size, cudaMemcpyDeviceToHost);
out << " OLD VELOCITIES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_velocity_old_x[i] << " , " << h_velocity_old_y[i] << " , " << h_velocity_old_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos FUERZAS resultantes */
/* ************************************************ */
/* Fx = dE(r) / dr * (x1-x2) / r *
* Fy = dE(r) / dr * (y1-y2) / r *
* Fz = dE(r) / dr * (z1-z2) / r */
/* Calculo de vectores parciales */
/**Variables y memoria*/
width = cant_particles;
height = cant_particles;
dimGrid.x = ceil((double)width / (double)dimBlock.x);
dimGrid.y = ceil((double)height / (double)dimBlock.y);
/** Calculo del vector F **/
Parcial_Forces_Kernel<<<dimGrid, dimBlock>>>(d_Force_x, d_dEr, d_distance_x, d_distance_r, width, height);
Parcial_Forces_Kernel<<<dimGrid, dimBlock>>>(d_Force_y, d_dEr, d_distance_y, d_distance_r, width, height);
Parcial_Forces_Kernel<<<dimGrid, dimBlock>>>(d_Force_z, d_dEr, d_distance_z, d_distance_r, width, height);
if(results){
/** DEBUG **/
cudaMemcpy(h_Force_x, d_Force_x, s_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_Force_y, d_Force_y, s_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_Force_z, d_Force_z, s_size, cudaMemcpyDeviceToHost);
out << " FORCES" << endl << " ";
for(int i = 0; i<cant_particles; i++){
for(int j = 0; j<cant_particles; j++){
out << "(" << h_Force_x[i][j] << " , " << h_Force_y[i][j] << " , " << h_Force_z[i][j] << ")\t";
}
out << endl << " ";
}
out << endl;
/** DEBUG **/
}
/* Calculo del vector F */
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
Resultant_Forces_Kernel<<<dimGrid, dimBlock>>>(d_Force_x_resultant, d_Force_x, cant_particles);
Resultant_Forces_Kernel<<<dimGrid, dimBlock>>>(d_Force_y_resultant, d_Force_y, cant_particles);
Resultant_Forces_Kernel<<<dimGrid, dimBlock>>>(d_Force_z_resultant, d_Force_z, cant_particles);
if(results){
/** DEBUG **/
cudaMemcpy(h_Force_x_resultant, d_Force_x_resultant, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_Force_y_resultant, d_Force_y_resultant, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_Force_z_resultant, d_Force_z_resultant, cant_particles_size, cudaMemcpyDeviceToHost);
out << " RESULTANT FORCES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_Force_x_resultant[i] << " , " << h_Force_y_resultant[i] << " , " << h_Force_z_resultant[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos VELOCIDADES Resultantes */
/* ************************************************ */
/* V(t + Dt/2) = V(t - Dt/2) + [ F(t) * Dt ] / m */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Piso las velocidades acumuladas al tiempo t con las nuevas de t+Dt */
Resultant_Velocities_Kernel<<<dimGrid, dimBlock>>>(d_velocity_x, d_velocity_old_x, d_Force_x_resultant, d_mass, d_item_particle, delta_tiempo, cant_particles);
Resultant_Velocities_Kernel<<<dimGrid, dimBlock>>>(d_velocity_y, d_velocity_old_y, d_Force_y_resultant, d_mass, d_item_particle, delta_tiempo, cant_particles);
Resultant_Velocities_Kernel<<<dimGrid, dimBlock>>>(d_velocity_z, d_velocity_old_z, d_Force_z_resultant, d_mass, d_item_particle, delta_tiempo, cant_particles);
if(results){
/** DEBUG **/
cudaMemcpy(h_velocity_x, d_velocity_x, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_velocity_y, d_velocity_y, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_velocity_z, d_velocity_z, cant_particles_size, cudaMemcpyDeviceToHost);
out << " RESULTANT VELOCITIES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_velocity_x[i] << " , " << h_velocity_y[i] << " , " << h_velocity_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos POSICIONES Resultantes */
/* ************************************************ */
/* P(t + Dt) = P(t) + V(t + Dt/2) * Dt */
/* (TODO: ajustar condiciones de perioricidad */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
Resultant_Positions_Kernel<<<dimGrid, dimBlock>>>(d_position_x, d_velocity_x, delta_tiempo, cant_particles);
Resultant_Positions_Kernel<<<dimGrid, dimBlock>>>(d_position_y, d_velocity_y, delta_tiempo, cant_particles);
Resultant_Positions_Kernel<<<dimGrid, dimBlock>>>(d_position_z, d_velocity_z, delta_tiempo, cant_particles);
if(results){
/** DEBUG **/
cudaMemcpy(h_position_x, d_position_x, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_position_y, d_position_y, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_position_z, d_position_z, cant_particles_size, cudaMemcpyDeviceToHost);
out << " RESULTANT POSITIONS" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_particle_type[i] << " (" << h_position_x[i] << " , " << h_position_y[i] << " , " << h_position_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos POSICIONES con PERIORICIDAD */
/* ************************************************ */
/* P(t + Dt) = P(t) + V(t + Dt/2) * Dt */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
Adjustin_Positions_Kernel<<<dimGrid, dimBlock>>>(d_position_x, box_max_x, cant_particles);
Adjustin_Positions_Kernel<<<dimGrid, dimBlock>>>(d_position_y, box_max_y, cant_particles);
Adjustin_Positions_Kernel<<<dimGrid, dimBlock>>>(d_position_z, box_max_z, cant_particles);
if(coordenates){
/** DEBUG **/
cudaMemcpy(h_position_x, d_position_x, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_position_y, d_position_y, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_position_z, d_position_z, cant_particles_size, cudaMemcpyDeviceToHost);
if(results){
out << " RESULTANT POSITIONS in the CUBE" << endl;
for(int i = 0; i<cant_particles; i++){
out << i+1 << ": (" << h_particle_type[i] << " (" << h_position_x[i] << " , " << h_position_y[i] << " , " << h_position_z[i] << ")" << endl;
}
out << endl;
}
for(int i = 0; i<cant_particles; i+=2){
crd << " " << h_position_x[i] << " " << h_position_y[i] << " " << h_position_z[i];
if(i+1 < cant_particles){
crd << " " << h_position_x[i+1] << " " << h_position_y[i+1] << " " << h_position_z[i+1] << endl;
} else
crd << endl;
}
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Ek de cada partícula */
/* ************************************************ */
/* Ek = |vp|^2 * m / 2 con vp = (vold+v)/2 */
/* Ek_x = (v_x)^2 * m / 2 */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Calculamos la energía cinética para las tres coordenadas de cada partícula **/
/** Puede hacerse directamente así, sin calcular módulo por propiedades algebraicas **/
Kinetic_Energy_Kernel<<<dimGrid, dimBlock>>>(d_kinetic_energy_x, d_velocity_old_x, d_velocity_x, d_mass, d_item_particle, cant_particles);
Kinetic_Energy_Kernel<<<dimGrid, dimBlock>>>(d_kinetic_energy_y, d_velocity_old_y, d_velocity_y, d_mass, d_item_particle, cant_particles);
Kinetic_Energy_Kernel<<<dimGrid, dimBlock>>>(d_kinetic_energy_z, d_velocity_old_z, d_velocity_z, d_mass, d_item_particle, cant_particles);
if(results){
/** DEBUG **/
cudaMemcpy(h_kinetic_energy_x, d_kinetic_energy_x, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_kinetic_energy_y, d_kinetic_energy_y, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_kinetic_energy_z, d_kinetic_energy_z, cant_particles_size, cudaMemcpyDeviceToHost);
out << " KINETIC ENERGY" << endl;
for(int i = 0; i<cant_particles; i++){
out << " " << i << " | ";
out << i+1 << ": (" << h_kinetic_energy_x[i] << " , " << h_kinetic_energy_y[i] << " , " << h_kinetic_energy_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Ek Resultante */
/* ************************************************ */
/* Ek_TOT = sum (Ek_i) */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Calculamos la Energía cinética total de cada partícula **/
Total_Kinetic_Energy_Kernel<<<dimGrid, dimBlock>>>(d_kinetic_energy, d_kinetic_energy_x, d_kinetic_energy_y, d_kinetic_energy_z, cant_particles);
/* */
/** Calculamos la Energía cinética total del sistema **/
cudaMemcpy(h_kinetic_energy, d_kinetic_energy, cant_particles_size, cudaMemcpyDeviceToHost);
double Ek_TOT = 0;
for(int i = 0; i<cant_particles; i++){
Ek_TOT += h_kinetic_energy[i];
}
if(results){
/** DEBUG **/
out << " KINETIC ENERGY" << endl;
for(int i = 0; i<cant_particles; i++){
out << " " << i << " | ";
out << " " << h_kinetic_energy[i] << endl;
}
out << endl;
/** DEBUG **/
}
if(amberResults){
out << " Total Kinetic Energy(t) = " << Ek_TOT << endl << endl;
}
/* ************************************************ */
/* Calculamos Temperatura Resultante */
/* ************************************************ */
/* T(t) = 2*Ek_TOT / (Kb*(3N-Nc)) */
double Temp_TOT = Ek_TOT * factor_conv_T_Ek;
if(amberResults){
/** DEBUG **/
out << " Temp(t) = " << Temp_TOT << endl << endl;
/** DEBUG **/
}
/* *********************************************** */
/* Calculamos Factor de Correccion */
/* *********************************************** */
/* lambda = sqrt( 1 + 2 * dt / tautp * (T/T(t) -1) ) */
double lambda = sqrt( 1 + delta_tiempo / tautp * (temp0/Temp_TOT -1) );
if(amberResults){
/** DEBUG **/
out << " lambda(t) = " << lambda << endl << endl;
/** DEBUG **/
}
/* ************************************************ */
/* Calculamos Velocidades Corregidas */
/* ************************************************ */
/* vi = lambda * vi */
/**Variables y memoria*/
dimBlock.x = 1024;
dimBlock.y = 1;
dimGrid.x = ceil((double)cant_particles / (double)dimBlock.x);
dimGrid.y = 1;
/** Piso las velocidades acumuladas al tiempo t+Dt con las nuevas de t+Dt corregidas */
Corrected_Velocities_Kernel<<<dimGrid, dimBlock>>>(d_velocity_old_x, d_velocity_x, lambda, cant_particles);
Corrected_Velocities_Kernel<<<dimGrid, dimBlock>>>(d_velocity_old_y, d_velocity_y, lambda, cant_particles);
Corrected_Velocities_Kernel<<<dimGrid, dimBlock>>>(d_velocity_old_z, d_velocity_z, lambda, cant_particles);
if(results){
/** DEBUG **/
cudaMemcpy(h_velocity_x, d_velocity_old_x, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_velocity_y, d_velocity_old_y, cant_particles_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_velocity_z, d_velocity_old_z, cant_particles_size, cudaMemcpyDeviceToHost);
out << " CORRECTED RESULTANT VELOCITIES" << endl;
for(int i = 0; i<cant_particles; i++){
out << i << ": (" << h_velocity_x[i] << " , " << h_velocity_y[i] << " , " << h_velocity_z[i] << ")" << endl;
}
out << endl;
/** DEBUG **/
}
dimBlock.x = BLOCK_SIZE_X;
dimBlock.y = BLOCK_SIZE_Y;
/* ********************************************************************************************************** */
/* ******************************************* FIN Iteracion DM ********************************************* */
/* ********************************************************************************************************** */
}
if(!results){ //timer mode ON
gettimeofday(&tv2, NULL);
taim << cant_steps << " " << (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec) << endl;
}
// if(!analytic){
/** Unbindeamos Textura y liberamos memoria **/
cudaUnbindTexture(texRef);
cudaFreeArray(cuLennard_i);
// }
if(results or amberResults){
out.close();
}
if(coordenates){
crd.close();
}
/* ************************************************ */
/* Liberamos memoria en Dispositivo */
/* ************************************************ */
cudaFree(&d_item_particle);
/** Positions **/
cudaFree(&d_position_x);
cudaFree(&d_position_y);
cudaFree(&d_position_z);
/** Distances **/
cudaFree(&d_distance_x);
cudaFree(&d_distance_y);
cudaFree(&d_distance_z);
cudaFree(&d_distance_r);
/** Particle's mass **/
cudaFree(d_mass);
/** Velocities **/
cudaFree(d_velocity_x);
cudaFree(d_velocity_y);
cudaFree(d_velocity_z);
/** Derivatives **/
cudaFree(&d_dEr);
/** Forces **/
cudaFree(&d_Force_x);
cudaFree(&d_Force_y);
cudaFree(&d_Force_z);
cudaFree(d_Force_x_resultant);
cudaFree(d_Force_y_resultant);
cudaFree(d_Force_z_resultant);
/** Kinetic Energy **/
cudaFree(d_kinetic_energy);
cudaFree(d_kinetic_energy_x);
cudaFree(d_kinetic_energy_y);
cudaFree(d_kinetic_energy_z);
/* ************************************************ */
/* Liberamos memoria en Host */
/* ************************************************ */
free(h_sigma);
free(h_epsilon);
free(h_mass);
/** Matriz de Lennard Jones **/
if(derivative)
free(h_dLJPot);
else
free(h_LJPot);
free(h_item_particle);
/** Positions **/
free(h_position_x);
free(h_position_y);
free(h_position_z);
/** Distances **/
free(h_distance_x);
free(h_distance_y);
free(h_distance_z);
free(h_distance_r);
/** Velocities **/
free(h_velocity_x);
free(h_velocity_y);
free(h_velocity_z);
/** Chargue **/
free(h_chargue);
/** Forces **/
free(h_Force_x);
free(h_Force_y);
free(h_Force_z);
free(h_Force_x_resultant);
free(h_Force_y_resultant);
free(h_Force_z_resultant);
/** Kinetic Energy **/
free(h_kinetic_energy);
free(h_kinetic_energy_x);
free(h_kinetic_energy_y);
free(h_kinetic_energy_z);
return 0;
}
|
978675f5f8a3ad03948a17e1234e40243e7caa97.hip | // !!! This is a file automatically generated by hipify!!!
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <hiprand/hiprand_kernel.h>
#include <stdlib.h>
#include <hip/hip_runtime.h>
#include <sys/time.h>
#include "dBinaryCrossEntropyCost.cu"
#include<chrono>
#include<iostream>
using namespace std;
using namespace std::chrono;
int blocks_[20][2] = {{8,8},{16,16},{24,24},{32,32},{1,64},{1,128},{1,192},{1,256},{1,320},{1,384},{1,448},{1,512},{1,576},{1,640},{1,704},{1,768},{1,832},{1,896},{1,960},{1,1024}};
int matrices_[7][2] = {{240,240},{496,496},{784,784},{1016,1016},{1232,1232},{1680,1680},{2024,2024}};
int main(int argc, char **argv) {
hipSetDevice(0);
char* p;int matrix_len=strtol(argv[1], &p, 10);
for(int matrix_looper=0;matrix_looper<matrix_len;matrix_looper++){
for(int block_looper=0;block_looper<20;block_looper++){
int XSIZE=matrices_[matrix_looper][0],YSIZE=matrices_[matrix_looper][1],BLOCKX=blocks_[block_looper][0],BLOCKY=blocks_[block_looper][1];
float *predictions = NULL;
hipMalloc(&predictions, XSIZE*YSIZE);
float *target = NULL;
hipMalloc(&target, XSIZE*YSIZE);
float *dY = NULL;
hipMalloc(&dY, XSIZE*YSIZE);
int x = 1;
int iXSIZE= XSIZE;
int iYSIZE= YSIZE;
while(iXSIZE%BLOCKX!=0)
{
iXSIZE++;
}
while(iYSIZE%BLOCKY!=0)
{
iYSIZE++;
}
dim3 gridBlock(iXSIZE/BLOCKX, iYSIZE/BLOCKY);
dim3 threadBlock(BLOCKX, BLOCKY);
hipFree(0);hipLaunchKernelGGL((
dBinaryCrossEntropyCost), dim3(gridBlock),dim3(threadBlock), 0, 0, predictions,target,dY,x);
hipDeviceSynchronize();
for (int loop_counter = 0; loop_counter < 10; ++loop_counter) {hipLaunchKernelGGL((
dBinaryCrossEntropyCost), dim3(gridBlock),dim3(threadBlock), 0, 0, predictions,target,dY,x);
}
auto start = steady_clock::now();
for (int loop_counter = 0; loop_counter < 1000; loop_counter++) {hipLaunchKernelGGL((
dBinaryCrossEntropyCost), dim3(gridBlock),dim3(threadBlock), 0, 0, predictions,target,dY,x);
}
auto end = steady_clock::now();
auto usecs = duration_cast<duration<float, microseconds::period> >(end - start);
cout <<'['<<usecs.count()<<','<<'('<<BLOCKX<<','<<BLOCKY<<')' << ','<<'('<<XSIZE<<','<<YSIZE<<')'<<']' << endl;
}
}} | 978675f5f8a3ad03948a17e1234e40243e7caa97.cu | #include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <curand_kernel.h>
#include <stdlib.h>
#include <cuda.h>
#include <sys/time.h>
#include "dBinaryCrossEntropyCost.cu"
#include<chrono>
#include<iostream>
using namespace std;
using namespace std::chrono;
int blocks_[20][2] = {{8,8},{16,16},{24,24},{32,32},{1,64},{1,128},{1,192},{1,256},{1,320},{1,384},{1,448},{1,512},{1,576},{1,640},{1,704},{1,768},{1,832},{1,896},{1,960},{1,1024}};
int matrices_[7][2] = {{240,240},{496,496},{784,784},{1016,1016},{1232,1232},{1680,1680},{2024,2024}};
int main(int argc, char **argv) {
cudaSetDevice(0);
char* p;int matrix_len=strtol(argv[1], &p, 10);
for(int matrix_looper=0;matrix_looper<matrix_len;matrix_looper++){
for(int block_looper=0;block_looper<20;block_looper++){
int XSIZE=matrices_[matrix_looper][0],YSIZE=matrices_[matrix_looper][1],BLOCKX=blocks_[block_looper][0],BLOCKY=blocks_[block_looper][1];
float *predictions = NULL;
cudaMalloc(&predictions, XSIZE*YSIZE);
float *target = NULL;
cudaMalloc(&target, XSIZE*YSIZE);
float *dY = NULL;
cudaMalloc(&dY, XSIZE*YSIZE);
int x = 1;
int iXSIZE= XSIZE;
int iYSIZE= YSIZE;
while(iXSIZE%BLOCKX!=0)
{
iXSIZE++;
}
while(iYSIZE%BLOCKY!=0)
{
iYSIZE++;
}
dim3 gridBlock(iXSIZE/BLOCKX, iYSIZE/BLOCKY);
dim3 threadBlock(BLOCKX, BLOCKY);
cudaFree(0);
dBinaryCrossEntropyCost<<<gridBlock,threadBlock>>>(predictions,target,dY,x);
cudaDeviceSynchronize();
for (int loop_counter = 0; loop_counter < 10; ++loop_counter) {
dBinaryCrossEntropyCost<<<gridBlock,threadBlock>>>(predictions,target,dY,x);
}
auto start = steady_clock::now();
for (int loop_counter = 0; loop_counter < 1000; loop_counter++) {
dBinaryCrossEntropyCost<<<gridBlock,threadBlock>>>(predictions,target,dY,x);
}
auto end = steady_clock::now();
auto usecs = duration_cast<duration<float, microseconds::period> >(end - start);
cout <<'['<<usecs.count()<<','<<'('<<BLOCKX<<','<<BLOCKY<<')' << ','<<'('<<XSIZE<<','<<YSIZE<<')'<<']' << endl;
}
}} |
20f8dac45f2bf570bd49d64847a35c59fa2f2e98.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__global__ void _kpolymap64(int n, double *k, double c, double d) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
while (i < n) {
k[i] = pow(k[i] + c, d);
i += blockDim.x * gridDim.x;
}
} | 20f8dac45f2bf570bd49d64847a35c59fa2f2e98.cu | #include "includes.h"
__global__ void _kpolymap64(int n, double *k, double c, double d) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
while (i < n) {
k[i] = pow(k[i] + c, d);
i += blockDim.x * gridDim.x;
}
} |
021b14827ce121a567578b85d3bbd62ddd1348c5.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
//scan.cu
//#include "kernel.hip"
#include "comm.h"
#include "wtime.h"
#include "iostream"
#define max_thd 256
#define max_block 256
#define thread_limit 256
#define block_limit 1024
#define GPU_COWORKER 1
graph * mygraph;
long total_count1;
long total_count2;
__global__ void block_binary_kernel
( vertex_t* head,
vertex_t* adj,
vertex_t* adj_list,
index_t* begin,
index_t Ns,
index_t Ne,
long int* counter_1,
long int* counter_2,
index_t* count
)
{
int p = threadIdx.x/32;
long counter1=0;
long counter2=0;
__shared__ int warp_path[24];//counter for divergence
//phase 1, partition
index_t tid = Ns + (threadIdx.x + blockIdx.x * blockDim.x)/ max_thd;
int i = threadIdx.x% max_thd;
index_t mycount=0;
// __shared__ vertex_t cache[256];
__shared__ index_t local[max_thd];
while(tid<Ne){
vertex_t A = head[tid];
vertex_t B = adj[tid];
index_t m = begin[A+1]-begin[A];//degree[A];
index_t n = begin[B+1]-begin[B];//degree[B];
index_t temp;
if(m<n){
temp = A;
A = B;
B = temp;
temp = m;
m = n;
n = temp;
}
vertex_t* a = &(adj_list[begin[A]]);
vertex_t* b = &(adj_list[begin[B]]);
//initial cache
local[i]=a[i*m/max_thd];
__syncthreads();
counter1 += 9;
//search
int j=i;
while(j<n){
vertex_t X = b[j];
counter1++;
vertex_t Y;
//phase 1: cache
int bot = 0;
int top = max_thd;
int r;
while(top>bot+1){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = local[r];
if(X==Y){
mycount++;
bot = top + max_thd;
warp_path[3*p]=1;
}
if(X<Y){
top = r;
warp_path[3*p+1]=1;
}
if(X>Y){
bot = r;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
//phase 2
bot = bot*m/max_thd;
top = top*m/max_thd -1;
while(top>=bot){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = a[r];
counter1++;
if(X==Y){
mycount++;
warp_path[3*p]=1;
}
if(X<=Y){
top = r-1;
warp_path[3*p+1]=1;
}
if(X>=Y){
bot = r+1;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
j += max_thd;
}
tid += GPU_COWORKER * gridDim.x*blockDim.x/ max_thd;
__syncthreads();
}
//reduce
__syncthreads();
local[threadIdx.x] = mycount;
__syncthreads();
if(threadIdx.x==0){
index_t val=0;
for(int i=0; i<blockDim.x; i++){
val+= local[i];
}
count[blockIdx.x]+=val;
// count[blockIdx.x]=val;
}
counter_1[blockDim.x*blockIdx.x+threadIdx.x] +=counter1;
counter_2[blockDim.x*blockIdx.x+threadIdx.x] +=counter2;
}
__global__ void warp_binary_kernel
( vertex_t* head,
vertex_t* adj,
vertex_t* adj_list,
index_t* begin,
index_t Ns,
index_t Ne,
long int* counter_1,
long int* counter_2,
index_t* count
)
{
long counter1=0;
long counter2=0;
__shared__ int warp_path[24];//counter for divergence
//phase 1, partition
index_t tid = (threadIdx.x + blockIdx.x * blockDim.x)/32 + Ns;
index_t mycount=0;
__shared__ index_t local[max_thd];
int i = threadIdx.x%32;
int p = threadIdx.x/32;
while(tid<Ne){
vertex_t A = head[tid];
vertex_t B = adj[tid];
index_t m = begin[A+1]-begin[A];//degree[A];
index_t n = begin[B+1]-begin[B];//degree[B];
index_t temp;
if(m<n){
temp = A;
A = B;
B = temp;
temp = m;
m = n;
n = temp;
}
vertex_t* a = &(adj_list[begin[A]]);
vertex_t* b = &(adj_list[begin[B]]);
//initial cache
local[p*32+i]=a[i*m/32];
__syncthreads();
counter1 += 9;
//search
int j=i;
while(j<n){
vertex_t X = b[j];
counter1++;
vertex_t Y;
//phase 1: cache
int bot = 0;
int top = 32;
int r;
while(top>bot+1){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = local[p*32+r];
if(X==Y){
mycount++;
bot = top + 32;
warp_path[3*p]=1;
}
if(X<Y){
top = r;
warp_path[3*p+1]=1;
}
if(X>Y){
bot = r;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
//phase 2
bot = bot*m/32;
top = top*m/32 -1;
while(top>=bot){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = a[r];
counter1++;
if(X==Y){
mycount++;
warp_path[3*p]=1;
}
if(X<=Y){
top = r-1;
warp_path[3*p+1]=1;
}
if(X>=Y){
bot = r+1;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
j += 32;
}
tid += GPU_COWORKER* blockDim.x*gridDim.x/32;
__syncthreads();
}
__syncthreads();
//reduce
local[threadIdx.x] = mycount;
__syncthreads();
if(threadIdx.x==0){
index_t val=0;
for(int i=0; i<blockDim.x; i++){
val+= local[i];
}
count[blockIdx.x]=val;
}
__syncthreads();
counter_1[blockDim.x*blockIdx.x+threadIdx.x] =counter1;
counter_2[blockDim.x*blockIdx.x+threadIdx.x] =counter2;
}
//----------------------------------------------------------------------------------------
__global__ void reduce_kernel2(index_t* count)
{
index_t val = 0;
for(int i=0; i<max_block; i++){
val += count[i];
}
count[0] = val;
}
__global__ void reduce_kernel_count(index_t* count)
{
index_t val = 0;
for(int i=0; i<max_block*max_block; i++){
val += count[i];
}
count[0] = val;
}
//---------------------------------------- cpu function--------------------
//------------------------------------------------------------------
void* part_scan(void * data){
index_t thd_count=0;
int GPU_id = *(int*)data;
int i = GPU_id;
// cout<<"GPU id = "<<GPU_id<<"\n";
hipSetDevice(GPU_id);
H_ERR(hipDeviceSynchronize() );
vertex_t* dev_adj;
index_t* dev_begin;
index_t* dev_count;
index_t partEdgeCount = mygraph->partEdgeCount[i];
vertex_t vert_count = mygraph->vert_count;
vertex_t* partAdj = mygraph->partAdj[i];
vertex_t* partHead= mygraph->partHead[i];
index_t* partBegin = mygraph->partBegin[i];
index_t* count = mygraph->count;
H_ERR(hipMalloc(&dev_adj, partEdgeCount*sizeof(vertex_t)) );
H_ERR(hipMalloc(&dev_begin, (vert_count+1)*sizeof(index_t)) );
H_ERR(hipMalloc(&dev_count, max_block*sizeof(index_t)) );
index_t* block_offset;
H_ERR(hipMalloc(&block_offset, max_block*sizeof(index_t)) );
H_ERR(hipMemcpy(dev_adj, partAdj, partEdgeCount*sizeof(vertex_t), hipMemcpyHostToDevice) );
H_ERR(hipMemcpy(dev_begin, partBegin, (vert_count+1)*sizeof(index_t), hipMemcpyHostToDevice) );
long counter_1_cpu=0;
long counter_2_cpu=0;
long tmp_counter1;
long tmp_counter2;
long int* counter_1;//counter for memory read
long int* counter_2;//counter for divergence
H_ERR(hipMalloc(&counter_1, max_thd*max_block*sizeof(long int)) );
H_ERR(hipMalloc(&counter_2, max_thd*max_block*sizeof(long int)) );
double time2=wtime();
for(int j=0; j<PART_NUM; j++){
index_t totalEdgeCount = mygraph->partEdgeCount[j];
vertex_t* head = mygraph->partHead[j];
vertex_t* adj = mygraph->partAdj[j];
vertex_t* src_head;
vertex_t* src_adj;
H_ERR(hipMalloc(&src_head, totalEdgeCount*sizeof(vertex_t)) );
H_ERR(hipMalloc(&src_adj, totalEdgeCount*sizeof(vertex_t)) );
H_ERR(hipMemcpy(src_adj, adj, totalEdgeCount*sizeof(vertex_t), hipMemcpyHostToDevice) );
H_ERR(hipMemcpy(src_head, head, totalEdgeCount*sizeof(vertex_t), hipMemcpyHostToDevice) );
double time1=wtime();
H_ERR(hipDeviceSynchronize() );
hipLaunchKernelGGL(( warp_binary_kernel), dim3(max_block),dim3(max_thd), 0, 0,
src_head,
src_adj,
dev_adj,
dev_begin,
0,
totalEdgeCount,
counter_1,
counter_2,
dev_count
);
H_ERR(hipDeviceSynchronize() );
hipLaunchKernelGGL(( reduce_kernel2) , dim3(1),dim3(1), 0, 0, dev_count);
H_ERR(hipDeviceSynchronize() );
H_ERR(hipMemcpy(&count[i], dev_count, sizeof(index_t), hipMemcpyDeviceToHost));
thd_count += count[i];
hipLaunchKernelGGL(( reduce_kernel_count) , dim3(1),dim3(1), 0, 0, counter_1);
H_ERR(hipDeviceSynchronize() );
hipLaunchKernelGGL(( reduce_kernel_count) , dim3(1),dim3(1), 0, 0, counter_2);
H_ERR(hipDeviceSynchronize() );
H_ERR(hipMemcpy(&tmp_counter1, counter_1, sizeof(long), hipMemcpyDeviceToHost));
H_ERR(hipMemcpy(&tmp_counter2, counter_2, sizeof(long), hipMemcpyDeviceToHost));
counter_1_cpu += tmp_counter1;
counter_2_cpu += tmp_counter2;
H_ERR(hipFree(src_head) );
H_ERR(hipFree(src_adj) );
// cout<<"GPU "<<i<<" part "<<j<<"\n";
}
double time4 = wtime();
count[i] = thd_count;
// cout<<"gpu "<<i<<" binary count="<<count[i]<<"\n";
// cout<<"time = "<<time4-time2<<" seconds"<<endl;
// cout<<"counter for mem_read = "<<counter_1_cpu<<endl;
// cout<<"counter for divergence = "<<counter_2_cpu<<endl;
total_count1 +=counter_1_cpu;
total_count2 +=counter_2_cpu;
H_ERR(hipFree(dev_adj) );
H_ERR(hipFree(dev_begin) );
H_ERR(hipFree(block_offset) );
H_ERR(hipFree(dev_count) );
return NULL;
}
| 021b14827ce121a567578b85d3bbd62ddd1348c5.cu | //scan.cu
//#include "kernel.cu"
#include "comm.h"
#include "wtime.h"
#include "iostream"
#define max_thd 256
#define max_block 256
#define thread_limit 256
#define block_limit 1024
#define GPU_COWORKER 1
graph * mygraph;
long total_count1;
long total_count2;
__global__ void block_binary_kernel
( vertex_t* head,
vertex_t* adj,
vertex_t* adj_list,
index_t* begin,
index_t Ns,
index_t Ne,
long int* counter_1,
long int* counter_2,
index_t* count
)
{
int p = threadIdx.x/32;
long counter1=0;
long counter2=0;
__shared__ int warp_path[24];//counter for divergence
//phase 1, partition
index_t tid = Ns + (threadIdx.x + blockIdx.x * blockDim.x)/ max_thd;
int i = threadIdx.x% max_thd;
index_t mycount=0;
// __shared__ vertex_t cache[256];
__shared__ index_t local[max_thd];
while(tid<Ne){
vertex_t A = head[tid];
vertex_t B = adj[tid];
index_t m = begin[A+1]-begin[A];//degree[A];
index_t n = begin[B+1]-begin[B];//degree[B];
index_t temp;
if(m<n){
temp = A;
A = B;
B = temp;
temp = m;
m = n;
n = temp;
}
vertex_t* a = &(adj_list[begin[A]]);
vertex_t* b = &(adj_list[begin[B]]);
//initial cache
local[i]=a[i*m/max_thd];
__syncthreads();
counter1 += 9;
//search
int j=i;
while(j<n){
vertex_t X = b[j];
counter1++;
vertex_t Y;
//phase 1: cache
int bot = 0;
int top = max_thd;
int r;
while(top>bot+1){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = local[r];
if(X==Y){
mycount++;
bot = top + max_thd;
warp_path[3*p]=1;
}
if(X<Y){
top = r;
warp_path[3*p+1]=1;
}
if(X>Y){
bot = r;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
//phase 2
bot = bot*m/max_thd;
top = top*m/max_thd -1;
while(top>=bot){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = a[r];
counter1++;
if(X==Y){
mycount++;
warp_path[3*p]=1;
}
if(X<=Y){
top = r-1;
warp_path[3*p+1]=1;
}
if(X>=Y){
bot = r+1;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
j += max_thd;
}
tid += GPU_COWORKER * gridDim.x*blockDim.x/ max_thd;
__syncthreads();
}
//reduce
__syncthreads();
local[threadIdx.x] = mycount;
__syncthreads();
if(threadIdx.x==0){
index_t val=0;
for(int i=0; i<blockDim.x; i++){
val+= local[i];
}
count[blockIdx.x]+=val;
// count[blockIdx.x]=val;
}
counter_1[blockDim.x*blockIdx.x+threadIdx.x] +=counter1;
counter_2[blockDim.x*blockIdx.x+threadIdx.x] +=counter2;
}
__global__ void warp_binary_kernel
( vertex_t* head,
vertex_t* adj,
vertex_t* adj_list,
index_t* begin,
index_t Ns,
index_t Ne,
long int* counter_1,
long int* counter_2,
index_t* count
)
{
long counter1=0;
long counter2=0;
__shared__ int warp_path[24];//counter for divergence
//phase 1, partition
index_t tid = (threadIdx.x + blockIdx.x * blockDim.x)/32 + Ns;
index_t mycount=0;
__shared__ index_t local[max_thd];
int i = threadIdx.x%32;
int p = threadIdx.x/32;
while(tid<Ne){
vertex_t A = head[tid];
vertex_t B = adj[tid];
index_t m = begin[A+1]-begin[A];//degree[A];
index_t n = begin[B+1]-begin[B];//degree[B];
index_t temp;
if(m<n){
temp = A;
A = B;
B = temp;
temp = m;
m = n;
n = temp;
}
vertex_t* a = &(adj_list[begin[A]]);
vertex_t* b = &(adj_list[begin[B]]);
//initial cache
local[p*32+i]=a[i*m/32];
__syncthreads();
counter1 += 9;
//search
int j=i;
while(j<n){
vertex_t X = b[j];
counter1++;
vertex_t Y;
//phase 1: cache
int bot = 0;
int top = 32;
int r;
while(top>bot+1){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = local[p*32+r];
if(X==Y){
mycount++;
bot = top + 32;
warp_path[3*p]=1;
}
if(X<Y){
top = r;
warp_path[3*p+1]=1;
}
if(X>Y){
bot = r;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
//phase 2
bot = bot*m/32;
top = top*m/32 -1;
while(top>=bot){
warp_path[3*p]=0;
warp_path[3*p+1]=0;
warp_path[3*p+2]=0;
r = (top+bot)/2;
Y = a[r];
counter1++;
if(X==Y){
mycount++;
warp_path[3*p]=1;
}
if(X<=Y){
top = r-1;
warp_path[3*p+1]=1;
}
if(X>=Y){
bot = r+1;
warp_path[3*p+2]=1;
}
int k=0;
if(warp_path[3*p]!=0){
k++;
}
if(warp_path[3*p+1]!=0){
k++;
}
if(warp_path[3*p+2]!=0){
k++;
}
counter2 +=k;
}
j += 32;
}
tid += GPU_COWORKER* blockDim.x*gridDim.x/32;
__syncthreads();
}
__syncthreads();
//reduce
local[threadIdx.x] = mycount;
__syncthreads();
if(threadIdx.x==0){
index_t val=0;
for(int i=0; i<blockDim.x; i++){
val+= local[i];
}
count[blockIdx.x]=val;
}
__syncthreads();
counter_1[blockDim.x*blockIdx.x+threadIdx.x] =counter1;
counter_2[blockDim.x*blockIdx.x+threadIdx.x] =counter2;
}
//----------------------------------------------------------------------------------------
__global__ void reduce_kernel2(index_t* count)
{
index_t val = 0;
for(int i=0; i<max_block; i++){
val += count[i];
}
count[0] = val;
}
__global__ void reduce_kernel_count(index_t* count)
{
index_t val = 0;
for(int i=0; i<max_block*max_block; i++){
val += count[i];
}
count[0] = val;
}
//---------------------------------------- cpu function--------------------
//------------------------------------------------------------------
void* part_scan(void * data){
index_t thd_count=0;
int GPU_id = *(int*)data;
int i = GPU_id;
// cout<<"GPU id = "<<GPU_id<<"\n";
cudaSetDevice(GPU_id);
H_ERR(cudaDeviceSynchronize() );
vertex_t* dev_adj;
index_t* dev_begin;
index_t* dev_count;
index_t partEdgeCount = mygraph->partEdgeCount[i];
vertex_t vert_count = mygraph->vert_count;
vertex_t* partAdj = mygraph->partAdj[i];
vertex_t* partHead= mygraph->partHead[i];
index_t* partBegin = mygraph->partBegin[i];
index_t* count = mygraph->count;
H_ERR(cudaMalloc(&dev_adj, partEdgeCount*sizeof(vertex_t)) );
H_ERR(cudaMalloc(&dev_begin, (vert_count+1)*sizeof(index_t)) );
H_ERR(cudaMalloc(&dev_count, max_block*sizeof(index_t)) );
index_t* block_offset;
H_ERR(cudaMalloc(&block_offset, max_block*sizeof(index_t)) );
H_ERR(cudaMemcpy(dev_adj, partAdj, partEdgeCount*sizeof(vertex_t), cudaMemcpyHostToDevice) );
H_ERR(cudaMemcpy(dev_begin, partBegin, (vert_count+1)*sizeof(index_t), cudaMemcpyHostToDevice) );
long counter_1_cpu=0;
long counter_2_cpu=0;
long tmp_counter1;
long tmp_counter2;
long int* counter_1;//counter for memory read
long int* counter_2;//counter for divergence
H_ERR(cudaMalloc(&counter_1, max_thd*max_block*sizeof(long int)) );
H_ERR(cudaMalloc(&counter_2, max_thd*max_block*sizeof(long int)) );
double time2=wtime();
for(int j=0; j<PART_NUM; j++){
index_t totalEdgeCount = mygraph->partEdgeCount[j];
vertex_t* head = mygraph->partHead[j];
vertex_t* adj = mygraph->partAdj[j];
vertex_t* src_head;
vertex_t* src_adj;
H_ERR(cudaMalloc(&src_head, totalEdgeCount*sizeof(vertex_t)) );
H_ERR(cudaMalloc(&src_adj, totalEdgeCount*sizeof(vertex_t)) );
H_ERR(cudaMemcpy(src_adj, adj, totalEdgeCount*sizeof(vertex_t), cudaMemcpyHostToDevice) );
H_ERR(cudaMemcpy(src_head, head, totalEdgeCount*sizeof(vertex_t), cudaMemcpyHostToDevice) );
double time1=wtime();
H_ERR(cudaDeviceSynchronize() );
warp_binary_kernel<<<max_block,max_thd>>>
( src_head,
src_adj,
dev_adj,
dev_begin,
0,
totalEdgeCount,
counter_1,
counter_2,
dev_count
);
H_ERR(cudaDeviceSynchronize() );
reduce_kernel2 <<<1,1>>>(dev_count);
H_ERR(cudaDeviceSynchronize() );
H_ERR(cudaMemcpy(&count[i], dev_count, sizeof(index_t), cudaMemcpyDeviceToHost));
thd_count += count[i];
reduce_kernel_count <<<1,1>>>(counter_1);
H_ERR(cudaDeviceSynchronize() );
reduce_kernel_count <<<1,1>>>(counter_2);
H_ERR(cudaDeviceSynchronize() );
H_ERR(cudaMemcpy(&tmp_counter1, counter_1, sizeof(long), cudaMemcpyDeviceToHost));
H_ERR(cudaMemcpy(&tmp_counter2, counter_2, sizeof(long), cudaMemcpyDeviceToHost));
counter_1_cpu += tmp_counter1;
counter_2_cpu += tmp_counter2;
H_ERR(cudaFree(src_head) );
H_ERR(cudaFree(src_adj) );
// cout<<"GPU "<<i<<" part "<<j<<"\n";
}
double time4 = wtime();
count[i] = thd_count;
// cout<<"gpu "<<i<<" binary count="<<count[i]<<"\n";
// cout<<"time = "<<time4-time2<<" seconds"<<endl;
// cout<<"counter for mem_read = "<<counter_1_cpu<<endl;
// cout<<"counter for divergence = "<<counter_2_cpu<<endl;
total_count1 +=counter_1_cpu;
total_count2 +=counter_2_cpu;
H_ERR(cudaFree(dev_adj) );
H_ERR(cudaFree(dev_begin) );
H_ERR(cudaFree(block_offset) );
H_ERR(cudaFree(dev_count) );
return NULL;
}
|
edb71ba1212384980b37ec5dd89c03392945bc7e.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/////////////////////////////////////////////////////////////////////////////
/// Copyright 2020 Google LLC
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// https://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/////////////////////////////////////////////////////////////////////////////
/// Modifications: pedro hermosilla (pedro-1.hermosilla-casajus@uni-ulm.de)
/////////////////////////////////////////////////////////////////////////////
#include <vector>
#include "cuda_kernel_utils.cuh"
#include "scan_alg.cuh"
#define NUM_THREADS 256
///////////////////////// GPU
/**
* GPU kernel to execute the parallel scan algorithm in an int array.
* Code based on the paper: Parallel Prefix Sum (Scan) with CUDA
* https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html
* @param pNumElems Number of elements in the array.
* @param pNumProcBlocks Number of blocks to process.
* @param pElems Input pointer to the array.
* @param pOutAuxBlockCounter Output pointer to the array containing
* the counter of each block. If null only the individual blocks
* are executed (for arrays of length smaller than T).
*/
__global__ void scan_alg_gpu_kernel(
const unsigned int pNumElems,
const unsigned int pNumProcBlocks,
int* __restrict__ pElems,
int* __restrict__ pOutAuxBlockCounter)
{
//Declare shared memory.
__shared__ int temp[NUM_THREADS*2];
//Get the local and global thread index.
int localThread = threadIdx.x;
int initElemIndex = mccnn::compute_global_index_gpu_funct();
int totalThreads = mccnn::compute_total_threads_gpu_funct();
for(int curElemIndex = initElemIndex;
curElemIndex < pNumProcBlocks*NUM_THREADS;
curElemIndex+=totalThreads)
{
//Initialize the offset.
int offset = 1;
//Load the global memory into shared memory.
if((curElemIndex*2) < pNumElems){
temp[2*localThread] = pElems[2*curElemIndex];
}else{
temp[2*localThread] = 0;
}
if((curElemIndex*2+1) < pNumElems){
temp[2*localThread+1] = pElems[2*curElemIndex+1];
}else{
temp[2*localThread+1] = 0;
}
//Build sum in place up the tree
for (int d = NUM_THREADS; d > 0; d >>= 1)
{
__syncthreads();
if (localThread < d)
{
int ai = offset*(2*localThread+1)-1;
int bi = offset*(2*localThread+2)-1;
temp[bi] += temp[ai];
}
offset *= 2;
}
//Clear the last element
if (localThread == 0){
temp[(NUM_THREADS*2) - 1] = 0;
}
//Traverse down tree & build scan
for (int d = 1; d < (NUM_THREADS*2); d *= 2)
{
offset >>= 1;
__syncthreads();
if (localThread < d)
{
int ai = offset*(2*localThread+1)-1;
int bi = offset*(2*localThread+2)-1;
int t = temp[ai];
temp[ai] = temp[bi];
temp[bi] += t;
}
}
__syncthreads();
//Update the block counters.
if(localThread == 0){
int blockId = curElemIndex/NUM_THREADS;
int elemIndex = min((2*NUM_THREADS-1), pNumElems-(curElemIndex*2)-1);
pOutAuxBlockCounter[blockId] = temp[elemIndex] + pElems[2*curElemIndex+elemIndex];
}
__syncthreads();
//Write the results to device memory
if((curElemIndex*2) < pNumElems)
pElems[2*curElemIndex] = temp[2*localThread];
if((curElemIndex*2+1) < pNumElems)
pElems[2*curElemIndex+1] = temp[2*localThread+1];
__syncthreads();
}
}
/**
* GPU kernel to execute the parallel scan algorithm in an int array.
* NOTE: The number of threads per block have to be a divisor of
* pCBlockSize in order to work.
* @param pNumElems Number of elements in the array.
* @param pCBlockSize Block size used for the counters.
* @param pBlockCounter Counter values for each block.
* @param pElems Input pointer to the array.
*/
__global__ void propagate_down_counters_gpu_kernel(
const unsigned int pNumElems,
const unsigned int pCBlockSize,
const int* __restrict__ pBlockCounter,
int* __restrict__ pElems)
{
//Declare the shared memory.
__shared__ int blockOffset;
//Get the local and global thread index.
int localThread = threadIdx.x;
int initElemIndex = mccnn::compute_global_index_gpu_funct();
int totalThreads = mccnn::compute_total_threads_gpu_funct();
for(int curElemIndex = initElemIndex+pCBlockSize;
curElemIndex < pNumElems;
curElemIndex+=totalThreads)
{
//The the offset of the block.
if(localThread == 0){
blockOffset = pBlockCounter[curElemIndex/pCBlockSize];
}
__syncthreads();
//Update the counters.
pElems[curElemIndex] += blockOffset;
}
}
///////////////////////// CPU
unsigned int mccnn::scan_alg(
std::unique_ptr<IGPUDevice>& pDevice,
const unsigned int pNumElems,
int* pInGPUPtrElems)
{
//Get the cuda stream.
auto cudaStream = pDevice->getCUDAStream();
#ifdef DEBUG_INFO
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);
hipEventRecord(start, cudaStream);
#endif
//Get the device properties.
const GpuDeviceProperties& gpuProps = pDevice->get_device_properties();
//Calculate the ideal number of blocks for the selected block size.
unsigned int numMP = gpuProps.numMPs_;
unsigned int blockSize = NUM_THREADS;
unsigned int numBlocks = pDevice->get_max_active_block_x_sm(
blockSize,
(const void*)scan_alg_gpu_kernel,
blockSize*2*sizeof(int));
pDevice->check_error(__FILE__, __LINE__);
//Compute the hierarchical scan.
unsigned int numIterations = 0;
int curNumElems = pNumElems;
int* curGPUPtr = pInGPUPtrElems;
std::vector<std::pair<int*, int> > counters;
counters.push_back(std::make_pair(curGPUPtr, curNumElems));
while(curNumElems > 1 || numIterations == 0)
{
//Calculate the total number of blocks to execute.
unsigned int execBlocks = curNumElems/(blockSize*2);
execBlocks += (curNumElems%(blockSize*2) != 0)?1:0;
unsigned int totalNumBlocks = numMP*numBlocks;
totalNumBlocks = (totalNumBlocks > execBlocks)?execBlocks:totalNumBlocks;
//Create the auxiliar counter array.
int* auxiliarCoutner = pDevice->getIntTmpGPUBuffer(execBlocks);
pDevice->memset(auxiliarCoutner, 0, sizeof(int)*execBlocks);
//Store the auxiliar counter in the vector.
counters.push_back(std::make_pair(auxiliarCoutner, execBlocks));
//Execute the cuda kernel.
hipLaunchKernelGGL(( scan_alg_gpu_kernel), dim3(totalNumBlocks), dim3(blockSize), 0, cudaStream,
curNumElems,
execBlocks,
curGPUPtr,
auxiliarCoutner);
pDevice->check_error(__FILE__, __LINE__);
//Set the variables for the next pass.
curNumElems = execBlocks;
curGPUPtr = auxiliarCoutner;
//Increment the iteration counter.
numIterations++;
}
//Propagate down the counters.
unsigned int propBlockSize = gpuProps.warpSize_*2;
for(int i = counters.size()-1; i > 0; i--)
{
curNumElems = counters[i-1].second-(blockSize*2);
if(curNumElems > 0){
//Calculate the total number of blocks to execute.
unsigned int execBlocks = curNumElems/propBlockSize;
execBlocks += (curNumElems%propBlockSize != 0)?1:0;
unsigned int totalNumBlocks = numMP*numBlocks;
totalNumBlocks = (totalNumBlocks > execBlocks)?execBlocks:totalNumBlocks;
//Propagate the offsets.
hipLaunchKernelGGL(( propagate_down_counters_gpu_kernel), dim3(totalNumBlocks), dim3(propBlockSize), 0, cudaStream,
counters[i-1].second,
blockSize*2,
counters[i].first,
counters[i-1].first);
}
}
//Get the total accumulated value.
int accumScan = 1;
pDevice->memcpy_device_to_host(
(void*)&accumScan,
(void*)counters[counters.size()-1].first,
sizeof(int));
#ifdef DEBUG_INFO
hipEventRecord(stop, cudaStream);
hipEventSynchronize(stop);
float milliseconds = 0;
hipEventElapsedTime(&milliseconds, start, stop);
float gpuOccupancy = (float)(numBlocks*blockSize)/(float)gpuProps.maxThreadsXMP_;
fprintf(stderr, "### SCAN ALG ###\n");
fprintf(stderr, "Num elements: %d\n", pNumElems);
fprintf(stderr, "Num iterations: %d\n", numIterations);
fprintf(stderr, "Total accum: %d\n", accumScan);
fprintf(stderr, "Occupancy: %f\n", gpuOccupancy);
fprintf(stderr, "Execution time: %f\n", milliseconds);
fprintf(stderr, "\n");
#endif
return accumScan;
} | edb71ba1212384980b37ec5dd89c03392945bc7e.cu | /////////////////////////////////////////////////////////////////////////////
/// Copyright 2020 Google LLC
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// https://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/////////////////////////////////////////////////////////////////////////////
/// Modifications: pedro hermosilla (pedro-1.hermosilla-casajus@uni-ulm.de)
/////////////////////////////////////////////////////////////////////////////
#include <vector>
#include "cuda_kernel_utils.cuh"
#include "scan_alg.cuh"
#define NUM_THREADS 256
///////////////////////// GPU
/**
* GPU kernel to execute the parallel scan algorithm in an int array.
* Code based on the paper: Parallel Prefix Sum (Scan) with CUDA
* https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html
* @param pNumElems Number of elements in the array.
* @param pNumProcBlocks Number of blocks to process.
* @param pElems Input pointer to the array.
* @param pOutAuxBlockCounter Output pointer to the array containing
* the counter of each block. If null only the individual blocks
* are executed (for arrays of length smaller than T).
*/
__global__ void scan_alg_gpu_kernel(
const unsigned int pNumElems,
const unsigned int pNumProcBlocks,
int* __restrict__ pElems,
int* __restrict__ pOutAuxBlockCounter)
{
//Declare shared memory.
__shared__ int temp[NUM_THREADS*2];
//Get the local and global thread index.
int localThread = threadIdx.x;
int initElemIndex = mccnn::compute_global_index_gpu_funct();
int totalThreads = mccnn::compute_total_threads_gpu_funct();
for(int curElemIndex = initElemIndex;
curElemIndex < pNumProcBlocks*NUM_THREADS;
curElemIndex+=totalThreads)
{
//Initialize the offset.
int offset = 1;
//Load the global memory into shared memory.
if((curElemIndex*2) < pNumElems){
temp[2*localThread] = pElems[2*curElemIndex];
}else{
temp[2*localThread] = 0;
}
if((curElemIndex*2+1) < pNumElems){
temp[2*localThread+1] = pElems[2*curElemIndex+1];
}else{
temp[2*localThread+1] = 0;
}
//Build sum in place up the tree
for (int d = NUM_THREADS; d > 0; d >>= 1)
{
__syncthreads();
if (localThread < d)
{
int ai = offset*(2*localThread+1)-1;
int bi = offset*(2*localThread+2)-1;
temp[bi] += temp[ai];
}
offset *= 2;
}
//Clear the last element
if (localThread == 0){
temp[(NUM_THREADS*2) - 1] = 0;
}
//Traverse down tree & build scan
for (int d = 1; d < (NUM_THREADS*2); d *= 2)
{
offset >>= 1;
__syncthreads();
if (localThread < d)
{
int ai = offset*(2*localThread+1)-1;
int bi = offset*(2*localThread+2)-1;
int t = temp[ai];
temp[ai] = temp[bi];
temp[bi] += t;
}
}
__syncthreads();
//Update the block counters.
if(localThread == 0){
int blockId = curElemIndex/NUM_THREADS;
int elemIndex = min((2*NUM_THREADS-1), pNumElems-(curElemIndex*2)-1);
pOutAuxBlockCounter[blockId] = temp[elemIndex] + pElems[2*curElemIndex+elemIndex];
}
__syncthreads();
//Write the results to device memory
if((curElemIndex*2) < pNumElems)
pElems[2*curElemIndex] = temp[2*localThread];
if((curElemIndex*2+1) < pNumElems)
pElems[2*curElemIndex+1] = temp[2*localThread+1];
__syncthreads();
}
}
/**
* GPU kernel to execute the parallel scan algorithm in an int array.
* NOTE: The number of threads per block have to be a divisor of
* pCBlockSize in order to work.
* @param pNumElems Number of elements in the array.
* @param pCBlockSize Block size used for the counters.
* @param pBlockCounter Counter values for each block.
* @param pElems Input pointer to the array.
*/
__global__ void propagate_down_counters_gpu_kernel(
const unsigned int pNumElems,
const unsigned int pCBlockSize,
const int* __restrict__ pBlockCounter,
int* __restrict__ pElems)
{
//Declare the shared memory.
__shared__ int blockOffset;
//Get the local and global thread index.
int localThread = threadIdx.x;
int initElemIndex = mccnn::compute_global_index_gpu_funct();
int totalThreads = mccnn::compute_total_threads_gpu_funct();
for(int curElemIndex = initElemIndex+pCBlockSize;
curElemIndex < pNumElems;
curElemIndex+=totalThreads)
{
//The the offset of the block.
if(localThread == 0){
blockOffset = pBlockCounter[curElemIndex/pCBlockSize];
}
__syncthreads();
//Update the counters.
pElems[curElemIndex] += blockOffset;
}
}
///////////////////////// CPU
unsigned int mccnn::scan_alg(
std::unique_ptr<IGPUDevice>& pDevice,
const unsigned int pNumElems,
int* pInGPUPtrElems)
{
//Get the cuda stream.
auto cudaStream = pDevice->getCUDAStream();
#ifdef DEBUG_INFO
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, cudaStream);
#endif
//Get the device properties.
const GpuDeviceProperties& gpuProps = pDevice->get_device_properties();
//Calculate the ideal number of blocks for the selected block size.
unsigned int numMP = gpuProps.numMPs_;
unsigned int blockSize = NUM_THREADS;
unsigned int numBlocks = pDevice->get_max_active_block_x_sm(
blockSize,
(const void*)scan_alg_gpu_kernel,
blockSize*2*sizeof(int));
pDevice->check_error(__FILE__, __LINE__);
//Compute the hierarchical scan.
unsigned int numIterations = 0;
int curNumElems = pNumElems;
int* curGPUPtr = pInGPUPtrElems;
std::vector<std::pair<int*, int> > counters;
counters.push_back(std::make_pair(curGPUPtr, curNumElems));
while(curNumElems > 1 || numIterations == 0)
{
//Calculate the total number of blocks to execute.
unsigned int execBlocks = curNumElems/(blockSize*2);
execBlocks += (curNumElems%(blockSize*2) != 0)?1:0;
unsigned int totalNumBlocks = numMP*numBlocks;
totalNumBlocks = (totalNumBlocks > execBlocks)?execBlocks:totalNumBlocks;
//Create the auxiliar counter array.
int* auxiliarCoutner = pDevice->getIntTmpGPUBuffer(execBlocks);
pDevice->memset(auxiliarCoutner, 0, sizeof(int)*execBlocks);
//Store the auxiliar counter in the vector.
counters.push_back(std::make_pair(auxiliarCoutner, execBlocks));
//Execute the cuda kernel.
scan_alg_gpu_kernel<<<totalNumBlocks, blockSize, 0, cudaStream>>>(
curNumElems,
execBlocks,
curGPUPtr,
auxiliarCoutner);
pDevice->check_error(__FILE__, __LINE__);
//Set the variables for the next pass.
curNumElems = execBlocks;
curGPUPtr = auxiliarCoutner;
//Increment the iteration counter.
numIterations++;
}
//Propagate down the counters.
unsigned int propBlockSize = gpuProps.warpSize_*2;
for(int i = counters.size()-1; i > 0; i--)
{
curNumElems = counters[i-1].second-(blockSize*2);
if(curNumElems > 0){
//Calculate the total number of blocks to execute.
unsigned int execBlocks = curNumElems/propBlockSize;
execBlocks += (curNumElems%propBlockSize != 0)?1:0;
unsigned int totalNumBlocks = numMP*numBlocks;
totalNumBlocks = (totalNumBlocks > execBlocks)?execBlocks:totalNumBlocks;
//Propagate the offsets.
propagate_down_counters_gpu_kernel<<<totalNumBlocks, propBlockSize, 0, cudaStream>>>(
counters[i-1].second,
blockSize*2,
counters[i].first,
counters[i-1].first);
}
}
//Get the total accumulated value.
int accumScan = 1;
pDevice->memcpy_device_to_host(
(void*)&accumScan,
(void*)counters[counters.size()-1].first,
sizeof(int));
#ifdef DEBUG_INFO
cudaEventRecord(stop, cudaStream);
cudaEventSynchronize(stop);
float milliseconds = 0;
cudaEventElapsedTime(&milliseconds, start, stop);
float gpuOccupancy = (float)(numBlocks*blockSize)/(float)gpuProps.maxThreadsXMP_;
fprintf(stderr, "### SCAN ALG ###\n");
fprintf(stderr, "Num elements: %d\n", pNumElems);
fprintf(stderr, "Num iterations: %d\n", numIterations);
fprintf(stderr, "Total accum: %d\n", accumScan);
fprintf(stderr, "Occupancy: %f\n", gpuOccupancy);
fprintf(stderr, "Execution time: %f\n", milliseconds);
fprintf(stderr, "\n");
#endif
return accumScan;
} |
bf98b63ed3c2d50e7e4d0045d45ead033ca9c49e.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "hsv_gpu.hpp"
void __global__ hsv_filter(uchar *dev_src, uchar *dev_hsrc, int cols,
int hue1, int hue2, int saturation1, int saturation2, int value1, int value2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 0] < hue1 || dev_hsrc[cols*3*tid + 3*c + 0] > hue2 ||
dev_hsrc[cols*3*tid + 3*c + 1] < saturation1 || dev_hsrc[cols*3*tid + 3*c + 1] > saturation2 ||
dev_hsrc[cols*3*tid + 3*c + 2] < value1 || dev_hsrc[cols*3*tid + 3*c + 1] > value2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void __global__ h_filter(uchar *dev_src, uchar *dev_hsrc, int cols, int hue1, int hue2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 0] < hue1 || dev_hsrc[cols*3*tid + 3*c + 0] > hue2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void __global__ s_filter(uchar *dev_src, uchar *dev_hsrc, int cols, int saturation1, int saturation2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 1] < saturation1 || dev_hsrc[cols*3*tid + 3*c + 1] > saturation2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void __global__ v_filter(uchar *dev_src, uchar *dev_hsrc, int cols, int value1, int value2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 2] < value1 || dev_hsrc[cols*3*tid + 3*c + 2] > value2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void HSV::setThreshold(double h1, double h2, double s1, double s2, double v1, double v2)
{
hue1 = h1;
hue2 = h2;
saturation1 = s1;
saturation2 = s2;
value1 = v1;
value2 = v2;
}
void HSV::adjustHSV(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
hipMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
hipMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
hipMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyHostToDevice);
hipMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), hipMemcpyHostToDevice);
hipLaunchKernelGGL(( hsv_filter), dim3(src->rows), dim3(1), 0, 0, dev_src, dev_hsrc, src->cols, hue1, hue2, saturation1, saturation2, value1, value2);
hipMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyDeviceToHost);
hipFree(dev_src);
hipFree(dev_hsrc);
}
void HSV::adjustH(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
hipMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
hipMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
hipMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyHostToDevice);
hipMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), hipMemcpyHostToDevice);
hipLaunchKernelGGL(( h_filter), dim3(src->rows), dim3(1), 0, 0, dev_src, dev_hsrc, src->cols, hue1, hue2);
hipMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyDeviceToHost);
hipFree(dev_src);
hipFree(dev_hsrc);
}
void HSV::adjustS(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
hipMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
hipMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
hipMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyHostToDevice);
hipMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), hipMemcpyHostToDevice);
hipLaunchKernelGGL(( s_filter), dim3(src->rows), dim3(1), 0, 0, dev_src, dev_hsrc, src->cols, saturation1, saturation2);
hipMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyDeviceToHost);
hipFree(dev_src);
hipFree(dev_hsrc);
}
void HSV::adjustV(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
hipMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
hipMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
hipMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyHostToDevice);
hipMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), hipMemcpyHostToDevice);
hipLaunchKernelGGL(( v_filter), dim3(src->rows), dim3(1), 0, 0, dev_src, dev_hsrc, src->cols, value1, value2);
hipMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), hipMemcpyDeviceToHost);
hipFree(dev_src);
hipFree(dev_hsrc);
}
| bf98b63ed3c2d50e7e4d0045d45ead033ca9c49e.cu | #include "hsv_gpu.hpp"
void __global__ hsv_filter(uchar *dev_src, uchar *dev_hsrc, int cols,
int hue1, int hue2, int saturation1, int saturation2, int value1, int value2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 0] < hue1 || dev_hsrc[cols*3*tid + 3*c + 0] > hue2 ||
dev_hsrc[cols*3*tid + 3*c + 1] < saturation1 || dev_hsrc[cols*3*tid + 3*c + 1] > saturation2 ||
dev_hsrc[cols*3*tid + 3*c + 2] < value1 || dev_hsrc[cols*3*tid + 3*c + 1] > value2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void __global__ h_filter(uchar *dev_src, uchar *dev_hsrc, int cols, int hue1, int hue2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 0] < hue1 || dev_hsrc[cols*3*tid + 3*c + 0] > hue2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void __global__ s_filter(uchar *dev_src, uchar *dev_hsrc, int cols, int saturation1, int saturation2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 1] < saturation1 || dev_hsrc[cols*3*tid + 3*c + 1] > saturation2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void __global__ v_filter(uchar *dev_src, uchar *dev_hsrc, int cols, int value1, int value2)
{
int tid = blockIdx.x;
int c;
for(c=0;c<cols;c++)
{
if(dev_hsrc[cols*3*tid + 3*c + 2] < value1 || dev_hsrc[cols*3*tid + 3*c + 2] > value2)
{
dev_src[cols*3*tid + 3*c + 0] = 0;
dev_src[cols*3*tid + 3*c + 1] = 0;
dev_src[cols*3*tid + 3*c + 2] = 0;
}
}
}
void HSV::setThreshold(double h1, double h2, double s1, double s2, double v1, double v2)
{
hue1 = h1;
hue2 = h2;
saturation1 = s1;
saturation2 = s2;
value1 = v1;
value2 = v2;
}
void HSV::adjustHSV(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
cudaMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
cudaMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
cudaMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyHostToDevice);
cudaMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), cudaMemcpyHostToDevice);
hsv_filter<<<src->rows, 1>>>(dev_src, dev_hsrc, src->cols, hue1, hue2, saturation1, saturation2, value1, value2);
cudaMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyDeviceToHost);
cudaFree(dev_src);
cudaFree(dev_hsrc);
}
void HSV::adjustH(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
cudaMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
cudaMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
cudaMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyHostToDevice);
cudaMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), cudaMemcpyHostToDevice);
h_filter<<<src->rows, 1>>>(dev_src, dev_hsrc, src->cols, hue1, hue2);
cudaMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyDeviceToHost);
cudaFree(dev_src);
cudaFree(dev_hsrc);
}
void HSV::adjustS(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
cudaMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
cudaMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
cudaMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyHostToDevice);
cudaMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), cudaMemcpyHostToDevice);
s_filter<<<src->rows, 1>>>(dev_src, dev_hsrc, src->cols, saturation1, saturation2);
cudaMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyDeviceToHost);
cudaFree(dev_src);
cudaFree(dev_hsrc);
}
void HSV::adjustV(Mat* src, Mat* dst)
{
gsrc.upload(*src);
gpu::cvtColor(gsrc, gdst, CV_RGB2HSV);
gdst.download(hsrc);
cudaMalloc((void**)&dev_src, src->rows*src->cols*src->channels()*src->elemSize1());
cudaMalloc((void**)&dev_hsrc, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1());
cudaMemcpy(dev_src, src->data, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyHostToDevice);
cudaMemcpy(dev_hsrc, hsrc.data, hsrc.rows*hsrc.cols*hsrc.channels()*hsrc.elemSize1(), cudaMemcpyHostToDevice);
v_filter<<<src->rows, 1>>>(dev_src, dev_hsrc, src->cols, value1, value2);
cudaMemcpy(dst->data, dev_src, src->rows*src->cols*src->channels()*src->elemSize1(), cudaMemcpyDeviceToHost);
cudaFree(dev_src);
cudaFree(dev_hsrc);
}
|
a4736e0ecab3ba0c07bbf09efabb1819774bc292.hip | // !!! This is a file automatically generated by hipify!!!
/*
* Copyright 2011-2017 NVIDIA Corporation. All rights reserved
*
* Sample app to demonstrate use of CUPTI library to obtain metric values
* using callbacks for CUDA runtime APIs
*
*/
#include <stdio.h>
#include <hip/hip_runtime.h>
#include <cupti.h>
#define METRIC_NAME "ipc"
#define DRIVER_API_CALL(apiFuncCall) \
do { \
hipError_t _status = apiFuncCall; \
if (_status != hipSuccess) { \
fprintf(stderr, "%s:%d: error: function %s failed with error %d.\n", \
__FILE__, __LINE__, #apiFuncCall, _status); \
exit(-1); \
} \
} while (0)
#define RUNTIME_API_CALL(apiFuncCall) \
do { \
hipError_t _status = apiFuncCall; \
if (_status != hipSuccess) { \
fprintf(stderr, "%s:%d: error: function %s failed with error %s.\n", \
__FILE__, __LINE__, #apiFuncCall, hipGetErrorString(_status));\
exit(-1); \
} \
} while (0)
#define CUPTI_CALL(call) \
do { \
CUptiResult _status = call; \
if (_status != CUPTI_SUCCESS) { \
const char *errstr; \
cuptiGetResultString(_status, &errstr); \
fprintf(stderr, "%s:%d: error: function %s failed with error %s.\n", \
__FILE__, __LINE__, #call, errstr); \
exit(-1); \
} \
} while (0)
#define ALIGN_SIZE (8)
#define ALIGN_BUFFER(buffer, align) \
(((uintptr_t) (buffer) & ((align)-1)) ? ((buffer) + (align) - ((uintptr_t) (buffer) & ((align)-1))) : (buffer))
// User data for event collection callback
typedef struct MetricData_st {
// the device where metric is being collected
hipDevice_t device;
// the set of event groups to collect for a pass
CUpti_EventGroupSet *eventGroups;
// the current number of events collected in eventIdArray and
// eventValueArray
uint32_t eventIdx;
// the number of entries in eventIdArray and eventValueArray
uint32_t numEvents;
// array of event ids
CUpti_EventID *eventIdArray;
// array of event values
uint64_t *eventValueArray;
} MetricData_t;
static uint64_t kernelDuration;
// Device code
__global__ void VecAdd(const int* A, const int* B, int* C, int N)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < N)
C[i] = A[i] + B[i];
}
static void
initVec(int *vec, int n)
{
for (int i=0; i< n; i++)
vec[i] = i;
}
void CUPTIAPI
getMetricValueCallback(void *userdata, CUpti_CallbackDomain domain,
CUpti_CallbackId cbid, const CUpti_CallbackData *cbInfo)
{
MetricData_t *metricData = (MetricData_t*)userdata;
unsigned int i, j, k;
// This callback is enabled only for launch so we shouldn't see
// anything else.
if ((cbid != CUPTI_RUNTIME_TRACE_CBID_cudaLaunch_v3020) &&
(cbid != CUPTI_RUNTIME_TRACE_CBID_cudaLaunchKernel_v7000))
{
printf("%s:%d: unexpected cbid %d\n", __FILE__, __LINE__, cbid);
exit(-1);
}
// on entry, enable all the event groups being collected this pass,
// for metrics we collect for all instances of the event
if (cbInfo->callbackSite == CUPTI_API_ENTER) {
hipDeviceSynchronize();
CUPTI_CALL(cuptiSetEventCollectionMode(cbInfo->context,
CUPTI_EVENT_COLLECTION_MODE_KERNEL));
for (i = 0; i < metricData->eventGroups->numEventGroups; i++) {
uint32_t all = 1;
CUPTI_CALL(cuptiEventGroupSetAttribute(metricData->eventGroups->eventGroups[i],
CUPTI_EVENT_GROUP_ATTR_PROFILE_ALL_DOMAIN_INSTANCES,
sizeof(all), &all));
CUPTI_CALL(cuptiEventGroupEnable(metricData->eventGroups->eventGroups[i]));
}
}
// on exit, read and record event values
if (cbInfo->callbackSite == CUPTI_API_EXIT) {
hipDeviceSynchronize();
// for each group, read the event values from the group and record
// in metricData
for (i = 0; i < metricData->eventGroups->numEventGroups; i++) {
CUpti_EventGroup group = metricData->eventGroups->eventGroups[i];
CUpti_EventDomainID groupDomain;
uint32_t numEvents, numInstances, numTotalInstances;
CUpti_EventID *eventIds;
size_t groupDomainSize = sizeof(groupDomain);
size_t numEventsSize = sizeof(numEvents);
size_t numInstancesSize = sizeof(numInstances);
size_t numTotalInstancesSize = sizeof(numTotalInstances);
uint64_t *values, normalized, *sum;
size_t valuesSize, eventIdsSize;
size_t numCountersRead = 0;
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_EVENT_DOMAIN_ID,
&groupDomainSize, &groupDomain));
CUPTI_CALL(cuptiDeviceGetEventDomainAttribute(metricData->device, groupDomain,
CUPTI_EVENT_DOMAIN_ATTR_TOTAL_INSTANCE_COUNT,
&numTotalInstancesSize, &numTotalInstances));
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_INSTANCE_COUNT,
&numInstancesSize, &numInstances));
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_NUM_EVENTS,
&numEventsSize, &numEvents));
eventIdsSize = numEvents * sizeof(CUpti_EventID);
eventIds = (CUpti_EventID *)malloc(eventIdsSize);
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_EVENTS,
&eventIdsSize, eventIds));
valuesSize = sizeof(uint64_t) * numInstances * numEvents;
values = (uint64_t *)malloc(valuesSize);
CUPTI_CALL(cuptiEventGroupReadAllEvents(group,
CUPTI_EVENT_READ_FLAG_NONE,
&valuesSize,
values,
&eventIdsSize,
eventIds,
&numCountersRead));
if (metricData->eventIdx >= metricData->numEvents) {
fprintf(stderr, "error: too many events collected, metric expects only %d\n",
(int)metricData->numEvents);
exit(-1);
}
sum = (uint64_t *)calloc(sizeof(uint64_t), numEvents);
// sum collect event values from all instances
for (k = 0; k < numInstances; k++) {
for (j = 0; j < numEvents; j++) {
sum[j] += values[(k * numEvents) + j];
}
}
for (j = 0; j < numEvents; j++) {
// normalize the event value to represent the total number of
// domain instances on the device
normalized = (sum[j] * numTotalInstances) / numInstances;
metricData->eventIdArray[metricData->eventIdx] = eventIds[j];
metricData->eventValueArray[metricData->eventIdx] = normalized;
metricData->eventIdx++;
// print collected value
{
char eventName[128];
size_t eventNameSize = sizeof(eventName) - 1;
CUPTI_CALL(cuptiEventGetAttribute(eventIds[j], CUPTI_EVENT_ATTR_NAME,
&eventNameSize, eventName));
eventName[127] = '\0';
printf("\t%s = %llu (", eventName, (unsigned long long)sum[j]);
if (numInstances > 1) {
for (k = 0; k < numInstances; k++) {
if (k != 0)
printf(", ");
printf("%llu", (unsigned long long)values[(k * numEvents) + j]);
}
}
printf(")\n");
printf("\t%s (normalized) (%llu * %u) / %u = %llu\n",
eventName, (unsigned long long)sum[j],
numTotalInstances, numInstances,
(unsigned long long)normalized);
}
}
free(values);
free(sum);
}
for (i = 0; i < metricData->eventGroups->numEventGroups; i++)
CUPTI_CALL(cuptiEventGroupDisable(metricData->eventGroups->eventGroups[i]));
}
}
static void
cleanUp(int *h_A, int *h_B, int *h_C, int *d_A, int *d_B, int *d_C)
{
if (d_A)
hipFree(d_A);
if (d_B)
hipFree(d_B);
if (d_C)
hipFree(d_C);
// Free host memory
if (h_A)
free(h_A);
if (h_B)
free(h_B);
if (h_C)
free(h_C);
}
static void
runPass()
{
int N = 50000;
size_t size = N * sizeof(int);
int threadsPerBlock = 0;
int blocksPerGrid = 0;
int *h_A, *h_B, *h_C;
int *d_A, *d_B, *d_C;
int i, sum;
// Allocate input vectors h_A and h_B in host memory
h_A = (int*)malloc(size);
h_B = (int*)malloc(size);
h_C = (int*)malloc(size);
// Initialize input vectors
initVec(h_A, N);
initVec(h_B, N);
memset(h_C, 0, size);
// Allocate vectors in device memory
hipMalloc((void**)&d_A, size);
hipMalloc((void**)&d_B, size);
hipMalloc((void**)&d_C, size);
// Copy vectors from host memory to device memory
hipMemcpy(d_A, h_A, size, hipMemcpyHostToDevice);
hipMemcpy(d_B, h_B, size, hipMemcpyHostToDevice);
// Invoke kernel
threadsPerBlock = 256;
blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
printf("Launching kernel: blocks %d, thread/block %d\n",
blocksPerGrid, threadsPerBlock);
hipLaunchKernelGGL(( VecAdd), dim3(blocksPerGrid), dim3(threadsPerBlock), 0, 0, d_A, d_B, d_C, N);
// Copy result from device memory to host memory
// h_C contains the result in host memory
hipMemcpy(h_C, d_C, size, hipMemcpyDeviceToHost);
// Verify result
for (i = 0; i < N; ++i) {
sum = h_A[i] + h_B[i];
if (h_C[i] != sum) {
fprintf(stderr, "error: result verification failed\n");
exit(-1);
}
}
cleanUp(h_A, h_B, h_C, d_A, d_B, d_C);
}
static void CUPTIAPI
bufferRequested(uint8_t **buffer, size_t *size, size_t *maxNumRecords)
{
uint8_t *rawBuffer;
*size = 16 * 1024;
rawBuffer = (uint8_t *)malloc(*size + ALIGN_SIZE);
*buffer = ALIGN_BUFFER(rawBuffer, ALIGN_SIZE);
*maxNumRecords = 0;
if (*buffer == NULL) {
printf("Error: out of memory\n");
exit(-1);
}
}
static void CUPTIAPI
bufferCompleted(hipCtx_t ctx, uint32_t streamId, uint8_t *buffer, size_t size, size_t validSize)
{
CUpti_Activity *record = NULL;
CUpti_ActivityKernel5 *kernel;
//since we launched only 1 kernel, we should have only 1 kernel record
CUPTI_CALL(cuptiActivityGetNextRecord(buffer, validSize, &record));
kernel = (CUpti_ActivityKernel5 *)record;
if (kernel->kind != CUPTI_ACTIVITY_KIND_KERNEL) {
fprintf(stderr, "Error: expected kernel activity record, got %d\n", (int)kernel->kind);
exit(-1);
}
kernelDuration = kernel->end - kernel->start;
free(buffer);
}
int
main(int argc, char *argv[])
{
CUpti_SubscriberHandle subscriber;
hipCtx_t context = 0;
hipDevice_t device = 0;
int deviceNum;
int deviceCount;
char deviceName[32];
const char *metricName;
CUpti_MetricID metricId;
CUpti_EventGroupSets *passData;
MetricData_t metricData;
unsigned int pass;
CUpti_MetricValue metricValue;
printf("Usage: %s [device_num] [metric_name]\n", argv[0]);
// make sure activity is enabled before any CUDA API
CUPTI_CALL(cuptiActivityEnable(CUPTI_ACTIVITY_KIND_KERNEL));
DRIVER_API_CALL(hipInit(0));
DRIVER_API_CALL(hipGetDeviceCount(&deviceCount));
if (deviceCount == 0) {
printf("There is no device supporting CUDA.\n");
return -2;
}
if (argc > 1)
deviceNum = atoi(argv[1]);
else
deviceNum = 0;
printf("CUDA Device Number: %d\n", deviceNum);
DRIVER_API_CALL(hipDeviceGet(&device, deviceNum));
DRIVER_API_CALL(hipDeviceGetName(deviceName, 32, device));
printf("CUDA Device Name: %s\n", deviceName);
DRIVER_API_CALL(hipCtxCreate(&context, 0, device));
// Get the name of the metric to collect
if (argc > 2)
metricName = argv[2];
else {
metricName = METRIC_NAME;
}
// need to collect duration of kernel execution without any event
// collection enabled (some metrics need kernel duration as part of
// calculation). The only accurate way to do this is by using the
// activity API.
{
CUPTI_CALL(cuptiActivityRegisterCallbacks(bufferRequested, bufferCompleted));
runPass();
hipDeviceSynchronize();
CUPTI_CALL(cuptiActivityFlushAll(0));
}
// setup launch callback for event collection
CUPTI_CALL(cuptiSubscribe(&subscriber, (CUpti_CallbackFunc)getMetricValueCallback, &metricData));
CUPTI_CALL(cuptiEnableCallback(1, subscriber, CUPTI_CB_DOMAIN_RUNTIME_API,
CUPTI_RUNTIME_TRACE_CBID_cudaLaunch_v3020));
CUPTI_CALL(cuptiEnableCallback(1, subscriber, CUPTI_CB_DOMAIN_RUNTIME_API,
CUPTI_RUNTIME_TRACE_CBID_cudaLaunchKernel_v7000));
// allocate space to hold all the events needed for the metric
CUPTI_CALL(cuptiMetricGetIdFromName(device, metricName, &metricId));
CUPTI_CALL(cuptiMetricGetNumEvents(metricId, &metricData.numEvents));
metricData.device = device;
metricData.eventIdArray = (CUpti_EventID *)malloc(metricData.numEvents * sizeof(CUpti_EventID));
metricData.eventValueArray = (uint64_t *)malloc(metricData.numEvents * sizeof(uint64_t));
metricData.eventIdx = 0;
// get the number of passes required to collect all the events
// needed for the metric and the event groups for each pass
CUPTI_CALL(cuptiMetricCreateEventGroupSets(context, sizeof(metricId), &metricId, &passData));
for (pass = 0; pass < passData->numSets; pass++) {
printf("Pass %u\n", pass);
metricData.eventGroups = passData->sets + pass;
runPass();
}
if (metricData.eventIdx != metricData.numEvents) {
fprintf(stderr, "error: expected %u metric events, got %u\n",
metricData.numEvents, metricData.eventIdx);
exit(-1);
}
// use all the collected events to calculate the metric value
CUPTI_CALL(cuptiMetricGetValue(device, metricId,
metricData.numEvents * sizeof(CUpti_EventID),
metricData.eventIdArray,
metricData.numEvents * sizeof(uint64_t),
metricData.eventValueArray,
kernelDuration, &metricValue));
// print metric value, we format based on the value kind
{
CUpti_MetricValueKind valueKind;
size_t valueKindSize = sizeof(valueKind);
CUPTI_CALL(cuptiMetricGetAttribute(metricId, CUPTI_METRIC_ATTR_VALUE_KIND,
&valueKindSize, &valueKind));
switch (valueKind) {
case CUPTI_METRIC_VALUE_KIND_DOUBLE:
printf("Metric %s = %f\n", metricName, metricValue.metricValueDouble);
break;
case CUPTI_METRIC_VALUE_KIND_UINT64:
printf("Metric %s = %llu\n", metricName,
(unsigned long long)metricValue.metricValueUint64);
break;
case CUPTI_METRIC_VALUE_KIND_INT64:
printf("Metric %s = %lld\n", metricName,
(long long)metricValue.metricValueInt64);
break;
case CUPTI_METRIC_VALUE_KIND_PERCENT:
printf("Metric %s = %f%%\n", metricName, metricValue.metricValuePercent);
break;
case CUPTI_METRIC_VALUE_KIND_THROUGHPUT:
printf("Metric %s = %llu bytes/sec\n", metricName,
(unsigned long long)metricValue.metricValueThroughput);
break;
case CUPTI_METRIC_VALUE_KIND_UTILIZATION_LEVEL:
printf("Metric %s = utilization level %u\n", metricName,
(unsigned int)metricValue.metricValueUtilizationLevel);
break;
default:
fprintf(stderr, "error: unknown value kind\n");
exit(-1);
}
}
CUPTI_CALL(cuptiUnsubscribe(subscriber));
return 0;
}
| a4736e0ecab3ba0c07bbf09efabb1819774bc292.cu | /*
* Copyright 2011-2017 NVIDIA Corporation. All rights reserved
*
* Sample app to demonstrate use of CUPTI library to obtain metric values
* using callbacks for CUDA runtime APIs
*
*/
#include <stdio.h>
#include <cuda.h>
#include <cupti.h>
#define METRIC_NAME "ipc"
#define DRIVER_API_CALL(apiFuncCall) \
do { \
CUresult _status = apiFuncCall; \
if (_status != CUDA_SUCCESS) { \
fprintf(stderr, "%s:%d: error: function %s failed with error %d.\n", \
__FILE__, __LINE__, #apiFuncCall, _status); \
exit(-1); \
} \
} while (0)
#define RUNTIME_API_CALL(apiFuncCall) \
do { \
cudaError_t _status = apiFuncCall; \
if (_status != cudaSuccess) { \
fprintf(stderr, "%s:%d: error: function %s failed with error %s.\n", \
__FILE__, __LINE__, #apiFuncCall, cudaGetErrorString(_status));\
exit(-1); \
} \
} while (0)
#define CUPTI_CALL(call) \
do { \
CUptiResult _status = call; \
if (_status != CUPTI_SUCCESS) { \
const char *errstr; \
cuptiGetResultString(_status, &errstr); \
fprintf(stderr, "%s:%d: error: function %s failed with error %s.\n", \
__FILE__, __LINE__, #call, errstr); \
exit(-1); \
} \
} while (0)
#define ALIGN_SIZE (8)
#define ALIGN_BUFFER(buffer, align) \
(((uintptr_t) (buffer) & ((align)-1)) ? ((buffer) + (align) - ((uintptr_t) (buffer) & ((align)-1))) : (buffer))
// User data for event collection callback
typedef struct MetricData_st {
// the device where metric is being collected
CUdevice device;
// the set of event groups to collect for a pass
CUpti_EventGroupSet *eventGroups;
// the current number of events collected in eventIdArray and
// eventValueArray
uint32_t eventIdx;
// the number of entries in eventIdArray and eventValueArray
uint32_t numEvents;
// array of event ids
CUpti_EventID *eventIdArray;
// array of event values
uint64_t *eventValueArray;
} MetricData_t;
static uint64_t kernelDuration;
// Device code
__global__ void VecAdd(const int* A, const int* B, int* C, int N)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < N)
C[i] = A[i] + B[i];
}
static void
initVec(int *vec, int n)
{
for (int i=0; i< n; i++)
vec[i] = i;
}
void CUPTIAPI
getMetricValueCallback(void *userdata, CUpti_CallbackDomain domain,
CUpti_CallbackId cbid, const CUpti_CallbackData *cbInfo)
{
MetricData_t *metricData = (MetricData_t*)userdata;
unsigned int i, j, k;
// This callback is enabled only for launch so we shouldn't see
// anything else.
if ((cbid != CUPTI_RUNTIME_TRACE_CBID_cudaLaunch_v3020) &&
(cbid != CUPTI_RUNTIME_TRACE_CBID_cudaLaunchKernel_v7000))
{
printf("%s:%d: unexpected cbid %d\n", __FILE__, __LINE__, cbid);
exit(-1);
}
// on entry, enable all the event groups being collected this pass,
// for metrics we collect for all instances of the event
if (cbInfo->callbackSite == CUPTI_API_ENTER) {
cudaDeviceSynchronize();
CUPTI_CALL(cuptiSetEventCollectionMode(cbInfo->context,
CUPTI_EVENT_COLLECTION_MODE_KERNEL));
for (i = 0; i < metricData->eventGroups->numEventGroups; i++) {
uint32_t all = 1;
CUPTI_CALL(cuptiEventGroupSetAttribute(metricData->eventGroups->eventGroups[i],
CUPTI_EVENT_GROUP_ATTR_PROFILE_ALL_DOMAIN_INSTANCES,
sizeof(all), &all));
CUPTI_CALL(cuptiEventGroupEnable(metricData->eventGroups->eventGroups[i]));
}
}
// on exit, read and record event values
if (cbInfo->callbackSite == CUPTI_API_EXIT) {
cudaDeviceSynchronize();
// for each group, read the event values from the group and record
// in metricData
for (i = 0; i < metricData->eventGroups->numEventGroups; i++) {
CUpti_EventGroup group = metricData->eventGroups->eventGroups[i];
CUpti_EventDomainID groupDomain;
uint32_t numEvents, numInstances, numTotalInstances;
CUpti_EventID *eventIds;
size_t groupDomainSize = sizeof(groupDomain);
size_t numEventsSize = sizeof(numEvents);
size_t numInstancesSize = sizeof(numInstances);
size_t numTotalInstancesSize = sizeof(numTotalInstances);
uint64_t *values, normalized, *sum;
size_t valuesSize, eventIdsSize;
size_t numCountersRead = 0;
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_EVENT_DOMAIN_ID,
&groupDomainSize, &groupDomain));
CUPTI_CALL(cuptiDeviceGetEventDomainAttribute(metricData->device, groupDomain,
CUPTI_EVENT_DOMAIN_ATTR_TOTAL_INSTANCE_COUNT,
&numTotalInstancesSize, &numTotalInstances));
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_INSTANCE_COUNT,
&numInstancesSize, &numInstances));
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_NUM_EVENTS,
&numEventsSize, &numEvents));
eventIdsSize = numEvents * sizeof(CUpti_EventID);
eventIds = (CUpti_EventID *)malloc(eventIdsSize);
CUPTI_CALL(cuptiEventGroupGetAttribute(group,
CUPTI_EVENT_GROUP_ATTR_EVENTS,
&eventIdsSize, eventIds));
valuesSize = sizeof(uint64_t) * numInstances * numEvents;
values = (uint64_t *)malloc(valuesSize);
CUPTI_CALL(cuptiEventGroupReadAllEvents(group,
CUPTI_EVENT_READ_FLAG_NONE,
&valuesSize,
values,
&eventIdsSize,
eventIds,
&numCountersRead));
if (metricData->eventIdx >= metricData->numEvents) {
fprintf(stderr, "error: too many events collected, metric expects only %d\n",
(int)metricData->numEvents);
exit(-1);
}
sum = (uint64_t *)calloc(sizeof(uint64_t), numEvents);
// sum collect event values from all instances
for (k = 0; k < numInstances; k++) {
for (j = 0; j < numEvents; j++) {
sum[j] += values[(k * numEvents) + j];
}
}
for (j = 0; j < numEvents; j++) {
// normalize the event value to represent the total number of
// domain instances on the device
normalized = (sum[j] * numTotalInstances) / numInstances;
metricData->eventIdArray[metricData->eventIdx] = eventIds[j];
metricData->eventValueArray[metricData->eventIdx] = normalized;
metricData->eventIdx++;
// print collected value
{
char eventName[128];
size_t eventNameSize = sizeof(eventName) - 1;
CUPTI_CALL(cuptiEventGetAttribute(eventIds[j], CUPTI_EVENT_ATTR_NAME,
&eventNameSize, eventName));
eventName[127] = '\0';
printf("\t%s = %llu (", eventName, (unsigned long long)sum[j]);
if (numInstances > 1) {
for (k = 0; k < numInstances; k++) {
if (k != 0)
printf(", ");
printf("%llu", (unsigned long long)values[(k * numEvents) + j]);
}
}
printf(")\n");
printf("\t%s (normalized) (%llu * %u) / %u = %llu\n",
eventName, (unsigned long long)sum[j],
numTotalInstances, numInstances,
(unsigned long long)normalized);
}
}
free(values);
free(sum);
}
for (i = 0; i < metricData->eventGroups->numEventGroups; i++)
CUPTI_CALL(cuptiEventGroupDisable(metricData->eventGroups->eventGroups[i]));
}
}
static void
cleanUp(int *h_A, int *h_B, int *h_C, int *d_A, int *d_B, int *d_C)
{
if (d_A)
cudaFree(d_A);
if (d_B)
cudaFree(d_B);
if (d_C)
cudaFree(d_C);
// Free host memory
if (h_A)
free(h_A);
if (h_B)
free(h_B);
if (h_C)
free(h_C);
}
static void
runPass()
{
int N = 50000;
size_t size = N * sizeof(int);
int threadsPerBlock = 0;
int blocksPerGrid = 0;
int *h_A, *h_B, *h_C;
int *d_A, *d_B, *d_C;
int i, sum;
// Allocate input vectors h_A and h_B in host memory
h_A = (int*)malloc(size);
h_B = (int*)malloc(size);
h_C = (int*)malloc(size);
// Initialize input vectors
initVec(h_A, N);
initVec(h_B, N);
memset(h_C, 0, size);
// Allocate vectors in device memory
cudaMalloc((void**)&d_A, size);
cudaMalloc((void**)&d_B, size);
cudaMalloc((void**)&d_C, size);
// Copy vectors from host memory to device memory
cudaMemcpy(d_A, h_A, size, cudaMemcpyHostToDevice);
cudaMemcpy(d_B, h_B, size, cudaMemcpyHostToDevice);
// Invoke kernel
threadsPerBlock = 256;
blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
printf("Launching kernel: blocks %d, thread/block %d\n",
blocksPerGrid, threadsPerBlock);
VecAdd<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N);
// Copy result from device memory to host memory
// h_C contains the result in host memory
cudaMemcpy(h_C, d_C, size, cudaMemcpyDeviceToHost);
// Verify result
for (i = 0; i < N; ++i) {
sum = h_A[i] + h_B[i];
if (h_C[i] != sum) {
fprintf(stderr, "error: result verification failed\n");
exit(-1);
}
}
cleanUp(h_A, h_B, h_C, d_A, d_B, d_C);
}
static void CUPTIAPI
bufferRequested(uint8_t **buffer, size_t *size, size_t *maxNumRecords)
{
uint8_t *rawBuffer;
*size = 16 * 1024;
rawBuffer = (uint8_t *)malloc(*size + ALIGN_SIZE);
*buffer = ALIGN_BUFFER(rawBuffer, ALIGN_SIZE);
*maxNumRecords = 0;
if (*buffer == NULL) {
printf("Error: out of memory\n");
exit(-1);
}
}
static void CUPTIAPI
bufferCompleted(CUcontext ctx, uint32_t streamId, uint8_t *buffer, size_t size, size_t validSize)
{
CUpti_Activity *record = NULL;
CUpti_ActivityKernel5 *kernel;
//since we launched only 1 kernel, we should have only 1 kernel record
CUPTI_CALL(cuptiActivityGetNextRecord(buffer, validSize, &record));
kernel = (CUpti_ActivityKernel5 *)record;
if (kernel->kind != CUPTI_ACTIVITY_KIND_KERNEL) {
fprintf(stderr, "Error: expected kernel activity record, got %d\n", (int)kernel->kind);
exit(-1);
}
kernelDuration = kernel->end - kernel->start;
free(buffer);
}
int
main(int argc, char *argv[])
{
CUpti_SubscriberHandle subscriber;
CUcontext context = 0;
CUdevice device = 0;
int deviceNum;
int deviceCount;
char deviceName[32];
const char *metricName;
CUpti_MetricID metricId;
CUpti_EventGroupSets *passData;
MetricData_t metricData;
unsigned int pass;
CUpti_MetricValue metricValue;
printf("Usage: %s [device_num] [metric_name]\n", argv[0]);
// make sure activity is enabled before any CUDA API
CUPTI_CALL(cuptiActivityEnable(CUPTI_ACTIVITY_KIND_KERNEL));
DRIVER_API_CALL(cuInit(0));
DRIVER_API_CALL(cuDeviceGetCount(&deviceCount));
if (deviceCount == 0) {
printf("There is no device supporting CUDA.\n");
return -2;
}
if (argc > 1)
deviceNum = atoi(argv[1]);
else
deviceNum = 0;
printf("CUDA Device Number: %d\n", deviceNum);
DRIVER_API_CALL(cuDeviceGet(&device, deviceNum));
DRIVER_API_CALL(cuDeviceGetName(deviceName, 32, device));
printf("CUDA Device Name: %s\n", deviceName);
DRIVER_API_CALL(cuCtxCreate(&context, 0, device));
// Get the name of the metric to collect
if (argc > 2)
metricName = argv[2];
else {
metricName = METRIC_NAME;
}
// need to collect duration of kernel execution without any event
// collection enabled (some metrics need kernel duration as part of
// calculation). The only accurate way to do this is by using the
// activity API.
{
CUPTI_CALL(cuptiActivityRegisterCallbacks(bufferRequested, bufferCompleted));
runPass();
cudaDeviceSynchronize();
CUPTI_CALL(cuptiActivityFlushAll(0));
}
// setup launch callback for event collection
CUPTI_CALL(cuptiSubscribe(&subscriber, (CUpti_CallbackFunc)getMetricValueCallback, &metricData));
CUPTI_CALL(cuptiEnableCallback(1, subscriber, CUPTI_CB_DOMAIN_RUNTIME_API,
CUPTI_RUNTIME_TRACE_CBID_cudaLaunch_v3020));
CUPTI_CALL(cuptiEnableCallback(1, subscriber, CUPTI_CB_DOMAIN_RUNTIME_API,
CUPTI_RUNTIME_TRACE_CBID_cudaLaunchKernel_v7000));
// allocate space to hold all the events needed for the metric
CUPTI_CALL(cuptiMetricGetIdFromName(device, metricName, &metricId));
CUPTI_CALL(cuptiMetricGetNumEvents(metricId, &metricData.numEvents));
metricData.device = device;
metricData.eventIdArray = (CUpti_EventID *)malloc(metricData.numEvents * sizeof(CUpti_EventID));
metricData.eventValueArray = (uint64_t *)malloc(metricData.numEvents * sizeof(uint64_t));
metricData.eventIdx = 0;
// get the number of passes required to collect all the events
// needed for the metric and the event groups for each pass
CUPTI_CALL(cuptiMetricCreateEventGroupSets(context, sizeof(metricId), &metricId, &passData));
for (pass = 0; pass < passData->numSets; pass++) {
printf("Pass %u\n", pass);
metricData.eventGroups = passData->sets + pass;
runPass();
}
if (metricData.eventIdx != metricData.numEvents) {
fprintf(stderr, "error: expected %u metric events, got %u\n",
metricData.numEvents, metricData.eventIdx);
exit(-1);
}
// use all the collected events to calculate the metric value
CUPTI_CALL(cuptiMetricGetValue(device, metricId,
metricData.numEvents * sizeof(CUpti_EventID),
metricData.eventIdArray,
metricData.numEvents * sizeof(uint64_t),
metricData.eventValueArray,
kernelDuration, &metricValue));
// print metric value, we format based on the value kind
{
CUpti_MetricValueKind valueKind;
size_t valueKindSize = sizeof(valueKind);
CUPTI_CALL(cuptiMetricGetAttribute(metricId, CUPTI_METRIC_ATTR_VALUE_KIND,
&valueKindSize, &valueKind));
switch (valueKind) {
case CUPTI_METRIC_VALUE_KIND_DOUBLE:
printf("Metric %s = %f\n", metricName, metricValue.metricValueDouble);
break;
case CUPTI_METRIC_VALUE_KIND_UINT64:
printf("Metric %s = %llu\n", metricName,
(unsigned long long)metricValue.metricValueUint64);
break;
case CUPTI_METRIC_VALUE_KIND_INT64:
printf("Metric %s = %lld\n", metricName,
(long long)metricValue.metricValueInt64);
break;
case CUPTI_METRIC_VALUE_KIND_PERCENT:
printf("Metric %s = %f%%\n", metricName, metricValue.metricValuePercent);
break;
case CUPTI_METRIC_VALUE_KIND_THROUGHPUT:
printf("Metric %s = %llu bytes/sec\n", metricName,
(unsigned long long)metricValue.metricValueThroughput);
break;
case CUPTI_METRIC_VALUE_KIND_UTILIZATION_LEVEL:
printf("Metric %s = utilization level %u\n", metricName,
(unsigned int)metricValue.metricValueUtilizationLevel);
break;
default:
fprintf(stderr, "error: unknown value kind\n");
exit(-1);
}
}
CUPTI_CALL(cuptiUnsubscribe(subscriber));
return 0;
}
|
34369385fbe7baf061ff1ed769b5bb2a96319f11.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "kernels_hip.cuh"
// Global random number generator and distributions for generating random numbers on the host. The random number generator used
// is the Mersenne Twister mt19937 from the BOOST library.
boost::random::mt19937 rng;
boost::random::normal_distribution<> snorm(0.0, 1.0); // Standard normal distribution
boost::random::uniform_real_distribution<> uniform(0.0, 1.0); // Uniform distribution from 0.0 to 1.0
__constant__ double c_theta[100];
// Function to compute the rank-1 Cholesky update/downdate. Note that this is done in place.
__device__ __host__
void chol_update_r1(double* cholfactor, double* v, int dim_v, bool downdate) {
double sign = 1.0;
if (downdate) {
// Perform the downdate instead
sign = -1.0;
}
int diag_index = 0; // index of the diagonal of the cholesky factor
for (int i=0; i<dim_v; i++) {
// loop over the columns of the Cholesky factor
double L_ii = cholfactor[diag_index];
double v_i = v[i];
double r = sqrt( L_ii * L_ii + sign * v_i * v_i);
double c = r / L_ii;
double s = v_i / L_ii;
cholfactor[diag_index] = r;
int index_ji = diag_index; // index of the cholesky factor array that points to L[j,i]
// update the rest of the rows of the Cholesky factor for this column
for (int j=i+1; j<dim_v; j++) {
// loop over the rows of the i^th column of the Cholesky factor
index_ji += j;
cholfactor[index_ji] = (cholfactor[index_ji] + sign * s * v[j]) / c;
}
// update the elements of the vector v[i+1:dim_v-1]
index_ji = diag_index;
for (int j=i+1; j<dim_v; j++) {
index_ji += j;
v[j] = c * v[j] - s * cholfactor[index_ji];
}
diag_index += i + 2;
}
}
// compute the conditional log-posterior density of the measurements given the characteristic
//__device__ double LogDensityMeas(double* chi, double* meas, double* meas_unc, int mfeat, int pchi) { return 0.0; }
// compute the conditional log-posterior density of the characteristic given the population parameter
//__device__ double LogDensityPop(double* chi, double* theta, int pchi, int dim_theta) { return 0.0; }
// propose a new value for the characteristic
__device__ __host__
void Propose(double* chi, double* cholfact, double* proposed_chi, double* snorm_deviate,
double* scaled_proposal, int pchi, hiprandState_t* p_state)
{
// get the unit proposal
for (int j=0; j<pchi; j++) {
#ifdef __CUDA_ARCH__
snorm_deviate[j] = hiprand_normal_double(p_state);
#else
snorm_deviate[j] = snorm(rng);
#endif
}
// propose a new chi value
int cholfact_index = 0;
for (int j=0; j<pchi; j++) {
double scaled_proposal_j = 0.0;
for (int k=0; k<(j+1); k++) {
// transform the unit proposal to the centered proposal, drawn from a multivariate normal.
scaled_proposal_j += cholfact[cholfact_index] * snorm_deviate[k];
cholfact_index++;
}
proposed_chi[j] = chi[j] + scaled_proposal_j;
scaled_proposal[j] = scaled_proposal_j;
}
}
// adapt the covariance matrix of the proposals for the characteristics
__device__ __host__
void AdaptProp(double* cholfact, double* snorm_deviate, double* scaled_proposal, double metro_ratio,
int pchi, int current_iter)
{
double unit_norm = 0.0;
for (int j=0; j<pchi; j++) {
unit_norm += snorm_deviate[j] * snorm_deviate[j];
}
unit_norm = sqrt(unit_norm);
double decay_rate = 0.667;
double target_rate = 0.4;
double decay_sequence = 1.0 / pow(current_iter, decay_rate);
double scaled_coef = sqrt(decay_sequence * fabs(metro_ratio - target_rate)) / unit_norm;
for (int j=0; j<pchi; j++) {
scaled_proposal[j] *= scaled_coef;
}
bool downdate = (metro_ratio < target_rate);
// do rank-1 cholesky update to update the proposal covariance matrix
chol_update_r1(cholfact, scaled_proposal, pchi, downdate);
}
// decide whether to accept or reject the proposal based on the metropolist-hasting ratio
__device__ __host__
bool AcceptProp(double logdens_prop, double logdens_current, double forward_dens,
double backward_dens, double& ratio, hiprandState_t* p_state)
{
double lograt = logdens_prop - forward_dens - (logdens_current - backward_dens);
lograt = min(lograt, 0.0);
ratio = exp(lograt);
#ifdef __CUDA_ARCH__
double unif = hiprand_uniform_double(p_state);
#else
double unif = uniform(rng);
#endif
bool accept = (unif < ratio) && isfinite(ratio);
return accept;
}
/*
* Kernels
*/
// Initialize the parallel random number generator state on the device
__global__ void initialize_rng(hiprandState_t *state)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
/* Each thread gets same seed, a different sequence
number, no offset */
hiprand_init(1234, id, 0, &state[id]);
}
| 34369385fbe7baf061ff1ed769b5bb2a96319f11.cu | #include "kernels.cuh"
// Global random number generator and distributions for generating random numbers on the host. The random number generator used
// is the Mersenne Twister mt19937 from the BOOST library.
boost::random::mt19937 rng;
boost::random::normal_distribution<> snorm(0.0, 1.0); // Standard normal distribution
boost::random::uniform_real_distribution<> uniform(0.0, 1.0); // Uniform distribution from 0.0 to 1.0
__constant__ double c_theta[100];
// Function to compute the rank-1 Cholesky update/downdate. Note that this is done in place.
__device__ __host__
void chol_update_r1(double* cholfactor, double* v, int dim_v, bool downdate) {
double sign = 1.0;
if (downdate) {
// Perform the downdate instead
sign = -1.0;
}
int diag_index = 0; // index of the diagonal of the cholesky factor
for (int i=0; i<dim_v; i++) {
// loop over the columns of the Cholesky factor
double L_ii = cholfactor[diag_index];
double v_i = v[i];
double r = sqrt( L_ii * L_ii + sign * v_i * v_i);
double c = r / L_ii;
double s = v_i / L_ii;
cholfactor[diag_index] = r;
int index_ji = diag_index; // index of the cholesky factor array that points to L[j,i]
// update the rest of the rows of the Cholesky factor for this column
for (int j=i+1; j<dim_v; j++) {
// loop over the rows of the i^th column of the Cholesky factor
index_ji += j;
cholfactor[index_ji] = (cholfactor[index_ji] + sign * s * v[j]) / c;
}
// update the elements of the vector v[i+1:dim_v-1]
index_ji = diag_index;
for (int j=i+1; j<dim_v; j++) {
index_ji += j;
v[j] = c * v[j] - s * cholfactor[index_ji];
}
diag_index += i + 2;
}
}
// compute the conditional log-posterior density of the measurements given the characteristic
//__device__ double LogDensityMeas(double* chi, double* meas, double* meas_unc, int mfeat, int pchi) { return 0.0; }
// compute the conditional log-posterior density of the characteristic given the population parameter
//__device__ double LogDensityPop(double* chi, double* theta, int pchi, int dim_theta) { return 0.0; }
// propose a new value for the characteristic
__device__ __host__
void Propose(double* chi, double* cholfact, double* proposed_chi, double* snorm_deviate,
double* scaled_proposal, int pchi, curandState* p_state)
{
// get the unit proposal
for (int j=0; j<pchi; j++) {
#ifdef __CUDA_ARCH__
snorm_deviate[j] = curand_normal_double(p_state);
#else
snorm_deviate[j] = snorm(rng);
#endif
}
// propose a new chi value
int cholfact_index = 0;
for (int j=0; j<pchi; j++) {
double scaled_proposal_j = 0.0;
for (int k=0; k<(j+1); k++) {
// transform the unit proposal to the centered proposal, drawn from a multivariate normal.
scaled_proposal_j += cholfact[cholfact_index] * snorm_deviate[k];
cholfact_index++;
}
proposed_chi[j] = chi[j] + scaled_proposal_j;
scaled_proposal[j] = scaled_proposal_j;
}
}
// adapt the covariance matrix of the proposals for the characteristics
__device__ __host__
void AdaptProp(double* cholfact, double* snorm_deviate, double* scaled_proposal, double metro_ratio,
int pchi, int current_iter)
{
double unit_norm = 0.0;
for (int j=0; j<pchi; j++) {
unit_norm += snorm_deviate[j] * snorm_deviate[j];
}
unit_norm = sqrt(unit_norm);
double decay_rate = 0.667;
double target_rate = 0.4;
double decay_sequence = 1.0 / pow(current_iter, decay_rate);
double scaled_coef = sqrt(decay_sequence * fabs(metro_ratio - target_rate)) / unit_norm;
for (int j=0; j<pchi; j++) {
scaled_proposal[j] *= scaled_coef;
}
bool downdate = (metro_ratio < target_rate);
// do rank-1 cholesky update to update the proposal covariance matrix
chol_update_r1(cholfact, scaled_proposal, pchi, downdate);
}
// decide whether to accept or reject the proposal based on the metropolist-hasting ratio
__device__ __host__
bool AcceptProp(double logdens_prop, double logdens_current, double forward_dens,
double backward_dens, double& ratio, curandState* p_state)
{
double lograt = logdens_prop - forward_dens - (logdens_current - backward_dens);
lograt = min(lograt, 0.0);
ratio = exp(lograt);
#ifdef __CUDA_ARCH__
double unif = curand_uniform_double(p_state);
#else
double unif = uniform(rng);
#endif
bool accept = (unif < ratio) && isfinite(ratio);
return accept;
}
/*
* Kernels
*/
// Initialize the parallel random number generator state on the device
__global__ void initialize_rng(curandState *state)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
/* Each thread gets same seed, a different sequence
number, no offset */
curand_init(1234, id, 0, &state[id]);
}
|
fd3a6bc500084de64d4ccee94b2340128cbdc326.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/* Copyright (c) 2016 paddlepaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/math/maxouting.h"
#include "paddle/fluid/platform/device/gpu/gpu_primitives.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
namespace paddle {
namespace operators {
namespace math {
template <typename T>
__global__ void KernelMaxOut(const int nthreads,
const T* input_data,
const int channels,
const int input_height,
const int input_width,
const int groups,
const int axis,
T* output_data) {
const int size = input_height * input_width * channels / groups;
const int feat_len = input_height * input_width;
int index = blockIdx.x * blockDim.x + threadIdx.x;
int offset = blockDim.x * gridDim.x;
for (int i = index; i < nthreads; i += offset) {
int batch_idx = i / size;
int batch_offset = i % size;
int channel_idx, feat_idx, data_idx;
if (axis == 1) {
channel_idx = batch_offset / feat_len;
feat_idx = batch_offset % feat_len;
data_idx =
(batch_idx * size + channel_idx * feat_len) * groups + feat_idx;
} else {
channel_idx = batch_offset % channels;
feat_idx = batch_offset / channels;
data_idx =
(batch_idx * size + feat_idx * channels + channel_idx) * groups;
}
T ele = static_cast<T>(-FLT_MAX);
for (int g = 0; g < groups; ++g) {
int idx_offset = (axis == 1 ? g * feat_len : g);
T x = input_data[data_idx + idx_offset];
ele = ele > x ? ele : x;
}
output_data[i] = ele;
}
}
template <typename T>
__global__ void KernelMaxoutGrad(const int nthreads,
const T* input_data,
const T* output_data,
const T* output_grad,
T* input_grad,
const int channels,
const int input_height,
const int input_width,
const int groups,
const int axis) {
const int size = input_height * input_width * channels / groups;
const int feat_len = input_height * input_width;
int index = blockIdx.x * blockDim.x + threadIdx.x;
int offset = blockDim.x * gridDim.x;
for (int i = index; i < nthreads; i += offset) {
int batch_idx = i / size;
int batch_offset = i % size;
int channel_idx, feat_idx, data_idx;
if (axis == 1) {
channel_idx = batch_offset / feat_len;
feat_idx = batch_offset % feat_len;
data_idx =
(batch_idx * size + channel_idx * feat_len) * groups + feat_idx;
} else {
channel_idx = batch_offset % channels;
feat_idx = batch_offset / channels;
data_idx =
(batch_idx * size + feat_idx * channels + channel_idx) * groups;
}
int max_index = -1;
bool continue_match = true;
for (int g = 0; g < groups && continue_match; ++g) {
int idx_offset = (axis == 1 ? g * feat_len : g);
if (input_data[data_idx + idx_offset] == output_data[i]) {
max_index = data_idx + idx_offset;
continue_match = false;
break;
}
}
if (max_index != -1) {
input_grad[max_index] += output_grad[index];
}
}
}
/*
* All tensors are in NCHW or NHWC format.
*/
template <typename DeviceContext, typename T>
void MaxOutFunctor<DeviceContext, T>::operator()(const DeviceContext& context,
const phi::DenseTensor& input,
phi::DenseTensor* output,
const int groups,
const int axis) {
const int batch_size = input.dims()[0];
const int input_channels = input.dims()[axis];
const int input_height = (axis == 1 ? input.dims()[2] : input.dims()[1]);
const int input_width = (axis == 1 ? input.dims()[3] : input.dims()[2]);
const int output_channels = output->dims()[axis];
const T* input_data = input.data<T>();
T* output_data = output->mutable_data<T>(context.GetPlace());
int nthreads = output->numel();
int blocks = (nthreads + 1024 - 1) / 1024;
dim3 threads(1024, 1);
dim3 grid(blocks, 1);
hipLaunchKernelGGL(( KernelMaxOut<T>), dim3(grid), dim3(threads), 0, context.stream(), nthreads,
input_data,
input_channels,
input_height,
input_width,
groups,
axis,
output_data);
}
/*
* All tensors are in NCHW or NHWC format.
*/
template <typename DeviceContext, typename T>
void MaxOutGradFunctor<DeviceContext, T>::operator()(
const DeviceContext& context,
const phi::DenseTensor& input,
phi::DenseTensor* input_grad,
const phi::DenseTensor& output,
const phi::DenseTensor& output_grad,
const int groups,
const int axis) {
const int batch_size = input.dims()[0];
const int input_channels = input.dims()[axis];
const int input_height = (axis == 1 ? input.dims()[2] : input.dims()[1]);
const int input_width = (axis == 1 ? input.dims()[3] : input.dims()[2]);
const int output_channels = output.dims()[axis];
const T* input_data = input.data<T>();
const T* output_data = output.data<T>();
const T* output_grad_data = output_grad.data<T>();
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
int nthreads = output.numel();
int blocks = (nthreads + 1024 - 1) / 1024;
dim3 threads(1024, 1);
dim3 grid(blocks, 1);
hipLaunchKernelGGL(( KernelMaxoutGrad<T>), dim3(grid), dim3(threads), 0, context.stream(), nthreads,
input_data,
output_data,
output_grad_data,
input_grad_data,
input_channels,
input_height,
input_width,
groups,
axis);
}
template class MaxOutGradFunctor<phi::GPUContext, float>;
template class MaxOutGradFunctor<phi::GPUContext, double>;
template class MaxOutFunctor<phi::GPUContext, float>;
template class MaxOutFunctor<phi::GPUContext, double>;
} // namespace math
} // namespace operators
} // namespace paddle
| fd3a6bc500084de64d4ccee94b2340128cbdc326.cu | /* Copyright (c) 2016 paddlepaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/math/maxouting.h"
#include "paddle/fluid/platform/device/gpu/gpu_primitives.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
namespace paddle {
namespace operators {
namespace math {
template <typename T>
__global__ void KernelMaxOut(const int nthreads,
const T* input_data,
const int channels,
const int input_height,
const int input_width,
const int groups,
const int axis,
T* output_data) {
const int size = input_height * input_width * channels / groups;
const int feat_len = input_height * input_width;
int index = blockIdx.x * blockDim.x + threadIdx.x;
int offset = blockDim.x * gridDim.x;
for (int i = index; i < nthreads; i += offset) {
int batch_idx = i / size;
int batch_offset = i % size;
int channel_idx, feat_idx, data_idx;
if (axis == 1) {
channel_idx = batch_offset / feat_len;
feat_idx = batch_offset % feat_len;
data_idx =
(batch_idx * size + channel_idx * feat_len) * groups + feat_idx;
} else {
channel_idx = batch_offset % channels;
feat_idx = batch_offset / channels;
data_idx =
(batch_idx * size + feat_idx * channels + channel_idx) * groups;
}
T ele = static_cast<T>(-FLT_MAX);
for (int g = 0; g < groups; ++g) {
int idx_offset = (axis == 1 ? g * feat_len : g);
T x = input_data[data_idx + idx_offset];
ele = ele > x ? ele : x;
}
output_data[i] = ele;
}
}
template <typename T>
__global__ void KernelMaxoutGrad(const int nthreads,
const T* input_data,
const T* output_data,
const T* output_grad,
T* input_grad,
const int channels,
const int input_height,
const int input_width,
const int groups,
const int axis) {
const int size = input_height * input_width * channels / groups;
const int feat_len = input_height * input_width;
int index = blockIdx.x * blockDim.x + threadIdx.x;
int offset = blockDim.x * gridDim.x;
for (int i = index; i < nthreads; i += offset) {
int batch_idx = i / size;
int batch_offset = i % size;
int channel_idx, feat_idx, data_idx;
if (axis == 1) {
channel_idx = batch_offset / feat_len;
feat_idx = batch_offset % feat_len;
data_idx =
(batch_idx * size + channel_idx * feat_len) * groups + feat_idx;
} else {
channel_idx = batch_offset % channels;
feat_idx = batch_offset / channels;
data_idx =
(batch_idx * size + feat_idx * channels + channel_idx) * groups;
}
int max_index = -1;
bool continue_match = true;
for (int g = 0; g < groups && continue_match; ++g) {
int idx_offset = (axis == 1 ? g * feat_len : g);
if (input_data[data_idx + idx_offset] == output_data[i]) {
max_index = data_idx + idx_offset;
continue_match = false;
break;
}
}
if (max_index != -1) {
input_grad[max_index] += output_grad[index];
}
}
}
/*
* All tensors are in NCHW or NHWC format.
*/
template <typename DeviceContext, typename T>
void MaxOutFunctor<DeviceContext, T>::operator()(const DeviceContext& context,
const phi::DenseTensor& input,
phi::DenseTensor* output,
const int groups,
const int axis) {
const int batch_size = input.dims()[0];
const int input_channels = input.dims()[axis];
const int input_height = (axis == 1 ? input.dims()[2] : input.dims()[1]);
const int input_width = (axis == 1 ? input.dims()[3] : input.dims()[2]);
const int output_channels = output->dims()[axis];
const T* input_data = input.data<T>();
T* output_data = output->mutable_data<T>(context.GetPlace());
int nthreads = output->numel();
int blocks = (nthreads + 1024 - 1) / 1024;
dim3 threads(1024, 1);
dim3 grid(blocks, 1);
KernelMaxOut<T><<<grid, threads, 0, context.stream()>>>(nthreads,
input_data,
input_channels,
input_height,
input_width,
groups,
axis,
output_data);
}
/*
* All tensors are in NCHW or NHWC format.
*/
template <typename DeviceContext, typename T>
void MaxOutGradFunctor<DeviceContext, T>::operator()(
const DeviceContext& context,
const phi::DenseTensor& input,
phi::DenseTensor* input_grad,
const phi::DenseTensor& output,
const phi::DenseTensor& output_grad,
const int groups,
const int axis) {
const int batch_size = input.dims()[0];
const int input_channels = input.dims()[axis];
const int input_height = (axis == 1 ? input.dims()[2] : input.dims()[1]);
const int input_width = (axis == 1 ? input.dims()[3] : input.dims()[2]);
const int output_channels = output.dims()[axis];
const T* input_data = input.data<T>();
const T* output_data = output.data<T>();
const T* output_grad_data = output_grad.data<T>();
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
int nthreads = output.numel();
int blocks = (nthreads + 1024 - 1) / 1024;
dim3 threads(1024, 1);
dim3 grid(blocks, 1);
KernelMaxoutGrad<T><<<grid, threads, 0, context.stream()>>>(nthreads,
input_data,
output_data,
output_grad_data,
input_grad_data,
input_channels,
input_height,
input_width,
groups,
axis);
}
template class MaxOutGradFunctor<phi::GPUContext, float>;
template class MaxOutGradFunctor<phi::GPUContext, double>;
template class MaxOutFunctor<phi::GPUContext, float>;
template class MaxOutFunctor<phi::GPUContext, double>;
} // namespace math
} // namespace operators
} // namespace paddle
|
11d5dbd0708c41e9aaa8ab4ab9a270923e4aac68.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
// includes, system
#include <stdio.h>
#include <assert.h>
// Here you can set the device ID that was assigned to you
#define MYDEVICE 0
// Simple utility function to check for CUDA runtime errors
void checkCUDAError(const char *msg);
// Part 3 of 5: implement the kernel
__global__ void myFirstKernel(int *d_a)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
d_a[i] = blockIdx.x + threadIdx.x;
}
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main( int argc, char** argv)
{
hipSetDevice(MYDEVICE);
// pointer for host memory
int *h_a;
// pointer for device memory
int *d_a;
// define grid and block size
int numBlocks = 8;
int numThreadsPerBlock = 8;
// Part 1 of 5: allocate host and device memory
size_t memSize = numBlocks * numThreadsPerBlock * sizeof(int);
h_a = (int *) malloc(memSize);
hipMalloc((void **) &d_a, memSize);
// Part 2 of 5: configure and launch kernel
dim3 dimGrid( numBlocks );
dim3 dimBlock( numThreadsPerBlock );
hipLaunchKernelGGL(( myFirstKernel), dim3(dimGrid) , dim3(dimBlock) , 0, 0, d_a);
// block until the device has completed
hipDeviceSynchronize();
// check if kernel execution generated an error
checkCUDAError("kernel execution");
// Part 4 of 5: device to host copy
hipMemcpy( h_a, d_a, memSize ,hipMemcpyDeviceToHost);
// Check for any CUDA errors
checkCUDAError("hipMemcpy");
// Part 5 of 5: verify the data returned to the host is correct
for (int i = 0; i < numBlocks ; i++)
{
for (int j = 0; j < numThreadsPerBlock ; j++)
{
assert(h_a[i * numThreadsPerBlock + j] == i + j);
}
}
// free device memory
hipFree(d_a);
// free host memory
free(h_a);
// If the program makes it this far, then the results are correct and
// there are no run-time errors. Good work!
printf("Correct!\n");
return 0;
}
void checkCUDAError(const char *msg)
{
hipError_t err = hipGetLastError();
if( hipSuccess != err)
{
fprintf(stderr, "Cuda error: %s: %s.\n", msg, hipGetErrorString( err) );
exit(-1);
}
}
| 11d5dbd0708c41e9aaa8ab4ab9a270923e4aac68.cu | // includes, system
#include <stdio.h>
#include <assert.h>
// Here you can set the device ID that was assigned to you
#define MYDEVICE 0
// Simple utility function to check for CUDA runtime errors
void checkCUDAError(const char *msg);
// Part 3 of 5: implement the kernel
__global__ void myFirstKernel(int *d_a)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
d_a[i] = blockIdx.x + threadIdx.x;
}
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main( int argc, char** argv)
{
cudaSetDevice(MYDEVICE);
// pointer for host memory
int *h_a;
// pointer for device memory
int *d_a;
// define grid and block size
int numBlocks = 8;
int numThreadsPerBlock = 8;
// Part 1 of 5: allocate host and device memory
size_t memSize = numBlocks * numThreadsPerBlock * sizeof(int);
h_a = (int *) malloc(memSize);
cudaMalloc((void **) &d_a, memSize);
// Part 2 of 5: configure and launch kernel
dim3 dimGrid( numBlocks );
dim3 dimBlock( numThreadsPerBlock );
myFirstKernel<<< dimGrid , dimBlock >>>(d_a);
// block until the device has completed
cudaThreadSynchronize();
// check if kernel execution generated an error
checkCUDAError("kernel execution");
// Part 4 of 5: device to host copy
cudaMemcpy( h_a, d_a, memSize ,cudaMemcpyDeviceToHost);
// Check for any CUDA errors
checkCUDAError("cudaMemcpy");
// Part 5 of 5: verify the data returned to the host is correct
for (int i = 0; i < numBlocks ; i++)
{
for (int j = 0; j < numThreadsPerBlock ; j++)
{
assert(h_a[i * numThreadsPerBlock + j] == i + j);
}
}
// free device memory
cudaFree(d_a);
// free host memory
free(h_a);
// If the program makes it this far, then the results are correct and
// there are no run-time errors. Good work!
printf("Correct!\n");
return 0;
}
void checkCUDAError(const char *msg)
{
cudaError_t err = cudaGetLastError();
if( cudaSuccess != err)
{
fprintf(stderr, "Cuda error: %s: %s.\n", msg, cudaGetErrorString( err) );
exit(-1);
}
}
|
87ee328d1dea2aeef40796841009b227ba74766e.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
//
// Created by lshi on 17-9-25.
//
#include "deform_conv2d_cuda_kernel.h"
#include "THH/THH.h"
#include "TH/TH.h"
#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
#else
__device__ double atomicAdd(double* address, double val) {
unsigned long long int* address_as_ull = (unsigned long long int*)address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__double_as_longlong(val + __longlong_as_double(assumed)));
} while (assumed != old);
return __longlong_as_double(old); }
#endif
#define THREAD_PRE_BLOCK 1024
//--------------------------------------------------forward---------------------------------------------
template<typename DType>
__device__ DType Bi_Linear(const DType *bottom_data,
const int height, const int width,
const double h, const double w) {
//get the cube, the function floor can not be used in template
int h_low = int(h);
int w_low = int(w);
int h_high = (h >= height - 1 || h <= 0) ? h_low : h_low + 1;
int w_high = (w >= width - 1 || w <= 0) ? w_low : w_low + 1;
//the corner, format is hw
DType c00 = bottom_data[h_low * width + w_low];
DType c01 = bottom_data[h_low * width + w_high];
DType c10 = bottom_data[h_high * width + w_low];
DType c11 = bottom_data[h_high * width + w_high];
//calculate the distance between the point and corner, using 1 to make sure using the low if equal
DType l_width = w - w_low;
DType h_width = 1 - l_width;
DType l_height = h - h_low;
DType h_height = 1 - l_height;
//interpolation
DType c0 = c00 * h_width + c01 * l_width;
DType c1 = c10 * h_width + c11 * l_width;
DType c = c0 * h_height + c1 * l_height;
return c;
}
template<typename DType>
__global__ void deformable_im2col_gpu_kernel(
const int num_kernels, const DType *data_im, const DType *data_offset,
const int input_c, const int input_h, const int input_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group,
const int output_h, const int output_w, DType *data_col) {
for (int index = blockIdx.x * blockDim.x + threadIdx.x; index < num_kernels;
index += blockDim.x * gridDim.x) {
const int input_v = input_w * input_h;
const int output_v = output_h * output_w;
const int kernel_v = kernel_h * kernel_w;
//CH'W'H"W"
const int w_out = index % output_w;
const int h_out = index / output_w % output_h;
const int w_kernel = index / output_v % kernel_w;
const int h_kernel = index / output_v / kernel_w % kernel_h;
const int c_in = index / output_v / kernel_v % input_c;
const int h_in = h_out * stride_h - pad_h;
const int w_in = w_out * stride_w - pad_w;
const int g_off = c_in / channel_per_deformable_group;
// const int deform_group = input_c / channel_per_deformable_group;
// if (threadIdx.x == 0)
// printf("%d %d %d %d %d %d\n",threadIdx.x,c_in,h_kernel,w_kernel,h_out,w_out);
// printf("%d\n",index);
//(CH'W')(H"W")
DType *data_col_base_ptr = data_col +
(c_in * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v +
h_out * output_w +
w_out;
//CHW
const DType *data_in_base_ptr = data_im + c_in * input_v;
//GH'W'2H"W"
const DType *data_offset_base_ptr = data_offset +
(g_off * kernel_v +
h_kernel * kernel_w +
w_kernel) * 2 * output_v;
// printf("%d %f %f %f\n",threadIdx.x, *data_col_base_ptr, *data_in_base_ptr, *data_offset_base_ptr);
const int offset = h_out * output_w + w_out;
// printf("%d %d %d %d %f %f %f\n",threadIdx.x,l_in,h_in,w_in,data_offset_base_ptr[offset + output_v * 0],
// data_offset_base_ptr[offset + output_v * 1],data_offset_base_ptr[offset + output_v * 2]);
const DType h_in_after = h_in + h_kernel + data_offset_base_ptr[offset + output_v * 0];
const DType w_in_after = w_in + w_kernel + data_offset_base_ptr[offset + output_v * 1];
// printf("%d %f %f %f\n",threadIdx.x,l_in_after,h_in_after,w_in_after);
DType val = 0;
if (h_in_after > -1 && w_in_after > -1 &&
h_in_after < input_h && w_in_after < input_w) {
//interpolation
val = Bi_Linear(data_in_base_ptr, input_h, input_w,
h_in_after, w_in_after);
}
*data_col_base_ptr = val;
// if (threadIdx.x==0)
// printf("%d %f %f %f\n",threadIdx.x,h_in_after,w_in_after ,val);
}
}
inline int get_cuda_blocks(const int num_kernel) {
return (num_kernel + THREAD_PRE_BLOCK - 1) / THREAD_PRE_BLOCK;
}
void deformable_im2col(hipStream_t stream,
const double *data_in, const double *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group, double *data_col) {
int num_kernels = output_h * output_w * input_c * kernel_h * kernel_w;
deformable_im2col_gpu_kernel << < get_cuda_blocks(num_kernels), THREAD_PRE_BLOCK, 0, stream >> > (
num_kernels, data_in, data_offset,
input_c, input_h, input_w,
kernel_h, kernel_w,
pad_h, pad_w,
stride_h, stride_w,
channel_per_deformable_group,
output_h, output_w,
data_col);
}
//---------------------------------------------backward to input---------------------------------------------------
template<typename DType>
__global__ void deformable_col2im_input_gpu_kernel(
const int num_kernels, const DType *data_col, const DType *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group, DType *grad_im) {
for (int index = blockIdx.x * blockDim.x + threadIdx.x; index < num_kernels;
index += blockDim.x * gridDim.x) {
const int input_v = input_w * input_h;
const int output_v = output_h * output_w;
const int kernel_v = kernel_h * kernel_w;
//H"W"CH'W'
const int w_kernel = index % kernel_w;
const int h_kernel = index / kernel_w % kernel_h;
const int c_in = index / kernel_v % input_c;
const int w_out = index / kernel_v / input_c % output_w;
const int h_out = index / kernel_v / input_c / output_w % output_h;
const int h_in = h_out * stride_h - pad_h;
const int w_in = w_out * stride_w - pad_w;
const int g_off = c_in / channel_per_deformable_group;
// const int deform_group = input_c / channel_per_deformable_group;
//CH'W' H"W"
const DType *data_col_base_ptr = data_col +
(c_in * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v +
h_out * output_w +
w_out;
//GH'W'3H"W"
int offset_base = (g_off * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v * 2;
int offset = h_out * output_w + w_out;
const DType *data_offset_base_ptr = data_offset + offset_base;
//CHW
DType *grad_in_base_ptr = grad_im + c_in * input_v;
const int width = input_w;
const DType h_in_after = h_in + h_kernel + data_offset_base_ptr[0 * output_v + offset];
const DType w_in_after = w_in + w_kernel + data_offset_base_ptr[1 * output_v + offset];
if (h_in_after > -1 && w_in_after > -1 &&
h_in_after < input_h && w_in_after < input_w) {
//eight point around
int h_low = int(h_in_after);
int w_low = int(w_in_after);
int h_high = (h_in_after >= input_h - 1 || h_in_after <= 0) ? h_low : h_low + 1;
int w_high = (w_in_after >= input_w - 1 || w_in_after <= 0) ? w_low : w_low + 1;
int a00 = h_low * width + w_low;
int a01 = h_low * width + w_high;
int a10 = h_high * width + w_low;
int a11 = h_high * width + w_high;
DType l_width = w_in_after - w_low;
DType h_width = 1 - l_width;
DType l_height = h_in_after - h_low;
DType h_height = 1 - l_height;
//grad for input
atomicAdd(
grad_in_base_ptr + a00,
h_height * h_width *
(*data_col_base_ptr));
atomicAdd(
grad_in_base_ptr + a01,
h_height * l_width *
(*data_col_base_ptr));
atomicAdd(
grad_in_base_ptr + a10,
l_height * h_width *
(*data_col_base_ptr));
atomicAdd(
grad_in_base_ptr + a11,
l_height * l_width *
(*data_col_base_ptr));
}
}
}
void deformable_col2im_input(hipStream_t stream,
const double *data_col, const double *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group, double *grad_im) {
const int num_kernels = output_h * output_w * input_c * kernel_h * kernel_w;
deformable_col2im_input_gpu_kernel << < get_cuda_blocks(num_kernels), THREAD_PRE_BLOCK, 0, stream >> > (
num_kernels, data_col, data_offset,
input_c, input_h, input_w,
output_h, output_w,
kernel_h, kernel_w,
pad_h, pad_w,
stride_h, stride_w,
channel_per_deformable_group, grad_im
);
}
//--------------------------------------------------backward to offset---------------------------------------------
template<typename DType>
__global__ void deformable_col2im_offset_gpu_kernel(
const int num_kernels, const DType *data_col, const DType *data_im, const DType *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group,
DType *grad_off) {
for (int index = blockIdx.x * blockDim.x + threadIdx.x; index < num_kernels;
index += blockDim.x * gridDim.x) {
//GH'W'2H"W"
const int input_v = input_w * input_h;
const int output_v = output_h * output_w;
const int kernel_v = kernel_h * kernel_w;
const int deform_group = input_c / channel_per_deformable_group;
const int w_out = index % output_w;
const int h_out = index / output_w % output_h;
const int int_2 = index / output_v % 2;
const int w_kernel = index / output_v / 2 % kernel_w;
const int h_kernel = index / output_v / 2 / kernel_w % kernel_h;
const int g_off = index / output_v / 2 / kernel_v % deform_group;
const int h_in = h_out * stride_h - pad_h;
const int w_in = w_out * stride_w - pad_w;
//GH"W"H'W'2
int offset_base = (g_off * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v * 2;
int offset = h_out * output_w + w_out;
const DType *data_offset_base_ptr = data_offset + offset_base;
DType *grad_offset_base_ptr = grad_off + offset_base + int_2 * output_v + offset;
DType val = 0;
for (int i = 0; i < channel_per_deformable_group; ++i) {
const int c_in = g_off * channel_per_deformable_group + i;
//CH'W' H"W"
const DType *data_col_base_ptr = data_col +
(c_in * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v +
h_out * output_w +
w_out;
//CHW
const DType *data_in_base_ptr = data_im + c_in * input_v;
const int width = input_w;
const DType h_in_after = h_in + h_kernel + data_offset_base_ptr[0 * output_v + offset];
const DType w_in_after = w_in + w_kernel + data_offset_base_ptr[1 * output_v + offset];
if (h_in_after > -1 && w_in_after > -1 &&
h_in_after < input_h && w_in_after < input_w) {
int h_low = int(h_in_after);
int w_low = int(w_in_after);
int h_high = (h_in_after >= input_h - 1 || h_in_after <= 0) ? h_low : h_low + 1;
int w_high = (w_in_after >= input_w - 1 || w_in_after <= 0) ? w_low : w_low + 1;
int a00 = h_low * width + w_low;
int a01 = h_low * width + w_high;
int a10 = h_high * width + w_low;
int a11 = h_high * width + w_high;
//value of eight point
DType c00 = data_in_base_ptr[a00];
DType c01 = data_in_base_ptr[a01];
DType c10 = data_in_base_ptr[a10];
DType c11 = data_in_base_ptr[a11];
//six distance
DType l_width = w_in_after - w_low;
DType h_width = 1 - l_width;
DType l_height = h_in_after - h_low;
DType h_height = 1 - l_height;
//h:1+ w:0*h_width
switch (int_2) {
case 0:
val += *data_col_base_ptr *
(c11 * l_width + c10 * h_width -
c01 * l_width - c00 * h_width);
break;
case 1:
val += *data_col_base_ptr *
(c01 * h_height + c11 * l_height -
c00 * h_height - c10 * l_height);
break;
default:
printf("error in switch");
}
}
}
*grad_offset_base_ptr = val;
}
}
void deformable_col2im_offset(hipStream_t stream,
const double *data_col, const double *data_im, const double *data_offset,
const int input_c, const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group,
double *grad_offset) {
const int num_kernels = (input_c / channel_per_deformable_group)
* kernel_h * kernel_w * 2 * output_h * output_w;
deformable_col2im_offset_gpu_kernel << < get_cuda_blocks(num_kernels), THREAD_PRE_BLOCK, 0, stream >> > (
num_kernels, data_col, data_im, data_offset,
input_c, input_h, input_w,
output_h, output_w,
kernel_h, kernel_w,
pad_h, pad_w,
stride_h, stride_w,
channel_per_deformable_group, grad_offset
);
}
| 87ee328d1dea2aeef40796841009b227ba74766e.cu | //
// Created by lshi on 17-9-25.
//
#include "deform_conv2d_cuda_kernel.h"
#include "THC/THC.h"
#include "TH/TH.h"
#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
#else
__device__ double atomicAdd(double* address, double val) {
unsigned long long int* address_as_ull = (unsigned long long int*)address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__double_as_longlong(val + __longlong_as_double(assumed)));
} while (assumed != old);
return __longlong_as_double(old); }
#endif
#define THREAD_PRE_BLOCK 1024
//--------------------------------------------------forward---------------------------------------------
template<typename DType>
__device__ DType Bi_Linear(const DType *bottom_data,
const int height, const int width,
const double h, const double w) {
//get the cube, the function floor can not be used in template
int h_low = int(h);
int w_low = int(w);
int h_high = (h >= height - 1 || h <= 0) ? h_low : h_low + 1;
int w_high = (w >= width - 1 || w <= 0) ? w_low : w_low + 1;
//the corner, format is hw
DType c00 = bottom_data[h_low * width + w_low];
DType c01 = bottom_data[h_low * width + w_high];
DType c10 = bottom_data[h_high * width + w_low];
DType c11 = bottom_data[h_high * width + w_high];
//calculate the distance between the point and corner, using 1 to make sure using the low if equal
DType l_width = w - w_low;
DType h_width = 1 - l_width;
DType l_height = h - h_low;
DType h_height = 1 - l_height;
//interpolation
DType c0 = c00 * h_width + c01 * l_width;
DType c1 = c10 * h_width + c11 * l_width;
DType c = c0 * h_height + c1 * l_height;
return c;
}
template<typename DType>
__global__ void deformable_im2col_gpu_kernel(
const int num_kernels, const DType *data_im, const DType *data_offset,
const int input_c, const int input_h, const int input_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group,
const int output_h, const int output_w, DType *data_col) {
for (int index = blockIdx.x * blockDim.x + threadIdx.x; index < num_kernels;
index += blockDim.x * gridDim.x) {
const int input_v = input_w * input_h;
const int output_v = output_h * output_w;
const int kernel_v = kernel_h * kernel_w;
//CH'W'H"W"
const int w_out = index % output_w;
const int h_out = index / output_w % output_h;
const int w_kernel = index / output_v % kernel_w;
const int h_kernel = index / output_v / kernel_w % kernel_h;
const int c_in = index / output_v / kernel_v % input_c;
const int h_in = h_out * stride_h - pad_h;
const int w_in = w_out * stride_w - pad_w;
const int g_off = c_in / channel_per_deformable_group;
// const int deform_group = input_c / channel_per_deformable_group;
// if (threadIdx.x == 0)
// printf("%d %d %d %d %d %d\n",threadIdx.x,c_in,h_kernel,w_kernel,h_out,w_out);
// printf("%d\n",index);
//(CH'W')(H"W")
DType *data_col_base_ptr = data_col +
(c_in * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v +
h_out * output_w +
w_out;
//CHW
const DType *data_in_base_ptr = data_im + c_in * input_v;
//GH'W'2H"W"
const DType *data_offset_base_ptr = data_offset +
(g_off * kernel_v +
h_kernel * kernel_w +
w_kernel) * 2 * output_v;
// printf("%d %f %f %f\n",threadIdx.x, *data_col_base_ptr, *data_in_base_ptr, *data_offset_base_ptr);
const int offset = h_out * output_w + w_out;
// printf("%d %d %d %d %f %f %f\n",threadIdx.x,l_in,h_in,w_in,data_offset_base_ptr[offset + output_v * 0],
// data_offset_base_ptr[offset + output_v * 1],data_offset_base_ptr[offset + output_v * 2]);
const DType h_in_after = h_in + h_kernel + data_offset_base_ptr[offset + output_v * 0];
const DType w_in_after = w_in + w_kernel + data_offset_base_ptr[offset + output_v * 1];
// printf("%d %f %f %f\n",threadIdx.x,l_in_after,h_in_after,w_in_after);
DType val = 0;
if (h_in_after > -1 && w_in_after > -1 &&
h_in_after < input_h && w_in_after < input_w) {
//interpolation
val = Bi_Linear(data_in_base_ptr, input_h, input_w,
h_in_after, w_in_after);
}
*data_col_base_ptr = val;
// if (threadIdx.x==0)
// printf("%d %f %f %f\n",threadIdx.x,h_in_after,w_in_after ,val);
}
}
inline int get_cuda_blocks(const int num_kernel) {
return (num_kernel + THREAD_PRE_BLOCK - 1) / THREAD_PRE_BLOCK;
}
void deformable_im2col(cudaStream_t stream,
const double *data_in, const double *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group, double *data_col) {
int num_kernels = output_h * output_w * input_c * kernel_h * kernel_w;
deformable_im2col_gpu_kernel << < get_cuda_blocks(num_kernels), THREAD_PRE_BLOCK, 0, stream >> > (
num_kernels, data_in, data_offset,
input_c, input_h, input_w,
kernel_h, kernel_w,
pad_h, pad_w,
stride_h, stride_w,
channel_per_deformable_group,
output_h, output_w,
data_col);
}
//---------------------------------------------backward to input---------------------------------------------------
template<typename DType>
__global__ void deformable_col2im_input_gpu_kernel(
const int num_kernels, const DType *data_col, const DType *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group, DType *grad_im) {
for (int index = blockIdx.x * blockDim.x + threadIdx.x; index < num_kernels;
index += blockDim.x * gridDim.x) {
const int input_v = input_w * input_h;
const int output_v = output_h * output_w;
const int kernel_v = kernel_h * kernel_w;
//H"W"CH'W'
const int w_kernel = index % kernel_w;
const int h_kernel = index / kernel_w % kernel_h;
const int c_in = index / kernel_v % input_c;
const int w_out = index / kernel_v / input_c % output_w;
const int h_out = index / kernel_v / input_c / output_w % output_h;
const int h_in = h_out * stride_h - pad_h;
const int w_in = w_out * stride_w - pad_w;
const int g_off = c_in / channel_per_deformable_group;
// const int deform_group = input_c / channel_per_deformable_group;
//CH'W' H"W"
const DType *data_col_base_ptr = data_col +
(c_in * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v +
h_out * output_w +
w_out;
//GH'W'3H"W"
int offset_base = (g_off * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v * 2;
int offset = h_out * output_w + w_out;
const DType *data_offset_base_ptr = data_offset + offset_base;
//CHW
DType *grad_in_base_ptr = grad_im + c_in * input_v;
const int width = input_w;
const DType h_in_after = h_in + h_kernel + data_offset_base_ptr[0 * output_v + offset];
const DType w_in_after = w_in + w_kernel + data_offset_base_ptr[1 * output_v + offset];
if (h_in_after > -1 && w_in_after > -1 &&
h_in_after < input_h && w_in_after < input_w) {
//eight point around
int h_low = int(h_in_after);
int w_low = int(w_in_after);
int h_high = (h_in_after >= input_h - 1 || h_in_after <= 0) ? h_low : h_low + 1;
int w_high = (w_in_after >= input_w - 1 || w_in_after <= 0) ? w_low : w_low + 1;
int a00 = h_low * width + w_low;
int a01 = h_low * width + w_high;
int a10 = h_high * width + w_low;
int a11 = h_high * width + w_high;
DType l_width = w_in_after - w_low;
DType h_width = 1 - l_width;
DType l_height = h_in_after - h_low;
DType h_height = 1 - l_height;
//grad for input
atomicAdd(
grad_in_base_ptr + a00,
h_height * h_width *
(*data_col_base_ptr));
atomicAdd(
grad_in_base_ptr + a01,
h_height * l_width *
(*data_col_base_ptr));
atomicAdd(
grad_in_base_ptr + a10,
l_height * h_width *
(*data_col_base_ptr));
atomicAdd(
grad_in_base_ptr + a11,
l_height * l_width *
(*data_col_base_ptr));
}
}
}
void deformable_col2im_input(cudaStream_t stream,
const double *data_col, const double *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group, double *grad_im) {
const int num_kernels = output_h * output_w * input_c * kernel_h * kernel_w;
deformable_col2im_input_gpu_kernel << < get_cuda_blocks(num_kernels), THREAD_PRE_BLOCK, 0, stream >> > (
num_kernels, data_col, data_offset,
input_c, input_h, input_w,
output_h, output_w,
kernel_h, kernel_w,
pad_h, pad_w,
stride_h, stride_w,
channel_per_deformable_group, grad_im
);
}
//--------------------------------------------------backward to offset---------------------------------------------
template<typename DType>
__global__ void deformable_col2im_offset_gpu_kernel(
const int num_kernels, const DType *data_col, const DType *data_im, const DType *data_offset,
const int input_c,
const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group,
DType *grad_off) {
for (int index = blockIdx.x * blockDim.x + threadIdx.x; index < num_kernels;
index += blockDim.x * gridDim.x) {
//GH'W'2H"W"
const int input_v = input_w * input_h;
const int output_v = output_h * output_w;
const int kernel_v = kernel_h * kernel_w;
const int deform_group = input_c / channel_per_deformable_group;
const int w_out = index % output_w;
const int h_out = index / output_w % output_h;
const int int_2 = index / output_v % 2;
const int w_kernel = index / output_v / 2 % kernel_w;
const int h_kernel = index / output_v / 2 / kernel_w % kernel_h;
const int g_off = index / output_v / 2 / kernel_v % deform_group;
const int h_in = h_out * stride_h - pad_h;
const int w_in = w_out * stride_w - pad_w;
//GH"W"H'W'2
int offset_base = (g_off * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v * 2;
int offset = h_out * output_w + w_out;
const DType *data_offset_base_ptr = data_offset + offset_base;
DType *grad_offset_base_ptr = grad_off + offset_base + int_2 * output_v + offset;
DType val = 0;
for (int i = 0; i < channel_per_deformable_group; ++i) {
const int c_in = g_off * channel_per_deformable_group + i;
//CH'W' H"W"
const DType *data_col_base_ptr = data_col +
(c_in * kernel_v +
h_kernel * kernel_w +
w_kernel) * output_v +
h_out * output_w +
w_out;
//CHW
const DType *data_in_base_ptr = data_im + c_in * input_v;
const int width = input_w;
const DType h_in_after = h_in + h_kernel + data_offset_base_ptr[0 * output_v + offset];
const DType w_in_after = w_in + w_kernel + data_offset_base_ptr[1 * output_v + offset];
if (h_in_after > -1 && w_in_after > -1 &&
h_in_after < input_h && w_in_after < input_w) {
int h_low = int(h_in_after);
int w_low = int(w_in_after);
int h_high = (h_in_after >= input_h - 1 || h_in_after <= 0) ? h_low : h_low + 1;
int w_high = (w_in_after >= input_w - 1 || w_in_after <= 0) ? w_low : w_low + 1;
int a00 = h_low * width + w_low;
int a01 = h_low * width + w_high;
int a10 = h_high * width + w_low;
int a11 = h_high * width + w_high;
//value of eight point
DType c00 = data_in_base_ptr[a00];
DType c01 = data_in_base_ptr[a01];
DType c10 = data_in_base_ptr[a10];
DType c11 = data_in_base_ptr[a11];
//six distance
DType l_width = w_in_after - w_low;
DType h_width = 1 - l_width;
DType l_height = h_in_after - h_low;
DType h_height = 1 - l_height;
//h:1+ w:0*h_width
switch (int_2) {
case 0:
val += *data_col_base_ptr *
(c11 * l_width + c10 * h_width -
c01 * l_width - c00 * h_width);
break;
case 1:
val += *data_col_base_ptr *
(c01 * h_height + c11 * l_height -
c00 * h_height - c10 * l_height);
break;
default:
printf("error in switch");
}
}
}
*grad_offset_base_ptr = val;
}
}
void deformable_col2im_offset(cudaStream_t stream,
const double *data_col, const double *data_im, const double *data_offset,
const int input_c, const int input_h, const int input_w,
const int output_h, const int output_w,
const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int channel_per_deformable_group,
double *grad_offset) {
const int num_kernels = (input_c / channel_per_deformable_group)
* kernel_h * kernel_w * 2 * output_h * output_w;
deformable_col2im_offset_gpu_kernel << < get_cuda_blocks(num_kernels), THREAD_PRE_BLOCK, 0, stream >> > (
num_kernels, data_col, data_im, data_offset,
input_c, input_h, input_w,
output_h, output_w,
kernel_h, kernel_w,
pad_h, pad_w,
stride_h, stride_w,
channel_per_deformable_group, grad_offset
);
}
|
bddf145def810a84156662a05bee53b374bff9cd.hip | // !!! This is a file automatically generated by hipify!!!
// Utilities and system includes
#include <stdio.h>
#include <stdlib.h>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#define DATA_TYPE 1 // 0-SP, 1-INT, 2-DP
#define SIZE 60000000
#define TILE_DIM 1024
#define INNER_REPS 16
template <class T> __global__ void simpleKernel(T *A, T *C1, T *C2, T *C3, T *C4)
{
int xIndex = blockIdx.x * TILE_DIM + threadIdx.x;
T ra, rb, rc, rd;
if (xIndex < SIZE) {
ra=A[xIndex];
rb=A[SIZE-xIndex];
rc=A[xIndex];
rd=A[SIZE-xIndex];
// rb=A[xIndex];
#pragma unroll 16
for (int i=0;i<INNER_REPS;i++) {
ra=ra*rc+rb;
rb=rb*rd+rc;
rc=rc*ra+rd;
rd=rd*rb+ra;
}
C1[xIndex]=ra;
C2[xIndex]=rb;
C3[xIndex]=rc;
C4[xIndex]=rd;
}
}
int main(int argc, char **argv) {
int outer_reps, vector_size, tile_dim;
vector_size = SIZE;
tile_dim = TILE_DIM;
if (argc>1){
outer_reps = atoi(argv[1]);
}else{
outer_reps = 1;
}
// execution configuration parameters
dim3 grid(vector_size/tile_dim, 1), threads(tile_dim, 1);
// CUDA events
hipEvent_t start, stop;
size_t mem_size = static_cast<size_t>(sizeof(double) * vector_size);
// allocate host memory
double *h_iA = (double *) malloc(mem_size);
double *h_oC1 = (double *) malloc(mem_size);
double *h_oC2 = (double *) malloc(mem_size);
double *h_oC3 = (double *) malloc(mem_size);
double *h_oC4 = (double *) malloc(mem_size);
// initalize host data
for (int i = 0; i < vector_size; ++i)
{
h_iA[i] = (double) i+3;
// h_iB[i] = (float) i+3;
}
// allocate device memory
double *d_iA, *d_iB, *d_oC1, *d_oC2, *d_oC3, *d_oC4;
hipMalloc((void **) &d_iA, mem_size);
// hipMalloc((void **) &d_iB, mem_size);
hipMalloc((void **) &d_oC1, mem_size);
hipMalloc((void **) &d_oC2, mem_size);
hipMalloc((void **) &d_oC3, mem_size);
hipMalloc((void **) &d_oC4, mem_size);
// copy host data to device
hipMemcpy(d_iA, h_iA, mem_size, hipMemcpyHostToDevice);
// hipMemcpy(d_iB, h_iB, mem_size, hipMemcpyHostToDevice);
// print out common data for all kernels
printf("\nVector size: %d TotalBlocks: %d blockSize: %d\n\n", vector_size, grid.x, threads.x);
// initialize events
hipEventCreate(&start);
hipEventCreate(&stop);
// take measurements for loop over kernel launches
hipEventRecord(start, 0);
for (int i=0; i < outer_reps; i++)
{
hipLaunchKernelGGL(( simpleKernel<double>), dim3(grid), dim3(threads), 0, 0, d_iA, d_oC1, d_oC2, d_oC3, d_oC4);
}
hipEventRecord(stop, 0);
hipEventSynchronize(stop);
float kernelTime;
hipEventElapsedTime(&kernelTime, start, stop);
// take measurements for loop inside kernel
hipMemcpy(h_oC1, d_oC1, mem_size, hipMemcpyDeviceToHost);
hipMemcpy(h_oC2, d_oC2, mem_size, hipMemcpyDeviceToHost);
hipMemcpy(h_oC3, d_oC3, mem_size, hipMemcpyDeviceToHost);
hipMemcpy(h_oC4, d_oC4, mem_size, hipMemcpyDeviceToHost);
printf("teste: %f\n", h_oC1[0]);
// report effective bandwidths
float kernelBandwidth = 2.0f * 1000.0f * mem_size/(1024*1024*1024)/(kernelTime/outer_reps);
printf("simpleKernel, Throughput = %.4f GB/s, Time = %.5f ms, Size = %u fp32 elements, NumDevsUsed = %u, Workgroup = %u\n",
kernelBandwidth,
kernelTime/outer_reps,
vector_size, 1, tile_dim * 1);
free(h_iA);
// free(h_iB);
free(h_oC1);
free(h_oC2);
free(h_oC3);
free(h_oC4);
hipFree(d_iA);
// hipFree(d_iB);
hipFree(d_oC1);
hipFree(d_oC2);
hipFree(d_oC3);
hipFree(d_oC4);
hipEventDestroy(start);
hipEventDestroy(stop);
hipDeviceReset();
printf("Test passed\n");
exit(EXIT_SUCCESS);
}
| bddf145def810a84156662a05bee53b374bff9cd.cu | // Utilities and system includes
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <cuda_profiler_api.h>
#define DATA_TYPE 1 // 0-SP, 1-INT, 2-DP
#define SIZE 60000000
#define TILE_DIM 1024
#define INNER_REPS 16
template <class T> __global__ void simpleKernel(T *A, T *C1, T *C2, T *C3, T *C4)
{
int xIndex = blockIdx.x * TILE_DIM + threadIdx.x;
T ra, rb, rc, rd;
if (xIndex < SIZE) {
ra=A[xIndex];
rb=A[SIZE-xIndex];
rc=A[xIndex];
rd=A[SIZE-xIndex];
// rb=A[xIndex];
#pragma unroll 16
for (int i=0;i<INNER_REPS;i++) {
ra=ra*rc+rb;
rb=rb*rd+rc;
rc=rc*ra+rd;
rd=rd*rb+ra;
}
C1[xIndex]=ra;
C2[xIndex]=rb;
C3[xIndex]=rc;
C4[xIndex]=rd;
}
}
int main(int argc, char **argv) {
int outer_reps, vector_size, tile_dim;
vector_size = SIZE;
tile_dim = TILE_DIM;
if (argc>1){
outer_reps = atoi(argv[1]);
}else{
outer_reps = 1;
}
// execution configuration parameters
dim3 grid(vector_size/tile_dim, 1), threads(tile_dim, 1);
// CUDA events
cudaEvent_t start, stop;
size_t mem_size = static_cast<size_t>(sizeof(double) * vector_size);
// allocate host memory
double *h_iA = (double *) malloc(mem_size);
double *h_oC1 = (double *) malloc(mem_size);
double *h_oC2 = (double *) malloc(mem_size);
double *h_oC3 = (double *) malloc(mem_size);
double *h_oC4 = (double *) malloc(mem_size);
// initalize host data
for (int i = 0; i < vector_size; ++i)
{
h_iA[i] = (double) i+3;
// h_iB[i] = (float) i+3;
}
// allocate device memory
double *d_iA, *d_iB, *d_oC1, *d_oC2, *d_oC3, *d_oC4;
cudaMalloc((void **) &d_iA, mem_size);
// cudaMalloc((void **) &d_iB, mem_size);
cudaMalloc((void **) &d_oC1, mem_size);
cudaMalloc((void **) &d_oC2, mem_size);
cudaMalloc((void **) &d_oC3, mem_size);
cudaMalloc((void **) &d_oC4, mem_size);
// copy host data to device
cudaMemcpy(d_iA, h_iA, mem_size, cudaMemcpyHostToDevice);
// cudaMemcpy(d_iB, h_iB, mem_size, cudaMemcpyHostToDevice);
// print out common data for all kernels
printf("\nVector size: %d TotalBlocks: %d blockSize: %d\n\n", vector_size, grid.x, threads.x);
// initialize events
cudaEventCreate(&start);
cudaEventCreate(&stop);
// take measurements for loop over kernel launches
cudaEventRecord(start, 0);
for (int i=0; i < outer_reps; i++)
{
simpleKernel<double><<<grid, threads>>>(d_iA, d_oC1, d_oC2, d_oC3, d_oC4);
}
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float kernelTime;
cudaEventElapsedTime(&kernelTime, start, stop);
// take measurements for loop inside kernel
cudaMemcpy(h_oC1, d_oC1, mem_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_oC2, d_oC2, mem_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_oC3, d_oC3, mem_size, cudaMemcpyDeviceToHost);
cudaMemcpy(h_oC4, d_oC4, mem_size, cudaMemcpyDeviceToHost);
printf("teste: %f\n", h_oC1[0]);
// report effective bandwidths
float kernelBandwidth = 2.0f * 1000.0f * mem_size/(1024*1024*1024)/(kernelTime/outer_reps);
printf("simpleKernel, Throughput = %.4f GB/s, Time = %.5f ms, Size = %u fp32 elements, NumDevsUsed = %u, Workgroup = %u\n",
kernelBandwidth,
kernelTime/outer_reps,
vector_size, 1, tile_dim * 1);
free(h_iA);
// free(h_iB);
free(h_oC1);
free(h_oC2);
free(h_oC3);
free(h_oC4);
cudaFree(d_iA);
// cudaFree(d_iB);
cudaFree(d_oC1);
cudaFree(d_oC2);
cudaFree(d_oC3);
cudaFree(d_oC4);
cudaEventDestroy(start);
cudaEventDestroy(stop);
cudaDeviceReset();
printf("Test passed\n");
exit(EXIT_SUCCESS);
}
|
f42e95a06939e04fda8823cdc567251e13983f9d.hip | // !!! This is a file automatically generated by hipify!!!
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <thrust/sequence.h>
#include <thrust/random.h>
#include <thrust/generate.h>
#include <thrust/detail/type_traits.h>
#include <helper_cuda.h>
#include <algorithm>
#include <time.h>
#include <limits.h>
template <typename T, bool floatKeys>
bool testSort(int argc, char **argv)
{
int cmdVal;
int keybits = 32;
unsigned int numElements = 1048576;
bool keysOnly = (checkCmdLineFlag(argc, (const char **)argv, "keysonly") == true);
bool quiet = (checkCmdLineFlag(argc, (const char **)argv, "quiet") == true);
if (checkCmdLineFlag(argc, (const char **)argv, "n"))
{
cmdVal = getCmdLineArgumentInt(argc, (const char **)argv, "n");
numElements = cmdVal;
if (cmdVal < 0)
{
printf("Error: elements must be > 0, elements=%d is invalid\n", cmdVal);
exit(EXIT_SUCCESS);
}
}
if (checkCmdLineFlag(argc, (const char **)argv, "keybits"))
{
cmdVal = getCmdLineArgumentInt(argc, (const char **)argv, "keybits");
keybits = cmdVal;
if (keybits <= 0)
{
printf("Error: keybits must be > 0, keybits=%d is invalid\n", keybits);
exit(EXIT_SUCCESS);
}
}
unsigned int numIterations = (numElements >= 16777216) ? 10 : 100;
if (checkCmdLineFlag(argc, (const char **)argv, "iterations"))
{
cmdVal = getCmdLineArgumentInt(argc, (const char **)argv, "iterations");
numIterations = cmdVal;
}
if (checkCmdLineFlag(argc, (const char **)argv, "help"))
{
printf("Command line:\nradixSortThrust [-option]\n");
printf("Valid options:\n");
printf("-n=<N> : number of elements to sort\n");
printf("-keybits=bits : keybits must be > 0\n");
printf("-keysonly : only sort an array of keys (default sorts key-value pairs)\n");
printf("-float : use 32-bit float keys (default is 32-bit signed int)\n");
printf("-quiet : Output only the number of elements and the time to sort\n");
printf("-help : Output a help message\n");
exit(EXIT_SUCCESS);
}
if (!quiet)
printf("\nSorting %d %d-bit %s keys %s\n\n", numElements, keybits, floatKeys ? "float" : "int", keysOnly ? "(only)" : "and values");
int deviceID = -1;
if (hipSuccess == hipGetDevice(&deviceID))
{
hipDeviceProp_t devprop;
hipGetDeviceProperties(&devprop, deviceID);
unsigned int totalMem = (keysOnly ? 2 : 4) * numElements * sizeof(T);
if (devprop.totalGlobalMem < totalMem)
{
printf("Error: insufficient amount of memory to sort %d elements.\n", numElements);
printf("%d bytes needed, %d bytes available\n", (int) totalMem, (int) devprop.totalGlobalMem);
exit(EXIT_SUCCESS);
}
}
thrust::host_vector<T> h_keys(numElements);
thrust::host_vector<T> h_keysSorted(numElements);
thrust::host_vector<unsigned int> h_values;
if (!keysOnly)
h_values = thrust::host_vector<unsigned int>(numElements);
// Fill up with some random data
thrust::default_random_engine rng(clock());
if (floatKeys)
{
thrust::uniform_real_distribution<float> u01(0, 1);
for (int i = 0; i < (int)numElements; i++)
h_keys[i] = u01(rng);
}
else
{
thrust::uniform_int_distribution<int> u(INT_MIN, INT_MAX);
for (int i = 0; i < (int)numElements; i++)
h_keys[i] = u(rng);
}
if (!keysOnly)
thrust::sequence(h_values.begin(), h_values.end());
// Copy data onto the GPU
thrust::device_vector<T> d_keys;
thrust::device_vector<unsigned int> d_values;
// run multiple iterations to compute an average sort time
hipEvent_t start_event, stop_event;
checkCudaErrors(hipEventCreate(&start_event));
checkCudaErrors(hipEventCreate(&stop_event));
float totalTime = 0;
for (unsigned int i = 0; i < numIterations; i++)
{
// reset data before sort
d_keys= h_keys;
if (!keysOnly)
d_values = h_values;
checkCudaErrors(hipEventRecord(start_event, 0));
if (keysOnly)
thrust::sort(d_keys.begin(), d_keys.end());
else
thrust::sort_by_key(d_keys.begin(), d_keys.end(), d_values.begin());
checkCudaErrors(hipEventRecord(stop_event, 0));
checkCudaErrors(hipEventSynchronize(stop_event));
float time = 0;
checkCudaErrors(hipEventElapsedTime(&time, start_event, stop_event));
totalTime += time;
}
totalTime /= (1.0e3f * numIterations);
printf("radixSort, Throughput = %.4f MElements/s, Time = %.5f ms, Size = %u elements\n",
1.0e-6f * numElements / totalTime, totalTime * 1000, numElements);
getLastCudaError("after radixsort");
// Get results back to host for correctness checking
thrust::copy(d_keys.begin(), d_keys.end(), h_keysSorted.begin());
if (!keysOnly)
thrust::copy(d_values.begin(), d_values.end(), h_values.begin());
getLastCudaError("copying results to host memory");
// Check results
bool bTestResult = thrust::is_sorted(h_keysSorted.begin(), h_keysSorted.end());
checkCudaErrors(hipEventDestroy(start_event));
checkCudaErrors(hipEventDestroy(stop_event));
if (!bTestResult && !quiet)
{
return false;
}
return bTestResult;
}
int main(int argc, char **argv)
{
// Start logs
printf("%s starting...\n\n", argv[0]);
findCudaDevice(argc, (const char **)argv);
bool bTestResult = false;
if (checkCmdLineFlag(argc, (const char **)argv, "float"))
bTestResult = testSort<float, true>(argc, argv);
else
bTestResult = testSort<int, false>(argc, argv);
checkCudaErrors(hipDeviceReset());
printf(bTestResult ? "Test passed\n" : "Test failed!\n");
}
| f42e95a06939e04fda8823cdc567251e13983f9d.cu | #include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <thrust/sequence.h>
#include <thrust/random.h>
#include <thrust/generate.h>
#include <thrust/detail/type_traits.h>
#include <helper_cuda.h>
#include <algorithm>
#include <time.h>
#include <limits.h>
template <typename T, bool floatKeys>
bool testSort(int argc, char **argv)
{
int cmdVal;
int keybits = 32;
unsigned int numElements = 1048576;
bool keysOnly = (checkCmdLineFlag(argc, (const char **)argv, "keysonly") == true);
bool quiet = (checkCmdLineFlag(argc, (const char **)argv, "quiet") == true);
if (checkCmdLineFlag(argc, (const char **)argv, "n"))
{
cmdVal = getCmdLineArgumentInt(argc, (const char **)argv, "n");
numElements = cmdVal;
if (cmdVal < 0)
{
printf("Error: elements must be > 0, elements=%d is invalid\n", cmdVal);
exit(EXIT_SUCCESS);
}
}
if (checkCmdLineFlag(argc, (const char **)argv, "keybits"))
{
cmdVal = getCmdLineArgumentInt(argc, (const char **)argv, "keybits");
keybits = cmdVal;
if (keybits <= 0)
{
printf("Error: keybits must be > 0, keybits=%d is invalid\n", keybits);
exit(EXIT_SUCCESS);
}
}
unsigned int numIterations = (numElements >= 16777216) ? 10 : 100;
if (checkCmdLineFlag(argc, (const char **)argv, "iterations"))
{
cmdVal = getCmdLineArgumentInt(argc, (const char **)argv, "iterations");
numIterations = cmdVal;
}
if (checkCmdLineFlag(argc, (const char **)argv, "help"))
{
printf("Command line:\nradixSortThrust [-option]\n");
printf("Valid options:\n");
printf("-n=<N> : number of elements to sort\n");
printf("-keybits=bits : keybits must be > 0\n");
printf("-keysonly : only sort an array of keys (default sorts key-value pairs)\n");
printf("-float : use 32-bit float keys (default is 32-bit signed int)\n");
printf("-quiet : Output only the number of elements and the time to sort\n");
printf("-help : Output a help message\n");
exit(EXIT_SUCCESS);
}
if (!quiet)
printf("\nSorting %d %d-bit %s keys %s\n\n", numElements, keybits, floatKeys ? "float" : "int", keysOnly ? "(only)" : "and values");
int deviceID = -1;
if (cudaSuccess == cudaGetDevice(&deviceID))
{
cudaDeviceProp devprop;
cudaGetDeviceProperties(&devprop, deviceID);
unsigned int totalMem = (keysOnly ? 2 : 4) * numElements * sizeof(T);
if (devprop.totalGlobalMem < totalMem)
{
printf("Error: insufficient amount of memory to sort %d elements.\n", numElements);
printf("%d bytes needed, %d bytes available\n", (int) totalMem, (int) devprop.totalGlobalMem);
exit(EXIT_SUCCESS);
}
}
thrust::host_vector<T> h_keys(numElements);
thrust::host_vector<T> h_keysSorted(numElements);
thrust::host_vector<unsigned int> h_values;
if (!keysOnly)
h_values = thrust::host_vector<unsigned int>(numElements);
// Fill up with some random data
thrust::default_random_engine rng(clock());
if (floatKeys)
{
thrust::uniform_real_distribution<float> u01(0, 1);
for (int i = 0; i < (int)numElements; i++)
h_keys[i] = u01(rng);
}
else
{
thrust::uniform_int_distribution<int> u(INT_MIN, INT_MAX);
for (int i = 0; i < (int)numElements; i++)
h_keys[i] = u(rng);
}
if (!keysOnly)
thrust::sequence(h_values.begin(), h_values.end());
// Copy data onto the GPU
thrust::device_vector<T> d_keys;
thrust::device_vector<unsigned int> d_values;
// run multiple iterations to compute an average sort time
cudaEvent_t start_event, stop_event;
checkCudaErrors(cudaEventCreate(&start_event));
checkCudaErrors(cudaEventCreate(&stop_event));
float totalTime = 0;
for (unsigned int i = 0; i < numIterations; i++)
{
// reset data before sort
d_keys= h_keys;
if (!keysOnly)
d_values = h_values;
checkCudaErrors(cudaEventRecord(start_event, 0));
if (keysOnly)
thrust::sort(d_keys.begin(), d_keys.end());
else
thrust::sort_by_key(d_keys.begin(), d_keys.end(), d_values.begin());
checkCudaErrors(cudaEventRecord(stop_event, 0));
checkCudaErrors(cudaEventSynchronize(stop_event));
float time = 0;
checkCudaErrors(cudaEventElapsedTime(&time, start_event, stop_event));
totalTime += time;
}
totalTime /= (1.0e3f * numIterations);
printf("radixSort, Throughput = %.4f MElements/s, Time = %.5f ms, Size = %u elements\n",
1.0e-6f * numElements / totalTime, totalTime * 1000, numElements);
getLastCudaError("after radixsort");
// Get results back to host for correctness checking
thrust::copy(d_keys.begin(), d_keys.end(), h_keysSorted.begin());
if (!keysOnly)
thrust::copy(d_values.begin(), d_values.end(), h_values.begin());
getLastCudaError("copying results to host memory");
// Check results
bool bTestResult = thrust::is_sorted(h_keysSorted.begin(), h_keysSorted.end());
checkCudaErrors(cudaEventDestroy(start_event));
checkCudaErrors(cudaEventDestroy(stop_event));
if (!bTestResult && !quiet)
{
return false;
}
return bTestResult;
}
int main(int argc, char **argv)
{
// Start logs
printf("%s starting...\n\n", argv[0]);
findCudaDevice(argc, (const char **)argv);
bool bTestResult = false;
if (checkCmdLineFlag(argc, (const char **)argv, "float"))
bTestResult = testSort<float, true>(argc, argv);
else
bTestResult = testSort<int, false>(argc, argv);
checkCudaErrors(cudaDeviceReset());
printf(bTestResult ? "Test passed\n" : "Test failed!\n");
}
|
00f3623f491abf8656e9c7dbd9a69abbf0773a6a.hip | // !!! This is a file automatically generated by hipify!!!
#include <iostream>
#include <fstream>
#include <ctime>
#include <chrono>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb/stb_image_write.h>
#include <hip/hip_runtime.h>
#include <device_launch_parameters.h>
#include <Color.cuh>
#include <Ray.cuh>
#include <Camera.cuh>
#include <Sphere.cuh>
#include <HittableList.cuh>
#include <Material.cuh>
#include <MovingSphere.cuh>
#include <helperUtils.cuh>
#include <hiprand/hiprand_kernel.h>
using namespace TinyRT;
constexpr int objLoopLimit = 11;
constexpr int objNum = (2 * objLoopLimit * 2 * objLoopLimit) + 1 + 3;
__device__ void generateRandomScene(Hittable** hittablePtrList, hiprandState_t* const objRandStatePtr) {
int objIdx = 0;
hittablePtrList[objIdx++] = new Sphere(Vec3(0.0f, -1000.0f, 0.0f), 1000.0f, new Lambertian(Color(0.5f, 0.5f, 0.5f)));
for (int a = -objLoopLimit; a < objLoopLimit; a++) {
for (int b = -objLoopLimit; b < objLoopLimit; b++) {
const float choose_mat = randomFloat(objRandStatePtr);
const Color center(a + randomFloat(objRandStatePtr), 0.2f, b + randomFloat(objRandStatePtr));
const float radius = 0.2f;
if (choose_mat < 0.7f) {
// diffuse
const auto albedo = Color::random(objRandStatePtr);
Material* sphereMat = new Lambertian(albedo);
const Point3 centerMoved = center + Vec3(0.0f, randomFloat(0.0f, 0.5f, objRandStatePtr), 0.0f);
const float time0 = 0.0f;
const float time1 = 1.0f;
hittablePtrList[objIdx++] = new MovingSphere(center, centerMoved, time0, time1, radius, sphereMat);
}
else if (choose_mat < 0.85f) {
// metal
const auto albedo = Color::random(objRandStatePtr);
const auto fuzz = 0.5f * randomFloat(objRandStatePtr);
Material* sphereMat = new Metal(albedo, fuzz);
hittablePtrList[objIdx++] = new Sphere(center, radius, sphereMat);
}
else {
// glass
Material* sphereMat = new Dielectric(1.5f);
hittablePtrList[objIdx++] = new Sphere(center, radius, sphereMat);
}
}
}
hittablePtrList[objIdx++] = new Sphere(Point3(0.0f, 1.0f, 0.0f), 1.0f, new Dielectric(1.5f));
hittablePtrList[objIdx++] = new Sphere(Point3(-4.0f, 1.0f, 0.0f), 1.0f, new Lambertian(Color(0.4f, 0.2f, 0.1f)));
hittablePtrList[objIdx] = new Sphere(Point3(4.0f, 1.0f, 0.0f), 1.0f, new Metal(Color(0.7f, 0.6f, 0.5f), 0.0f));
}
__device__ Color rayColor(const Ray& r, Hittable** hittablePtr, const int maxDepth, hiprandState_t* const randStatePtr) {
Ray curRay = r;
Vec3 curAttenuation(1.0f, 1.0f, 1.0f);
for (size_t i = 0; i < maxDepth; ++i) {
HitRecord rec;
if ((*hittablePtr)->hit(curRay, 0.001f, M_FLOAT_INFINITY, rec)) {
Ray scattered;
Vec3 attenuation;
if (rec.matPtr->scatter(curRay, rec, attenuation, scattered, randStatePtr)) {
curRay = scattered;
curAttenuation *= attenuation;
} else {
return { 0.0f, 0.0f, 0.0f };
}
} else {
const Vec3 unitDirection = unitVec3(curRay.direction());
const double t = 0.5f * (unitDirection.y() + 1.0f);
const Color background = (1.0f - t) * Color(1.0f, 1.0f, 1.0f) + t * Color(0.5f, 0.7f, 1.0f);
return curAttenuation * background;
}
}
// exceed max depth
return { 0.0f, 0.0f, 0.0f };
}
__global__ void renderInit(const int imageWidth, const int imageHeight, hiprandState_t* const randStateList, unsigned int seed) {
const int col = threadIdx.x + blockIdx.x * blockDim.x;
const int row = threadIdx.y + blockIdx.y * blockDim.y;
if ((col >= imageWidth) || (row >= imageHeight))
return;
const int idx = row * imageWidth + col;
// init random numbers for anti-aliasing
// each thread gets its own special seed, fixed sequence number, fixed offset
hiprand_init(seed + idx, 0, 0, &randStateList[idx]);
}
__global__ void render(
Color* const pixelBuffer,
const int imageWidth,
const int imageHeight,
Camera** const camera,
hiprandState_t* const pixelRandStateList,
const int samplesPerPixel,
const int maxDepth,
Hittable** const hittablePtrList) {
const int col = threadIdx.x + blockIdx.x * blockDim.x;
const int row = threadIdx.y + blockIdx.y * blockDim.y;
if (col >= imageWidth || row >= imageHeight)
return;
const int idx = row * imageWidth + col;
hiprandState_t randState = pixelRandStateList[idx];
Color pixelColor(0.0f, 0.0f, 0.0f);
for (size_t s = 0; s < samplesPerPixel; ++s) {
const auto u = (static_cast<float>(col) + randomFloat(&randState)) / static_cast<float>(imageWidth - 1);
const auto v = 1.0 - (static_cast<float>(row) + randomFloat(&randState)) / static_cast<float>(imageHeight - 1);
const Ray r = (*camera)->getRay(u, v, &randState);
pixelColor += rayColor(r, hittablePtrList, maxDepth, &randState);
}
pixelColor /= samplesPerPixel;
pixelColor.gammaCorrect();
pixelBuffer[idx] = pixelColor;
}
__global__ void createInit(hiprandState_t* const randStatePtr, unsigned int seed) {
if (threadIdx.x == 0 && blockIdx.x == 0) {
// init a random number for sphere generating
hiprand_init(seed, 0, 0, randStatePtr);
}
}
__global__ void createWorld(Camera** camera, float aspectRatio, Hittable** hittablePtrList, Hittable** hittableWorldObjListPtr, hiprandState_t* objRandStatePtr) {
if (threadIdx.x == 0 && blockIdx.x == 0) {
const Point3 lookFrom(13.0f, 2.0f, -3.0f);
const Point3 lookAt(0.0f, 0.0f, 0.0f);
const Vec3 vUp(0.0f, 1.0f, 0.0f);
const float vFov = 25.0f;
const float aperture = 0.1f;
const float distToFocus = 10.0f;
const float time0 = 0.0f;
const float time1 = 1.0f;
*camera = new Camera(lookFrom, lookAt, vUp, vFov, aspectRatio, aperture, distToFocus, time0, time1);
generateRandomScene(hittablePtrList, objRandStatePtr);
*hittableWorldObjListPtr = new HittableList(hittablePtrList, objNum);
}
}
__global__ void freeWorld(Camera** camera, Hittable** hittableList, Hittable** hittableWorldObjList) {
delete* camera;
for (int i = 0; i < objNum; ++i) {
// delete material instances
delete hittableList[i]->matPtr();
// delete object instances
delete hittableList[i];
}
delete* hittableWorldObjList;
}
int main() {
/* image config */
constexpr float aspectRatio = 16.0f / 9.0f;
constexpr int imageWidth = 800;
constexpr int imageHeight = static_cast<int>(imageWidth / aspectRatio);
constexpr int samplesPerPixel = 20;
constexpr int maxDepth = 5;
/* image output file */
const std::string fileName("output.png");
/* thread block config */
constexpr int threadBlockWidth = 8;
constexpr int threadBlockHeight = 8;
// preparation
constexpr int channelNum = 3; // rgb
constexpr int pixelNum = imageWidth * imageHeight;
constexpr size_t pixelBufferBytes = pixelNum * sizeof(Color);
constexpr size_t randStateListBytes = pixelNum * sizeof(hiprandState_t);
// allocate memory for pixel buffer
const auto pixelBufferPtr = cudaManagedUniquePtr<Color>(pixelBufferBytes);
// allocate random state
const auto seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
const auto objRandStatePtr = cudaUniquePtr<hiprandState_t>(sizeof(hiprandState_t));
const auto pixelRandStateListPtr = cudaUniquePtr<hiprandState_t>(randStateListBytes);
// create world of hittable objects and the camera
const auto cameraPtr = cudaUniquePtr<Camera*>(sizeof(Camera*));
const auto hittablePtrList = cudaUniquePtr<Hittable*>(objNum * sizeof(Hittable*));
const auto hittableWorldObjListPtr = cudaUniquePtr<Hittable*>(sizeof(Hittable*));
hipLaunchKernelGGL(( createInit), dim3(1), dim3(1), 0, 0, objRandStatePtr.get(), seed);
checkCudaErrors(hipGetLastError());
checkCudaErrors(hipDeviceSynchronize());
hipLaunchKernelGGL(( createWorld), dim3(1), dim3(1), 0, 0, cameraPtr.get(), aspectRatio, hittablePtrList.get(), hittableWorldObjListPtr.get(), objRandStatePtr.get());
checkCudaErrors(hipGetLastError());
checkCudaErrors(hipDeviceSynchronize());
// start timer
const clock_t start = clock();
const dim3 blockDim(imageWidth / threadBlockWidth + 1, imageHeight / threadBlockHeight + 1);
const dim3 threadDim(threadBlockWidth, threadBlockHeight);
// render init
hipLaunchKernelGGL(( renderInit), dim3(blockDim), dim3(threadDim), 0, 0, imageWidth, imageHeight, pixelRandStateListPtr.get(), seed);
checkCudaErrors(hipGetLastError());
checkCudaErrors(hipDeviceSynchronize());
// render the image into buffer
hipLaunchKernelGGL(( render), dim3(blockDim), dim3(threadDim), 0, 0,
pixelBufferPtr.get(),
imageWidth,
imageHeight,
cameraPtr.get(),
pixelRandStateListPtr.get(),
samplesPerPixel,
maxDepth,
hittableWorldObjListPtr.get()
);
checkCudaErrors(hipGetLastError());
checkCudaErrors(hipDeviceSynchronize());
// stop timer
const clock_t stop = clock();
// measure rendering time
const auto renderingMillisecond = stop - start;
// other image writer arguments
constexpr int imageSize = pixelNum * channelNum;
constexpr size_t strideBytes = imageWidth * channelNum * sizeof(unsigned char);
const std::unique_ptr<unsigned char[]> pixelDataPtr(new unsigned char[imageSize]);
// store the pixel data into writing buffer as 8bit color
for (int pixelIdx = 0, dataIdx = 0; pixelIdx < pixelNum; ++pixelIdx) {
const Color color = pixelBufferPtr.get()[pixelIdx];
pixelDataPtr[dataIdx++] = static_cast<unsigned char>(color.r8bit());
pixelDataPtr[dataIdx++] = static_cast<unsigned char>(color.g8bit());
pixelDataPtr[dataIdx++] = static_cast<unsigned char>(color.b8bit());
}
// print rendering time
std::cout << "Complete!\n" << "The rendering took " << renderingMillisecond << "ms" << std::endl;
// write pixel data to output file
stbi_write_png(fileName.c_str(), imageWidth, imageHeight, channelNum, pixelDataPtr.get(), strideBytes);
// free world of hittable objects
hipLaunchKernelGGL(( freeWorld), dim3(1), dim3(1), 0, 0, cameraPtr.get(), hittablePtrList.get(), hittableWorldObjListPtr.get());
checkCudaErrors(hipGetLastError());
checkCudaErrors(hipDeviceSynchronize());
return 0;
} | 00f3623f491abf8656e9c7dbd9a69abbf0773a6a.cu | #include <iostream>
#include <fstream>
#include <ctime>
#include <chrono>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb/stb_image_write.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <Color.cuh>
#include <Ray.cuh>
#include <Camera.cuh>
#include <Sphere.cuh>
#include <HittableList.cuh>
#include <Material.cuh>
#include <MovingSphere.cuh>
#include <helperUtils.cuh>
#include <curand_kernel.h>
using namespace TinyRT;
constexpr int objLoopLimit = 11;
constexpr int objNum = (2 * objLoopLimit * 2 * objLoopLimit) + 1 + 3;
__device__ void generateRandomScene(Hittable** hittablePtrList, curandState* const objRandStatePtr) {
int objIdx = 0;
hittablePtrList[objIdx++] = new Sphere(Vec3(0.0f, -1000.0f, 0.0f), 1000.0f, new Lambertian(Color(0.5f, 0.5f, 0.5f)));
for (int a = -objLoopLimit; a < objLoopLimit; a++) {
for (int b = -objLoopLimit; b < objLoopLimit; b++) {
const float choose_mat = randomFloat(objRandStatePtr);
const Color center(a + randomFloat(objRandStatePtr), 0.2f, b + randomFloat(objRandStatePtr));
const float radius = 0.2f;
if (choose_mat < 0.7f) {
// diffuse
const auto albedo = Color::random(objRandStatePtr);
Material* sphereMat = new Lambertian(albedo);
const Point3 centerMoved = center + Vec3(0.0f, randomFloat(0.0f, 0.5f, objRandStatePtr), 0.0f);
const float time0 = 0.0f;
const float time1 = 1.0f;
hittablePtrList[objIdx++] = new MovingSphere(center, centerMoved, time0, time1, radius, sphereMat);
}
else if (choose_mat < 0.85f) {
// metal
const auto albedo = Color::random(objRandStatePtr);
const auto fuzz = 0.5f * randomFloat(objRandStatePtr);
Material* sphereMat = new Metal(albedo, fuzz);
hittablePtrList[objIdx++] = new Sphere(center, radius, sphereMat);
}
else {
// glass
Material* sphereMat = new Dielectric(1.5f);
hittablePtrList[objIdx++] = new Sphere(center, radius, sphereMat);
}
}
}
hittablePtrList[objIdx++] = new Sphere(Point3(0.0f, 1.0f, 0.0f), 1.0f, new Dielectric(1.5f));
hittablePtrList[objIdx++] = new Sphere(Point3(-4.0f, 1.0f, 0.0f), 1.0f, new Lambertian(Color(0.4f, 0.2f, 0.1f)));
hittablePtrList[objIdx] = new Sphere(Point3(4.0f, 1.0f, 0.0f), 1.0f, new Metal(Color(0.7f, 0.6f, 0.5f), 0.0f));
}
__device__ Color rayColor(const Ray& r, Hittable** hittablePtr, const int maxDepth, curandState* const randStatePtr) {
Ray curRay = r;
Vec3 curAttenuation(1.0f, 1.0f, 1.0f);
for (size_t i = 0; i < maxDepth; ++i) {
HitRecord rec;
if ((*hittablePtr)->hit(curRay, 0.001f, M_FLOAT_INFINITY, rec)) {
Ray scattered;
Vec3 attenuation;
if (rec.matPtr->scatter(curRay, rec, attenuation, scattered, randStatePtr)) {
curRay = scattered;
curAttenuation *= attenuation;
} else {
return { 0.0f, 0.0f, 0.0f };
}
} else {
const Vec3 unitDirection = unitVec3(curRay.direction());
const double t = 0.5f * (unitDirection.y() + 1.0f);
const Color background = (1.0f - t) * Color(1.0f, 1.0f, 1.0f) + t * Color(0.5f, 0.7f, 1.0f);
return curAttenuation * background;
}
}
// exceed max depth
return { 0.0f, 0.0f, 0.0f };
}
__global__ void renderInit(const int imageWidth, const int imageHeight, curandState* const randStateList, unsigned int seed) {
const int col = threadIdx.x + blockIdx.x * blockDim.x;
const int row = threadIdx.y + blockIdx.y * blockDim.y;
if ((col >= imageWidth) || (row >= imageHeight))
return;
const int idx = row * imageWidth + col;
// init random numbers for anti-aliasing
// each thread gets its own special seed, fixed sequence number, fixed offset
curand_init(seed + idx, 0, 0, &randStateList[idx]);
}
__global__ void render(
Color* const pixelBuffer,
const int imageWidth,
const int imageHeight,
Camera** const camera,
curandState* const pixelRandStateList,
const int samplesPerPixel,
const int maxDepth,
Hittable** const hittablePtrList) {
const int col = threadIdx.x + blockIdx.x * blockDim.x;
const int row = threadIdx.y + blockIdx.y * blockDim.y;
if (col >= imageWidth || row >= imageHeight)
return;
const int idx = row * imageWidth + col;
curandState randState = pixelRandStateList[idx];
Color pixelColor(0.0f, 0.0f, 0.0f);
for (size_t s = 0; s < samplesPerPixel; ++s) {
const auto u = (static_cast<float>(col) + randomFloat(&randState)) / static_cast<float>(imageWidth - 1);
const auto v = 1.0 - (static_cast<float>(row) + randomFloat(&randState)) / static_cast<float>(imageHeight - 1);
const Ray r = (*camera)->getRay(u, v, &randState);
pixelColor += rayColor(r, hittablePtrList, maxDepth, &randState);
}
pixelColor /= samplesPerPixel;
pixelColor.gammaCorrect();
pixelBuffer[idx] = pixelColor;
}
__global__ void createInit(curandState* const randStatePtr, unsigned int seed) {
if (threadIdx.x == 0 && blockIdx.x == 0) {
// init a random number for sphere generating
curand_init(seed, 0, 0, randStatePtr);
}
}
__global__ void createWorld(Camera** camera, float aspectRatio, Hittable** hittablePtrList, Hittable** hittableWorldObjListPtr, curandState* objRandStatePtr) {
if (threadIdx.x == 0 && blockIdx.x == 0) {
const Point3 lookFrom(13.0f, 2.0f, -3.0f);
const Point3 lookAt(0.0f, 0.0f, 0.0f);
const Vec3 vUp(0.0f, 1.0f, 0.0f);
const float vFov = 25.0f;
const float aperture = 0.1f;
const float distToFocus = 10.0f;
const float time0 = 0.0f;
const float time1 = 1.0f;
*camera = new Camera(lookFrom, lookAt, vUp, vFov, aspectRatio, aperture, distToFocus, time0, time1);
generateRandomScene(hittablePtrList, objRandStatePtr);
*hittableWorldObjListPtr = new HittableList(hittablePtrList, objNum);
}
}
__global__ void freeWorld(Camera** camera, Hittable** hittableList, Hittable** hittableWorldObjList) {
delete* camera;
for (int i = 0; i < objNum; ++i) {
// delete material instances
delete hittableList[i]->matPtr();
// delete object instances
delete hittableList[i];
}
delete* hittableWorldObjList;
}
int main() {
/* image config */
constexpr float aspectRatio = 16.0f / 9.0f;
constexpr int imageWidth = 800;
constexpr int imageHeight = static_cast<int>(imageWidth / aspectRatio);
constexpr int samplesPerPixel = 20;
constexpr int maxDepth = 5;
/* image output file */
const std::string fileName("output.png");
/* thread block config */
constexpr int threadBlockWidth = 8;
constexpr int threadBlockHeight = 8;
// preparation
constexpr int channelNum = 3; // rgb
constexpr int pixelNum = imageWidth * imageHeight;
constexpr size_t pixelBufferBytes = pixelNum * sizeof(Color);
constexpr size_t randStateListBytes = pixelNum * sizeof(curandState);
// allocate memory for pixel buffer
const auto pixelBufferPtr = cudaManagedUniquePtr<Color>(pixelBufferBytes);
// allocate random state
const auto seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
const auto objRandStatePtr = cudaUniquePtr<curandState>(sizeof(curandState));
const auto pixelRandStateListPtr = cudaUniquePtr<curandState>(randStateListBytes);
// create world of hittable objects and the camera
const auto cameraPtr = cudaUniquePtr<Camera*>(sizeof(Camera*));
const auto hittablePtrList = cudaUniquePtr<Hittable*>(objNum * sizeof(Hittable*));
const auto hittableWorldObjListPtr = cudaUniquePtr<Hittable*>(sizeof(Hittable*));
createInit<<<1, 1>>>(objRandStatePtr.get(), seed);
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaDeviceSynchronize());
createWorld<<<1, 1>>>(cameraPtr.get(), aspectRatio, hittablePtrList.get(), hittableWorldObjListPtr.get(), objRandStatePtr.get());
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaDeviceSynchronize());
// start timer
const clock_t start = clock();
const dim3 blockDim(imageWidth / threadBlockWidth + 1, imageHeight / threadBlockHeight + 1);
const dim3 threadDim(threadBlockWidth, threadBlockHeight);
// render init
renderInit<<<blockDim, threadDim>>>(imageWidth, imageHeight, pixelRandStateListPtr.get(), seed);
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaDeviceSynchronize());
// render the image into buffer
render<<<blockDim, threadDim>>>(
pixelBufferPtr.get(),
imageWidth,
imageHeight,
cameraPtr.get(),
pixelRandStateListPtr.get(),
samplesPerPixel,
maxDepth,
hittableWorldObjListPtr.get()
);
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaDeviceSynchronize());
// stop timer
const clock_t stop = clock();
// measure rendering time
const auto renderingMillisecond = stop - start;
// other image writer arguments
constexpr int imageSize = pixelNum * channelNum;
constexpr size_t strideBytes = imageWidth * channelNum * sizeof(unsigned char);
const std::unique_ptr<unsigned char[]> pixelDataPtr(new unsigned char[imageSize]);
// store the pixel data into writing buffer as 8bit color
for (int pixelIdx = 0, dataIdx = 0; pixelIdx < pixelNum; ++pixelIdx) {
const Color color = pixelBufferPtr.get()[pixelIdx];
pixelDataPtr[dataIdx++] = static_cast<unsigned char>(color.r8bit());
pixelDataPtr[dataIdx++] = static_cast<unsigned char>(color.g8bit());
pixelDataPtr[dataIdx++] = static_cast<unsigned char>(color.b8bit());
}
// print rendering time
std::cout << "Complete!\n" << "The rendering took " << renderingMillisecond << "ms" << std::endl;
// write pixel data to output file
stbi_write_png(fileName.c_str(), imageWidth, imageHeight, channelNum, pixelDataPtr.get(), strideBytes);
// free world of hittable objects
freeWorld<<<1, 1>>>(cameraPtr.get(), hittablePtrList.get(), hittableWorldObjListPtr.get());
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaDeviceSynchronize());
return 0;
} |
b4d6b7cefb73c328dac4567b97c1459b6d4f507d.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <stdio.h>
__global__ void mykernel(void) {
}
int main(void) {
mykernel << <1, 1 >> > ();
printf("Hello, world!\n");
return 0;
} | b4d6b7cefb73c328dac4567b97c1459b6d4f507d.cu | #include "cuda_runtime.h"
#include <stdio.h>
__global__ void mykernel(void) {
}
int main(void) {
mykernel << <1, 1 >> > ();
printf("Hello, world!\n");
return 0;
} |
0a559cabcb9444ffa81718554abe1372507c8ebb.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#define COALESCED_NUM 16
#define blockDimX 256
#define blockDimY 1
#define gridDimX (gridDim.x)
#define gridDimY (gridDim.y)
#define idx (blockIdx.x*blockDimX+threadIdx.x)
#define idy (blockIdx.y*blockDimY+threadIdx.y)
#define bidy (blockIdx.y)
#define bidx (blockIdx.x)
#define tidx (threadIdx.x)
#define tidy (threadIdx.y)
#define merger_y 8
#define coalesced_idy (bidy/(COALESCED_NUM/(merger_y*blockDimY))*COALESCED_NUM)
#define A(y,x) A[(y)*WIDTH_A+(x)]
#define B(y,x) B[(y)*WIDTH_B+(x)]
#define C(y,x) C[(y)*WIDTH_C+(x)]
#define WIDTH_C 2048
#define WIDTH_B 16
#define WIDTH_A (2048+16)
__global__ void conv(float * A, float * B, float * C, int width, int height, int w, int h)
{
__shared__ float shared_1[16][9];
__shared__ float shared_0[272];
int j;
float sum_0 = 0;
float sum_1 = 0;
float sum_2 = 0;
float sum_3 = 0;
float sum_4 = 0;
float sum_5 = 0;
float sum_6 = 0;
float sum_7 = 0;
int it_2;
for (j=0; j<(h-7); j=(j+1))
{
int it_2;
if ((tidx<16))
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*j))+h), (idx+(( - 1)*0)));
}
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*j))+h), ((idx+(( - 1)*0))+16));
__syncthreads();
if ((tidx<16))
{
shared_1[(tidx+0)][0]=B((j+0), (0+tidx));
shared_1[(tidx+0)][1]=B((j+1), (0+tidx));
shared_1[(tidx+0)][2]=B((j+2), (0+tidx));
shared_1[(tidx+0)][3]=B((j+3), (0+tidx));
shared_1[(tidx+0)][4]=B((j+4), (0+tidx));
shared_1[(tidx+0)][5]=B((j+5), (0+tidx));
shared_1[(tidx+0)][6]=B((j+6), (0+tidx));
shared_1[(tidx+0)][7]=B((j+7), (0+tidx));
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
__syncthreads();
__syncthreads();
}
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-1)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-1)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
sum_0+=(a*b_0);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-2)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-2)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-3)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-3)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-4)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-4)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-5)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-5)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-5), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][4]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-6)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-6)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-6), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-5), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][4]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][5]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-7)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-7)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-7), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-6), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-5), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][4]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][5]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][6]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
}
{
C(((idy*8)+0), idx)=sum_0;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-1)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-1)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][1]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][2]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][3]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][4]=B(3, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(4, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(5, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(6, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+1), idx)=sum_1;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-2)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-2)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][2]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][3]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][4]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(3, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(4, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(5, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+2), idx)=sum_2;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-3)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-3)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][3]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][4]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(3, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(4, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+3), idx)=sum_3;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-4)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-4)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][4]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(3, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+4), idx)=sum_4;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-5)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-5)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][5]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(2, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+5), idx)=sum_5;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-6)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-6)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][6]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(1, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+6), idx)=sum_6;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-7)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-7)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][7]=B(0, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_7=shared_1[it_2][7];
sum_7+=(a*b_7);
}
{
C(((idy*8)+7), idx)=sum_7;
}
__syncthreads();
__syncthreads();
}
| 0a559cabcb9444ffa81718554abe1372507c8ebb.cu | #define COALESCED_NUM 16
#define blockDimX 256
#define blockDimY 1
#define gridDimX (gridDim.x)
#define gridDimY (gridDim.y)
#define idx (blockIdx.x*blockDimX+threadIdx.x)
#define idy (blockIdx.y*blockDimY+threadIdx.y)
#define bidy (blockIdx.y)
#define bidx (blockIdx.x)
#define tidx (threadIdx.x)
#define tidy (threadIdx.y)
#define merger_y 8
#define coalesced_idy (bidy/(COALESCED_NUM/(merger_y*blockDimY))*COALESCED_NUM)
#define A(y,x) A[(y)*WIDTH_A+(x)]
#define B(y,x) B[(y)*WIDTH_B+(x)]
#define C(y,x) C[(y)*WIDTH_C+(x)]
#define WIDTH_C 2048
#define WIDTH_B 16
#define WIDTH_A (2048+16)
__global__ void conv(float * A, float * B, float * C, int width, int height, int w, int h)
{
__shared__ float shared_1[16][9];
__shared__ float shared_0[272];
int j;
float sum_0 = 0;
float sum_1 = 0;
float sum_2 = 0;
float sum_3 = 0;
float sum_4 = 0;
float sum_5 = 0;
float sum_6 = 0;
float sum_7 = 0;
int it_2;
for (j=0; j<(h-7); j=(j+1))
{
int it_2;
if ((tidx<16))
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*j))+h), (idx+(( - 1)*0)));
}
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*j))+h), ((idx+(( - 1)*0))+16));
__syncthreads();
if ((tidx<16))
{
shared_1[(tidx+0)][0]=B((j+0), (0+tidx));
shared_1[(tidx+0)][1]=B((j+1), (0+tidx));
shared_1[(tidx+0)][2]=B((j+2), (0+tidx));
shared_1[(tidx+0)][3]=B((j+3), (0+tidx));
shared_1[(tidx+0)][4]=B((j+4), (0+tidx));
shared_1[(tidx+0)][5]=B((j+5), (0+tidx));
shared_1[(tidx+0)][6]=B((j+6), (0+tidx));
shared_1[(tidx+0)][7]=B((j+7), (0+tidx));
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
__syncthreads();
__syncthreads();
}
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-1)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-1)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
sum_0+=(a*b_0);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-2)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-2)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-3)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-3)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-4)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-4)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-5)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-5)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-5), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][4]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-6)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-6)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-6), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-5), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][4]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][5]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(h-7)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(h-7)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][0]=B((h-7), (0+tidx));
}
{
shared_1[(tidx+0)][1]=B((h-6), (0+tidx));
}
{
shared_1[(tidx+0)][2]=B((h-5), (0+tidx));
}
{
shared_1[(tidx+0)][3]=B((h-4), (0+tidx));
}
{
shared_1[(tidx+0)][4]=B((h-3), (0+tidx));
}
{
shared_1[(tidx+0)][5]=B((h-2), (0+tidx));
}
{
shared_1[(tidx+0)][6]=B((h-1), (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_0;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_0=shared_1[it_2][0];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
sum_0+=(a*b_0);
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
}
{
C(((idy*8)+0), idx)=sum_0;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-1)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-1)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][1]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][2]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][3]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][4]=B(3, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(4, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(5, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(6, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_1;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_1=shared_1[it_2][1];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_1+=(a*b_1);
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+1), idx)=sum_1;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-2)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-2)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][2]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][3]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][4]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(3, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(4, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(5, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_2;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_2=shared_1[it_2][2];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_2+=(a*b_2);
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+2), idx)=sum_2;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-3)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-3)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][3]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][4]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(3, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(4, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_3;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_3=shared_1[it_2][3];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_3+=(a*b_3);
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+3), idx)=sum_3;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-4)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-4)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][4]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][5]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(2, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(3, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_4;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_4=shared_1[it_2][4];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_4+=(a*b_4);
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+4), idx)=sum_4;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-5)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-5)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][5]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][6]=B(1, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(2, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_5;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_5=shared_1[it_2][5];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_5+=(a*b_5);
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+5), idx)=sum_5;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-6)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-6)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][6]=B(0, (0+tidx));
}
{
shared_1[(tidx+0)][7]=B(1, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_6;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_6=shared_1[it_2][6];
b_7=shared_1[it_2][7];
sum_6+=(a*b_6);
sum_7+=(a*b_7);
}
{
C(((idy*8)+6), idx)=sum_6;
}
__syncthreads();
__syncthreads();
if ((tidx<16))
{
{
shared_0[(tidx+0)]=A((((idy*8)+(( - 1)*(0-7)))+h), (idx+(( - 1)*0)));
}
}
{
shared_0[(tidx+16)]=A((((idy*8)+(( - 1)*(0-7)))+h), ((idx+(( - 1)*0))+16));
}
__syncthreads();
if ((tidx<16))
{
{
shared_1[(tidx+0)][7]=B(0, (0+tidx));
}
}
__syncthreads();
#pragma unroll
for (it_2=0; it_2<16; it_2=(it_2+1))
{
float a;
float b_7;
a=shared_0[((tidx+(( - 1)*(it_2+0)))+16)];
b_7=shared_1[it_2][7];
sum_7+=(a*b_7);
}
{
C(((idy*8)+7), idx)=sum_7;
}
__syncthreads();
__syncthreads();
}
|
ef654c9e914f59ad2242fb105c46acf3776ff6b6.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "cuda_MP5.cuh"
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int cuda_MP5(int argc, char* argv[])
{
int num_elements = NUM_ELEMENTS;
int errorM = 0;
const unsigned int array_mem_size = sizeof(float) * num_elements;
// allocate host memory to store the input data
float* h_data = (float*)malloc(array_mem_size);
// * No arguments: Randomly generate input data and compare against the
// host's result.
// * One argument: Read the input data array from the given file.
switch (argc - 1)
{
case 1: // One Argument
// errorM = ReadFile(h_data, argv[1]);
errorM = ReadFileData_MP5(h_data, argv[1]);
if (errorM != 1)
{
printf("Error reading input file!\n");
exit(1);
}
break;
default:
// No Arguments or one argument
// initialize the input data on the host to be integer values
// between 0 and 1000
for (unsigned int i = 0; i < num_elements; ++i)
{
h_data[i] = floorf(1000 * (rand() / (float)RAND_MAX));
}
break;
}
// compute reference solution
float reference = 0.0f;
computeGold_MP5(&reference, h_data, num_elements);
// **===-------- Modify the body of this function -----------===**
float result = computeOnDevice_MP5(h_data, num_elements);
// **===-----------------------------------------------------------===**
// We can use an epsilon of 0 since values are integral and in a range
// that can be exactly represented
float epsilon = 0.0f;
unsigned int result_regtest = (abs(result - reference) <= epsilon);
printf("Test %s\n", (1 == result_regtest) ? "PASSED" : "FAILED");
printf("device: %f host: %f\n", result, reference);
// cleanup memory
free(h_data);
return 0;
}
int ReadFileData_MP5(float* M, char* file_name)
{
unsigned int data_read = NUM_ELEMENTS;
// cutReadFilef(file_name, &(M->elements), &data_read, true);
ifstream iFile(file_name);
unsigned i = 0;
if (iFile) {
float data;
while (iFile >> data) {
M[i++] = data;
}
}
return (i != data_read);
}
////////////////////////////////////////////////////////////////////////////////
//! Compute reference data set
//! Each element is the sum of the elements before it in the array.
//! @param reference reference data, computed but preallocated
//! @param idata input data as provided to device
//! @param len number of elements in reference / idata
////////////////////////////////////////////////////////////////////////////////
void computeGold_MP5(float* reference, float* idata, const unsigned int len)
{
reference[0] = 0;
double total_sum = 0;
unsigned int i;
for (i = 0; i < len; ++i)
{
total_sum += idata[i];
}
*reference = total_sum;
}
// **===----------------- Modify this function ---------------------===**
// Take h_data from host, copies it to device, setup grid and thread
// dimensions, excutes kernel function, and copy result of scan back
// to h_data.
// Note: float* h_data is both the input and the output of this function.
float computeOnDevice_MP5(float* h_data, int num_elements)
{
float* d_data;
hipMalloc((void**)&d_data, sizeof(float)*num_elements);
hipMemcpy(d_data, h_data, sizeof(float)*num_elements,
hipMemcpyHostToDevice);
int num_block = ceil((float)num_elements / (2 * RD_BLOCK_SIZE));
float* d_block_sum;
hipMalloc((void**)&d_block_sum, sizeof(float)*num_block);
// placeholder
dim3 dimGrid, dimBlock;
dimGrid.x = num_block;
dimGrid.y = dimGrid.z = 1;
dimBlock.x = RD_BLOCK_SIZE;
dimBlock.y = dimBlock.z = 1;
reduction_kernel_MP5 << <dimGrid, dimBlock >> > (d_data, d_block_sum, num_elements);
hipDeviceSynchronize();
float* h_block_sum = (float*)malloc(sizeof(float)*num_block);
hipMemcpy(h_block_sum, d_block_sum, sizeof(float)*num_block,
hipMemcpyDeviceToHost);
hipMemcpy(h_data, d_data, sizeof(float)*num_elements,
hipMemcpyDeviceToHost);
hipFree(d_block_sum);
hipFree(d_data);
float sum = 0;
for (int i = 0; i < num_block; i++) {
sum += h_block_sum[i];
// cout << i << " " << h_block_sum[i] << endl;
// cout << (i + 1) * 128 - 1 << " " << h_data[(i + 1) * 128 - 1] << endl;
}
return sum;
// return h_data[num_elements-1];
}
// **===----------------- MP4.1 - Modify this function --------------------===**
//! @param g_idata input data in global memory
// result is expected in index 0 of g_idata
//! @param n input number of elements to scan from input data
// **===------------------------------------------------------------------===**
__global__ void reduction_kernel_MP5(float *g_data, float *blocksum, int n)
{
__shared__ float ds_data[2 * RD_BLOCK_SIZE];
unsigned int tx = threadIdx.x;
unsigned int id = threadIdx.x + blockIdx.x*blockDim.x;
if (2 * id + 1 < n) {
ds_data[2 * tx] = g_data[2 * id];
ds_data[2 * tx + 1] = g_data[2 * id + 1];
}
for (unsigned int stride = 1; stride <= blockDim.x; stride *= 2) {
__syncthreads();
unsigned int index = (threadIdx.x + 1) * 2 * stride - 1;
if (index < 2 * blockDim.x)
ds_data[index] += ds_data[index - stride];
}
__syncthreads();
if (threadIdx.x == 0)
blocksum[blockIdx.x] = ds_data[2 * blockDim.x - 1];
if (2 * id + 1 < n) {
g_data[2 * id] = ds_data[2 * tx];
g_data[2 * id + 1] = ds_data[2 * tx + 1];
}
} | ef654c9e914f59ad2242fb105c46acf3776ff6b6.cu | #include "cuda_MP5.cuh"
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int cuda_MP5(int argc, char* argv[])
{
int num_elements = NUM_ELEMENTS;
int errorM = 0;
const unsigned int array_mem_size = sizeof(float) * num_elements;
// allocate host memory to store the input data
float* h_data = (float*)malloc(array_mem_size);
// * No arguments: Randomly generate input data and compare against the
// host's result.
// * One argument: Read the input data array from the given file.
switch (argc - 1)
{
case 1: // One Argument
// errorM = ReadFile(h_data, argv[1]);
errorM = ReadFileData_MP5(h_data, argv[1]);
if (errorM != 1)
{
printf("Error reading input file!\n");
exit(1);
}
break;
default:
// No Arguments or one argument
// initialize the input data on the host to be integer values
// between 0 and 1000
for (unsigned int i = 0; i < num_elements; ++i)
{
h_data[i] = floorf(1000 * (rand() / (float)RAND_MAX));
}
break;
}
// compute reference solution
float reference = 0.0f;
computeGold_MP5(&reference, h_data, num_elements);
// **===-------- Modify the body of this function -----------===**
float result = computeOnDevice_MP5(h_data, num_elements);
// **===-----------------------------------------------------------===**
// We can use an epsilon of 0 since values are integral and in a range
// that can be exactly represented
float epsilon = 0.0f;
unsigned int result_regtest = (abs(result - reference) <= epsilon);
printf("Test %s\n", (1 == result_regtest) ? "PASSED" : "FAILED");
printf("device: %f host: %f\n", result, reference);
// cleanup memory
free(h_data);
return 0;
}
int ReadFileData_MP5(float* M, char* file_name)
{
unsigned int data_read = NUM_ELEMENTS;
// cutReadFilef(file_name, &(M->elements), &data_read, true);
ifstream iFile(file_name);
unsigned i = 0;
if (iFile) {
float data;
while (iFile >> data) {
M[i++] = data;
}
}
return (i != data_read);
}
////////////////////////////////////////////////////////////////////////////////
//! Compute reference data set
//! Each element is the sum of the elements before it in the array.
//! @param reference reference data, computed but preallocated
//! @param idata input data as provided to device
//! @param len number of elements in reference / idata
////////////////////////////////////////////////////////////////////////////////
void computeGold_MP5(float* reference, float* idata, const unsigned int len)
{
reference[0] = 0;
double total_sum = 0;
unsigned int i;
for (i = 0; i < len; ++i)
{
total_sum += idata[i];
}
*reference = total_sum;
}
// **===----------------- Modify this function ---------------------===**
// Take h_data from host, copies it to device, setup grid and thread
// dimensions, excutes kernel function, and copy result of scan back
// to h_data.
// Note: float* h_data is both the input and the output of this function.
float computeOnDevice_MP5(float* h_data, int num_elements)
{
float* d_data;
cudaMalloc((void**)&d_data, sizeof(float)*num_elements);
cudaMemcpy(d_data, h_data, sizeof(float)*num_elements,
cudaMemcpyHostToDevice);
int num_block = ceil((float)num_elements / (2 * RD_BLOCK_SIZE));
float* d_block_sum;
cudaMalloc((void**)&d_block_sum, sizeof(float)*num_block);
// placeholder
dim3 dimGrid, dimBlock;
dimGrid.x = num_block;
dimGrid.y = dimGrid.z = 1;
dimBlock.x = RD_BLOCK_SIZE;
dimBlock.y = dimBlock.z = 1;
reduction_kernel_MP5 << <dimGrid, dimBlock >> > (d_data, d_block_sum, num_elements);
cudaDeviceSynchronize();
float* h_block_sum = (float*)malloc(sizeof(float)*num_block);
cudaMemcpy(h_block_sum, d_block_sum, sizeof(float)*num_block,
cudaMemcpyDeviceToHost);
cudaMemcpy(h_data, d_data, sizeof(float)*num_elements,
cudaMemcpyDeviceToHost);
cudaFree(d_block_sum);
cudaFree(d_data);
float sum = 0;
for (int i = 0; i < num_block; i++) {
sum += h_block_sum[i];
// cout << i << " " << h_block_sum[i] << endl;
// cout << (i + 1) * 128 - 1 << " " << h_data[(i + 1) * 128 - 1] << endl;
}
return sum;
// return h_data[num_elements-1];
}
// **===----------------- MP4.1 - Modify this function --------------------===**
//! @param g_idata input data in global memory
// result is expected in index 0 of g_idata
//! @param n input number of elements to scan from input data
// **===------------------------------------------------------------------===**
__global__ void reduction_kernel_MP5(float *g_data, float *blocksum, int n)
{
__shared__ float ds_data[2 * RD_BLOCK_SIZE];
unsigned int tx = threadIdx.x;
unsigned int id = threadIdx.x + blockIdx.x*blockDim.x;
if (2 * id + 1 < n) {
ds_data[2 * tx] = g_data[2 * id];
ds_data[2 * tx + 1] = g_data[2 * id + 1];
}
for (unsigned int stride = 1; stride <= blockDim.x; stride *= 2) {
__syncthreads();
unsigned int index = (threadIdx.x + 1) * 2 * stride - 1;
if (index < 2 * blockDim.x)
ds_data[index] += ds_data[index - stride];
}
__syncthreads();
if (threadIdx.x == 0)
blocksum[blockIdx.x] = ds_data[2 * blockDim.x - 1];
if (2 * id + 1 < n) {
g_data[2 * id] = ds_data[2 * tx];
g_data[2 * id + 1] = ds_data[2 * tx + 1];
}
} |
7cf621ce39fc6bf7fba99e5f06ee28bef49bcc42.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "Main.cuh"
extern int blocksize2, size_grid, NRAD, NSEC;
extern double *GLOBAL_bufarray, *SoundSpeed_d;
extern double *gridfield_d, *GLOBAL_bufarray_d, *axifield_d, *SG_Accr_d, *GLOBAL_AxiSGAccr_d;
extern double ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRATIO, TRANSITIONRADIUS, LAMBDADOUBLING;
extern double PhysicalTime, PhysicalTimeInitial;
extern dim3 dimGrid, dimBlock, dimGrid4;
__global__ void Substep1Kernel (double *Pressure, double *Dens, double *VradInt, double *invdiffRmed, double *Potential,
double *Rinf, double *invRinf, double *Vrad, double *VthetaInt, double *Vtheta, double *Rmed, double dt,
int nrad, int nsec, double OmegaFrame, int ZMPlus, double IMPOSEDDISKDRIFT, double SIGMASLOPE)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double gradp, gradphi, vradint, vradint2, supp_torque, dxtheta, invdxtheta;
double vt2;
// i=1->nrad , j=0->nsec
if (i > 0 && i<nrad && j<nsec){
gradp = (Pressure[i*nsec + j] - Pressure[(i-1)*nsec + j])*2.0/(Dens[i*nsec + j] + Dens[(i-1)*nsec + j])*invdiffRmed[i];
gradphi = (Potential[i*nsec + j] - Potential[(i-1)*nsec + j])*invdiffRmed[i];
vt2 = Vtheta[i*nsec + j] + Vtheta[i*nsec + (j+1)%nsec] + Vtheta[(i-1)*nsec + j] + Vtheta[(i-1)*nsec + (j+1)%nsec];
vt2 = vt2/4.0 +OmegaFrame*Rinf[i];
vt2 = vt2*vt2;
vradint = -gradp - gradphi;
vradint2 = vradint + vt2*invRinf[i];
VradInt[i*nsec + j] = Vrad[i*nsec+j] + dt*vradint2;
}
// i=0->nrad , j=0->nsec
if (i<nrad && j<nsec){
supp_torque = IMPOSEDDISKDRIFT*0.5*pow(Rmed[i], -2.5+SIGMASLOPE);
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
gradp = (Pressure[i*nsec + j] - Pressure[i*nsec + ((j-1)+nsec)%nsec])*2.0/(Dens[i*nsec +j] +Dens[i*nsec + ((j-1)+nsec)%nsec]) \
*invdxtheta;
//if (ZMPlus) gradp *= 1; //gradp *= SG_aniso_coeff; Definir mas adelante SG_aniso_coeff
gradphi = (Potential[i*nsec+ j] - Potential[i*nsec + ((j-1)+nsec)%nsec])*invdxtheta;
VthetaInt[i*nsec + j] = Vtheta[i*nsec+j] - dt*(gradp+gradphi);
VthetaInt[i*nsec + j] += dt*supp_torque;
}
}
__global__ void Substep3Kernel (double *Dens, double *Qplus, double *viscosity_array, double *TAURR, double *TAURP,double *TAUPP,
double *DivergenceVelocity, int nrad, int nsec, double *Rmed, int Cooling, double *EnergyNew, double dt, double *EnergyMed,
double *SigmaMed, double *CoolingTimeMed, double *EnergyInt, double ADIABATICINDEX, double *QplusMed)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double den, num;
if (i > 0 && i<nrad && j<nsec){
if (viscosity_array[i] != 0.0){
Qplus[i*nsec + j] = 0.5/viscosity_array[i]/Dens[i*nsec + j]*(TAURR[i*nsec + j]*TAURR[i*nsec + j] + \
TAURP[i*nsec + j]* TAURP[i*nsec + j] + TAUPP[i*nsec + j]*TAUPP[i*nsec + j]);
Qplus[i*nsec + j] += (2.0/9.0)*viscosity_array[i]*Dens[i*nsec + j]*DivergenceVelocity[i*nsec + j]* \
DivergenceVelocity[i*nsec + j];
}
else
Qplus[i*nsec + j] = 0.0;
}
}
__global__ void Substep3Kernel2 (double *Dens, double *Qplus, double *viscosity_array, double *TAURR, double *TAURP,double *TAUPP,
double *DivergenceVelocity, int nrad, int nsec, double *Rmed, int Cooling, double *EnergyNew, double dt, double *EnergyMed,
double *SigmaMed, double *CoolingTimeMed, double *EnergyInt, double ADIABATICINDEX, double *QplusMed)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double den, num;
if (i==0 && j<nsec){
/* We calculate the heating source term Qplus for i=0 */
if (viscosity_array[nrad-1] != 0.0) {
/* power-law extrapolation */
Qplus[i*nsec + j] = Qplus[(i+1)*nsec + j]*exp(log(Qplus[(i+1)*nsec + j]/Qplus[(i+2)*nsec + j]) * \
log(Rmed[i]/Rmed[i+1]) / log(Rmed[i+1]/Rmed[i+2]));
}
else
Qplus[i*nsec + j] = 0.0;
}
/* Now we can update energy with source terms from i=0 */
if (i<nrad && j<nsec){
if (!Cooling){
num = dt*Qplus[i*nsec + j] + EnergyInt[i*nsec + j];
den = 1.0+(ADIABATICINDEX-1.0)*dt*DivergenceVelocity[i*nsec + j];
EnergyNew[i*nsec + j] = num/den;
}
else{
num = EnergyMed[i]*dt*Dens[i*nsec + j]/SigmaMed[i] + CoolingTimeMed[i]*EnergyInt[i*nsec + j] + \
dt*CoolingTimeMed[i]*(Qplus[i*nsec + j]-QplusMed[i]*Dens[i*nsec + j]/SigmaMed[i]);
den = dt + CoolingTimeMed[i] + (ADIABATICINDEX-1.0)*dt*CoolingTimeMed[i]*DivergenceVelocity[i*nsec + j];
EnergyNew[i*nsec + j] = num/den;
}
}
}
__global__ void UpdateVelocitiesKernel (double *VthetaInt, double *VradInt, double *invRmed, double *Rmed, double *Rsup,
double *Rinf, double *invdiffRmed, double *invdiffRsup, double *Dens, double *invRinf, double *TAURR, double *TAURP,
double *TAUPP, double DeltaT, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dphi, invdphi;
/* Now we can update velocities
with the viscous source term
of Navier-Stokes equation */
/* vtheta first */
if (i > 0 && i<nrad-1 && j<nsec){
dphi = 2.0*M_PI/(double)nsec;
invdphi = 1.0/dphi;
VthetaInt[i*nsec +j] += DeltaT*invRmed[i]*((Rsup[i]*TAURP[(i+1)*nsec+ j] - Rinf[i]*TAURP[i*nsec +j])*invdiffRsup[i] + \
(TAUPP[i*nsec +j] - TAUPP[i*nsec + ((j-1)+nsec)%nsec])*invdphi + 0.5*(TAURP[i*nsec + j] + TAURP[(i+1)*nsec +j]))/ \
(0.5*(Dens[i*nsec +j]+Dens[i*nsec + ((j-1)+nsec)%nsec]));
}
/* now vrad */
if (i > 0 && i<nrad && j<nsec){
dphi = 2.0*M_PI/(double)nsec;
invdphi = 1.0/dphi;
VradInt[i*nsec +j] += DeltaT*invRinf[i]*((Rmed[i]*TAURR[i*nsec +j] - Rmed[i-1]*TAURR[(i-1)*nsec + j])*invdiffRmed[i] + \
(TAURP[i*nsec + (j+1)%nsec] - TAURP[i*nsec + j])*invdphi - 0.5*(TAUPP[i*nsec +j] + TAUPP[(i-1)*nsec + j]))/ \
(0.5*(Dens[i*nsec +j] + Dens[(i-1)*nsec + j]));
}
}
__global__ void InitComputeAccelKernel (double *CellAbscissa, double *CellOrdinate, double *Rmed, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
CellAbscissa[i*nsec+j] = Rmed[i] * cos((2.0*PI*(double)j)/(double)nsec);
CellOrdinate[i*nsec+j] = Rmed[i] * sin((2.0*PI*(double)j)/(double)nsec);
}
}
__global__ void ComputeSoundSpeedKernel (double *SoundSpeed, double *Dens, double *Rmed, double *Energy, int nsec, int nrad,
int Adiabatic, double ADIABATICINDEX, double FLARINGINDEX, double ASPECTRATIO, double TRANSITIONWIDTH,
double TRANSITIONRADIUS, double TRANSITIONRATIO, double PhysicalTime, double PhysicalTimeInitial, double LAMBDADOUBLING)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double AspectRatio;
if (i<nrad && j<nsec){
if (!Adiabatic){
AspectRatio = AspectRatioDevice(Rmed[i], ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRADIUS, TRANSITIONRATIO,
PhysicalTime, PhysicalTimeInitial, LAMBDADOUBLING);
SoundSpeed[i*nsec + j] = AspectRatio*sqrt(G*1.0/Rmed[i])*pow(Rmed[i], FLARINGINDEX);
}
else SoundSpeed[i*nsec + j] = sqrt(ADIABATICINDEX*(ADIABATICINDEX-1.0)*Energy[i*nsec + j]/Dens[i*nsec + j]);
}
}
__global__ void ComputePressureFieldKernel (double *SoundSpeed, double *Dens, double *Pressure, int Adiabatic, int nrad,
int nsec, double ADIABATICINDEX, double *Energy) /* LISTO */
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (!Adiabatic)
Pressure[i*nsec + j] = Dens[i*nsec + j]*SoundSpeed[i*nsec + j]*SoundSpeed[i*nsec + j];
/* Since SoundSpeed is not update from initialization, cs remains axisymmetric*/
else Pressure[i*nsec + j] = (ADIABATICINDEX-1.0)*Energy[i*nsec + j];
}
}
__global__ void ComputeTemperatureFieldKernel (double *Dens, double *Temperature, double *Pressure, double *Energy,
double ADIABATICINDEX, int Adiabatic, int nsec, int nrad) /* LISTO */
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (!Adiabatic) Temperature[i*nsec + j] = MU/R*Pressure[i*nsec + j]/Dens[i*nsec + j];
else Temperature[i*nsec + j] = MU/R*(ADIABATICINDEX-1.0)*Energy[i*nsec + j]/Dens[i*nsec + j];
}
}
/* LISTO */
__global__ void InitLabelKernel (double *Label, double xp, double yp, double rhill, double *Rmed, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
double distance, angle, x, y;
angle = (double)j / (double)nsec*2.0*PI;
x = Rmed[i] * cos(angle);
y = Rmed[i] * sin(angle);
distance = sqrt((x - xp) * (x - xp) + (y - yp)*(y -yp));
if (distance < rhill) Label[i*nsec + j] = 1.0;
else Label[i*nsec + j] = 0.0;
}
}
__global__ void CircumPlanetaryMassKernel (double *Dens, double *Surf, double *CellAbscissa, double *CellOrdinate,
double xpl, double ypl, int nrad, int nsec, double HillRadius, double *mdcp0) /* LISTA */
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dist;
if (i<nrad && j<nsec){
dist = sqrt((CellAbscissa[i*nsec + j]-xpl)*(CellAbscissa[i*nsec + j]-xpl) + (CellOrdinate[i*nsec + j]-ypl) * \
(CellOrdinate[i*nsec + j]-ypl));
if (dist < HillRadius) mdcp0[i*nsec + j] = Surf[i]* Dens[i*nsec + j];
else mdcp0[i*nsec + j] = 0.0;
}
}
template <bool nIsPow2>
__global__ void DeviceReduceKernel (double *g_idata, double *g_odata, unsigned int n)
{
extern __shared__ double sdata[];
// perform first level of reduction,
// reading from global memory, writing to shared memory
unsigned int tid = threadIdx.x;
unsigned int blockSize = blockDim.x;
unsigned int i = blockIdx.x*blockSize*2 + threadIdx.x;
unsigned int gridSize = blockSize*2*gridDim.x;
double mySum = 0.0;
// we reduce multiple elements per thread. The number is determined by the
// number of active thread blocks (via gridDim). More blocks will result
// in a larger gridSize and therefore fewer elements per thread
while (i < n){
mySum += g_idata[i];
// ensure we don't read out of bounds -- this is optimized away for powerOf2 sized arrays
if (nIsPow2 || i + blockSize < n)
mySum += g_idata[i+blockSize];
i += gridSize;
}
// each thread puts its local sum into shared memory
sdata[tid] = mySum;
__syncthreads();
// do reduction in shared mem
if ((blockSize >= 512) && (tid < 256)){
sdata[tid] = mySum = mySum + sdata[tid + 256];
}
__syncthreads();
if ((blockSize >= 256) &&(tid < 128)){
sdata[tid] = mySum = mySum + sdata[tid + 128];
}
__syncthreads();
if ((blockSize >= 128) && (tid < 64)){
sdata[tid] = mySum = mySum + sdata[tid + 64];
}
__syncthreads();
#if (__CUDA_ARCH__ >= 300 )
if (tid < 32){
// Fetch final intermediate sum from 2nd warp
if (blockSize >= 64) mySum += sdata[tid + 32];
// Reduce final warp using shuffle
for (int offset = warpSize/2; offset > 0; offset /= 2){
mySum += __shfl_down(mySum, offset);
}
}
#else
// fully unroll reduction within a single warp
if ((blockSize >= 64) && (tid < 32)){
sdata[tid] = mySum = mySum + sdata[tid + 32];
}
__syncthreads();
if ((blockSize >= 32) && (tid < 16)){
sdata[tid] = mySum = mySum + sdata[tid + 16];
}
__syncthreads();
if ((blockSize >= 16) && (tid < 8)){
sdata[tid] = mySum = mySum + sdata[tid + 8];
}
__syncthreads();
if ((blockSize >= 8) && (tid < 4)){
sdata[tid] = mySum = mySum + sdata[tid + 4];
}
__syncthreads();
if ((blockSize >= 4) && (tid < 2)){
sdata[tid] = mySum = mySum + sdata[tid + 2];
}
__syncthreads();
if ((blockSize >= 2) && ( tid < 1)){
sdata[tid] = mySum = mySum + sdata[tid + 1];
}
__syncthreads();
#endif
// write result for this block to global mem
if (tid == 0) g_odata[blockIdx.x] = mySum;
}
__host__ long NearestPowerOf2 (long n)
{
if(!n) return n; //(0 ==2^0)
int x=1;
while (x < n){
x<<=1;
}
return x;
}
__host__ bool IsPow2 (unsigned int x)
{
return ((x&(x-1)==0));
}
__host__ double DeviceReduce (double *in, int N)
{
double *device_out;
gpuErrchk(hipMalloc(&device_out, sizeof(double)*1024));
gpuErrchk(hipMemset(device_out, 0, sizeof(double)*1024));
int threads = 32;
int blocks = min((int(NearestPowerOf2(N)) + threads - 1) / threads, 1024);
int smemSize = (threads <= 32) ? 2 * threads * sizeof(double) : threads * sizeof(double);
bool isPower2 = IsPow2(N);
if(isPower2){
hipLaunchKernelGGL(( DeviceReduceKernel<true>), dim3(blocks), dim3(threads), smemSize, 0, in, device_out, N);
gpuErrchk(hipDeviceSynchronize());
}
else{
hipLaunchKernelGGL(( DeviceReduceKernel<false>), dim3(blocks), dim3(threads), smemSize, 0, in, device_out, N);
gpuErrchk(hipDeviceSynchronize());
}
double *h_odata = (double *) malloc(blocks*sizeof(double));
double sum = 0.0;
gpuErrchk(hipMemcpy(h_odata, device_out, blocks * sizeof(double),hipMemcpyDeviceToHost));
for (int i=0; i<blocks; i++){
sum += h_odata[i];
}
hipFree(device_out);
free(h_odata);
return sum;
}
/* LISTA */
__global__ void MultiplyPolarGridbyConstantKernel (double *Dens, int nrad, int nsec, double ScalingFactor)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<=nrad && j<nsec)
Dens[i*nsec + j] *= ScalingFactor;
}
__global__ void Substep2Kernel (double *Dens, double *VradInt, double *VthetaInt, double *TemperInt, int nrad,
int nsec, double *invdiffRmed, double *invdiffRsup, double *DensInt, int Adiabatic, double *Rmed,
double dt, double *VradNew, double *VthetaNew, double *Energy, double *EnergyInt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dv;
if (i<nrad && j<nsec){
dv = VradInt[(i+1)*nsec + j] - VradInt[i*nsec + j];
if (dv < 0.0)
DensInt[i*nsec + j] = CVNR*CVNR*Dens[i*nsec+j]*dv*dv;
else
DensInt[i*nsec + j] = 0.0;
dv = VthetaInt[i*nsec + (j+1)%nsec] - VthetaInt[i*nsec + j];
if (dv < 0.0)
TemperInt[i*nsec + j] = CVNR*CVNR*Dens[i*nsec+j]*dv*dv;
else
TemperInt[i*nsec + j] = 0.0;
}
}
__global__ void kernel(double *Dens, double *VradInt, double *VthetaInt, double *TemperInt, int nrad,
int nsec, double *invdiffRmed, double *invdiffRsup, double *DensInt, int Adiabatic, double *Rmed,
double dt, double *VradNew, double *VthetaNew, double *Energy, double *EnergyInt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dens, densint, dxtheta, invdxtheta, dens2, tempint;
if (i>0 && i<nrad && j<nsec){
dens = Dens[i*nsec + j] + Dens[(i-1)*nsec + j];
densint = DensInt[i*nsec+j] - DensInt[(i-1)*nsec + j];
VradNew[i*nsec+j] = VradInt[i*nsec+j] - dt*2.0/dens*densint*invdiffRmed[i];
}
if (i<nrad && j<nsec){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
dens2 = Dens[i*nsec + j] + Dens[i*nsec + ((j-1)+nsec)%nsec];
tempint = (TemperInt[i*nsec+j] - TemperInt[i*nsec + ((j-1)+nsec)%nsec]);
VthetaNew[i*nsec + j] = VthetaInt[i*nsec + j] - dt*2.0/dens2*tempint*invdxtheta;
}
/* If gas disk is adiabatic, we add artificial viscosity as a source */
/* term for advection of thermal energy polargrid */
if (Adiabatic){
if (i<nrad && j<nsec){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
EnergyInt[i*nsec + j] = Energy[i*nsec + j] - dt*DensInt[i*nsec + j]* \
(VradInt[(i+1)*nsec + j] - VradInt[i*nsec + j])*invdiffRsup[i] - \
dt*TemperInt[i*nsec + j]*(VthetaInt[i*nsec + (j+1)%nsec] - VthetaInt[i*nsec + j])* invdxtheta;
}
}
}
__global__ void OpenBoundaryKernel (double *Vrad, double *Dens, double *Energy, int nsec, double SigmaMed)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 1;
if(j < nsec){
Dens[(i-1)*nsec + j] = Dens[i*nsec + j]; // copy first ring into ghost ring
Energy[(i-1)*nsec + j] = Energy[i*nsec + j];
if (Vrad[(i+1)*nsec + j] > 0.0 || (Dens[i*nsec + j] < SigmaMed))
Vrad[i*nsec + j] = 0.0; // we just allow outflow [inwards]
else
Vrad[i*nsec +j] = Vrad[(i+1)*nsec + j];
}
}
__global__ void ReduceCsKernel (double *SoundSpeed, double *cs0, double *cs1, double *csnrm1, double *csnrm2, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i=0;
if(j<nsec){
cs0[j] = SoundSpeed[i*nsec +j];
cs1[j] = SoundSpeed[(i+1)*nsec +j];
}
i = nrad-1;
if(j<nsec){
csnrm2[j] = SoundSpeed[(i-1)*nsec +j];
csnrm1[j] = SoundSpeed[i*nsec +j];
}
}
__global__ void ReduceMeanKernel (double *Dens, double *Energy, int nsec, double *mean_dens, double *mean_energy,
double *mean_dens2, double *mean_energy2, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 0;
if(j<nsec){
mean_dens[j] = Dens[i*nsec+ j];
mean_energy[j] = Energy[i*nsec +j];
}
i = nrad-1;
if(j<nsec){
mean_dens2[j] = Dens[i*nsec + j];
mean_energy2[j] = Energy[i*nsec + j];
}
}
__global__ void NonReflectingBoundaryKernel (double *Dens, double *Energy, int i_angle, int nsec, double *Vrad, double *SoundSpeed,
double SigmaMed, int nrad, double SigmaMed2, int i_angle2)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 1;
double Vrad_med;
if (j<nsec){
if(j+i_angle >= nsec){
Dens[j+i_angle - nsec] = Dens[i*nsec + j];
Energy[j+i_angle - nsec] = Energy[i*nsec + j];
}
else if(j+i_angle < 0){
Dens[j+i_angle + nsec] = Dens[i*nsec + j];
Energy[j+i_angle + nsec] = Energy[i*nsec + j];
}
else{
Dens[j+i_angle] = Dens[i*nsec + j];
Energy[j+i_angle] = Energy[i*nsec + j];
}
}
i = nrad-1;
if (j<nsec){
if (j-i_angle2 >= nsec){
Dens[i*nsec + j] = Dens[j-i_angle2 + (i-2)*nsec ];
Energy[i*nsec + j] = Energy[j-i_angle2 + (i-2)*nsec ];
}
else if (j-i_angle2 < 0){
Dens[i*nsec + j] = Dens[j-i_angle2 + i*nsec];
Energy[i*nsec + j] = Energy[j-i_angle2 + i*nsec];
}
else{
Dens[i*nsec + j] = Dens[j-i_angle2 + (i-1)*nsec];
Energy[i*nsec + j] = Energy[j-i_angle2 + (i-1)*nsec];
}
}
}
__global__ void NonReflectingBoundaryKernel2 (double *Dens, double *Energy, int i_angle, int nsec, double *Vrad, double *SoundSpeed,
double SigmaMed, int nrad, double SigmaMed2, int i_angle2)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 1;
double Vrad_med;
Vrad_med = -SoundSpeed[i*nsec + j]*(Dens[i*nsec + j]-SigmaMed)/SigmaMed;
Vrad[i*nsec + j] = 2.0*Vrad_med-Vrad[(i+1)*nsec + j];
i = nrad-1;
Vrad_med = SoundSpeed[i*nsec + j]*(Dens[(i-1)*nsec + j]-SigmaMed2)/SigmaMed2;
Vrad[i*nsec + j] = 2.*Vrad_med - Vrad[(i-1)*nsec + j];
}
__global__ void MinusMeanKernel (double *Dens, double *Energy, double SigmaMed, double mean_dens_r, double mean_dens_r2,
double mean_energy_r,double mean_energy_r2, double EnergyMed, int nsec, int nrad, double SigmaMed2, double EnergyMed2)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 0;
if (j< nsec){
Dens[i*nsec + j] += SigmaMed - mean_dens_r;
Energy[i*nsec + j] += EnergyMed - mean_energy_r;
}
i = nrad-1;
if (j < nsec){
Dens[i*nsec + j] += SigmaMed2 - mean_dens_r2;
Energy[i*nsec + j] += EnergyMed2 - mean_energy_r2;
}
}
__global__ void Make1DprofileKernel (double *gridfield, double *axifield, int nsec, int nrad)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
int j;
if (i < nrad){
double sum = 0.0;
for (j = 0; j < nsec; j++)
sum += gridfield[i*nsec + j];
axifield[i] = sum/(double)nsec;
}
}
__host__ void Make1Dprofile (int option)
{
/* GLOBAL AxiSGAccr option */
if (option == 1){
gpuErrchk(hipMemcpy(gridfield_d, SoundSpeed_d, size_grid*sizeof(double), hipMemcpyDeviceToDevice));
//gpuErrchk(hipMemcpy(GLOBAL_AxiSGAccr_d, axifield_d, NRAD*sizeof(double), hipMemcpyDeviceToHost));
}
/* GLOBAL_bufarray option */
if (option == 2){
//gpuErrchk(hipMemcpy(gridfield_d, SG_Accr_d, size_grid*sizeof(double), hipMemcpyDeviceToDevice));
//gpuErrchk(hipMemcpy(GLOBAL_AxiSGAccr_d, axifield_d, NRAD*sizeof(double), hipMemcpyDeviceToHost));
}
hipLaunchKernelGGL(( Make1DprofileKernel), dim3(dimGrid4), dim3(dimBlock), 0, 0, gridfield_d, axifield_d, NSEC, NRAD);
gpuErrchk(hipDeviceSynchronize());
gpuErrchk(hipMemcpy(GLOBAL_bufarray, axifield_d, NRAD*sizeof(double), hipMemcpyDeviceToHost));
}
/* LISTO */
__global__ void InitGasVelocitiesKernel (int nsec, int nrad, int SelfGravity, double *Rmed,
double ASPECTRATIO, double FLARINGINDEX, double SIGMASLOPE, double *Vrad, double *Vtheta,
double IMPOSEDDISKDRIFT, double SIGMA0, double *SigmaInf, double OmegaFrame, double *Rinf, int ViscosityAlpha, double *viscosity_array)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double viscosity;
if (i <= nrad && j < nsec){
double omega, r, ri;
if (i == nrad){
r = Rmed[nrad - 1];
ri = Rinf[nrad - 1];
}
else{
r = Rmed[i];
ri = Rinf[i];
}
if (!SelfGravity){
omega = sqrt(G*1.0/r/r/r);
Vtheta[i*nsec + j] = omega*r*sqrt(1.0-pow(ASPECTRATIO,2.0)*pow(r,2.0*FLARINGINDEX)* \
(1.+SIGMASLOPE-2.0*FLARINGINDEX));
}
Vtheta[i*nsec + j ] -= OmegaFrame*r;
//if (CentrifugalBalance) Vtheta[i*nsec + j] = vt_cent[i];
if (i == nrad) Vrad[i*nsec + j] = 0.0;
else {
Vrad[i*nsec + j] = IMPOSEDDISKDRIFT*SIGMA0/SigmaInf[i]/ri;
if (ViscosityAlpha) Vrad[i*nsec+j] -= 3.0*viscosity_array[i]/r*(-SIGMASLOPE+2.0*FLARINGINDEX+1.0);
else Vrad[i*nsec+j] -= 3.0*viscosity_array[i]/r*(-SIGMASLOPE+.5);
}
if (i == 0 && j < nsec) Vrad[j] = Vrad[nrad*nsec + j] = 0.0;
}
}
__global__ void ComputeForceKernel (double *CellAbscissa, double *CellOrdinate, double *Surf, double *Dens, double x,
double y, double rsmoothing, int nsec, int nrad, double a, double *Rmed, int dimfxy, double rh, double *fxi,
double *fxo, double *fyi, double *fyo, int k)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double cellmass, dx, dy, d2, InvDist3, dist2, distance, resultxi, resultyi;
double resultxo, resultyo, hillcutfactor, hill_cut;
if (i<nrad && j<nsec){
cellmass = Surf[i]* Dens[i*nsec + j];
dx = CellAbscissa[i*nsec + j] - x;
dy = CellOrdinate[i*nsec + j] - y;
d2 = dx*dx + dy*dy;
dist2 = d2 + rsmoothing*rsmoothing;
distance = sqrt(dist2);
InvDist3 = 1.0/dist2/distance;
hillcutfactor = (double) k / (double)(dimfxy-1);
if (k != 0){
rh *= hillcutfactor;
hill_cut = 1.-exp(-d2/(rh*rh));
}
else
hill_cut = 1.;
if (Rmed[i] < a){
fxi[i*nsec + j] = G * cellmass * dx * InvDist3 * hill_cut;
fyi[i*nsec + j] = G * cellmass * dy * InvDist3 * hill_cut;
}
else{
fxo[i*nsec + j] = G * cellmass * dx * InvDist3 * hill_cut;
fyo[i*nsec + j] = G * cellmass * dy * InvDist3 * hill_cut;
}
}
}
__global__ void ViscousTermsKernel (double *Vradial, double *Vazimutal , double *DRR, double *DPP, double *DivergenceVelocity,
double *DRP, double *invdiffRsup, double *invRmed, double *Rsup, double *Rinf, double *invdiffRmed, int nrad,
int nsec, double *TAURR, double *TAUPP, double *dens, double *TAURP, double *invRinf, double *Rmed, double *viscosity_array_d)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dphi, invdphi, onethird, viscosity;
if (i<nrad && j<nsec){ /* Drr, Dpp and divV computation */
dphi = 2.0*M_PI/(double)nsec;
invdphi = 1.0/dphi;
onethird = 1.0/3.0;
DRR[i*nsec + j] = (Vradial[(i+1)*nsec + j] - Vradial[i*nsec + j])*invdiffRsup[i];
DPP[i*nsec + j] = (Vazimutal[i*nsec + (j+1)%nsec] - Vazimutal[i*nsec + j])*invdphi*invRmed[i]+0.5* \
(Vradial[(i+1)*nsec + j]+Vradial[i*nsec + j])*invRmed[i];
DivergenceVelocity[i*nsec + j] = (Vradial[(i+1)*nsec + j]*Rsup[i] - Vradial[i*nsec + j]*Rinf[i])*invdiffRsup[i] * \
invRmed[i];
DivergenceVelocity[i*nsec + j] += (Vazimutal[i*nsec + (j+1)%nsec] - Vazimutal[i*nsec + j])*invdphi*invRmed[i];
if (i > 0) DRP[i*nsec + j] = 0.5*(Rinf[i]*(Vazimutal[i*nsec + j]*invRmed[i] - Vazimutal[(i-1)*nsec + j]*invRmed[i-1])* \
invdiffRmed[i] + (Vradial[i*nsec + j] - Vradial[i*nsec + ((j-1)+nsec)%nsec])*invdphi*invRinf[i]);
}
if (i<nrad && j<nsec){ /* TAUrr and TAUpp computation */
TAURR[i*nsec + j] = 2.0*dens[i*nsec + j]*viscosity_array_d[i]*(DRR[i*nsec + j] - onethird*DivergenceVelocity[i*nsec + j]);
TAUPP[i*nsec + j] = 2.0*dens[i*nsec + j]*viscosity_array_d[i]*(DPP[i*nsec + j] - onethird*DivergenceVelocity[i*nsec + j]);
if (i > 0){
TAURP[i*nsec + j] = 2.0*0.25*(dens[i*nsec + j] + dens[(i-1)*nsec + j] + \
dens[i*nsec + ((j-1)+nsec)%nsec] + dens[(i-1)*nsec + ((j-1)+nsec)%nsec])* \
viscosity_array_d[i]*DRP[i*nsec + j];
}
}
}
__global__ void LRMomentaKernel (double *RadMomP, double *RadMomM, double *ThetaMomP, double *ThetaMomM, double *Dens,
double *Vrad, double *Vtheta, int nrad, int nsec, double *Rmed, double OmegaFrame)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
RadMomP[i*nsec + j] = Dens[i*nsec + j] * Vrad[(i+1)*nsec + j]; // (i+1)*nsec
RadMomM[i*nsec + j] = Dens[i*nsec + j] * Vrad[i*nsec + j];
/* it is the angular momentum -> ThetaMomP */
ThetaMomP[i*nsec + j] = Dens[i*nsec + j] * (Vtheta[i*nsec + (j+1)%nsec]+Rmed[i]*OmegaFrame)*Rmed[i];
ThetaMomM[i*nsec + j] = Dens[i*nsec + j] * (Vtheta[i*nsec + j]+Rmed[i]*OmegaFrame)*Rmed[i];
}
}
__global__ void ExtQtyKernel (double *ExtLabel, double *Dens, double *Label, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec)
ExtLabel[i*nsec + j] = Dens[i*nsec + j]*Label[i*nsec + j];
}
__global__ void StarRadKernel (double *Qbase2, double *Vrad, double *QStar, double dt, int nrad, int nsec,
double *invdiffRmed, double *Rmed, double *dq)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dqm, dqp;
if (i<nrad && j<nsec){
if ((i == 0 || i == nrad-1)) dq[i + j*nrad] = 0.0;
else {
dqm = (Qbase2[i*nsec + j] - Qbase2[(i-1)*nsec + j])*invdiffRmed[i];
dqp = (Qbase2[(i+1)*nsec + j] - Qbase2[i*nsec + j])*invdiffRmed[i+1];
if (dqp * dqm > 0.0)
dq[i+j*nrad] = 2.0*dqp*dqm/(dqp+dqm);
else
dq[i+j*nrad] = 0.0;
}
}
}
__global__ void StarRadKernel2 (double *Qbase2, double *Vrad, double *QStar, double dt, int nrad, int nsec,
double *invdiffRmed, double *Rmed, double *dq)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (Vrad[i*nsec + j] > 0.0 && i > 0)
QStar[i*nsec + j] = Qbase2[(i-1)*nsec + j] + (Rmed[i]-Rmed[i-1]-Vrad[i*nsec + j]*dt)*0.5*dq[i-1+j*nrad];
else
QStar[i*nsec + j] = Qbase2[i*nsec + j]-(Rmed[i+1]-Rmed[i]+Vrad[i*nsec + j]*dt)*0.5*dq[i+j*nrad];
}
if (i == 0 && j<nsec)
QStar[j] = QStar[j+nsec*nrad] = 0.0;
}
__global__ void ComputeFFTKernel (double *Radii, hipfftDoubleComplex *SGP_Kr, hipfftDoubleComplex *SGP_Kt, double SGP_eps, int nrad, int nsec,
hipfftDoubleComplex *SGP_Sr, hipfftDoubleComplex *SGP_St, double *Dens, double *Rmed, double *Kr_aux, double *Kt_aux)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double u, cosj, sinj, coshu, expu, den_SGP_K, theta, base;
double a, var, radii;
if (i<2*nrad && j<nsec){
SGP_Kr[i*nsec + j].x = Kr_aux[i*nsec + j];
SGP_Kr[i*nsec + j].y = 0.;
SGP_Kt[i*nsec + j].x = Kt_aux[i*nsec + j];
SGP_Kt[i*nsec + j].y = 0.;
SGP_Sr[i*nsec + j].y = 0.;
SGP_St[i*nsec + j].y = 0.;
if (i<nrad){
var = Dens[i*nsec + j] * sqrt(Rmed[i]/Rmed[0]);
SGP_Sr[i*nsec + j].x = var;
SGP_St[i*nsec + j].x = var*Rmed[i]/Rmed[0];
}
else{
SGP_Sr[i*nsec + j].x = 0.;
SGP_St[i*nsec + j].x = 0.;
}
}
}
__global__ void ComputeConvolutionKernel (hipfftDoubleComplex *Gr, hipfftDoubleComplex *Gphi, hipfftDoubleComplex *SGP_Kr, hipfftDoubleComplex *SGP_Kt,
hipfftDoubleComplex *SGP_Sr, hipfftDoubleComplex *SGP_St, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<2*nrad && j<nsec){
Gphi[i*nsec + j].x = -G*(SGP_Kt[i*nsec + j].x * SGP_St[i*nsec + j].x - \
SGP_Kt[i*nsec + j].y * SGP_St[i*nsec + j].y);
Gphi[i*nsec + j].y = -G*(SGP_Kt[i*nsec + j].x * SGP_St[i*nsec + j].y + \
SGP_Kt[i*nsec + j].y * SGP_St[i*nsec + j].x);
Gr[i*nsec + j].x = -G*(SGP_Kr[i*nsec + j].x * SGP_Sr[i*nsec + j].x - \
SGP_Kr[i*nsec + j].y * SGP_Sr[i*nsec + j].y);
Gr[i*nsec + j].y = -G*(SGP_Kr[i*nsec + j].x * SGP_Sr[i*nsec + j].y + \
SGP_Kr[i*nsec + j].y *SGP_Sr[i*nsec + j].x);
}
}
__global__ void ComputeSgAccKernel (double *SG_Accr, double *SG_Acct, double *Dens , double SGP_rstep, double SGP_tstep,
double SGP_eps, int nrad, int nsec, double *Rmed, hipfftDoubleComplex *Gr, hipfftDoubleComplex *Gphi)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double normaccr, normacct, divRmed;
if (i<nrad && j<nsec){
divRmed = Rmed[i]/Rmed[0];
normaccr = SGP_rstep * SGP_tstep / ((double)(2*nrad) * (double)nsec);
normacct = normaccr;
normaccr /= sqrt(divRmed);
normacct /= (divRmed * sqrt(divRmed));
SG_Acct[i*nsec + j] = Gphi[i*nsec + j].x * normacct;
SG_Accr[i*nsec + j] = Gr[i*nsec + j].x * normaccr;
SG_Accr[i*nsec + j] += G*Dens[i*nsec + j]*SGP_rstep*SGP_tstep / SGP_eps;
}
}
__global__ void Update_sgvelocityKernel (double *Vradial, double *Vazimutal, double *SG_Accr, double *SG_Acct, double *Rinf,
double *Rmed, double *invdiffRmed, double dt, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
int jm1, lm1;
/* Here we update velocity fields to take into acount self-gravity */
if (i<nrad && j<nsec){
/* We compute VRAD - half-centered in azimuth - from centered-in-cell radial sg acceleration. */
if (i > 0) Vradial[i*nsec + j] += dt*((Rinf[i] - Rmed[i-1]) * SG_Accr[i*nsec + j] + \
(Rmed[i] - Rinf[i]) * SG_Accr[(i-1)*nsec + j]) *invdiffRmed[i]; // caso !SGZeroMode
/* We compute VTHETA - half-centered in radius - from centered-in-cell azimutal sg acceleration. */
Vazimutal[i*nsec + j] += 0.5 * dt * (SG_Acct[i*nsec + j] + SG_Acct[i*nsec + (j-1)%nsec]);
}
}
__global__ void Azimutalvelocity_withSGKernel (double *Vtheta, double *Rmed, double FLARINGINDEX, double SIGMASLOPE,
double ASPECTRATIO, double *axifield_d, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double omegakep, omega, invr;
if (i<nrad && j<nsec){
invr = 1./Rmed[i];
omegakep = sqrt(G*1.0*invr*invr*invr);
omega = sqrt(omegakep*omegakep* (1.0 - (1.+SIGMASLOPE-2.0*FLARINGINDEX)*pow(ASPECTRATIO,2.0)* \
pow(Rmed[i],2.0*FLARINGINDEX)) - invr*axifield_d[i]);
Vtheta[i*nsec + j] = Rmed[i]*omega;
}
}
__global__ void CrashKernel (double *array, int nrad, int nsec, int Crash)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (array[i*nsec + j] < 0.0)
array[i*nsec + j] = 1.0;
else
array[i*nsec + j] = 0.0;
}
}
__global__ void EvanescentBoundaryKernel(double *Rmed, double *Vrad, double *Vtheta, double *Energy, double *Dens,
double *viscosity_array, double DRMIN, double DRMAX, int nrad, int nsec, double Tin,
double Tout, double step, double SIGMASLOPE, double FLARINGINDEX, double *GLOBAL_bufarray, double OmegaFrame,
double *SigmaMed, double *EnergyMed, int Adiabatic, int SelfGravity, double ASPECTRATIO, double TRANSITIONWIDTH,
double TRANSITIONRADIUS, double TRANSITIONRATIO, double PhysicalTime, double PhysicalTimeInitial, double LAMBDADOUBLING)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double damping, lambda, vtheta0, vrad0, energy0, dens0, AspectRatio;
if (i<nrad && j<nsec){
if ((Rmed[i] < DRMIN) || (Rmed[i] > DRMAX)){
/* Damping operates only inside the wave killing zones */
if(Rmed[i] < DRMIN){
damping = (Rmed[i]-DRMIN)/(Rmed[0]-DRMIN);
lambda = damping*damping*10.0*step/Tin;
}
if (Rmed[i] > DRMAX){
damping = (Rmed[i]-DRMAX)/(Rmed[nrad-1]-DRMAX);
lambda = damping*damping*10.0*step/Tout;
}
if(!SelfGravity){
AspectRatio = AspectRatioDevice(Rmed[i], ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRADIUS, TRANSITIONRATIO,
PhysicalTime, PhysicalTimeInitial, LAMBDADOUBLING);
vtheta0 = sqrt(G*1.0/Rmed[i] * (1.0 - (1.0+SIGMASLOPE-2.0*FLARINGINDEX)*pow(AspectRatio,2.0) * \
pow(Rmed[i],2.0*FLARINGINDEX)));
}
if (SelfGravity){
AspectRatio = AspectRatioDevice(Rmed[i], ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRADIUS, TRANSITIONRATIO,
PhysicalTime, PhysicalTimeInitial, LAMBDADOUBLING);
vtheta0 = sqrt(G*1.0/Rmed[i] * (1.0 - (1.0+SIGMASLOPE-2.0*FLARINGINDEX)*pow(AspectRatio,2.0) * \
pow(Rmed[i],2.0*FLARINGINDEX)) - Rmed[i]*GLOBAL_bufarray[i]);
}
/* this could be refined if CentrifugalBalance is used... */
vtheta0 -= Rmed[i]*OmegaFrame;
vrad0 = -3.0*viscosity_array[i]/Rmed[i]*(-SIGMASLOPE+.5);
dens0 = SigmaMed[i];
energy0 = EnergyMed[i];
Vrad[i*nsec + j] = (Vrad[i*nsec + j] + lambda*vrad0)/(1.0+lambda);
Vtheta[i*nsec + j] = (Vtheta[i*nsec + j] + lambda*vtheta0)/(1.0+lambda);
Dens[i*nsec + j] = (Dens[i*nsec + j] + lambda*dens0)/(1.0+lambda);
if (Adiabatic)
Energy[i*nsec + j] = (Energy[i*nsec + j] + lambda*energy0)/(1.0+lambda);
}
}
}
__global__ void DivisePolarGridKernel (double *Qbase, double *DensInt, double *Work, int nrad, int nsec)
{
int i = threadIdx.x + blockDim.x*blockIdx.x; //512
int j = threadIdx.y + blockDim.y*blockIdx.y; //256
if (i<=nsec && j<nrad)
Work[i*nrad + j] = Qbase[i*nrad + j]/(DensInt[i*nrad + j] + 1e-20);
}
__global__ void VanLeerRadialKernel (double *Rinf, double *Rsup, double *QRStar, double *DensStar, double *Vrad,
double *LostByDisk, int nsec, int nrad, double dt, int OpenInner, double *Qbase, double *invSurf)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double varq, dtheta;
if (i<nrad && j<nsec){
dtheta = 2.0*PI/(double)nsec;
varq = dt*dtheta*Rinf[i]*QRStar[i*nsec + j]* DensStar[i*nsec + j]*Vrad[i*nsec + j];
varq -= dt*dtheta*Rsup[i]*QRStar[(i+1)*nsec + j]* DensStar[(i+1)*nsec + j]*Vrad[(i+1)*nsec + j];
Qbase[i*nsec + j] += varq*invSurf[i];
if (i==0 && OpenInner)
LostByDisk[j] = varq;
}
}
__global__ void VanLeerThetaKernel (double *Rsup, double *Rinf, double *Surf, double dt, int nrad, int nsec,
int UniformTransport, int *NoSplitAdvection, double *QRStar, double *DensStar, double *Vazimutal_d, double *Qbase)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxrad, invsurf, varq;
if (i<nrad && j<nsec){
if ((UniformTransport == NO) || (NoSplitAdvection[i] == NO)){
dxrad = (Rsup[i]-Rinf[i])*dt;
invsurf = 1.0/Surf[i];
varq = dxrad*QRStar[i*nsec + j]*DensStar[i*nsec + j]*Vazimutal_d[i*nsec + j];
varq -= dxrad*QRStar[i*nsec + (j+1)%nsec]*DensStar[i*nsec + (j+1)%nsec]*Vazimutal_d[i*nsec + (j+1)%nsec];
Qbase[i*nsec + j] += varq*invsurf;
}
}
}
__global__ void ComputeAverageThetaVelocitiesKernel(double *Vtheta, double *VMed, int nsec, int nrad)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
double moy = 0.0;
if (i<nrad){
for (int j = 0; j < nsec; j++)
moy += Vtheta[i*nsec + j];
VMed[i] = moy/(double)nsec;
}
}
__global__ void ComputeResidualsKernel (double *VthetaRes, double *VMed, int nsec, int nrad, double *Vtheta)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec)
VthetaRes[i*nsec + j] = Vtheta[i*nsec + j]-VMed[i];
}
__global__ void ComputeConstantResidualKernel (double *VMed, double *invRmed, int *Nshift, int *NoSplitAdvection,
int nsec, int nrad, double dt, double *Vtheta, double *VthetaRes, double *Rmed, int FastTransport)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double maxfrac, Ntilde, Nround, invdt, dpinvns;
long nitemp;
if (i<nrad && j<nsec){
if (FastTransport)
maxfrac = 1.0;
else
maxfrac = 0.0;
invdt = 1.0/dt;
dpinvns = 2.0*PI/(double)nsec;
Ntilde = VMed[i]*invRmed[i]*dt*(double)nsec/2.0/PI;
Nround = floor(Ntilde+0.5);
nitemp = (long)Nround;
Nshift[i] = (long)nitemp;
Vtheta[i*nsec + j] = (Ntilde-Nround)*Rmed[i]*invdt*dpinvns;
if (maxfrac < 0.5){
NoSplitAdvection[i] = YES;
VthetaRes[i*nsec + j] += Vtheta[i*nsec + j];
Vtheta[i*nsec + j] = 0.0;
}
else{
NoSplitAdvection[i] = NO;
}
}
}
__global__ void StarThetaKernel (double *Qbase, double *Rmed, int nrad, int nsec, double *dq, double dt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxtheta, invdxtheta, dqp, dqm;
if (i<nrad && j<nsec){
if (i<nrad){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
}
dqm = (Qbase[i*nsec + j] - Qbase[i*nsec + ((j-1)+nsec)%nsec]);
dqp = (Qbase[i*nsec + (j+1)%nsec] - Qbase[i*nsec + j]);
if (dqp * dqm > 0.0)
dq[i*nsec + j] = dqp*dqm/(dqp+dqm)*invdxtheta;
else
dq[i*nsec + j] = 0.0;
}
}
__global__ void StarThetaKernel2 (double *Qbase, double *Rmed, double *Vazimutal, double *QStar, int nrad, int nsec,
double *dq, double dt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxtheta, ksi, invdxtheta, dqp, dqm;
if (i<nrad && j<nsec){
if (i<nrad){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
}
ksi = Vazimutal[i*nsec + j]*dt;
if (ksi > 0.0)
QStar[i*nsec + j] = Qbase[i*nsec + ((j-1)+nsec)%nsec]+(dxtheta-ksi)*dq[i*nsec + ((j-1)+nsec)%nsec];
else
QStar[i*nsec + j] = Qbase[i*nsec + j]-(dxtheta+ksi)*dq[i*nsec + j];
}
}
__global__ void AdvectSHIFTKernel (double *array, double *TempShift, int nsec, int nrad, int *Nshift)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
int ji, modji;
if (i<nrad && j<nsec){
ji = j-Nshift[i];
//if (ji < 0) ji = ji%nsec + nsec;
//if (ji >= nsec) ji = ji%nsec;
while (ji < 0 ) ji += nsec;
while (ji >= nsec) ji -= nsec;
TempShift[i*nsec + j] = array[i*nsec + ji];
}
}
__global__ void ComputeVelocitiesKernel (double *Vrad, double *Vtheta, double *Dens, double *Rmed, double *ThetaMomP,
double *ThetaMomM, double *RadMomP, double *RadMomM, int nrad, int nsec, double OmegaFrame)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (i == 0)
Vrad[i*nsec + j] = 0.0;
else {
Vrad[i*nsec + j] = (RadMomP[(i-1)*nsec + j] + RadMomM[i*nsec + j])/(Dens[i*nsec + j] +
Dens[(i-1)*nsec + j] + 1e-20);
}
Vtheta[i*nsec + j] = (ThetaMomP[i*nsec + ((j-1)+nsec)%nsec] + ThetaMomM[i*nsec + j])/(Dens[i*nsec + j] +
Dens[i*nsec + ((j-1)+nsec)%nsec] + 1e-15)/Rmed[i] - Rmed[i]*OmegaFrame;
/* It was the angular momentum */
}
}
__global__ void ComputeSpeQtyKernel (double *Label, double *Dens, double *ExtLabel, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
Label[i*nsec + j] = ExtLabel[i*nsec + j]/Dens[i*nsec + j];
/* Compressive flow if line commentarized
Label[i*nsec + j] = ExtLabel[i*nsec + j] */
}
}
__global__ void FillForcesArraysKernel (double *Rmed, int nsec, int nrad, double xplanet, double yplanet, double smooth,
double mplanet, int Indirect_Term, double InvPlanetDistance3, double *Potential, Pair IndirectTerm, int k)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double InvDistance, angle, x, y, distance, distancesmooth, pot;
if (i<nrad && j<nsec){
InvDistance = 1.0/Rmed[i];
angle = (double)j/(double)nsec*2.0*PI;
x = Rmed[i]*cos(angle);
y = Rmed[i]*sin(angle);
distance = (x-xplanet)*(x-xplanet)+(y-yplanet)*(y-yplanet);
distancesmooth = sqrt(distance+smooth);
pot = -G*mplanet/distancesmooth; /* Direct term from planet */
if (Indirect_Term == YES)
pot += G*mplanet*InvPlanetDistance3*(x*xplanet+y*yplanet); /* Indirect term from planet */
Potential[i*nsec + j] += pot;
if (k == 0) {
/* -- Gravitational potential from star on gas -- */
pot = -G*1.0*InvDistance; /* Direct term from star */
pot -= IndirectTerm.x*x + IndirectTerm.y*y; /* Indirect term from star */
Potential[i*nsec + j] += pot;
}
}
}
__global__ void CorrectVthetaKernel (double *Vtheta, double domega, double *Rmed, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec)
Vtheta[i*nsec + j] = Vtheta[i*nsec + j] - domega*Rmed[i];
}
__global__ void ConditionCFLKernel1D (double *Rsup, double *Rinf, double *Rmed, int nrad, int nsec,
double *Vtheta, double *Vmoy)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
int j;
if (i<nrad){
Vmoy[i] = 0.0;
for (j = 0; j < nsec; j++)
Vmoy[i] += Vtheta[i*nsec + j];
Vmoy[i] /= (double)nsec;
}
}
__global__ void ConditionCFLKernel2D1 (double *Rsup, double *Rinf, double *Rmed, int nsec, int nrad,
double *Vresidual, double *Vtheta, double *Vmoy, int FastTransport, double *SoundSpeed, double *Vrad,
double *DT2D)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxrad, dxtheta, invdt1, invdt2, invdt3, invdt4, dvr, dvt, dt;
if (i > 0 && i<nrad && j<nsec){
dxrad = Rsup[i]-Rinf[i];
dxtheta = Rmed[i]*2.0*PI/(double)nsec;
if (FastTransport) Vresidual[i*nsec + j] = Vtheta[i*nsec + j]-Vmoy[i]; /* Fargo algorithm */
else Vresidual[i*nsec + j] = Vtheta[i*nsec + j]; /* Standard algorithm */
//Vresidual[i*nsec + nsec] = Vresidual[i*nsec];
invdt1 = SoundSpeed[i*nsec + j]/(min2(dxrad,dxtheta));
invdt2 = fabs(Vrad[i*nsec + j])/dxrad;
invdt3 = fabs(Vresidual[i*nsec + j])/dxtheta;
dvr = Vrad[(i+1)*nsec + j]-Vrad[i*nsec + j];
dvt = Vtheta[i*nsec + (j+1)%nsec]-Vtheta[i*nsec + j];
if (dvr >= 0.0) dvr = 1e-10;
else dvr = -dvr;
if (dvt >= 0.0) dvt = 1e-10;
else dvt = -dvt;
invdt4 = max2(dvr/dxrad, dvt/dxtheta);
invdt4*= 4.0*CVNR*CVNR;
dt = CFLSECURITY/sqrt(invdt1*invdt1+invdt2*invdt2+invdt3*invdt3+invdt4*invdt4);
DT2D[i*nsec + j] = dt; // array nrad*nsec size dt
}
}
__global__ void ConditionCFLKernel2D2 (double *newDT, double *DT2D, double *DT1D, double *Vmoy, double *invRmed,
int *CFL, int nsec, int nrad, double DeltaT)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
int k;
double dt;
double newdt = 1e30;
if (i>0 && i<nrad){
newDT[i] = newdt;
for (k = 0; k < nsec; k++)
if (DT2D[i*nsec + k] < newDT[i]) newDT[i] = DT2D[i*nsec + k]; // for each dt in nrad
}
if (i<nrad-1){
dt = 2.0*PI*CFLSECURITY/(double)nsec/fabs(Vmoy[i]*invRmed[i]-Vmoy[i+1]*invRmed[i+1]);
DT1D[i] = dt; // array nrad size dt
}
}
__global__ void ConditionCFLKernel2D3 (double *newDT, double *DT2D, double *DT1D, double *Vmoy, double *invRmed,
int *CFL, int nsec, int nrad, double DeltaT)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
double newdt;
if (j == 0){
newdt = newDT[1];
for (int i=2; i<nrad; i++){
if (newDT[i] < newdt)
newdt = newDT[i];
}
for (int i = 0; i < nrad-1; i++) {
if (DT1D[i] < newdt)
newdt = DT1D[i];
}
if (DeltaT < newdt)
newdt = DeltaT;
CFL[0] = (int)(ceil(DeltaT/newdt));
}
}
__device__ double max2(double a, double b)
{
if (b > a) return b;
return a;
}
__device__ double min2(double a, double b)
{
if (b < a) return b;
return a;
}
__device__ double AspectRatioDevice(double r, double ASPECTRATIO, double TRANSITIONWIDTH, double TRANSITIONRADIUS,
double TRANSITIONRATIO, double PhysicalTime, double PhysicalTimeInitial, double LAMBDADOUBLING)
{
double aspectratio, rmin, rmax, scale;
aspectratio = ASPECTRATIO;
rmin = TRANSITIONRADIUS-TRANSITIONWIDTH*ASPECTRATIO;
rmax = TRANSITIONRADIUS+TRANSITIONWIDTH*ASPECTRATIO;
scale = 1.0+(PhysicalTime-PhysicalTimeInitial)*LAMBDADOUBLING;
rmin *= scale;
rmax *= scale;
if (r < rmin) aspectratio *= TRANSITIONRATIO;
if ((r >= rmin) && (r <= rmax)){
aspectratio *= exp((rmax-r)/(rmax-rmin)*log(TRANSITIONRATIO));
}
return aspectratio;
}
/*__device__ double FViscosityDevice(double r, double VISCOSITY, int ViscosityAlpha, double *Rmed, double ALPHAVISCOSITY,
double CAVITYWIDTH, double CAVITYRADIUS, double CAVITYRATIO, double PhysicalTime, double PhysicalTimeInitial,
double ASPECTRATIO, double LAMBDADOUBLING)
{
double viscosity, rmin, rmax, scale;
int i = 0;
viscosity = VISCOSITY;
if (ViscosityAlpha){
while (Rmed[i] < r) i++;
viscosity = ALPHAVISCOSITY*GLOBAL_bufarray[i] * GLOBAL_bufarray[i] * pow(r, 1.5);
}
rmin = CAVITYRADIUS-CAVITYWIDTH*ASPECTRATIO;
rmax = CAVITYRADIUS+CAVITYWIDTH*ASPECTRATIO;
scale = 1.0+(PhysicalTime-PhysicalTimeInitial)*LAMBDADOUBLING;
rmin *= scale;
rmax *= scale;
if (r < rmin) viscosity *= CAVITYRATIO;
if ((r >= rmin) && (r <= rmax)) viscosity *= exp((rmax-r)/(rmax-rmin)*log(CAVITYRATIO));
return viscosity;
}*/
__global__ void ApplySubKeplerianBoundaryKernel(double *VthetaInt, double *Rmed, double OmegaFrame, int nsec,
int nrad, double VKepIn, double VKepOut)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 0;
if (j<nsec)
VthetaInt[i*nsec + j] = VKepIn - Rmed[i]*OmegaFrame;
i = nrad - 1;
if (j<nsec)
VthetaInt[i*nsec + j] = VKepOut - Rmed[i]*OmegaFrame;
}
| 7cf621ce39fc6bf7fba99e5f06ee28bef49bcc42.cu | #include "Main.cuh"
extern int blocksize2, size_grid, NRAD, NSEC;
extern double *GLOBAL_bufarray, *SoundSpeed_d;
extern double *gridfield_d, *GLOBAL_bufarray_d, *axifield_d, *SG_Accr_d, *GLOBAL_AxiSGAccr_d;
extern double ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRATIO, TRANSITIONRADIUS, LAMBDADOUBLING;
extern double PhysicalTime, PhysicalTimeInitial;
extern dim3 dimGrid, dimBlock, dimGrid4;
__global__ void Substep1Kernel (double *Pressure, double *Dens, double *VradInt, double *invdiffRmed, double *Potential,
double *Rinf, double *invRinf, double *Vrad, double *VthetaInt, double *Vtheta, double *Rmed, double dt,
int nrad, int nsec, double OmegaFrame, int ZMPlus, double IMPOSEDDISKDRIFT, double SIGMASLOPE)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double gradp, gradphi, vradint, vradint2, supp_torque, dxtheta, invdxtheta;
double vt2;
// i=1->nrad , j=0->nsec
if (i > 0 && i<nrad && j<nsec){
gradp = (Pressure[i*nsec + j] - Pressure[(i-1)*nsec + j])*2.0/(Dens[i*nsec + j] + Dens[(i-1)*nsec + j])*invdiffRmed[i];
gradphi = (Potential[i*nsec + j] - Potential[(i-1)*nsec + j])*invdiffRmed[i];
vt2 = Vtheta[i*nsec + j] + Vtheta[i*nsec + (j+1)%nsec] + Vtheta[(i-1)*nsec + j] + Vtheta[(i-1)*nsec + (j+1)%nsec];
vt2 = vt2/4.0 +OmegaFrame*Rinf[i];
vt2 = vt2*vt2;
vradint = -gradp - gradphi;
vradint2 = vradint + vt2*invRinf[i];
VradInt[i*nsec + j] = Vrad[i*nsec+j] + dt*vradint2;
}
// i=0->nrad , j=0->nsec
if (i<nrad && j<nsec){
supp_torque = IMPOSEDDISKDRIFT*0.5*pow(Rmed[i], -2.5+SIGMASLOPE);
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
gradp = (Pressure[i*nsec + j] - Pressure[i*nsec + ((j-1)+nsec)%nsec])*2.0/(Dens[i*nsec +j] +Dens[i*nsec + ((j-1)+nsec)%nsec]) \
*invdxtheta;
//if (ZMPlus) gradp *= 1; //gradp *= SG_aniso_coeff; Definir mas adelante SG_aniso_coeff
gradphi = (Potential[i*nsec+ j] - Potential[i*nsec + ((j-1)+nsec)%nsec])*invdxtheta;
VthetaInt[i*nsec + j] = Vtheta[i*nsec+j] - dt*(gradp+gradphi);
VthetaInt[i*nsec + j] += dt*supp_torque;
}
}
__global__ void Substep3Kernel (double *Dens, double *Qplus, double *viscosity_array, double *TAURR, double *TAURP,double *TAUPP,
double *DivergenceVelocity, int nrad, int nsec, double *Rmed, int Cooling, double *EnergyNew, double dt, double *EnergyMed,
double *SigmaMed, double *CoolingTimeMed, double *EnergyInt, double ADIABATICINDEX, double *QplusMed)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double den, num;
if (i > 0 && i<nrad && j<nsec){
if (viscosity_array[i] != 0.0){
Qplus[i*nsec + j] = 0.5/viscosity_array[i]/Dens[i*nsec + j]*(TAURR[i*nsec + j]*TAURR[i*nsec + j] + \
TAURP[i*nsec + j]* TAURP[i*nsec + j] + TAUPP[i*nsec + j]*TAUPP[i*nsec + j]);
Qplus[i*nsec + j] += (2.0/9.0)*viscosity_array[i]*Dens[i*nsec + j]*DivergenceVelocity[i*nsec + j]* \
DivergenceVelocity[i*nsec + j];
}
else
Qplus[i*nsec + j] = 0.0;
}
}
__global__ void Substep3Kernel2 (double *Dens, double *Qplus, double *viscosity_array, double *TAURR, double *TAURP,double *TAUPP,
double *DivergenceVelocity, int nrad, int nsec, double *Rmed, int Cooling, double *EnergyNew, double dt, double *EnergyMed,
double *SigmaMed, double *CoolingTimeMed, double *EnergyInt, double ADIABATICINDEX, double *QplusMed)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double den, num;
if (i==0 && j<nsec){
/* We calculate the heating source term Qplus for i=0 */
if (viscosity_array[nrad-1] != 0.0) {
/* power-law extrapolation */
Qplus[i*nsec + j] = Qplus[(i+1)*nsec + j]*exp(log(Qplus[(i+1)*nsec + j]/Qplus[(i+2)*nsec + j]) * \
log(Rmed[i]/Rmed[i+1]) / log(Rmed[i+1]/Rmed[i+2]));
}
else
Qplus[i*nsec + j] = 0.0;
}
/* Now we can update energy with source terms from i=0 */
if (i<nrad && j<nsec){
if (!Cooling){
num = dt*Qplus[i*nsec + j] + EnergyInt[i*nsec + j];
den = 1.0+(ADIABATICINDEX-1.0)*dt*DivergenceVelocity[i*nsec + j];
EnergyNew[i*nsec + j] = num/den;
}
else{
num = EnergyMed[i]*dt*Dens[i*nsec + j]/SigmaMed[i] + CoolingTimeMed[i]*EnergyInt[i*nsec + j] + \
dt*CoolingTimeMed[i]*(Qplus[i*nsec + j]-QplusMed[i]*Dens[i*nsec + j]/SigmaMed[i]);
den = dt + CoolingTimeMed[i] + (ADIABATICINDEX-1.0)*dt*CoolingTimeMed[i]*DivergenceVelocity[i*nsec + j];
EnergyNew[i*nsec + j] = num/den;
}
}
}
__global__ void UpdateVelocitiesKernel (double *VthetaInt, double *VradInt, double *invRmed, double *Rmed, double *Rsup,
double *Rinf, double *invdiffRmed, double *invdiffRsup, double *Dens, double *invRinf, double *TAURR, double *TAURP,
double *TAUPP, double DeltaT, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dphi, invdphi;
/* Now we can update velocities
with the viscous source term
of Navier-Stokes equation */
/* vtheta first */
if (i > 0 && i<nrad-1 && j<nsec){
dphi = 2.0*M_PI/(double)nsec;
invdphi = 1.0/dphi;
VthetaInt[i*nsec +j] += DeltaT*invRmed[i]*((Rsup[i]*TAURP[(i+1)*nsec+ j] - Rinf[i]*TAURP[i*nsec +j])*invdiffRsup[i] + \
(TAUPP[i*nsec +j] - TAUPP[i*nsec + ((j-1)+nsec)%nsec])*invdphi + 0.5*(TAURP[i*nsec + j] + TAURP[(i+1)*nsec +j]))/ \
(0.5*(Dens[i*nsec +j]+Dens[i*nsec + ((j-1)+nsec)%nsec]));
}
/* now vrad */
if (i > 0 && i<nrad && j<nsec){
dphi = 2.0*M_PI/(double)nsec;
invdphi = 1.0/dphi;
VradInt[i*nsec +j] += DeltaT*invRinf[i]*((Rmed[i]*TAURR[i*nsec +j] - Rmed[i-1]*TAURR[(i-1)*nsec + j])*invdiffRmed[i] + \
(TAURP[i*nsec + (j+1)%nsec] - TAURP[i*nsec + j])*invdphi - 0.5*(TAUPP[i*nsec +j] + TAUPP[(i-1)*nsec + j]))/ \
(0.5*(Dens[i*nsec +j] + Dens[(i-1)*nsec + j]));
}
}
__global__ void InitComputeAccelKernel (double *CellAbscissa, double *CellOrdinate, double *Rmed, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
CellAbscissa[i*nsec+j] = Rmed[i] * cos((2.0*PI*(double)j)/(double)nsec);
CellOrdinate[i*nsec+j] = Rmed[i] * sin((2.0*PI*(double)j)/(double)nsec);
}
}
__global__ void ComputeSoundSpeedKernel (double *SoundSpeed, double *Dens, double *Rmed, double *Energy, int nsec, int nrad,
int Adiabatic, double ADIABATICINDEX, double FLARINGINDEX, double ASPECTRATIO, double TRANSITIONWIDTH,
double TRANSITIONRADIUS, double TRANSITIONRATIO, double PhysicalTime, double PhysicalTimeInitial, double LAMBDADOUBLING)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double AspectRatio;
if (i<nrad && j<nsec){
if (!Adiabatic){
AspectRatio = AspectRatioDevice(Rmed[i], ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRADIUS, TRANSITIONRATIO,
PhysicalTime, PhysicalTimeInitial, LAMBDADOUBLING);
SoundSpeed[i*nsec + j] = AspectRatio*sqrt(G*1.0/Rmed[i])*pow(Rmed[i], FLARINGINDEX);
}
else SoundSpeed[i*nsec + j] = sqrt(ADIABATICINDEX*(ADIABATICINDEX-1.0)*Energy[i*nsec + j]/Dens[i*nsec + j]);
}
}
__global__ void ComputePressureFieldKernel (double *SoundSpeed, double *Dens, double *Pressure, int Adiabatic, int nrad,
int nsec, double ADIABATICINDEX, double *Energy) /* LISTO */
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (!Adiabatic)
Pressure[i*nsec + j] = Dens[i*nsec + j]*SoundSpeed[i*nsec + j]*SoundSpeed[i*nsec + j];
/* Since SoundSpeed is not update from initialization, cs remains axisymmetric*/
else Pressure[i*nsec + j] = (ADIABATICINDEX-1.0)*Energy[i*nsec + j];
}
}
__global__ void ComputeTemperatureFieldKernel (double *Dens, double *Temperature, double *Pressure, double *Energy,
double ADIABATICINDEX, int Adiabatic, int nsec, int nrad) /* LISTO */
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (!Adiabatic) Temperature[i*nsec + j] = MU/R*Pressure[i*nsec + j]/Dens[i*nsec + j];
else Temperature[i*nsec + j] = MU/R*(ADIABATICINDEX-1.0)*Energy[i*nsec + j]/Dens[i*nsec + j];
}
}
/* LISTO */
__global__ void InitLabelKernel (double *Label, double xp, double yp, double rhill, double *Rmed, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
double distance, angle, x, y;
angle = (double)j / (double)nsec*2.0*PI;
x = Rmed[i] * cos(angle);
y = Rmed[i] * sin(angle);
distance = sqrt((x - xp) * (x - xp) + (y - yp)*(y -yp));
if (distance < rhill) Label[i*nsec + j] = 1.0;
else Label[i*nsec + j] = 0.0;
}
}
__global__ void CircumPlanetaryMassKernel (double *Dens, double *Surf, double *CellAbscissa, double *CellOrdinate,
double xpl, double ypl, int nrad, int nsec, double HillRadius, double *mdcp0) /* LISTA */
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dist;
if (i<nrad && j<nsec){
dist = sqrt((CellAbscissa[i*nsec + j]-xpl)*(CellAbscissa[i*nsec + j]-xpl) + (CellOrdinate[i*nsec + j]-ypl) * \
(CellOrdinate[i*nsec + j]-ypl));
if (dist < HillRadius) mdcp0[i*nsec + j] = Surf[i]* Dens[i*nsec + j];
else mdcp0[i*nsec + j] = 0.0;
}
}
template <bool nIsPow2>
__global__ void DeviceReduceKernel (double *g_idata, double *g_odata, unsigned int n)
{
extern __shared__ double sdata[];
// perform first level of reduction,
// reading from global memory, writing to shared memory
unsigned int tid = threadIdx.x;
unsigned int blockSize = blockDim.x;
unsigned int i = blockIdx.x*blockSize*2 + threadIdx.x;
unsigned int gridSize = blockSize*2*gridDim.x;
double mySum = 0.0;
// we reduce multiple elements per thread. The number is determined by the
// number of active thread blocks (via gridDim). More blocks will result
// in a larger gridSize and therefore fewer elements per thread
while (i < n){
mySum += g_idata[i];
// ensure we don't read out of bounds -- this is optimized away for powerOf2 sized arrays
if (nIsPow2 || i + blockSize < n)
mySum += g_idata[i+blockSize];
i += gridSize;
}
// each thread puts its local sum into shared memory
sdata[tid] = mySum;
__syncthreads();
// do reduction in shared mem
if ((blockSize >= 512) && (tid < 256)){
sdata[tid] = mySum = mySum + sdata[tid + 256];
}
__syncthreads();
if ((blockSize >= 256) &&(tid < 128)){
sdata[tid] = mySum = mySum + sdata[tid + 128];
}
__syncthreads();
if ((blockSize >= 128) && (tid < 64)){
sdata[tid] = mySum = mySum + sdata[tid + 64];
}
__syncthreads();
#if (__CUDA_ARCH__ >= 300 )
if (tid < 32){
// Fetch final intermediate sum from 2nd warp
if (blockSize >= 64) mySum += sdata[tid + 32];
// Reduce final warp using shuffle
for (int offset = warpSize/2; offset > 0; offset /= 2){
mySum += __shfl_down(mySum, offset);
}
}
#else
// fully unroll reduction within a single warp
if ((blockSize >= 64) && (tid < 32)){
sdata[tid] = mySum = mySum + sdata[tid + 32];
}
__syncthreads();
if ((blockSize >= 32) && (tid < 16)){
sdata[tid] = mySum = mySum + sdata[tid + 16];
}
__syncthreads();
if ((blockSize >= 16) && (tid < 8)){
sdata[tid] = mySum = mySum + sdata[tid + 8];
}
__syncthreads();
if ((blockSize >= 8) && (tid < 4)){
sdata[tid] = mySum = mySum + sdata[tid + 4];
}
__syncthreads();
if ((blockSize >= 4) && (tid < 2)){
sdata[tid] = mySum = mySum + sdata[tid + 2];
}
__syncthreads();
if ((blockSize >= 2) && ( tid < 1)){
sdata[tid] = mySum = mySum + sdata[tid + 1];
}
__syncthreads();
#endif
// write result for this block to global mem
if (tid == 0) g_odata[blockIdx.x] = mySum;
}
__host__ long NearestPowerOf2 (long n)
{
if(!n) return n; //(0 ==2^0)
int x=1;
while (x < n){
x<<=1;
}
return x;
}
__host__ bool IsPow2 (unsigned int x)
{
return ((x&(x-1)==0));
}
__host__ double DeviceReduce (double *in, int N)
{
double *device_out;
gpuErrchk(cudaMalloc(&device_out, sizeof(double)*1024));
gpuErrchk(cudaMemset(device_out, 0, sizeof(double)*1024));
int threads = 32;
int blocks = min((int(NearestPowerOf2(N)) + threads - 1) / threads, 1024);
int smemSize = (threads <= 32) ? 2 * threads * sizeof(double) : threads * sizeof(double);
bool isPower2 = IsPow2(N);
if(isPower2){
DeviceReduceKernel<true><<<blocks, threads, smemSize>>>(in, device_out, N);
gpuErrchk(cudaDeviceSynchronize());
}
else{
DeviceReduceKernel<false><<<blocks, threads, smemSize>>>(in, device_out, N);
gpuErrchk(cudaDeviceSynchronize());
}
double *h_odata = (double *) malloc(blocks*sizeof(double));
double sum = 0.0;
gpuErrchk(cudaMemcpy(h_odata, device_out, blocks * sizeof(double),cudaMemcpyDeviceToHost));
for (int i=0; i<blocks; i++){
sum += h_odata[i];
}
cudaFree(device_out);
free(h_odata);
return sum;
}
/* LISTA */
__global__ void MultiplyPolarGridbyConstantKernel (double *Dens, int nrad, int nsec, double ScalingFactor)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<=nrad && j<nsec)
Dens[i*nsec + j] *= ScalingFactor;
}
__global__ void Substep2Kernel (double *Dens, double *VradInt, double *VthetaInt, double *TemperInt, int nrad,
int nsec, double *invdiffRmed, double *invdiffRsup, double *DensInt, int Adiabatic, double *Rmed,
double dt, double *VradNew, double *VthetaNew, double *Energy, double *EnergyInt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dv;
if (i<nrad && j<nsec){
dv = VradInt[(i+1)*nsec + j] - VradInt[i*nsec + j];
if (dv < 0.0)
DensInt[i*nsec + j] = CVNR*CVNR*Dens[i*nsec+j]*dv*dv;
else
DensInt[i*nsec + j] = 0.0;
dv = VthetaInt[i*nsec + (j+1)%nsec] - VthetaInt[i*nsec + j];
if (dv < 0.0)
TemperInt[i*nsec + j] = CVNR*CVNR*Dens[i*nsec+j]*dv*dv;
else
TemperInt[i*nsec + j] = 0.0;
}
}
__global__ void kernel(double *Dens, double *VradInt, double *VthetaInt, double *TemperInt, int nrad,
int nsec, double *invdiffRmed, double *invdiffRsup, double *DensInt, int Adiabatic, double *Rmed,
double dt, double *VradNew, double *VthetaNew, double *Energy, double *EnergyInt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dens, densint, dxtheta, invdxtheta, dens2, tempint;
if (i>0 && i<nrad && j<nsec){
dens = Dens[i*nsec + j] + Dens[(i-1)*nsec + j];
densint = DensInt[i*nsec+j] - DensInt[(i-1)*nsec + j];
VradNew[i*nsec+j] = VradInt[i*nsec+j] - dt*2.0/dens*densint*invdiffRmed[i];
}
if (i<nrad && j<nsec){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
dens2 = Dens[i*nsec + j] + Dens[i*nsec + ((j-1)+nsec)%nsec];
tempint = (TemperInt[i*nsec+j] - TemperInt[i*nsec + ((j-1)+nsec)%nsec]);
VthetaNew[i*nsec + j] = VthetaInt[i*nsec + j] - dt*2.0/dens2*tempint*invdxtheta;
}
/* If gas disk is adiabatic, we add artificial viscosity as a source */
/* term for advection of thermal energy polargrid */
if (Adiabatic){
if (i<nrad && j<nsec){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
EnergyInt[i*nsec + j] = Energy[i*nsec + j] - dt*DensInt[i*nsec + j]* \
(VradInt[(i+1)*nsec + j] - VradInt[i*nsec + j])*invdiffRsup[i] - \
dt*TemperInt[i*nsec + j]*(VthetaInt[i*nsec + (j+1)%nsec] - VthetaInt[i*nsec + j])* invdxtheta;
}
}
}
__global__ void OpenBoundaryKernel (double *Vrad, double *Dens, double *Energy, int nsec, double SigmaMed)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 1;
if(j < nsec){
Dens[(i-1)*nsec + j] = Dens[i*nsec + j]; // copy first ring into ghost ring
Energy[(i-1)*nsec + j] = Energy[i*nsec + j];
if (Vrad[(i+1)*nsec + j] > 0.0 || (Dens[i*nsec + j] < SigmaMed))
Vrad[i*nsec + j] = 0.0; // we just allow outflow [inwards]
else
Vrad[i*nsec +j] = Vrad[(i+1)*nsec + j];
}
}
__global__ void ReduceCsKernel (double *SoundSpeed, double *cs0, double *cs1, double *csnrm1, double *csnrm2, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i=0;
if(j<nsec){
cs0[j] = SoundSpeed[i*nsec +j];
cs1[j] = SoundSpeed[(i+1)*nsec +j];
}
i = nrad-1;
if(j<nsec){
csnrm2[j] = SoundSpeed[(i-1)*nsec +j];
csnrm1[j] = SoundSpeed[i*nsec +j];
}
}
__global__ void ReduceMeanKernel (double *Dens, double *Energy, int nsec, double *mean_dens, double *mean_energy,
double *mean_dens2, double *mean_energy2, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 0;
if(j<nsec){
mean_dens[j] = Dens[i*nsec+ j];
mean_energy[j] = Energy[i*nsec +j];
}
i = nrad-1;
if(j<nsec){
mean_dens2[j] = Dens[i*nsec + j];
mean_energy2[j] = Energy[i*nsec + j];
}
}
__global__ void NonReflectingBoundaryKernel (double *Dens, double *Energy, int i_angle, int nsec, double *Vrad, double *SoundSpeed,
double SigmaMed, int nrad, double SigmaMed2, int i_angle2)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 1;
double Vrad_med;
if (j<nsec){
if(j+i_angle >= nsec){
Dens[j+i_angle - nsec] = Dens[i*nsec + j];
Energy[j+i_angle - nsec] = Energy[i*nsec + j];
}
else if(j+i_angle < 0){
Dens[j+i_angle + nsec] = Dens[i*nsec + j];
Energy[j+i_angle + nsec] = Energy[i*nsec + j];
}
else{
Dens[j+i_angle] = Dens[i*nsec + j];
Energy[j+i_angle] = Energy[i*nsec + j];
}
}
i = nrad-1;
if (j<nsec){
if (j-i_angle2 >= nsec){
Dens[i*nsec + j] = Dens[j-i_angle2 + (i-2)*nsec ];
Energy[i*nsec + j] = Energy[j-i_angle2 + (i-2)*nsec ];
}
else if (j-i_angle2 < 0){
Dens[i*nsec + j] = Dens[j-i_angle2 + i*nsec];
Energy[i*nsec + j] = Energy[j-i_angle2 + i*nsec];
}
else{
Dens[i*nsec + j] = Dens[j-i_angle2 + (i-1)*nsec];
Energy[i*nsec + j] = Energy[j-i_angle2 + (i-1)*nsec];
}
}
}
__global__ void NonReflectingBoundaryKernel2 (double *Dens, double *Energy, int i_angle, int nsec, double *Vrad, double *SoundSpeed,
double SigmaMed, int nrad, double SigmaMed2, int i_angle2)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 1;
double Vrad_med;
Vrad_med = -SoundSpeed[i*nsec + j]*(Dens[i*nsec + j]-SigmaMed)/SigmaMed;
Vrad[i*nsec + j] = 2.0*Vrad_med-Vrad[(i+1)*nsec + j];
i = nrad-1;
Vrad_med = SoundSpeed[i*nsec + j]*(Dens[(i-1)*nsec + j]-SigmaMed2)/SigmaMed2;
Vrad[i*nsec + j] = 2.*Vrad_med - Vrad[(i-1)*nsec + j];
}
__global__ void MinusMeanKernel (double *Dens, double *Energy, double SigmaMed, double mean_dens_r, double mean_dens_r2,
double mean_energy_r,double mean_energy_r2, double EnergyMed, int nsec, int nrad, double SigmaMed2, double EnergyMed2)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 0;
if (j< nsec){
Dens[i*nsec + j] += SigmaMed - mean_dens_r;
Energy[i*nsec + j] += EnergyMed - mean_energy_r;
}
i = nrad-1;
if (j < nsec){
Dens[i*nsec + j] += SigmaMed2 - mean_dens_r2;
Energy[i*nsec + j] += EnergyMed2 - mean_energy_r2;
}
}
__global__ void Make1DprofileKernel (double *gridfield, double *axifield, int nsec, int nrad)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
int j;
if (i < nrad){
double sum = 0.0;
for (j = 0; j < nsec; j++)
sum += gridfield[i*nsec + j];
axifield[i] = sum/(double)nsec;
}
}
__host__ void Make1Dprofile (int option)
{
/* GLOBAL AxiSGAccr option */
if (option == 1){
gpuErrchk(cudaMemcpy(gridfield_d, SoundSpeed_d, size_grid*sizeof(double), cudaMemcpyDeviceToDevice));
//gpuErrchk(cudaMemcpy(GLOBAL_AxiSGAccr_d, axifield_d, NRAD*sizeof(double), cudaMemcpyDeviceToHost));
}
/* GLOBAL_bufarray option */
if (option == 2){
//gpuErrchk(cudaMemcpy(gridfield_d, SG_Accr_d, size_grid*sizeof(double), cudaMemcpyDeviceToDevice));
//gpuErrchk(cudaMemcpy(GLOBAL_AxiSGAccr_d, axifield_d, NRAD*sizeof(double), cudaMemcpyDeviceToHost));
}
Make1DprofileKernel<<<dimGrid4, dimBlock>>>(gridfield_d, axifield_d, NSEC, NRAD);
gpuErrchk(cudaDeviceSynchronize());
gpuErrchk(cudaMemcpy(GLOBAL_bufarray, axifield_d, NRAD*sizeof(double), cudaMemcpyDeviceToHost));
}
/* LISTO */
__global__ void InitGasVelocitiesKernel (int nsec, int nrad, int SelfGravity, double *Rmed,
double ASPECTRATIO, double FLARINGINDEX, double SIGMASLOPE, double *Vrad, double *Vtheta,
double IMPOSEDDISKDRIFT, double SIGMA0, double *SigmaInf, double OmegaFrame, double *Rinf, int ViscosityAlpha, double *viscosity_array)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double viscosity;
if (i <= nrad && j < nsec){
double omega, r, ri;
if (i == nrad){
r = Rmed[nrad - 1];
ri = Rinf[nrad - 1];
}
else{
r = Rmed[i];
ri = Rinf[i];
}
if (!SelfGravity){
omega = sqrt(G*1.0/r/r/r);
Vtheta[i*nsec + j] = omega*r*sqrt(1.0-pow(ASPECTRATIO,2.0)*pow(r,2.0*FLARINGINDEX)* \
(1.+SIGMASLOPE-2.0*FLARINGINDEX));
}
Vtheta[i*nsec + j ] -= OmegaFrame*r;
//if (CentrifugalBalance) Vtheta[i*nsec + j] = vt_cent[i];
if (i == nrad) Vrad[i*nsec + j] = 0.0;
else {
Vrad[i*nsec + j] = IMPOSEDDISKDRIFT*SIGMA0/SigmaInf[i]/ri;
if (ViscosityAlpha) Vrad[i*nsec+j] -= 3.0*viscosity_array[i]/r*(-SIGMASLOPE+2.0*FLARINGINDEX+1.0);
else Vrad[i*nsec+j] -= 3.0*viscosity_array[i]/r*(-SIGMASLOPE+.5);
}
if (i == 0 && j < nsec) Vrad[j] = Vrad[nrad*nsec + j] = 0.0;
}
}
__global__ void ComputeForceKernel (double *CellAbscissa, double *CellOrdinate, double *Surf, double *Dens, double x,
double y, double rsmoothing, int nsec, int nrad, double a, double *Rmed, int dimfxy, double rh, double *fxi,
double *fxo, double *fyi, double *fyo, int k)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double cellmass, dx, dy, d2, InvDist3, dist2, distance, resultxi, resultyi;
double resultxo, resultyo, hillcutfactor, hill_cut;
if (i<nrad && j<nsec){
cellmass = Surf[i]* Dens[i*nsec + j];
dx = CellAbscissa[i*nsec + j] - x;
dy = CellOrdinate[i*nsec + j] - y;
d2 = dx*dx + dy*dy;
dist2 = d2 + rsmoothing*rsmoothing;
distance = sqrt(dist2);
InvDist3 = 1.0/dist2/distance;
hillcutfactor = (double) k / (double)(dimfxy-1);
if (k != 0){
rh *= hillcutfactor;
hill_cut = 1.-exp(-d2/(rh*rh));
}
else
hill_cut = 1.;
if (Rmed[i] < a){
fxi[i*nsec + j] = G * cellmass * dx * InvDist3 * hill_cut;
fyi[i*nsec + j] = G * cellmass * dy * InvDist3 * hill_cut;
}
else{
fxo[i*nsec + j] = G * cellmass * dx * InvDist3 * hill_cut;
fyo[i*nsec + j] = G * cellmass * dy * InvDist3 * hill_cut;
}
}
}
__global__ void ViscousTermsKernel (double *Vradial, double *Vazimutal , double *DRR, double *DPP, double *DivergenceVelocity,
double *DRP, double *invdiffRsup, double *invRmed, double *Rsup, double *Rinf, double *invdiffRmed, int nrad,
int nsec, double *TAURR, double *TAUPP, double *dens, double *TAURP, double *invRinf, double *Rmed, double *viscosity_array_d)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dphi, invdphi, onethird, viscosity;
if (i<nrad && j<nsec){ /* Drr, Dpp and divV computation */
dphi = 2.0*M_PI/(double)nsec;
invdphi = 1.0/dphi;
onethird = 1.0/3.0;
DRR[i*nsec + j] = (Vradial[(i+1)*nsec + j] - Vradial[i*nsec + j])*invdiffRsup[i];
DPP[i*nsec + j] = (Vazimutal[i*nsec + (j+1)%nsec] - Vazimutal[i*nsec + j])*invdphi*invRmed[i]+0.5* \
(Vradial[(i+1)*nsec + j]+Vradial[i*nsec + j])*invRmed[i];
DivergenceVelocity[i*nsec + j] = (Vradial[(i+1)*nsec + j]*Rsup[i] - Vradial[i*nsec + j]*Rinf[i])*invdiffRsup[i] * \
invRmed[i];
DivergenceVelocity[i*nsec + j] += (Vazimutal[i*nsec + (j+1)%nsec] - Vazimutal[i*nsec + j])*invdphi*invRmed[i];
if (i > 0) DRP[i*nsec + j] = 0.5*(Rinf[i]*(Vazimutal[i*nsec + j]*invRmed[i] - Vazimutal[(i-1)*nsec + j]*invRmed[i-1])* \
invdiffRmed[i] + (Vradial[i*nsec + j] - Vradial[i*nsec + ((j-1)+nsec)%nsec])*invdphi*invRinf[i]);
}
if (i<nrad && j<nsec){ /* TAUrr and TAUpp computation */
TAURR[i*nsec + j] = 2.0*dens[i*nsec + j]*viscosity_array_d[i]*(DRR[i*nsec + j] - onethird*DivergenceVelocity[i*nsec + j]);
TAUPP[i*nsec + j] = 2.0*dens[i*nsec + j]*viscosity_array_d[i]*(DPP[i*nsec + j] - onethird*DivergenceVelocity[i*nsec + j]);
if (i > 0){
TAURP[i*nsec + j] = 2.0*0.25*(dens[i*nsec + j] + dens[(i-1)*nsec + j] + \
dens[i*nsec + ((j-1)+nsec)%nsec] + dens[(i-1)*nsec + ((j-1)+nsec)%nsec])* \
viscosity_array_d[i]*DRP[i*nsec + j];
}
}
}
__global__ void LRMomentaKernel (double *RadMomP, double *RadMomM, double *ThetaMomP, double *ThetaMomM, double *Dens,
double *Vrad, double *Vtheta, int nrad, int nsec, double *Rmed, double OmegaFrame)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
RadMomP[i*nsec + j] = Dens[i*nsec + j] * Vrad[(i+1)*nsec + j]; // (i+1)*nsec
RadMomM[i*nsec + j] = Dens[i*nsec + j] * Vrad[i*nsec + j];
/* it is the angular momentum -> ThetaMomP */
ThetaMomP[i*nsec + j] = Dens[i*nsec + j] * (Vtheta[i*nsec + (j+1)%nsec]+Rmed[i]*OmegaFrame)*Rmed[i];
ThetaMomM[i*nsec + j] = Dens[i*nsec + j] * (Vtheta[i*nsec + j]+Rmed[i]*OmegaFrame)*Rmed[i];
}
}
__global__ void ExtQtyKernel (double *ExtLabel, double *Dens, double *Label, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec)
ExtLabel[i*nsec + j] = Dens[i*nsec + j]*Label[i*nsec + j];
}
__global__ void StarRadKernel (double *Qbase2, double *Vrad, double *QStar, double dt, int nrad, int nsec,
double *invdiffRmed, double *Rmed, double *dq)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dqm, dqp;
if (i<nrad && j<nsec){
if ((i == 0 || i == nrad-1)) dq[i + j*nrad] = 0.0;
else {
dqm = (Qbase2[i*nsec + j] - Qbase2[(i-1)*nsec + j])*invdiffRmed[i];
dqp = (Qbase2[(i+1)*nsec + j] - Qbase2[i*nsec + j])*invdiffRmed[i+1];
if (dqp * dqm > 0.0)
dq[i+j*nrad] = 2.0*dqp*dqm/(dqp+dqm);
else
dq[i+j*nrad] = 0.0;
}
}
}
__global__ void StarRadKernel2 (double *Qbase2, double *Vrad, double *QStar, double dt, int nrad, int nsec,
double *invdiffRmed, double *Rmed, double *dq)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (Vrad[i*nsec + j] > 0.0 && i > 0)
QStar[i*nsec + j] = Qbase2[(i-1)*nsec + j] + (Rmed[i]-Rmed[i-1]-Vrad[i*nsec + j]*dt)*0.5*dq[i-1+j*nrad];
else
QStar[i*nsec + j] = Qbase2[i*nsec + j]-(Rmed[i+1]-Rmed[i]+Vrad[i*nsec + j]*dt)*0.5*dq[i+j*nrad];
}
if (i == 0 && j<nsec)
QStar[j] = QStar[j+nsec*nrad] = 0.0;
}
__global__ void ComputeFFTKernel (double *Radii, cufftDoubleComplex *SGP_Kr, cufftDoubleComplex *SGP_Kt, double SGP_eps, int nrad, int nsec,
cufftDoubleComplex *SGP_Sr, cufftDoubleComplex *SGP_St, double *Dens, double *Rmed, double *Kr_aux, double *Kt_aux)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double u, cosj, sinj, coshu, expu, den_SGP_K, theta, base;
double a, var, radii;
if (i<2*nrad && j<nsec){
SGP_Kr[i*nsec + j].x = Kr_aux[i*nsec + j];
SGP_Kr[i*nsec + j].y = 0.;
SGP_Kt[i*nsec + j].x = Kt_aux[i*nsec + j];
SGP_Kt[i*nsec + j].y = 0.;
SGP_Sr[i*nsec + j].y = 0.;
SGP_St[i*nsec + j].y = 0.;
if (i<nrad){
var = Dens[i*nsec + j] * sqrt(Rmed[i]/Rmed[0]);
SGP_Sr[i*nsec + j].x = var;
SGP_St[i*nsec + j].x = var*Rmed[i]/Rmed[0];
}
else{
SGP_Sr[i*nsec + j].x = 0.;
SGP_St[i*nsec + j].x = 0.;
}
}
}
__global__ void ComputeConvolutionKernel (cufftDoubleComplex *Gr, cufftDoubleComplex *Gphi, cufftDoubleComplex *SGP_Kr, cufftDoubleComplex *SGP_Kt,
cufftDoubleComplex *SGP_Sr, cufftDoubleComplex *SGP_St, int nsec, int nrad)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<2*nrad && j<nsec){
Gphi[i*nsec + j].x = -G*(SGP_Kt[i*nsec + j].x * SGP_St[i*nsec + j].x - \
SGP_Kt[i*nsec + j].y * SGP_St[i*nsec + j].y);
Gphi[i*nsec + j].y = -G*(SGP_Kt[i*nsec + j].x * SGP_St[i*nsec + j].y + \
SGP_Kt[i*nsec + j].y * SGP_St[i*nsec + j].x);
Gr[i*nsec + j].x = -G*(SGP_Kr[i*nsec + j].x * SGP_Sr[i*nsec + j].x - \
SGP_Kr[i*nsec + j].y * SGP_Sr[i*nsec + j].y);
Gr[i*nsec + j].y = -G*(SGP_Kr[i*nsec + j].x * SGP_Sr[i*nsec + j].y + \
SGP_Kr[i*nsec + j].y *SGP_Sr[i*nsec + j].x);
}
}
__global__ void ComputeSgAccKernel (double *SG_Accr, double *SG_Acct, double *Dens , double SGP_rstep, double SGP_tstep,
double SGP_eps, int nrad, int nsec, double *Rmed, cufftDoubleComplex *Gr, cufftDoubleComplex *Gphi)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double normaccr, normacct, divRmed;
if (i<nrad && j<nsec){
divRmed = Rmed[i]/Rmed[0];
normaccr = SGP_rstep * SGP_tstep / ((double)(2*nrad) * (double)nsec);
normacct = normaccr;
normaccr /= sqrt(divRmed);
normacct /= (divRmed * sqrt(divRmed));
SG_Acct[i*nsec + j] = Gphi[i*nsec + j].x * normacct;
SG_Accr[i*nsec + j] = Gr[i*nsec + j].x * normaccr;
SG_Accr[i*nsec + j] += G*Dens[i*nsec + j]*SGP_rstep*SGP_tstep / SGP_eps;
}
}
__global__ void Update_sgvelocityKernel (double *Vradial, double *Vazimutal, double *SG_Accr, double *SG_Acct, double *Rinf,
double *Rmed, double *invdiffRmed, double dt, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
int jm1, lm1;
/* Here we update velocity fields to take into acount self-gravity */
if (i<nrad && j<nsec){
/* We compute VRAD - half-centered in azimuth - from centered-in-cell radial sg acceleration. */
if (i > 0) Vradial[i*nsec + j] += dt*((Rinf[i] - Rmed[i-1]) * SG_Accr[i*nsec + j] + \
(Rmed[i] - Rinf[i]) * SG_Accr[(i-1)*nsec + j]) *invdiffRmed[i]; // caso !SGZeroMode
/* We compute VTHETA - half-centered in radius - from centered-in-cell azimutal sg acceleration. */
Vazimutal[i*nsec + j] += 0.5 * dt * (SG_Acct[i*nsec + j] + SG_Acct[i*nsec + (j-1)%nsec]);
}
}
__global__ void Azimutalvelocity_withSGKernel (double *Vtheta, double *Rmed, double FLARINGINDEX, double SIGMASLOPE,
double ASPECTRATIO, double *axifield_d, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double omegakep, omega, invr;
if (i<nrad && j<nsec){
invr = 1./Rmed[i];
omegakep = sqrt(G*1.0*invr*invr*invr);
omega = sqrt(omegakep*omegakep* (1.0 - (1.+SIGMASLOPE-2.0*FLARINGINDEX)*pow(ASPECTRATIO,2.0)* \
pow(Rmed[i],2.0*FLARINGINDEX)) - invr*axifield_d[i]);
Vtheta[i*nsec + j] = Rmed[i]*omega;
}
}
__global__ void CrashKernel (double *array, int nrad, int nsec, int Crash)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (array[i*nsec + j] < 0.0)
array[i*nsec + j] = 1.0;
else
array[i*nsec + j] = 0.0;
}
}
__global__ void EvanescentBoundaryKernel(double *Rmed, double *Vrad, double *Vtheta, double *Energy, double *Dens,
double *viscosity_array, double DRMIN, double DRMAX, int nrad, int nsec, double Tin,
double Tout, double step, double SIGMASLOPE, double FLARINGINDEX, double *GLOBAL_bufarray, double OmegaFrame,
double *SigmaMed, double *EnergyMed, int Adiabatic, int SelfGravity, double ASPECTRATIO, double TRANSITIONWIDTH,
double TRANSITIONRADIUS, double TRANSITIONRATIO, double PhysicalTime, double PhysicalTimeInitial, double LAMBDADOUBLING)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double damping, lambda, vtheta0, vrad0, energy0, dens0, AspectRatio;
if (i<nrad && j<nsec){
if ((Rmed[i] < DRMIN) || (Rmed[i] > DRMAX)){
/* Damping operates only inside the wave killing zones */
if(Rmed[i] < DRMIN){
damping = (Rmed[i]-DRMIN)/(Rmed[0]-DRMIN);
lambda = damping*damping*10.0*step/Tin;
}
if (Rmed[i] > DRMAX){
damping = (Rmed[i]-DRMAX)/(Rmed[nrad-1]-DRMAX);
lambda = damping*damping*10.0*step/Tout;
}
if(!SelfGravity){
AspectRatio = AspectRatioDevice(Rmed[i], ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRADIUS, TRANSITIONRATIO,
PhysicalTime, PhysicalTimeInitial, LAMBDADOUBLING);
vtheta0 = sqrt(G*1.0/Rmed[i] * (1.0 - (1.0+SIGMASLOPE-2.0*FLARINGINDEX)*pow(AspectRatio,2.0) * \
pow(Rmed[i],2.0*FLARINGINDEX)));
}
if (SelfGravity){
AspectRatio = AspectRatioDevice(Rmed[i], ASPECTRATIO, TRANSITIONWIDTH, TRANSITIONRADIUS, TRANSITIONRATIO,
PhysicalTime, PhysicalTimeInitial, LAMBDADOUBLING);
vtheta0 = sqrt(G*1.0/Rmed[i] * (1.0 - (1.0+SIGMASLOPE-2.0*FLARINGINDEX)*pow(AspectRatio,2.0) * \
pow(Rmed[i],2.0*FLARINGINDEX)) - Rmed[i]*GLOBAL_bufarray[i]);
}
/* this could be refined if CentrifugalBalance is used... */
vtheta0 -= Rmed[i]*OmegaFrame;
vrad0 = -3.0*viscosity_array[i]/Rmed[i]*(-SIGMASLOPE+.5);
dens0 = SigmaMed[i];
energy0 = EnergyMed[i];
Vrad[i*nsec + j] = (Vrad[i*nsec + j] + lambda*vrad0)/(1.0+lambda);
Vtheta[i*nsec + j] = (Vtheta[i*nsec + j] + lambda*vtheta0)/(1.0+lambda);
Dens[i*nsec + j] = (Dens[i*nsec + j] + lambda*dens0)/(1.0+lambda);
if (Adiabatic)
Energy[i*nsec + j] = (Energy[i*nsec + j] + lambda*energy0)/(1.0+lambda);
}
}
}
__global__ void DivisePolarGridKernel (double *Qbase, double *DensInt, double *Work, int nrad, int nsec)
{
int i = threadIdx.x + blockDim.x*blockIdx.x; //512
int j = threadIdx.y + blockDim.y*blockIdx.y; //256
if (i<=nsec && j<nrad)
Work[i*nrad + j] = Qbase[i*nrad + j]/(DensInt[i*nrad + j] + 1e-20);
}
__global__ void VanLeerRadialKernel (double *Rinf, double *Rsup, double *QRStar, double *DensStar, double *Vrad,
double *LostByDisk, int nsec, int nrad, double dt, int OpenInner, double *Qbase, double *invSurf)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double varq, dtheta;
if (i<nrad && j<nsec){
dtheta = 2.0*PI/(double)nsec;
varq = dt*dtheta*Rinf[i]*QRStar[i*nsec + j]* DensStar[i*nsec + j]*Vrad[i*nsec + j];
varq -= dt*dtheta*Rsup[i]*QRStar[(i+1)*nsec + j]* DensStar[(i+1)*nsec + j]*Vrad[(i+1)*nsec + j];
Qbase[i*nsec + j] += varq*invSurf[i];
if (i==0 && OpenInner)
LostByDisk[j] = varq;
}
}
__global__ void VanLeerThetaKernel (double *Rsup, double *Rinf, double *Surf, double dt, int nrad, int nsec,
int UniformTransport, int *NoSplitAdvection, double *QRStar, double *DensStar, double *Vazimutal_d, double *Qbase)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxrad, invsurf, varq;
if (i<nrad && j<nsec){
if ((UniformTransport == NO) || (NoSplitAdvection[i] == NO)){
dxrad = (Rsup[i]-Rinf[i])*dt;
invsurf = 1.0/Surf[i];
varq = dxrad*QRStar[i*nsec + j]*DensStar[i*nsec + j]*Vazimutal_d[i*nsec + j];
varq -= dxrad*QRStar[i*nsec + (j+1)%nsec]*DensStar[i*nsec + (j+1)%nsec]*Vazimutal_d[i*nsec + (j+1)%nsec];
Qbase[i*nsec + j] += varq*invsurf;
}
}
}
__global__ void ComputeAverageThetaVelocitiesKernel(double *Vtheta, double *VMed, int nsec, int nrad)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
double moy = 0.0;
if (i<nrad){
for (int j = 0; j < nsec; j++)
moy += Vtheta[i*nsec + j];
VMed[i] = moy/(double)nsec;
}
}
__global__ void ComputeResidualsKernel (double *VthetaRes, double *VMed, int nsec, int nrad, double *Vtheta)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec)
VthetaRes[i*nsec + j] = Vtheta[i*nsec + j]-VMed[i];
}
__global__ void ComputeConstantResidualKernel (double *VMed, double *invRmed, int *Nshift, int *NoSplitAdvection,
int nsec, int nrad, double dt, double *Vtheta, double *VthetaRes, double *Rmed, int FastTransport)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double maxfrac, Ntilde, Nround, invdt, dpinvns;
long nitemp;
if (i<nrad && j<nsec){
if (FastTransport)
maxfrac = 1.0;
else
maxfrac = 0.0;
invdt = 1.0/dt;
dpinvns = 2.0*PI/(double)nsec;
Ntilde = VMed[i]*invRmed[i]*dt*(double)nsec/2.0/PI;
Nround = floor(Ntilde+0.5);
nitemp = (long)Nround;
Nshift[i] = (long)nitemp;
Vtheta[i*nsec + j] = (Ntilde-Nround)*Rmed[i]*invdt*dpinvns;
if (maxfrac < 0.5){
NoSplitAdvection[i] = YES;
VthetaRes[i*nsec + j] += Vtheta[i*nsec + j];
Vtheta[i*nsec + j] = 0.0;
}
else{
NoSplitAdvection[i] = NO;
}
}
}
__global__ void StarThetaKernel (double *Qbase, double *Rmed, int nrad, int nsec, double *dq, double dt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxtheta, invdxtheta, dqp, dqm;
if (i<nrad && j<nsec){
if (i<nrad){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
}
dqm = (Qbase[i*nsec + j] - Qbase[i*nsec + ((j-1)+nsec)%nsec]);
dqp = (Qbase[i*nsec + (j+1)%nsec] - Qbase[i*nsec + j]);
if (dqp * dqm > 0.0)
dq[i*nsec + j] = dqp*dqm/(dqp+dqm)*invdxtheta;
else
dq[i*nsec + j] = 0.0;
}
}
__global__ void StarThetaKernel2 (double *Qbase, double *Rmed, double *Vazimutal, double *QStar, int nrad, int nsec,
double *dq, double dt)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxtheta, ksi, invdxtheta, dqp, dqm;
if (i<nrad && j<nsec){
if (i<nrad){
dxtheta = 2.0*PI/(double)nsec*Rmed[i];
invdxtheta = 1.0/dxtheta;
}
ksi = Vazimutal[i*nsec + j]*dt;
if (ksi > 0.0)
QStar[i*nsec + j] = Qbase[i*nsec + ((j-1)+nsec)%nsec]+(dxtheta-ksi)*dq[i*nsec + ((j-1)+nsec)%nsec];
else
QStar[i*nsec + j] = Qbase[i*nsec + j]-(dxtheta+ksi)*dq[i*nsec + j];
}
}
__global__ void AdvectSHIFTKernel (double *array, double *TempShift, int nsec, int nrad, int *Nshift)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
int ji, modji;
if (i<nrad && j<nsec){
ji = j-Nshift[i];
//if (ji < 0) ji = ji%nsec + nsec;
//if (ji >= nsec) ji = ji%nsec;
while (ji < 0 ) ji += nsec;
while (ji >= nsec) ji -= nsec;
TempShift[i*nsec + j] = array[i*nsec + ji];
}
}
__global__ void ComputeVelocitiesKernel (double *Vrad, double *Vtheta, double *Dens, double *Rmed, double *ThetaMomP,
double *ThetaMomM, double *RadMomP, double *RadMomM, int nrad, int nsec, double OmegaFrame)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
if (i == 0)
Vrad[i*nsec + j] = 0.0;
else {
Vrad[i*nsec + j] = (RadMomP[(i-1)*nsec + j] + RadMomM[i*nsec + j])/(Dens[i*nsec + j] +
Dens[(i-1)*nsec + j] + 1e-20);
}
Vtheta[i*nsec + j] = (ThetaMomP[i*nsec + ((j-1)+nsec)%nsec] + ThetaMomM[i*nsec + j])/(Dens[i*nsec + j] +
Dens[i*nsec + ((j-1)+nsec)%nsec] + 1e-15)/Rmed[i] - Rmed[i]*OmegaFrame;
/* It was the angular momentum */
}
}
__global__ void ComputeSpeQtyKernel (double *Label, double *Dens, double *ExtLabel, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec){
Label[i*nsec + j] = ExtLabel[i*nsec + j]/Dens[i*nsec + j];
/* Compressive flow if line commentarized
Label[i*nsec + j] = ExtLabel[i*nsec + j] */
}
}
__global__ void FillForcesArraysKernel (double *Rmed, int nsec, int nrad, double xplanet, double yplanet, double smooth,
double mplanet, int Indirect_Term, double InvPlanetDistance3, double *Potential, Pair IndirectTerm, int k)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double InvDistance, angle, x, y, distance, distancesmooth, pot;
if (i<nrad && j<nsec){
InvDistance = 1.0/Rmed[i];
angle = (double)j/(double)nsec*2.0*PI;
x = Rmed[i]*cos(angle);
y = Rmed[i]*sin(angle);
distance = (x-xplanet)*(x-xplanet)+(y-yplanet)*(y-yplanet);
distancesmooth = sqrt(distance+smooth);
pot = -G*mplanet/distancesmooth; /* Direct term from planet */
if (Indirect_Term == YES)
pot += G*mplanet*InvPlanetDistance3*(x*xplanet+y*yplanet); /* Indirect term from planet */
Potential[i*nsec + j] += pot;
if (k == 0) {
/* -- Gravitational potential from star on gas -- */
pot = -G*1.0*InvDistance; /* Direct term from star */
pot -= IndirectTerm.x*x + IndirectTerm.y*y; /* Indirect term from star */
Potential[i*nsec + j] += pot;
}
}
}
__global__ void CorrectVthetaKernel (double *Vtheta, double domega, double *Rmed, int nrad, int nsec)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
if (i<nrad && j<nsec)
Vtheta[i*nsec + j] = Vtheta[i*nsec + j] - domega*Rmed[i];
}
__global__ void ConditionCFLKernel1D (double *Rsup, double *Rinf, double *Rmed, int nrad, int nsec,
double *Vtheta, double *Vmoy)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
int j;
if (i<nrad){
Vmoy[i] = 0.0;
for (j = 0; j < nsec; j++)
Vmoy[i] += Vtheta[i*nsec + j];
Vmoy[i] /= (double)nsec;
}
}
__global__ void ConditionCFLKernel2D1 (double *Rsup, double *Rinf, double *Rmed, int nsec, int nrad,
double *Vresidual, double *Vtheta, double *Vmoy, int FastTransport, double *SoundSpeed, double *Vrad,
double *DT2D)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = threadIdx.y + blockDim.y*blockIdx.y;
double dxrad, dxtheta, invdt1, invdt2, invdt3, invdt4, dvr, dvt, dt;
if (i > 0 && i<nrad && j<nsec){
dxrad = Rsup[i]-Rinf[i];
dxtheta = Rmed[i]*2.0*PI/(double)nsec;
if (FastTransport) Vresidual[i*nsec + j] = Vtheta[i*nsec + j]-Vmoy[i]; /* Fargo algorithm */
else Vresidual[i*nsec + j] = Vtheta[i*nsec + j]; /* Standard algorithm */
//Vresidual[i*nsec + nsec] = Vresidual[i*nsec];
invdt1 = SoundSpeed[i*nsec + j]/(min2(dxrad,dxtheta));
invdt2 = fabs(Vrad[i*nsec + j])/dxrad;
invdt3 = fabs(Vresidual[i*nsec + j])/dxtheta;
dvr = Vrad[(i+1)*nsec + j]-Vrad[i*nsec + j];
dvt = Vtheta[i*nsec + (j+1)%nsec]-Vtheta[i*nsec + j];
if (dvr >= 0.0) dvr = 1e-10;
else dvr = -dvr;
if (dvt >= 0.0) dvt = 1e-10;
else dvt = -dvt;
invdt4 = max2(dvr/dxrad, dvt/dxtheta);
invdt4*= 4.0*CVNR*CVNR;
dt = CFLSECURITY/sqrt(invdt1*invdt1+invdt2*invdt2+invdt3*invdt3+invdt4*invdt4);
DT2D[i*nsec + j] = dt; // array nrad*nsec size dt
}
}
__global__ void ConditionCFLKernel2D2 (double *newDT, double *DT2D, double *DT1D, double *Vmoy, double *invRmed,
int *CFL, int nsec, int nrad, double DeltaT)
{
int i = threadIdx.x + blockDim.x*blockIdx.x;
int k;
double dt;
double newdt = 1e30;
if (i>0 && i<nrad){
newDT[i] = newdt;
for (k = 0; k < nsec; k++)
if (DT2D[i*nsec + k] < newDT[i]) newDT[i] = DT2D[i*nsec + k]; // for each dt in nrad
}
if (i<nrad-1){
dt = 2.0*PI*CFLSECURITY/(double)nsec/fabs(Vmoy[i]*invRmed[i]-Vmoy[i+1]*invRmed[i+1]);
DT1D[i] = dt; // array nrad size dt
}
}
__global__ void ConditionCFLKernel2D3 (double *newDT, double *DT2D, double *DT1D, double *Vmoy, double *invRmed,
int *CFL, int nsec, int nrad, double DeltaT)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
double newdt;
if (j == 0){
newdt = newDT[1];
for (int i=2; i<nrad; i++){
if (newDT[i] < newdt)
newdt = newDT[i];
}
for (int i = 0; i < nrad-1; i++) {
if (DT1D[i] < newdt)
newdt = DT1D[i];
}
if (DeltaT < newdt)
newdt = DeltaT;
CFL[0] = (int)(ceil(DeltaT/newdt));
}
}
__device__ double max2(double a, double b)
{
if (b > a) return b;
return a;
}
__device__ double min2(double a, double b)
{
if (b < a) return b;
return a;
}
__device__ double AspectRatioDevice(double r, double ASPECTRATIO, double TRANSITIONWIDTH, double TRANSITIONRADIUS,
double TRANSITIONRATIO, double PhysicalTime, double PhysicalTimeInitial, double LAMBDADOUBLING)
{
double aspectratio, rmin, rmax, scale;
aspectratio = ASPECTRATIO;
rmin = TRANSITIONRADIUS-TRANSITIONWIDTH*ASPECTRATIO;
rmax = TRANSITIONRADIUS+TRANSITIONWIDTH*ASPECTRATIO;
scale = 1.0+(PhysicalTime-PhysicalTimeInitial)*LAMBDADOUBLING;
rmin *= scale;
rmax *= scale;
if (r < rmin) aspectratio *= TRANSITIONRATIO;
if ((r >= rmin) && (r <= rmax)){
aspectratio *= exp((rmax-r)/(rmax-rmin)*log(TRANSITIONRATIO));
}
return aspectratio;
}
/*__device__ double FViscosityDevice(double r, double VISCOSITY, int ViscosityAlpha, double *Rmed, double ALPHAVISCOSITY,
double CAVITYWIDTH, double CAVITYRADIUS, double CAVITYRATIO, double PhysicalTime, double PhysicalTimeInitial,
double ASPECTRATIO, double LAMBDADOUBLING)
{
double viscosity, rmin, rmax, scale;
int i = 0;
viscosity = VISCOSITY;
if (ViscosityAlpha){
while (Rmed[i] < r) i++;
viscosity = ALPHAVISCOSITY*GLOBAL_bufarray[i] * GLOBAL_bufarray[i] * pow(r, 1.5);
}
rmin = CAVITYRADIUS-CAVITYWIDTH*ASPECTRATIO;
rmax = CAVITYRADIUS+CAVITYWIDTH*ASPECTRATIO;
scale = 1.0+(PhysicalTime-PhysicalTimeInitial)*LAMBDADOUBLING;
rmin *= scale;
rmax *= scale;
if (r < rmin) viscosity *= CAVITYRATIO;
if ((r >= rmin) && (r <= rmax)) viscosity *= exp((rmax-r)/(rmax-rmin)*log(CAVITYRATIO));
return viscosity;
}*/
__global__ void ApplySubKeplerianBoundaryKernel(double *VthetaInt, double *Rmed, double OmegaFrame, int nsec,
int nrad, double VKepIn, double VKepOut)
{
int j = threadIdx.x + blockDim.x*blockIdx.x;
int i = 0;
if (j<nsec)
VthetaInt[i*nsec + j] = VKepIn - Rmed[i]*OmegaFrame;
i = nrad - 1;
if (j<nsec)
VthetaInt[i*nsec + j] = VKepOut - Rmed[i]*OmegaFrame;
}
|
14daa9f9561c644faa2ea0925ff67aa77f4c78d8.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* @Name: integer_add.cu
* @Description: Integer addition.
* Arguments passed as values.
*
* @Author: Giacomo Marciani <gmarciani@acm.org>
* @Institution: University of Rome Tor Vergata
*
* @Usage: add_int a b
*/
#include <stdio.h>
#include "../../common/error.h"
__global__ void intAdd(const int a, const int b, int *c) {
*c = a + b;
}
__host__ void gpuIntAdd(const int a, const int b, int *c, const dim3 gridDim, const dim3 blockDim) {
int *dev_c; // device copies of c
const unsigned int size = sizeof(int); // bytes for and integer
// allocate device copies of c
HANDLE_ERROR(hipMalloc((void**)&dev_c, size));
// launch kernel intAdd()
hipLaunchKernelGGL(( intAdd), dim3(gridDim), dim3(blockDim) , 0, 0, a, b, dev_c);
// copy device result back to host copy of c
HANDLE_ERROR(hipMemcpy(c, dev_c, size, hipMemcpyDeviceToHost));
// free device
HANDLE_ERROR(hipFree(dev_c));
}
int main(const int argc, char **argv) {
int a, b, c; // host copies of a, b, c
// check arguments
if (argc < 3) {
fprintf(stderr, "Usage: %s a b\n", argv[0]);
exit(1);
}
// set values
a = atoi(argv[1]);
b = atoi(argv[2]);
// launch kernel intAdd()
dim3 gridDim(1);
dim3 blockDim(1);
gpuIntAdd(a, b, &c, gridDim, blockDim);
// test result
const int expected = a + b;
if (c != expected) {
fprintf(stderr, "Error: expected %d, got %d\n", expected, c);
} else {
printf("Correct: %d\n", c);
}
return 0;
}
| 14daa9f9561c644faa2ea0925ff67aa77f4c78d8.cu | /*
* @Name: integer_add.cu
* @Description: Integer addition.
* Arguments passed as values.
*
* @Author: Giacomo Marciani <gmarciani@acm.org>
* @Institution: University of Rome Tor Vergata
*
* @Usage: add_int a b
*/
#include <stdio.h>
#include "../../common/error.h"
__global__ void intAdd(const int a, const int b, int *c) {
*c = a + b;
}
__host__ void gpuIntAdd(const int a, const int b, int *c, const dim3 gridDim, const dim3 blockDim) {
int *dev_c; // device copies of c
const unsigned int size = sizeof(int); // bytes for and integer
// allocate device copies of c
HANDLE_ERROR(cudaMalloc((void**)&dev_c, size));
// launch kernel intAdd()
intAdd<<< gridDim, blockDim >>>(a, b, dev_c);
// copy device result back to host copy of c
HANDLE_ERROR(cudaMemcpy(c, dev_c, size, cudaMemcpyDeviceToHost));
// free device
HANDLE_ERROR(cudaFree(dev_c));
}
int main(const int argc, char **argv) {
int a, b, c; // host copies of a, b, c
// check arguments
if (argc < 3) {
fprintf(stderr, "Usage: %s a b\n", argv[0]);
exit(1);
}
// set values
a = atoi(argv[1]);
b = atoi(argv[2]);
// launch kernel intAdd()
dim3 gridDim(1);
dim3 blockDim(1);
gpuIntAdd(a, b, &c, gridDim, blockDim);
// test result
const int expected = a + b;
if (c != expected) {
fprintf(stderr, "Error: expected %d, got %d\n", expected, c);
} else {
printf("Correct: %d\n", c);
}
return 0;
}
|
538c368b4b49428cc703722ebfe89b142143af75.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "matvec.h"
#include "constants.h"
__global__ void frameTanKernel(double *d_tanMat, double *d_lmkMat,
int *d_tanVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tanSumVec = {0.0, 0.0};
for ( int tanIdx = 0; tanIdx < TANNUM; ++tanIdx )
{
int lftIdx = d_tanVtxMat[(2 * tanIdx ) * elmNum + elmIdx];
int rgtIdx = d_tanVtxMat[(2 * tanIdx + 1) * elmNum + elmIdx];
vector lftVec, rgtVec;
getVector(lftVec, d_lmkMat, lftIdx, lmkNum);
getVector(rgtVec, d_lmkMat, rgtIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, rgtVec, lftVec);
double difLen = eucnorm(difVec);
tanSumVec.x += difVec.x / difLen;
tanSumVec.y += difVec.y / difLen;
}
double tanLen = eucnorm(tanSumVec);
d_tanMat[ elmIdx] = tanSumVec.x / tanLen;
d_tanMat[elmNum + elmIdx] = tanSumVec.y / tanLen;
}
return;
}
__global__ void frameTsvKernel(double *d_tsvMat, double *d_lmkMat,
int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tsvSumVec = {0.0, 0.0};
for ( int tsvIdx = 0; tsvIdx < TSVNUM; ++tsvIdx )
{
int dwnIdx = d_tsvVtxMat[(2 * tsvIdx ) * elmNum + elmIdx];
int uppIdx = d_tsvVtxMat[(2 * tsvIdx + 1) * elmNum + elmIdx];
vector dwnVec, uppVec;
getVector(dwnVec, d_lmkMat, dwnIdx, lmkNum);
getVector(uppVec, d_lmkMat, uppIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, uppVec, dwnVec);
double difLen = eucnorm(difVec);
tsvSumVec.x += difVec.x / difLen;
tsvSumVec.y += difVec.y / difLen;
}
double tsvLen = eucnorm(tsvSumVec);
d_tsvMat[ elmIdx] = tsvSumVec.x / tsvLen;
d_tsvMat[elmNum + elmIdx] = tsvSumVec.y / tsvLen;
}
return;
}
void computeFrame(double *d_tanMat, double *d_tsvMat,
double *d_lmkMat, int *d_tanVtxMat, int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int blkNum = (elmNum - 1) / BLKDIM + 1;
hipLaunchKernelGGL(( frameTanKernel) , dim3(blkNum), dim3(BLKDIM), 0, 0, d_tanMat, d_lmkMat, d_tanVtxMat, lmkNum, elmNum);
hipLaunchKernelGGL(( frameTsvKernel) , dim3(blkNum), dim3(BLKDIM), 0, 0, d_tsvMat, d_lmkMat, d_tsvVtxMat, lmkNum, elmNum);
return;
}
// - - -
__global__ void frameTanKernel(double *d_tanMat, double *d_tanLenVec, double *d_lmkMat,
int *d_tanVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tanSumVec = {0.0, 0.0};
for ( int tanIdx = 0; tanIdx < TANNUM; ++tanIdx )
{
int lftIdx = d_tanVtxMat[(2 * tanIdx ) * elmNum + elmIdx];
int rgtIdx = d_tanVtxMat[(2 * tanIdx + 1) * elmNum + elmIdx];
vector lftVec, rgtVec;
getVector(lftVec, d_lmkMat, lftIdx, lmkNum);
getVector(rgtVec, d_lmkMat, rgtIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, rgtVec, lftVec);
double difLen = eucnorm(difVec);
tanSumVec.x += difVec.x / difLen;
tanSumVec.y += difVec.y / difLen;
}
double tanLen = eucnorm(tanSumVec);
d_tanLenVec[elmIdx] = tanLen;
d_tanMat[ elmIdx] = tanSumVec.x / tanLen;
d_tanMat[elmNum + elmIdx] = tanSumVec.y / tanLen;
}
return;
}
__global__ void frameTsvKernel(double *d_tsvMat, double *d_tsvLenVec, double *d_lmkMat,
int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tsvSumVec = {0.0, 0.0};
for ( int tsvIdx = 0; tsvIdx < TSVNUM; ++tsvIdx )
{
int dwnIdx = d_tsvVtxMat[(2 * tsvIdx ) * elmNum + elmIdx];
int uppIdx = d_tsvVtxMat[(2 * tsvIdx + 1) * elmNum + elmIdx];
vector dwnVec, uppVec;
getVector(dwnVec, d_lmkMat, dwnIdx, lmkNum);
getVector(uppVec, d_lmkMat, uppIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, uppVec, dwnVec);
double difLen = eucnorm(difVec);
tsvSumVec.x += difVec.x / difLen;
tsvSumVec.y += difVec.y / difLen;
}
double tsvLen = eucnorm(tsvSumVec);
d_tsvLenVec[elmIdx] = tsvLen;
d_tsvMat[ elmIdx] = tsvSumVec.x / tsvLen;
d_tsvMat[elmNum + elmIdx] = tsvSumVec.y / tsvLen;
}
return;
}
void computeFrame(double *d_tanMat, double *d_tsvMat, double *d_tanLenVec, double *d_tsvLenVec,
double *d_lmkMat, int *d_tanVtxMat, int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int blkNum = (elmNum - 1) / BLKDIM + 1;
hipLaunchKernelGGL(( frameTanKernel) , dim3(blkNum), dim3(BLKDIM), 0, 0, d_tanMat, d_tanLenVec, d_lmkMat, d_tanVtxMat, lmkNum, elmNum);
hipLaunchKernelGGL(( frameTsvKernel) , dim3(blkNum), dim3(BLKDIM), 0, 0, d_tsvMat, d_tsvLenVec, d_lmkMat, d_tsvVtxMat, lmkNum, elmNum);
return;
}
| 538c368b4b49428cc703722ebfe89b142143af75.cu | #include "matvec.h"
#include "constants.h"
__global__ void frameTanKernel(double *d_tanMat, double *d_lmkMat,
int *d_tanVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tanSumVec = {0.0, 0.0};
for ( int tanIdx = 0; tanIdx < TANNUM; ++tanIdx )
{
int lftIdx = d_tanVtxMat[(2 * tanIdx ) * elmNum + elmIdx];
int rgtIdx = d_tanVtxMat[(2 * tanIdx + 1) * elmNum + elmIdx];
vector lftVec, rgtVec;
getVector(lftVec, d_lmkMat, lftIdx, lmkNum);
getVector(rgtVec, d_lmkMat, rgtIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, rgtVec, lftVec);
double difLen = eucnorm(difVec);
tanSumVec.x += difVec.x / difLen;
tanSumVec.y += difVec.y / difLen;
}
double tanLen = eucnorm(tanSumVec);
d_tanMat[ elmIdx] = tanSumVec.x / tanLen;
d_tanMat[elmNum + elmIdx] = tanSumVec.y / tanLen;
}
return;
}
__global__ void frameTsvKernel(double *d_tsvMat, double *d_lmkMat,
int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tsvSumVec = {0.0, 0.0};
for ( int tsvIdx = 0; tsvIdx < TSVNUM; ++tsvIdx )
{
int dwnIdx = d_tsvVtxMat[(2 * tsvIdx ) * elmNum + elmIdx];
int uppIdx = d_tsvVtxMat[(2 * tsvIdx + 1) * elmNum + elmIdx];
vector dwnVec, uppVec;
getVector(dwnVec, d_lmkMat, dwnIdx, lmkNum);
getVector(uppVec, d_lmkMat, uppIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, uppVec, dwnVec);
double difLen = eucnorm(difVec);
tsvSumVec.x += difVec.x / difLen;
tsvSumVec.y += difVec.y / difLen;
}
double tsvLen = eucnorm(tsvSumVec);
d_tsvMat[ elmIdx] = tsvSumVec.x / tsvLen;
d_tsvMat[elmNum + elmIdx] = tsvSumVec.y / tsvLen;
}
return;
}
void computeFrame(double *d_tanMat, double *d_tsvMat,
double *d_lmkMat, int *d_tanVtxMat, int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int blkNum = (elmNum - 1) / BLKDIM + 1;
frameTanKernel <<<blkNum, BLKDIM>>> (d_tanMat, d_lmkMat, d_tanVtxMat, lmkNum, elmNum);
frameTsvKernel <<<blkNum, BLKDIM>>> (d_tsvMat, d_lmkMat, d_tsvVtxMat, lmkNum, elmNum);
return;
}
// - - -
__global__ void frameTanKernel(double *d_tanMat, double *d_tanLenVec, double *d_lmkMat,
int *d_tanVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tanSumVec = {0.0, 0.0};
for ( int tanIdx = 0; tanIdx < TANNUM; ++tanIdx )
{
int lftIdx = d_tanVtxMat[(2 * tanIdx ) * elmNum + elmIdx];
int rgtIdx = d_tanVtxMat[(2 * tanIdx + 1) * elmNum + elmIdx];
vector lftVec, rgtVec;
getVector(lftVec, d_lmkMat, lftIdx, lmkNum);
getVector(rgtVec, d_lmkMat, rgtIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, rgtVec, lftVec);
double difLen = eucnorm(difVec);
tanSumVec.x += difVec.x / difLen;
tanSumVec.y += difVec.y / difLen;
}
double tanLen = eucnorm(tanSumVec);
d_tanLenVec[elmIdx] = tanLen;
d_tanMat[ elmIdx] = tanSumVec.x / tanLen;
d_tanMat[elmNum + elmIdx] = tanSumVec.y / tanLen;
}
return;
}
__global__ void frameTsvKernel(double *d_tsvMat, double *d_tsvLenVec, double *d_lmkMat,
int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int elmIdx = blockIdx.x * blockDim.x + threadIdx.x;
if ( elmIdx < elmNum )
{
vector tsvSumVec = {0.0, 0.0};
for ( int tsvIdx = 0; tsvIdx < TSVNUM; ++tsvIdx )
{
int dwnIdx = d_tsvVtxMat[(2 * tsvIdx ) * elmNum + elmIdx];
int uppIdx = d_tsvVtxMat[(2 * tsvIdx + 1) * elmNum + elmIdx];
vector dwnVec, uppVec;
getVector(dwnVec, d_lmkMat, dwnIdx, lmkNum);
getVector(uppVec, d_lmkMat, uppIdx, lmkNum);
vector difVec;
vectorSubtract(difVec, uppVec, dwnVec);
double difLen = eucnorm(difVec);
tsvSumVec.x += difVec.x / difLen;
tsvSumVec.y += difVec.y / difLen;
}
double tsvLen = eucnorm(tsvSumVec);
d_tsvLenVec[elmIdx] = tsvLen;
d_tsvMat[ elmIdx] = tsvSumVec.x / tsvLen;
d_tsvMat[elmNum + elmIdx] = tsvSumVec.y / tsvLen;
}
return;
}
void computeFrame(double *d_tanMat, double *d_tsvMat, double *d_tanLenVec, double *d_tsvLenVec,
double *d_lmkMat, int *d_tanVtxMat, int *d_tsvVtxMat, int lmkNum, int elmNum)
{
int blkNum = (elmNum - 1) / BLKDIM + 1;
frameTanKernel <<<blkNum, BLKDIM>>> (d_tanMat, d_tanLenVec, d_lmkMat, d_tanVtxMat, lmkNum, elmNum);
frameTsvKernel <<<blkNum, BLKDIM>>> (d_tsvMat, d_tsvLenVec, d_lmkMat, d_tsvVtxMat, lmkNum, elmNum);
return;
}
|
27c9f04109ac688b2fea9f6e9dbc739b24875609.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
// REQUIRES: x86-registered-target
// REQUIRES: nvptx-registered-target
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s
#include "Inputs/cuda.h"
// Opaque return types used to check that we pick the right overloads.
struct HostReturnTy {};
struct HostReturnTy2 {};
struct DeviceReturnTy {};
struct DeviceReturnTy2 {};
struct HostDeviceReturnTy {};
struct TemplateReturnTy {};
typedef HostReturnTy (*HostFnPtr)();
typedef DeviceReturnTy (*DeviceFnPtr)();
typedef HostDeviceReturnTy (*HostDeviceFnPtr)();
typedef void (*GlobalFnPtr)(); // __global__ functions must return void.
// CurrentReturnTy is {HostReturnTy,DeviceReturnTy} during {host,device}
// compilation.
#ifdef __CUDA_ARCH__
typedef DeviceReturnTy CurrentReturnTy;
#else
typedef HostReturnTy CurrentReturnTy;
#endif
// CurrentFnPtr is a function pointer to a {host,device} function during
// {host,device} compilation.
typedef CurrentReturnTy (*CurrentFnPtr)();
// Host and unattributed functions can't be overloaded.
__host__ void hh() {} // expected-note {{previous definition is here}}
void hh() {} // expected-error {{redefinition of 'hh'}}
// H/D overloading is OK.
__host__ HostReturnTy dh() { return HostReturnTy(); }
__device__ DeviceReturnTy dh() { return DeviceReturnTy(); }
// H/HD and D/HD are not allowed.
__host__ __device__ int hdh() { return 0; } // expected-note {{previous definition is here}}
__host__ int hdh() { return 0; } // expected-error {{redefinition of 'hdh'}}
__host__ int hhd() { return 0; } // expected-note {{previous definition is here}}
__host__ __device__ int hhd() { return 0; } // expected-error {{redefinition of 'hhd'}}
// expected-warning@-1 {{attribute declaration must precede definition}}
// expected-note@-3 {{previous definition is here}}
__host__ __device__ int hdd() { return 0; } // expected-note {{previous definition is here}}
__device__ int hdd() { return 0; } // expected-error {{redefinition of 'hdd'}}
__device__ int dhd() { return 0; } // expected-note {{previous definition is here}}
__host__ __device__ int dhd() { return 0; } // expected-error {{redefinition of 'dhd'}}
// expected-warning@-1 {{attribute declaration must precede definition}}
// expected-note@-3 {{previous definition is here}}
// Same tests for extern "C" functions.
extern "C" __host__ int chh() { return 0; } // expected-note {{previous definition is here}}
extern "C" int chh() { return 0; } // expected-error {{redefinition of 'chh'}}
// H/D overloading is OK.
extern "C" __device__ DeviceReturnTy cdh() { return DeviceReturnTy(); }
extern "C" __host__ HostReturnTy cdh() { return HostReturnTy(); }
// H/HD and D/HD overloading is not allowed.
extern "C" __host__ __device__ int chhd1() { return 0; } // expected-note {{previous definition is here}}
extern "C" __host__ int chhd1() { return 0; } // expected-error {{redefinition of 'chhd1'}}
extern "C" __host__ int chhd2() { return 0; } // expected-note {{previous definition is here}}
extern "C" __host__ __device__ int chhd2() { return 0; } // expected-error {{redefinition of 'chhd2'}}
// expected-warning@-1 {{attribute declaration must precede definition}}
// expected-note@-3 {{previous definition is here}}
// Helper functions to verify calling restrictions.
__device__ DeviceReturnTy d() { return DeviceReturnTy(); }
// expected-note@-1 1+ {{'d' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __device__ function from __host__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
__host__ HostReturnTy h() { return HostReturnTy(); }
// expected-note@-1 1+ {{'h' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __host__ function from __device__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
// expected-note@-4 1+ {{candidate function not viable: call to __host__ function from __global__ function}}
__global__ void g() {}
// expected-note@-1 1+ {{'g' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __global__ function from __device__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __global__ function from __host__ __device__ function}}
// expected-note@-4 1+ {{candidate function not viable: call to __global__ function from __global__ function}}
extern "C" __device__ DeviceReturnTy cd() { return DeviceReturnTy(); }
// expected-note@-1 1+ {{'cd' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __device__ function from __host__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
extern "C" __host__ HostReturnTy ch() { return HostReturnTy(); }
// expected-note@-1 1+ {{'ch' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __host__ function from __device__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
// expected-note@-4 1+ {{candidate function not viable: call to __host__ function from __global__ function}}
__host__ void hostf() {
DeviceFnPtr fp_d = d; // expected-error {{reference to __device__ function 'd' in __host__ function}}
DeviceReturnTy ret_d = d(); // expected-error {{no matching function for call to 'd'}}
DeviceFnPtr fp_cd = cd; // expected-error {{reference to __device__ function 'cd' in __host__ function}}
DeviceReturnTy ret_cd = cd(); // expected-error {{no matching function for call to 'cd'}}
HostFnPtr fp_h = h;
HostReturnTy ret_h = h();
HostFnPtr fp_ch = ch;
HostReturnTy ret_ch = ch();
HostFnPtr fp_dh = dh;
HostReturnTy ret_dh = dh();
HostFnPtr fp_cdh = cdh;
HostReturnTy ret_cdh = cdh();
GlobalFnPtr fp_g = g;
g(); // expected-error {{call to global function g not configured}}
hipLaunchKernelGGL(( g), dim3(0), dim3(0), 0, 0, );
}
__device__ void devicef() {
DeviceFnPtr fp_d = d;
DeviceReturnTy ret_d = d();
DeviceFnPtr fp_cd = cd;
DeviceReturnTy ret_cd = cd();
HostFnPtr fp_h = h; // expected-error {{reference to __host__ function 'h' in __device__ function}}
HostReturnTy ret_h = h(); // expected-error {{no matching function for call to 'h'}}
HostFnPtr fp_ch = ch; // expected-error {{reference to __host__ function 'ch' in __device__ function}}
HostReturnTy ret_ch = ch(); // expected-error {{no matching function for call to 'ch'}}
DeviceFnPtr fp_dh = dh;
DeviceReturnTy ret_dh = dh();
DeviceFnPtr fp_cdh = cdh;
DeviceReturnTy ret_cdh = cdh();
GlobalFnPtr fp_g = g; // expected-error {{reference to __global__ function 'g' in __device__ function}}
g(); // expected-error {{no matching function for call to 'g'}}
hipLaunchKernelGGL(( g), dim3(0),dim3(0), 0, 0, ); // expected-error {{reference to __global__ function 'g' in __device__ function}}
}
__global__ void globalf() {
DeviceFnPtr fp_d = d;
DeviceReturnTy ret_d = d();
DeviceFnPtr fp_cd = cd;
DeviceReturnTy ret_cd = cd();
HostFnPtr fp_h = h; // expected-error {{reference to __host__ function 'h' in __global__ function}}
HostReturnTy ret_h = h(); // expected-error {{no matching function for call to 'h'}}
HostFnPtr fp_ch = ch; // expected-error {{reference to __host__ function 'ch' in __global__ function}}
HostReturnTy ret_ch = ch(); // expected-error {{no matching function for call to 'ch'}}
DeviceFnPtr fp_dh = dh;
DeviceReturnTy ret_dh = dh();
DeviceFnPtr fp_cdh = cdh;
DeviceReturnTy ret_cdh = cdh();
GlobalFnPtr fp_g = g; // expected-error {{reference to __global__ function 'g' in __global__ function}}
g(); // expected-error {{no matching function for call to 'g'}}
hipLaunchKernelGGL(( g), dim3(0),dim3(0), 0, 0, ); // expected-error {{reference to __global__ function 'g' in __global__ function}}
}
__host__ __device__ void hostdevicef() {
DeviceFnPtr fp_d = d;
DeviceReturnTy ret_d = d();
DeviceFnPtr fp_cd = cd;
DeviceReturnTy ret_cd = cd();
HostFnPtr fp_h = h;
HostReturnTy ret_h = h();
HostFnPtr fp_ch = ch;
HostReturnTy ret_ch = ch();
CurrentFnPtr fp_dh = dh;
CurrentReturnTy ret_dh = dh();
CurrentFnPtr fp_cdh = cdh;
CurrentReturnTy ret_cdh = cdh();
g(); // expected-error {{call to global function g not configured}}
}
// Test for address of overloaded function resolution in the global context.
HostFnPtr fp_h = h;
HostFnPtr fp_ch = ch;
CurrentFnPtr fp_dh = dh;
CurrentFnPtr fp_cdh = cdh;
GlobalFnPtr fp_g = g;
// Test overloading of destructors
// Can't mix H and unattributed destructors
struct d_h {
~d_h() {} // expected-note {{previous declaration is here}}
__host__ ~d_h() {} // expected-error {{destructor cannot be redeclared}}
};
// HD is OK
struct d_hd {
__host__ __device__ ~d_hd() {}
};
// Test overloading of member functions
struct m_h {
void operator delete(void *ptr); // expected-note {{previous declaration is here}}
__host__ void operator delete(void *ptr); // expected-error {{class member cannot be redeclared}}
};
// D/H overloading is OK
struct m_dh {
__device__ void operator delete(void *ptr);
__host__ void operator delete(void *ptr);
};
// HD by itself is OK
struct m_hd {
__device__ __host__ void operator delete(void *ptr);
};
struct m_hhd {
__host__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__host__ __device__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
struct m_hdh {
__host__ __device__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__host__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
struct m_dhd {
__device__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__host__ __device__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
struct m_hdd {
__host__ __device__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__device__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
// __global__ functions can't be overloaded based on attribute
// difference.
struct G {
friend void friend_of_g(G &arg);
private:
int x;
};
__global__ void friend_of_g(G &arg) { int x = arg.x; } // expected-note {{previous definition is here}}
void friend_of_g(G &arg) { int x = arg.x; } // expected-error {{redefinition of 'friend_of_g'}}
// HD functions are sometimes allowed to call H or D functions -- this
// is an artifact of the source-to-source splitting performed by nvcc
// that we need to mimic. During device mode compilation in nvcc, host
// functions aren't present at all, so don't participate in
// overloading. But in clang, H and D functions are present in both
// compilation modes. Clang normally uses the target attribute as a
// tiebreaker between overloads with otherwise identical priority, but
// in order to match nvcc's behavior, we sometimes need to wholly
// discard overloads that would not be present during compilation
// under nvcc.
template <typename T> TemplateReturnTy template_vs_function(T arg) {
return TemplateReturnTy();
}
__device__ DeviceReturnTy template_vs_function(float arg) {
return DeviceReturnTy();
}
// Here we expect to call the templated function during host compilation, even
// if -fcuda-disable-target-call-checks is passed, and even though C++ overload
// rules prefer the non-templated function.
__host__ __device__ void test_host_device_calls_template(void) {
#ifdef __CUDA_ARCH__
typedef DeviceReturnTy ExpectedReturnTy;
#else
typedef TemplateReturnTy ExpectedReturnTy;
#endif
ExpectedReturnTy ret1 = template_vs_function(1.0f);
ExpectedReturnTy ret2 = template_vs_function(2.0);
}
// Calls from __host__ and __device__ functions should always call the
// overloaded function that matches their mode.
__host__ void test_host_calls_template_fn() {
TemplateReturnTy ret1 = template_vs_function(1.0f);
TemplateReturnTy ret2 = template_vs_function(2.0);
}
__device__ void test_device_calls_template_fn() {
DeviceReturnTy ret1 = template_vs_function(1.0f);
DeviceReturnTy ret2 = template_vs_function(2.0);
}
// If we have a mix of HD and H-only or D-only candidates in the overload set,
// normal C++ overload resolution rules apply first.
template <typename T> TemplateReturnTy template_vs_hd_function(T arg) {
return TemplateReturnTy();
}
__host__ __device__ HostDeviceReturnTy template_vs_hd_function(float arg) {
return HostDeviceReturnTy();
}
__host__ __device__ void test_host_device_calls_hd_template() {
HostDeviceReturnTy ret1 = template_vs_hd_function(1.0f);
TemplateReturnTy ret2 = template_vs_hd_function(1);
}
__host__ void test_host_calls_hd_template() {
HostDeviceReturnTy ret1 = template_vs_hd_function(1.0f);
TemplateReturnTy ret2 = template_vs_hd_function(1);
}
__device__ void test_device_calls_hd_template() {
HostDeviceReturnTy ret1 = template_vs_hd_function(1.0f);
// Host-only function template is not callable with strict call checks,
// so for device side HD function will be the only choice.
HostDeviceReturnTy ret2 = template_vs_hd_function(1);
}
// Check that overloads still work the same way on both host and
// device side when the overload set contains only functions from one
// side of compilation.
__device__ DeviceReturnTy device_only_function(int arg) { return DeviceReturnTy(); }
__device__ DeviceReturnTy2 device_only_function(float arg) { return DeviceReturnTy2(); }
__host__ HostReturnTy host_only_function(int arg) { return HostReturnTy(); }
__host__ HostReturnTy2 host_only_function(float arg) { return HostReturnTy2(); }
__host__ __device__ void test_host_device_single_side_overloading() {
DeviceReturnTy ret1 = device_only_function(1);
DeviceReturnTy2 ret2 = device_only_function(1.0f);
HostReturnTy ret3 = host_only_function(1);
HostReturnTy2 ret4 = host_only_function(1.0f);
}
// Verify that we allow overloading function templates.
template <typename T> __host__ T template_overload(const T &a) { return a; };
template <typename T> __device__ T template_overload(const T &a) { return a; };
__host__ void test_host_template_overload() {
template_overload(1); // OK. Attribute-based overloading picks __host__ variant.
}
__device__ void test_device_template_overload() {
template_overload(1); // OK. Attribute-based overloading picks __device__ variant.
}
| 27c9f04109ac688b2fea9f6e9dbc739b24875609.cu | // REQUIRES: x86-registered-target
// REQUIRES: nvptx-registered-target
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s
#include "Inputs/cuda.h"
// Opaque return types used to check that we pick the right overloads.
struct HostReturnTy {};
struct HostReturnTy2 {};
struct DeviceReturnTy {};
struct DeviceReturnTy2 {};
struct HostDeviceReturnTy {};
struct TemplateReturnTy {};
typedef HostReturnTy (*HostFnPtr)();
typedef DeviceReturnTy (*DeviceFnPtr)();
typedef HostDeviceReturnTy (*HostDeviceFnPtr)();
typedef void (*GlobalFnPtr)(); // __global__ functions must return void.
// CurrentReturnTy is {HostReturnTy,DeviceReturnTy} during {host,device}
// compilation.
#ifdef __CUDA_ARCH__
typedef DeviceReturnTy CurrentReturnTy;
#else
typedef HostReturnTy CurrentReturnTy;
#endif
// CurrentFnPtr is a function pointer to a {host,device} function during
// {host,device} compilation.
typedef CurrentReturnTy (*CurrentFnPtr)();
// Host and unattributed functions can't be overloaded.
__host__ void hh() {} // expected-note {{previous definition is here}}
void hh() {} // expected-error {{redefinition of 'hh'}}
// H/D overloading is OK.
__host__ HostReturnTy dh() { return HostReturnTy(); }
__device__ DeviceReturnTy dh() { return DeviceReturnTy(); }
// H/HD and D/HD are not allowed.
__host__ __device__ int hdh() { return 0; } // expected-note {{previous definition is here}}
__host__ int hdh() { return 0; } // expected-error {{redefinition of 'hdh'}}
__host__ int hhd() { return 0; } // expected-note {{previous definition is here}}
__host__ __device__ int hhd() { return 0; } // expected-error {{redefinition of 'hhd'}}
// expected-warning@-1 {{attribute declaration must precede definition}}
// expected-note@-3 {{previous definition is here}}
__host__ __device__ int hdd() { return 0; } // expected-note {{previous definition is here}}
__device__ int hdd() { return 0; } // expected-error {{redefinition of 'hdd'}}
__device__ int dhd() { return 0; } // expected-note {{previous definition is here}}
__host__ __device__ int dhd() { return 0; } // expected-error {{redefinition of 'dhd'}}
// expected-warning@-1 {{attribute declaration must precede definition}}
// expected-note@-3 {{previous definition is here}}
// Same tests for extern "C" functions.
extern "C" __host__ int chh() { return 0; } // expected-note {{previous definition is here}}
extern "C" int chh() { return 0; } // expected-error {{redefinition of 'chh'}}
// H/D overloading is OK.
extern "C" __device__ DeviceReturnTy cdh() { return DeviceReturnTy(); }
extern "C" __host__ HostReturnTy cdh() { return HostReturnTy(); }
// H/HD and D/HD overloading is not allowed.
extern "C" __host__ __device__ int chhd1() { return 0; } // expected-note {{previous definition is here}}
extern "C" __host__ int chhd1() { return 0; } // expected-error {{redefinition of 'chhd1'}}
extern "C" __host__ int chhd2() { return 0; } // expected-note {{previous definition is here}}
extern "C" __host__ __device__ int chhd2() { return 0; } // expected-error {{redefinition of 'chhd2'}}
// expected-warning@-1 {{attribute declaration must precede definition}}
// expected-note@-3 {{previous definition is here}}
// Helper functions to verify calling restrictions.
__device__ DeviceReturnTy d() { return DeviceReturnTy(); }
// expected-note@-1 1+ {{'d' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __device__ function from __host__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
__host__ HostReturnTy h() { return HostReturnTy(); }
// expected-note@-1 1+ {{'h' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __host__ function from __device__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
// expected-note@-4 1+ {{candidate function not viable: call to __host__ function from __global__ function}}
__global__ void g() {}
// expected-note@-1 1+ {{'g' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __global__ function from __device__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __global__ function from __host__ __device__ function}}
// expected-note@-4 1+ {{candidate function not viable: call to __global__ function from __global__ function}}
extern "C" __device__ DeviceReturnTy cd() { return DeviceReturnTy(); }
// expected-note@-1 1+ {{'cd' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __device__ function from __host__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __device__ function from __host__ __device__ function}}
extern "C" __host__ HostReturnTy ch() { return HostReturnTy(); }
// expected-note@-1 1+ {{'ch' declared here}}
// expected-note@-2 1+ {{candidate function not viable: call to __host__ function from __device__ function}}
// expected-note@-3 0+ {{candidate function not viable: call to __host__ function from __host__ __device__ function}}
// expected-note@-4 1+ {{candidate function not viable: call to __host__ function from __global__ function}}
__host__ void hostf() {
DeviceFnPtr fp_d = d; // expected-error {{reference to __device__ function 'd' in __host__ function}}
DeviceReturnTy ret_d = d(); // expected-error {{no matching function for call to 'd'}}
DeviceFnPtr fp_cd = cd; // expected-error {{reference to __device__ function 'cd' in __host__ function}}
DeviceReturnTy ret_cd = cd(); // expected-error {{no matching function for call to 'cd'}}
HostFnPtr fp_h = h;
HostReturnTy ret_h = h();
HostFnPtr fp_ch = ch;
HostReturnTy ret_ch = ch();
HostFnPtr fp_dh = dh;
HostReturnTy ret_dh = dh();
HostFnPtr fp_cdh = cdh;
HostReturnTy ret_cdh = cdh();
GlobalFnPtr fp_g = g;
g(); // expected-error {{call to global function g not configured}}
g<<<0, 0>>>();
}
__device__ void devicef() {
DeviceFnPtr fp_d = d;
DeviceReturnTy ret_d = d();
DeviceFnPtr fp_cd = cd;
DeviceReturnTy ret_cd = cd();
HostFnPtr fp_h = h; // expected-error {{reference to __host__ function 'h' in __device__ function}}
HostReturnTy ret_h = h(); // expected-error {{no matching function for call to 'h'}}
HostFnPtr fp_ch = ch; // expected-error {{reference to __host__ function 'ch' in __device__ function}}
HostReturnTy ret_ch = ch(); // expected-error {{no matching function for call to 'ch'}}
DeviceFnPtr fp_dh = dh;
DeviceReturnTy ret_dh = dh();
DeviceFnPtr fp_cdh = cdh;
DeviceReturnTy ret_cdh = cdh();
GlobalFnPtr fp_g = g; // expected-error {{reference to __global__ function 'g' in __device__ function}}
g(); // expected-error {{no matching function for call to 'g'}}
g<<<0,0>>>(); // expected-error {{reference to __global__ function 'g' in __device__ function}}
}
__global__ void globalf() {
DeviceFnPtr fp_d = d;
DeviceReturnTy ret_d = d();
DeviceFnPtr fp_cd = cd;
DeviceReturnTy ret_cd = cd();
HostFnPtr fp_h = h; // expected-error {{reference to __host__ function 'h' in __global__ function}}
HostReturnTy ret_h = h(); // expected-error {{no matching function for call to 'h'}}
HostFnPtr fp_ch = ch; // expected-error {{reference to __host__ function 'ch' in __global__ function}}
HostReturnTy ret_ch = ch(); // expected-error {{no matching function for call to 'ch'}}
DeviceFnPtr fp_dh = dh;
DeviceReturnTy ret_dh = dh();
DeviceFnPtr fp_cdh = cdh;
DeviceReturnTy ret_cdh = cdh();
GlobalFnPtr fp_g = g; // expected-error {{reference to __global__ function 'g' in __global__ function}}
g(); // expected-error {{no matching function for call to 'g'}}
g<<<0,0>>>(); // expected-error {{reference to __global__ function 'g' in __global__ function}}
}
__host__ __device__ void hostdevicef() {
DeviceFnPtr fp_d = d;
DeviceReturnTy ret_d = d();
DeviceFnPtr fp_cd = cd;
DeviceReturnTy ret_cd = cd();
HostFnPtr fp_h = h;
HostReturnTy ret_h = h();
HostFnPtr fp_ch = ch;
HostReturnTy ret_ch = ch();
CurrentFnPtr fp_dh = dh;
CurrentReturnTy ret_dh = dh();
CurrentFnPtr fp_cdh = cdh;
CurrentReturnTy ret_cdh = cdh();
g(); // expected-error {{call to global function g not configured}}
}
// Test for address of overloaded function resolution in the global context.
HostFnPtr fp_h = h;
HostFnPtr fp_ch = ch;
CurrentFnPtr fp_dh = dh;
CurrentFnPtr fp_cdh = cdh;
GlobalFnPtr fp_g = g;
// Test overloading of destructors
// Can't mix H and unattributed destructors
struct d_h {
~d_h() {} // expected-note {{previous declaration is here}}
__host__ ~d_h() {} // expected-error {{destructor cannot be redeclared}}
};
// HD is OK
struct d_hd {
__host__ __device__ ~d_hd() {}
};
// Test overloading of member functions
struct m_h {
void operator delete(void *ptr); // expected-note {{previous declaration is here}}
__host__ void operator delete(void *ptr); // expected-error {{class member cannot be redeclared}}
};
// D/H overloading is OK
struct m_dh {
__device__ void operator delete(void *ptr);
__host__ void operator delete(void *ptr);
};
// HD by itself is OK
struct m_hd {
__device__ __host__ void operator delete(void *ptr);
};
struct m_hhd {
__host__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__host__ __device__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
struct m_hdh {
__host__ __device__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__host__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
struct m_dhd {
__device__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__host__ __device__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
struct m_hdd {
__host__ __device__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
__device__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
};
// __global__ functions can't be overloaded based on attribute
// difference.
struct G {
friend void friend_of_g(G &arg);
private:
int x;
};
__global__ void friend_of_g(G &arg) { int x = arg.x; } // expected-note {{previous definition is here}}
void friend_of_g(G &arg) { int x = arg.x; } // expected-error {{redefinition of 'friend_of_g'}}
// HD functions are sometimes allowed to call H or D functions -- this
// is an artifact of the source-to-source splitting performed by nvcc
// that we need to mimic. During device mode compilation in nvcc, host
// functions aren't present at all, so don't participate in
// overloading. But in clang, H and D functions are present in both
// compilation modes. Clang normally uses the target attribute as a
// tiebreaker between overloads with otherwise identical priority, but
// in order to match nvcc's behavior, we sometimes need to wholly
// discard overloads that would not be present during compilation
// under nvcc.
template <typename T> TemplateReturnTy template_vs_function(T arg) {
return TemplateReturnTy();
}
__device__ DeviceReturnTy template_vs_function(float arg) {
return DeviceReturnTy();
}
// Here we expect to call the templated function during host compilation, even
// if -fcuda-disable-target-call-checks is passed, and even though C++ overload
// rules prefer the non-templated function.
__host__ __device__ void test_host_device_calls_template(void) {
#ifdef __CUDA_ARCH__
typedef DeviceReturnTy ExpectedReturnTy;
#else
typedef TemplateReturnTy ExpectedReturnTy;
#endif
ExpectedReturnTy ret1 = template_vs_function(1.0f);
ExpectedReturnTy ret2 = template_vs_function(2.0);
}
// Calls from __host__ and __device__ functions should always call the
// overloaded function that matches their mode.
__host__ void test_host_calls_template_fn() {
TemplateReturnTy ret1 = template_vs_function(1.0f);
TemplateReturnTy ret2 = template_vs_function(2.0);
}
__device__ void test_device_calls_template_fn() {
DeviceReturnTy ret1 = template_vs_function(1.0f);
DeviceReturnTy ret2 = template_vs_function(2.0);
}
// If we have a mix of HD and H-only or D-only candidates in the overload set,
// normal C++ overload resolution rules apply first.
template <typename T> TemplateReturnTy template_vs_hd_function(T arg) {
return TemplateReturnTy();
}
__host__ __device__ HostDeviceReturnTy template_vs_hd_function(float arg) {
return HostDeviceReturnTy();
}
__host__ __device__ void test_host_device_calls_hd_template() {
HostDeviceReturnTy ret1 = template_vs_hd_function(1.0f);
TemplateReturnTy ret2 = template_vs_hd_function(1);
}
__host__ void test_host_calls_hd_template() {
HostDeviceReturnTy ret1 = template_vs_hd_function(1.0f);
TemplateReturnTy ret2 = template_vs_hd_function(1);
}
__device__ void test_device_calls_hd_template() {
HostDeviceReturnTy ret1 = template_vs_hd_function(1.0f);
// Host-only function template is not callable with strict call checks,
// so for device side HD function will be the only choice.
HostDeviceReturnTy ret2 = template_vs_hd_function(1);
}
// Check that overloads still work the same way on both host and
// device side when the overload set contains only functions from one
// side of compilation.
__device__ DeviceReturnTy device_only_function(int arg) { return DeviceReturnTy(); }
__device__ DeviceReturnTy2 device_only_function(float arg) { return DeviceReturnTy2(); }
__host__ HostReturnTy host_only_function(int arg) { return HostReturnTy(); }
__host__ HostReturnTy2 host_only_function(float arg) { return HostReturnTy2(); }
__host__ __device__ void test_host_device_single_side_overloading() {
DeviceReturnTy ret1 = device_only_function(1);
DeviceReturnTy2 ret2 = device_only_function(1.0f);
HostReturnTy ret3 = host_only_function(1);
HostReturnTy2 ret4 = host_only_function(1.0f);
}
// Verify that we allow overloading function templates.
template <typename T> __host__ T template_overload(const T &a) { return a; };
template <typename T> __device__ T template_overload(const T &a) { return a; };
__host__ void test_host_template_overload() {
template_overload(1); // OK. Attribute-based overloading picks __host__ variant.
}
__device__ void test_device_template_overload() {
template_overload(1); // OK. Attribute-based overloading picks __device__ variant.
}
|
3db78232ab29c965c42c21c4af8636ab07e2296c.hip | // !!! This is a file automatically generated by hipify!!!
#include "SceECM.h"
#include "SceCells.h"
//# define debugModeECM
// task: frequency of plotting the ECM should be imported. Right now is given explicitly
// bending stiffness is given inside the code. It should be given as in input from a txt file.
//isInitPhase bool variable is not active anymore.
__constant__ double sceInterCell_ECM[5];
//__constant__ double wLCPara_ECM[4];
__constant__ double restLenECMAdhSpringGPU ;
__constant__ double maxLenECMAdhSpringGPU ;
__constant__ double kAdhECMGPU ;
__constant__ double stiffnessECMBasalGPU ;
__constant__ double stiffnessECMBCGPU ;
__constant__ double stiffnessECMPeripGPU ;
__constant__ double lknotECMBasalGPU ;
__constant__ double lknotECMBCGPU ;
__constant__ double lknotECMPeripGPU ;
namespace patch{
template <typename T> std::string to_string (const T& n)
{
std:: ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
__device__
void DefineECMStiffnessAndLknot ( EType nodeType, double & stiffness, double & sponLen) {
if (nodeType==excm) {
stiffness=stiffnessECMBasalGPU ; //* stiffness ;
sponLen=lknotECMBasalGPU ;
}
if (nodeType==perip) {
stiffness=stiffnessECMPeripGPU ; //*stiffness ;
sponLen=lknotECMPeripGPU ; // 0.1 ;
}
if (nodeType==bc2) {
stiffness=stiffnessECMBCGPU; // *stiffness ;
sponLen=lknotECMBCGPU ;// _sponLen ;
}
}
__device__
double calMorse_ECM(const double& linkLength ) {
double forceValue=0.0 ;
if (linkLength > sceInterCell_ECM[4]) {
forceValue = 0;
} else {
forceValue = -sceInterCell_ECM[0] / sceInterCell_ECM[2]
* exp(-linkLength / sceInterCell_ECM[2])
+ sceInterCell_ECM[1] / sceInterCell_ECM[3]
* exp(-linkLength / sceInterCell_ECM[3]);
// if (forceValue > 0) {
// forceValue = 0;
// }
}
return (forceValue) ;
}
__device__
double calMorseEnergy_ECM(const double& linkLength ) {
double energyValue=0.0 ;
if (linkLength > sceInterCell_ECM[4]) {
energyValue = 0;
} else {
energyValue = sceInterCell_ECM[0]* exp(-linkLength / sceInterCell_ECM[2])
- sceInterCell_ECM[1]* exp(-linkLength / sceInterCell_ECM[3]);
}
return (energyValue) ;
}
/*
__device__
double calWLC_ECM(const double& linkLength ) {
double x=linkLength/wLCPara_ECM[0] ;
return (wLCPara_ECM[1]*( 6*x+ ( x*x*(3.0-2*x))/( (1-x)*(1-x) ) )
-wLCPara_ECM[2]/pow(linkLength,wLCPara_ECM[3]) ) ;
}
*/
__device__
bool IsValidAdhPair(const double& dist ) {
if (dist > restLenECMAdhSpringGPU && dist < maxLenECMAdhSpringGPU){
return true ;
}
else {
return false ;
}
}
__device__
bool IsValidAdhPairForNotInitPhase(const double& dist ) {
if (dist > restLenECMAdhSpringGPU){
return true ;
}
else {
return false ;
}
}
__device__
double CalAdhECM(const double& dist ) {
return (kAdhECMGPU*(dist-restLenECMAdhSpringGPU));
// in the function IsValid pair, distance already checked to be greater than neutral length
}
__device__
double CalAdhEnergy(const double& dist ) {
return (0.5*kAdhECMGPU*(dist-restLenECMAdhSpringGPU)*(dist-restLenECMAdhSpringGPU));
// in the function IsValid pair, distance already checked to be greater than neutral length
}
EType SceECM:: ConvertStringToEType(string eNodeRead) {
if (eNodeRead=="perip") {
return perip ;
}
else if (eNodeRead=="bc2") {
return bc2 ;
}
else if (eNodeRead=="excm") {
return excm ;
}
else {
cout << "Error in defining type of external nodes" << endl ;
return excm ;// To just return something to avoid compiler complain
}
}
SceECM::SceECM() {
eCMRemoved=false ;
}
void SceECM::Initialize(uint maxAllNodePerCellECM, uint maxMembrNodePerCellECM, uint maxTotalNodesECM, int freqPlotData, string uniqueSymbolOutput) {
maxAllNodePerCell=maxAllNodePerCellECM ;
maxMembrNodePerCell= maxMembrNodePerCellECM ;
maxTotalNodes=maxTotalNodesECM ; //Ali
this->freqPlotData=freqPlotData ;
this->uniqueSymbolOutput=uniqueSymbolOutput ;
std::fstream readCoord_ECM ;
std::fstream readInput_ECM ;
int numberNodes_ECM ;
double tmpPosX_ECM,tmpPosY_ECM ;
vector<double> posXIni_ECM,posYIni_ECM ;
vector <EType> eNodeVec ;
readCoord_ECM.open("./resources/coordinate_ECM21.txt") ;
if (readCoord_ECM.is_open()) {
cout << "ECM coordinates file opened successfully" <<endl ;
}
else {
cout << "ECM coordinates file is not opened successfully" << endl ;
}
string inputInfoText ;
string eNodeRead ;
readCoord_ECM>>numberNodes_ECM ;
for (int i=0 ; i<numberNodes_ECM ; i++){
readCoord_ECM>>tmpPosX_ECM>>tmpPosY_ECM>>eNodeRead ;
posXIni_ECM.push_back(tmpPosX_ECM) ;
posYIni_ECM.push_back(tmpPosY_ECM) ;
EType eNode=ConvertStringToEType(eNodeRead) ;
eNodeVec.push_back(eNode) ;
}
readInput_ECM.open("./resources/ECM_input.txt") ;
if (readInput_ECM.is_open()) {
cout << "ECM Mech input opened successfully" <<endl ;
}
else {
cout << "ECM Mech input is not opened successfully" << endl ;
}
readInput_ECM>> inputInfoText ;
for (int i=0 ; i<5; i++) {
readInput_ECM>> mechPara_ECM.sceInterCellCPU_ECM[i] ; //=39.0 ;
}
// readInput_ECM>>restLenECMSpring ;
// readInput_ECM>>eCMLinSpringStiff ;
readInput_ECM>>restLenECMAdhSpring ;
readInput_ECM>>maxLenECMAdhSpring ;
readInput_ECM>>kAdhECM ;
//for ( int i=0 ; i<4 ; i++) {
// readInput_ECM>>mechPara_ECM.wLCParaCPU_ECM[i] ;
// }
std::fstream secondInput_ECM ;
std:: string secondInputInfo ; //dummy
std::string secondInputFileName = "./resources/ECM_" + uniqueSymbolOutput + "input.cfg";
secondInput_ECM.open(secondInputFileName.c_str()) ;
if (secondInput_ECM.is_open()) {
cout << "Second ECM Mech input opened successfully" <<endl ;
}
else {
cout << "Second ECM Mech input is not opened successfully" << endl ;
}
secondInput_ECM>>secondInputInfo ; // just for information no use in the code
secondInput_ECM>>stiffnessECMBasal ;
secondInput_ECM>>stiffnessECMBC ;
secondInput_ECM>>stiffnessECMPerip ;
secondInput_ECM>>lknotECMBasal ;
secondInput_ECM>>lknotECMBC ;
secondInput_ECM>>lknotECMPerip ;
cout <<" stiffness of ECM at the basal side is="<<stiffnessECMBasal <<endl ;
cout <<" stiffness of ECM at boundary is="<<stiffnessECMBC<<endl ;
cout <<" stiffness of ECM peripodial side is="<<stiffnessECMPerip<<endl ;
cout <<" rest len basal ECM is="<<lknotECMBasal<<endl ;
cout <<" rest len boundary ECM is= "<<lknotECMBC<<endl ;
cout << "rest len peripodial ECM is=" <<lknotECMPerip <<endl ;
cout<< "number of ECM nodes is"<< numberNodes_ECM <<endl ;
//for (int i=0 ; i<posXIni_ECM.size() ; i++){
// cout << "ECM nodes read in cpu"<<endl;
// cout << posXIni_ECM[i] <<", "<<posYIni_ECM[i]<<", " << eNodeVec[i] <<endl; ;
//}
for (int i=0 ; i<5; i++) {
cout <<"Morse parameter number"<<i<<" is " <<mechPara_ECM.sceInterCellCPU_ECM[i]<<endl ;
}
//cout <<"rest length of ECM spring is "<<restLenECMSpring<<endl ;
// cout <<"ECM spring stiffness is "<<eCMLinSpringStiff<<endl ;
cout <<"ECM Membrane neutral adhesion length is "<<restLenECMAdhSpring<<endl ;
cout <<"ECM Membrane max adhesion length is "<<maxLenECMAdhSpring<<endl ;
cout <<"ECM Membrane adhesion stiffness is "<<kAdhECM<<endl ;
cout << "ECM only applies adhesvie force" << endl ;
//for ( int i=0 ; i<4 ; i++) {
// cout<<"wLC parameter "<< i << " is "<<mechPara_ECM.wLCParaCPU_ECM[i]<<endl ; ;
//}
hipMemcpyToSymbol(sceInterCell_ECM,mechPara_ECM.sceInterCellCPU_ECM
,5*sizeof(double));
//hipMemcpyToSymbol(wLCPara_ECM,mechPara_ECM.wLCParaCPU_ECM
// ,4*sizeof(double));
hipMemcpyToSymbol(restLenECMAdhSpringGPU, &restLenECMAdhSpring,sizeof(double));
hipMemcpyToSymbol(maxLenECMAdhSpringGPU, &maxLenECMAdhSpring,sizeof(double));
hipMemcpyToSymbol(kAdhECMGPU, &kAdhECM,sizeof(double));
hipMemcpyToSymbol(stiffnessECMPeripGPU, &stiffnessECMPerip,sizeof(double));
hipMemcpyToSymbol(stiffnessECMBCGPU, &stiffnessECMBC,sizeof(double));
hipMemcpyToSymbol(stiffnessECMBasalGPU, &stiffnessECMBasal,sizeof(double));
hipMemcpyToSymbol(lknotECMPeripGPU, & lknotECMPerip,sizeof(double));
hipMemcpyToSymbol(lknotECMBCGPU, & lknotECMBC,sizeof(double));
hipMemcpyToSymbol(lknotECMBasalGPU, & lknotECMBasal,sizeof(double));
counter=100000 ; //large number
lastPrintECM=1000000 ; // large number
outputFrameECM=0 ;
numNodesECM= numberNodes_ECM ; //(eCMMaxX-eCMMinX)/eCMMinDist ;
indexECM.resize(numNodesECM,0) ;
peripORexcm.resize(numNodesECM,perip) ;
nodeECMLocX.resize(numNodesECM,0.0) ;
nodeECMLocY.resize(numNodesECM,0.0) ;
cellNeighborId.resize(numNodesECM,-1) ;
stiffLevel.resize(numNodesECM) ;
sponLen.resize(numNodesECM) ;
linSpringForceECMX.resize(numNodesECM,0.0);
linSpringForceECMY.resize(numNodesECM,0.0);
linSpringAvgTension.resize(numNodesECM,0.0);
linSpringEnergy.resize(numNodesECM,0.0);
morseEnergy.resize(numNodesECM,0.0);
adhEnergy.resize(numNodesECM,0.0);
bendSpringForceECMX.resize(numNodesECM,0.0);
bendSpringForceECMY.resize(numNodesECM,0.0);
memMorseForceECMX.resize(numNodesECM,0.0);
memMorseForceECMY.resize(numNodesECM,0.0);
fBendCenterX.resize(numNodesECM,0.0);
fBendCenterY.resize(numNodesECM,0.0);
fBendLeftX.resize(numNodesECM,0.0);
fBendLeftY.resize(numNodesECM,0.0);
fBendRightX.resize(numNodesECM,0.0);
fBendRightY.resize(numNodesECM,0.0);
totalForceECMX.resize(numNodesECM,0.0);
totalForceECMY.resize(numNodesECM,0.0);
//memNodeType.resize(maxTotalNodes,notAssigned1) ;
thrust::sequence (indexECM.begin(),indexECM.begin()+numNodesECM);
//thrust::fill (peripORexcm.begin(),peripORexcm.begin()+604,excm );
//thrust::fill (peripORexcm.begin()+1166,peripORexcm.end(),excm );
//thrust::fill (peripORexcm.begin(),peripORexcm.begin()+int(numNodesECM/2),excm );
//thrust::fill (peripORexcm.begin(),peripORexcm.begin()+int(numNodesECM/2),excm );
thrust::copy(posXIni_ECM.begin(),posXIni_ECM.end(),nodeECMLocX.begin()) ;
thrust::copy(posYIni_ECM.begin(),posYIni_ECM.end(),nodeECMLocY.begin()) ;
thrust::copy(eNodeVec.begin(),eNodeVec.end(),peripORexcm.begin()) ;
//cout << "GPU level initial coordinates and type of external nodes are: " << endl ;
//for (int i=0; i<nodeECMLocX.size() ; i++) {
// cout<< nodeECMLocX[i]<<", "<<nodeECMLocY[i]<<", "<<peripORexcm[i] << endl;
//}
PrintECM(0.0) ;
std::string cSVFileName = "./ECMFolder/EnergyExport_" + uniqueSymbolOutput + ".CSV";
ofstream EnergyExport ;
EnergyExport.open(cSVFileName.c_str());
EnergyExport <<"Time,"<<"TotalMorseEnergyECM," << "TotalAdhEnergyECM,"<<"TotalLinSpringEnergy,"<<"TotalEnergy, " <<"TotalEnergyDerivative"<< std::endl;
} //initilaization function finished
void SceECM:: ApplyECMConstrain(int currentActiveCellCount, int totalNodeCountForActiveCellsECM, double curTime, double dt, double Damp_Coef, bool cellPolar, bool subCellPolar, bool isInitPhase){
if (eCMRemoved) {
PrintECMRemoved(curTime);
return ;
}
#ifdef debugModeECM
hipEvent_t start1, start2, start3, start4, start5, start6, start7, start8, stop;
float elapsedTime1, elapsedTime2, elapsedTime3, elapsedTime4, elapsedTime5, elapsedTime6, elapsedTime7 , elapsedTime8 ;
hipEventCreate(&start1);
hipEventCreate(&start2);
hipEventCreate(&start3);
hipEventCreate(&start4);
hipEventCreate(&start5);
hipEventCreate(&start6);
hipEventCreate(&start7);
hipEventCreate(&start8);
hipEventCreate(&stop);
hipEventRecord(start1, 0);
#endif
thrust::counting_iterator<int> iBegin(0) ;
nodeDeviceTmpLocX.resize(totalNodeCountForActiveCellsECM,0.0) ;
nodeDeviceTmpLocY.resize(totalNodeCountForActiveCellsECM,0.0) ;
//isBasalMemNode.resize(totalNodeCountForActiveCellsECM,false) ;
adhPairECM_Cell.resize(totalNodeCountForActiveCellsECM,-1) ;
morseEnergyCell.resize(totalNodeCountForActiveCellsECM,0.0);
adhEnergyCell.resize(totalNodeCountForActiveCellsECM,0.0);
thrust::copy(nodesPointerECM->getInfoVecs().nodeLocX.begin(),nodesPointerECM->getInfoVecs().nodeLocX.begin()+totalNodeCountForActiveCellsECM,nodeDeviceTmpLocX.begin()) ;
thrust::copy(nodesPointerECM->getInfoVecs().nodeLocY.begin(),nodesPointerECM->getInfoVecs().nodeLocY.begin()+totalNodeCountForActiveCellsECM,nodeDeviceTmpLocY.begin()) ;
//cout << " max all node per cell in ECM module is " << maxAllNodePerCell << endl ;
//cout<< "max membrane node per cell in ECM module is " << maxMembrNodePerCell<< endl ;
//cout<< "I am in ECM module and dt is: " << dt << endl ;
#ifdef debugModeECM
hipEventRecord(start2, 0);
hipEventSynchronize(start2);
hipEventElapsedTime(&elapsedTime1, start1, start2);
#endif
double eCMBendStiff=6.0 ; // need to be an input
//if (cellPolar) {eCMLinSpringStiff=100 ; }
//if (subCellPolar) {eCMLinSpringStiff=100 ; }
//cout << "test to make sure ECM class reads cells class variables "<< cellsPointerECM->getCellInfoVecs().basalLocX[0] << endl ;
//cout << "test to make sure ECM class reads cells class variables "<< cellsPointerECM->getCellInfoVecs().basalLocY[0] << endl ;
double* nodeECMLocXAddr= thrust::raw_pointer_cast (
&nodeECMLocX[0]) ;
double* nodeECMLocYAddr= thrust::raw_pointer_cast (
&nodeECMLocY[0]) ;
EType* peripORexcmAddr= thrust::raw_pointer_cast (
&peripORexcm[0]) ;
// move the nodes of epithelial cells
//// find the closest ECM node to each each cell //
int numCells = cellsPointerECM->getCellInfoVecs().basalLocX.size() ;
counter ++ ;
if (counter>=100 || curTime<(100*dt)) {
counter=0 ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
cellsPointerECM->getCellInfoVecs().basalLocX.begin(),
cellsPointerECM->getCellInfoVecs().basalLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
cellsPointerECM->getCellInfoVecs().basalLocX.begin(),
cellsPointerECM->getCellInfoVecs().basalLocY.begin()))+numCells,
cellsPointerECM->getCellInfoVecs().eCMNeighborId.begin(),
FindECMNeighborPerCell(nodeECMLocXAddr,nodeECMLocYAddr,numNodesECM ));
double * basalCellLocXAddr= thrust::raw_pointer_cast ( & ( cellsPointerECM->getCellInfoVecs().basalLocX[0]) ) ;
double * basalCellLocYAddr= thrust::raw_pointer_cast ( & ( cellsPointerECM->getCellInfoVecs().basalLocY[0]) ) ;
// int numCells = cellsPointerECM->getCellInfoVecs().basalLocX.size() ;
//cout << " Number of cells in ECM class is equal to " << numCells << endl;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin()))+numNodesECM,
cellNeighborId.begin(),
FindCellNeighborPerECMNode(basalCellLocXAddr,basalCellLocYAddr, numCells));
}
thrust::counting_iterator<int> iBegin2(0) ;
//////////////////////////////////////////
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
make_permutation_iterator(
cellsPointerECM->getCellInfoVecs().eCMNeighborId.begin(),
make_transform_iterator(iBegin2,
DivideFunctor2(
maxAllNodePerCell))),
make_transform_iterator (iBegin,
DivideFunctor2(maxAllNodePerCell)),
make_transform_iterator (iBegin,
ModuloFunctor2(maxAllNodePerCell)),
nodesPointerECM->getInfoVecs().nodeLocX.begin(),
nodesPointerECM->getInfoVecs().nodeLocY.begin(),
nodesPointerECM->getInfoVecs().nodeIsActive.begin(),
nodesPointerECM->getInfoVecs().memNodeType1.begin()
)),
thrust::make_zip_iterator (
thrust:: make_tuple (
make_permutation_iterator(
cellsPointerECM->getCellInfoVecs().eCMNeighborId.begin(),
make_transform_iterator(iBegin2,
DivideFunctor2(
maxAllNodePerCell))),
make_transform_iterator (iBegin,
DivideFunctor2(maxAllNodePerCell)),
make_transform_iterator (iBegin,
ModuloFunctor2(maxAllNodePerCell)),
nodesPointerECM->getInfoVecs().nodeLocX.begin(),
nodesPointerECM->getInfoVecs().nodeLocY.begin(),
nodesPointerECM->getInfoVecs().nodeIsActive.begin(),
nodesPointerECM->getInfoVecs().memNodeType1.begin()
))+totalNodeCountForActiveCellsECM,
thrust::make_zip_iterator (
thrust::make_tuple (
nodesPointerECM->getInfoVecs().nodeLocX.begin(),
nodesPointerECM->getInfoVecs().nodeLocY.begin(),
adhPairECM_Cell.begin(),
morseEnergyCell.begin(),
adhEnergyCell.begin())),
MoveNodes2_Cell(nodeECMLocXAddr,nodeECMLocYAddr,maxMembrNodePerCell,numNodesECM,dt,Damp_Coef,isInitPhase,peripORexcmAddr,curTime,currentActiveCellCount));
#ifdef debugModeECM
hipEventRecord(start3, 0);
hipEventSynchronize(start3);
hipEventElapsedTime(&elapsedTime2, start2, start3);
#endif
/* To reduce computational cost
energyECM.totalMorseEnergyCellECM = thrust::reduce( morseEnergyCell.begin(),morseEnergyCell.begin()+totalNodeCountForActiveCellsECM,(double) 0.0, thrust::plus<double>() );
energyECM.totalAdhEnergyCellECM = thrust::reduce( adhEnergyCell.begin() ,adhEnergyCell.begin() +totalNodeCountForActiveCellsECM,(double) 0.0, thrust::plus<double>() );
*/
bool* nodeIsActiveAddr= thrust::raw_pointer_cast (
& (nodesPointerECM->getInfoVecs().nodeIsActive[0])) ;
int * adhPairECM_CellAddr= thrust::raw_pointer_cast (
&adhPairECM_Cell[0]) ;
thrust:: transform (peripORexcm.begin(), peripORexcm.begin()+numNodesECM,
thrust::make_zip_iterator (thrust::make_tuple (
stiffLevel.begin(),
sponLen.begin() ))
,MechProp(isInitPhase));
double* stiffLevelAddr=thrust::raw_pointer_cast (
&stiffLevel[0]) ;
double* sponLenAddr =thrust::raw_pointer_cast (
&sponLen[0]) ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
linSpringForceECMX.begin(),
linSpringForceECMY.begin(),
linSpringAvgTension.begin(),
linSpringEnergy.begin())),
LinSpringForceECM(numNodesECM,nodeECMLocXAddr,nodeECMLocYAddr,stiffLevelAddr,sponLenAddr));
//////////////////////////////////// find the closest Cell to each ECM node ///////////
///////////////////////////////////
//cout << " I am after FindCellNeighbor functor" << endl ;
#ifdef debugModeECM
hipEventRecord(start4, 0);
hipEventSynchronize(start4);
hipEventElapsedTime(&elapsedTime3, start3, start4);
#endif
//energyECM.totalLinSpringEnergyECM = 0.5 * ( thrust::reduce( linSpringEnergy.begin(),linSpringEnergy.begin()+numNodesECM,(double) 0.0, thrust::plus<double>() ));
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
fBendCenterX.begin(),
fBendCenterY.begin(),
fBendLeftX.begin(),
fBendLeftY.begin(),
fBendRightX.begin(),
fBendRightY.begin())),
CalBendECM(nodeECMLocXAddr,nodeECMLocYAddr,numNodesECM,eCMBendStiff));
#ifdef debugModeECM
hipEventRecord(start5, 0);
hipEventSynchronize(start5);
hipEventElapsedTime(&elapsedTime4, start4, start5);
#endif
double* fBendLeftXAddr= thrust::raw_pointer_cast (
&fBendLeftX[0]) ;
double* fBendLeftYAddr= thrust::raw_pointer_cast (
&fBendLeftY[0]) ;
double* fBendRightXAddr= thrust::raw_pointer_cast (
&fBendRightX[0]) ;
double* fBendRightYAddr= thrust::raw_pointer_cast (
&fBendRightY[0]) ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
fBendCenterX.begin(),
fBendCenterY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
fBendCenterX.begin(),
fBendCenterY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
bendSpringForceECMX.begin(),
bendSpringForceECMY.begin())),
SumBendForce(fBendLeftXAddr,fBendLeftYAddr,fBendRightXAddr,fBendRightYAddr,numNodesECM));
#ifdef debugModeECM
hipEventRecord(start6, 0);
hipEventSynchronize(start6);
hipEventElapsedTime(&elapsedTime5, start5, start6);
#endif
//to make sure it is based on the distance used for action force calculation.
double* nodeCellLocXAddr= thrust::raw_pointer_cast (
&nodeDeviceTmpLocX[0]) ;
double* nodeCellLocYAddr= thrust::raw_pointer_cast (
&nodeDeviceTmpLocY[0]) ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin(),
cellNeighborId.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin(),
cellNeighborId.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
memMorseForceECMX.begin(),
memMorseForceECMY.begin(),
morseEnergy.begin(),
adhEnergy.begin())),
MorseAndAdhForceECM(numCells,maxAllNodePerCell,maxMembrNodePerCell,nodeCellLocXAddr,nodeCellLocYAddr,nodeIsActiveAddr,adhPairECM_CellAddr));
//cout << " I am after MorseAndAdhForceECM functor" << endl ;
#ifdef debugModeECM
hipEventRecord(start7, 0);
hipEventSynchronize(start7);
hipEventElapsedTime(&elapsedTime6, start6, start7);
#endif
/* To reduce computational cost
energyECM.totalMorseEnergyECMCell = thrust::reduce( morseEnergy.begin(),morseEnergy.begin()+numNodesECM,(double) 0.0, thrust::plus<double>() );
energyECM.totalAdhEnergyECMCell = thrust::reduce( adhEnergy.begin() ,adhEnergy.begin() +numNodesECM,(double) 0.0, thrust::plus<double>() );
*/
double dummy=0.0 ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
linSpringForceECMX.begin(),
linSpringForceECMY.begin(),
bendSpringForceECMX.begin(),
bendSpringForceECMY.begin(),
memMorseForceECMX.begin(),
memMorseForceECMY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
linSpringForceECMX.begin(),
linSpringForceECMY.begin(),
bendSpringForceECMX.begin(),
bendSpringForceECMY.begin(),
memMorseForceECMX.begin(),
memMorseForceECMY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
totalForceECMX.begin(),
totalForceECMY.begin())),
TotalECMForceCompute(dummy));
#ifdef debugModeECM
hipEventRecord(start8, 0);
hipEventSynchronize(start8);
hipEventElapsedTime(&elapsedTime7, start7, start8);
#endif
double Damp_CoefECM=Damp_Coef ;
double Damp_CoefPerip=Damp_Coef ;
// move the nodes of ECM
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin(),
totalForceECMX.begin(),
totalForceECMY.begin(),
indexECM.begin(),
peripORexcm.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin(),
totalForceECMX.begin(),
totalForceECMY.begin(),
indexECM.begin(),
peripORexcm.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin())),
MoveNodeECM(dt,Damp_CoefECM,Damp_CoefPerip,numNodesECM,curTime));
/* To reduce computational cost
cout << "total Morse energy for cell-ECM is= "<< energyECM.totalMorseEnergyCellECM << endl ;
cout << "total Morse energy for ECM-cell is= "<< energyECM.totalMorseEnergyECMCell << endl ;
cout << "total adhesion energy for cell-ECM is= "<< energyECM.totalAdhEnergyCellECM << endl ;
cout << "total adhesion energy for ECM-cell is= "<< energyECM.totalAdhEnergyECMCell << endl ;
//assert (abs (energyECM.totalMorseEnergyCellECM-energyECM.totalMorseEnergyECMCell)<1.0) ;
//assert (abs (energyECM.totalAdhEnergyCellECM- energyECM.totalAdhEnergyECMCell) <1.0) ;
if ( (abs (energyECM.totalMorseEnergyCellECM-energyECM.totalMorseEnergyECMCell)>1.0) ||
(abs (energyECM.totalAdhEnergyCellECM- energyECM.totalAdhEnergyECMCell) >1.0)
) {
cout << "Warning: Action and reaction forces in the ECM do not match each other" << endl ;
}
*/
# ifdef debugModeECM
hipEventRecord(stop, 0);
hipEventSynchronize(stop);
hipEventElapsedTime(&elapsedTime8, start8, stop);
std::cout << "time 1 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime1 << endl ;
std::cout << "time 2 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime2 << endl ;
std::cout << "time 3 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime3 << endl ;
std::cout << "time 4 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime4 << endl ;
std::cout << "time 5 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime5 << endl ;
std::cout << "time 6 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime6 << endl ;
std::cout << "time 7 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime7 << endl ;
std::cout << "time 8 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime8 << endl ;
#endif
PrintECM(curTime);
}
void SceECM:: PrintECM(double curTime) {
lastPrintECM=lastPrintECM+1 ;
if (lastPrintECM>=freqPlotData) {
outputFrameECM++ ;
lastPrintECM=0 ;
cout << " I am in regular print function" << endl ;
// First ECM output file for paraview //
std::string vtkFileName = "./ECMFolder/ECM_" + uniqueSymbolOutput +patch::to_string(outputFrameECM-1) + ".vtk";
ofstream ECMOut;
ECMOut.open(vtkFileName.c_str());
ECMOut<< "# vtk DataFile Version 3.0" << endl;
ECMOut<< "Result for paraview 2d code" << endl;
ECMOut << "ASCII" << endl;
ECMOut << "DATASET UNSTRUCTURED_GRID" << std::endl;
ECMOut << "POINTS " << nodeECMLocX.size() << " float" << std::endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut << nodeECMLocX[i] << " " << nodeECMLocY[i] << " "
<< 0.0 << std::endl;
}
ECMOut<< std::endl;
ECMOut<< "CELLS " << nodeECMLocX.size()<< " " << 3 *nodeECMLocX.size()<< std::endl;
for (uint i = 0; i < (nodeECMLocX.size()-1); i++) {
ECMOut << 2 << " " << indexECM[i] << " "
<< indexECM[i+1] << std::endl;
}
ECMOut << 2 << " " << indexECM[nodeECMLocX.size()-1] << " "<< indexECM[0] << std::endl; //last point to the first point
ECMOut << "CELL_TYPES " << nodeECMLocX.size()<< endl;
for (uint i = 0; i < nodeECMLocX.size() ; i++) {
ECMOut << "3" << endl;
}
ECMOut << "POINT_DATA "<<nodeECMLocX.size() <<endl ;
ECMOut << "SCALARS Avg_Tension " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<linSpringAvgTension[i] <<endl ;
}
ECMOut << "SCALARS Node_Type " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<peripORexcm[i] <<endl ;
}
ECMOut.close();
// second output file for curvature estimation //
std::string txtFileName = "./ECMFolder/ECMLocationExport_" + uniqueSymbolOutput+ patch::to_string(outputFrameECM-1) + ".txt";
ofstream ECMLocationExport ;
ECMLocationExport.open(txtFileName.c_str());
//ECMExport << "ECM pouch coordinates" << std::endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
// if (peripORexcm[i]==excm) {
ECMLocationExport<< nodeECMLocX[i] << " " << nodeECMLocY[i] << " " << 0.0 << " "<< peripORexcm[i]<<std::endl;
// }
}
//ECMExport << "ECM lumen side coordinates" << std::endl;
// for (uint i = 0; i < nodeECMLocX.size(); i++) {
// if (peripORexcm[i]==perip) {
// ECMLocationExport << nodeECMLocX[i] << " " << nodeECMLocY[i] << " "
// << 0.0 << std::endl;
// }
// }
ECMLocationExport.close();
//Third write file for ECM
txtFileName = "./ECMFolder/ECMTensionExport_" + uniqueSymbolOutput+ patch::to_string(outputFrameECM-1) + ".txt";
ofstream ECMTensionExport ;
ECMTensionExport.open(txtFileName.c_str());
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMTensionExport<< linSpringAvgTension[i]<< " " << peripORexcm[i]<< std::endl;
}
ECMTensionExport.close();
///
//Fourth write file for ECM
energyECM.totalEnergyECMOld=energyECM.totalEnergyECM ;
energyECM.totalEnergyECM= energyECM.totalMorseEnergyECMCell
+ energyECM.totalAdhEnergyECMCell
+ energyECM.totalLinSpringEnergyECM ;
std::string cSVFileName = "./ECMFolder/EnergyExport_" + uniqueSymbolOutput+ ".CSV";
ofstream EnergyExport ;
EnergyExport.open(cSVFileName.c_str(),ofstream::app);
//EnergyExport <<"totalMorseEnergyCell " << "totalAdhEnergyCell "<< "totalMorseEnergy "<<"totalAdhEnergy "<< "totalLinSpringEnergy " << std::endl;
EnergyExport <<curTime<<","<<energyECM.totalMorseEnergyECMCell << "," << energyECM.totalAdhEnergyECMCell<< "," << energyECM.totalLinSpringEnergyECM <<"," << energyECM.totalEnergyECM <<","<<energyECM.totalEnergyPrimeECM <<std::endl;
}
}
// This is just to create a file to be able to generate the movie with consisten frames
void SceECM:: PrintECMRemoved(double curTime) {
lastPrintECM=lastPrintECM+1 ;
if (lastPrintECM>=freqPlotData) {
outputFrameECM++ ;
lastPrintECM=0 ;
cout << " I am in ECM removed print function" << endl ;
// First ECM output file for paraview //
std::string vtkFileName = "./ECMFolder/ECM_" + uniqueSymbolOutput +patch::to_string(outputFrameECM-1) + ".vtk";
ofstream ECMOut;
ECMOut.open(vtkFileName.c_str());
ECMOut<< "# vtk DataFile Version 3.0" << endl;
ECMOut<< "Result for paraview 2d code" << endl;
ECMOut << "ASCII" << endl;
ECMOut << "DATASET UNSTRUCTURED_GRID" << std::endl;
ECMOut << "POINTS " << nodeECMLocX.size() << " float" << std::endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut << -500.0 << " " << -500.0 << " "
<< 0.0 << std::endl; // Just out of domain
}
ECMOut<< std::endl;
ECMOut<< "CELLS " << nodeECMLocX.size()<< " " << 3 *nodeECMLocX.size()<< std::endl;
for (uint i = 0; i < (nodeECMLocX.size()-1); i++) {
ECMOut << 2 << " " << indexECM[i] << " "
<< indexECM[i+1] << std::endl;
}
ECMOut << 2 << " " << indexECM[nodeECMLocX.size()-1] << " "<< indexECM[0] << std::endl; //last point to the first point
ECMOut << "CELL_TYPES " << nodeECMLocX.size()<< endl;
for (uint i = 0; i < nodeECMLocX.size() ; i++) {
ECMOut << "3" << endl;
}
ECMOut << "POINT_DATA "<<nodeECMLocX.size() <<endl ;
ECMOut << "SCALARS Avg_Tension " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<linSpringAvgTension[i] <<endl ;
}
ECMOut << "SCALARS Node_Type " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<peripORexcm[i] <<endl ;
}
ECMOut.close();
}
}
| 3db78232ab29c965c42c21c4af8636ab07e2296c.cu | #include "SceECM.h"
#include "SceCells.h"
//# define debugModeECM
// task: frequency of plotting the ECM should be imported. Right now is given explicitly
// bending stiffness is given inside the code. It should be given as in input from a txt file.
//isInitPhase bool variable is not active anymore.
__constant__ double sceInterCell_ECM[5];
//__constant__ double wLCPara_ECM[4];
__constant__ double restLenECMAdhSpringGPU ;
__constant__ double maxLenECMAdhSpringGPU ;
__constant__ double kAdhECMGPU ;
__constant__ double stiffnessECMBasalGPU ;
__constant__ double stiffnessECMBCGPU ;
__constant__ double stiffnessECMPeripGPU ;
__constant__ double lknotECMBasalGPU ;
__constant__ double lknotECMBCGPU ;
__constant__ double lknotECMPeripGPU ;
namespace patch{
template <typename T> std::string to_string (const T& n)
{
std:: ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
__device__
void DefineECMStiffnessAndLknot ( EType nodeType, double & stiffness, double & sponLen) {
if (nodeType==excm) {
stiffness=stiffnessECMBasalGPU ; //* stiffness ;
sponLen=lknotECMBasalGPU ;
}
if (nodeType==perip) {
stiffness=stiffnessECMPeripGPU ; //*stiffness ;
sponLen=lknotECMPeripGPU ; // 0.1 ;
}
if (nodeType==bc2) {
stiffness=stiffnessECMBCGPU; // *stiffness ;
sponLen=lknotECMBCGPU ;// _sponLen ;
}
}
__device__
double calMorse_ECM(const double& linkLength ) {
double forceValue=0.0 ;
if (linkLength > sceInterCell_ECM[4]) {
forceValue = 0;
} else {
forceValue = -sceInterCell_ECM[0] / sceInterCell_ECM[2]
* exp(-linkLength / sceInterCell_ECM[2])
+ sceInterCell_ECM[1] / sceInterCell_ECM[3]
* exp(-linkLength / sceInterCell_ECM[3]);
// if (forceValue > 0) {
// forceValue = 0;
// }
}
return (forceValue) ;
}
__device__
double calMorseEnergy_ECM(const double& linkLength ) {
double energyValue=0.0 ;
if (linkLength > sceInterCell_ECM[4]) {
energyValue = 0;
} else {
energyValue = sceInterCell_ECM[0]* exp(-linkLength / sceInterCell_ECM[2])
- sceInterCell_ECM[1]* exp(-linkLength / sceInterCell_ECM[3]);
}
return (energyValue) ;
}
/*
__device__
double calWLC_ECM(const double& linkLength ) {
double x=linkLength/wLCPara_ECM[0] ;
return (wLCPara_ECM[1]*( 6*x+ ( x*x*(3.0-2*x))/( (1-x)*(1-x) ) )
-wLCPara_ECM[2]/pow(linkLength,wLCPara_ECM[3]) ) ;
}
*/
__device__
bool IsValidAdhPair(const double& dist ) {
if (dist > restLenECMAdhSpringGPU && dist < maxLenECMAdhSpringGPU){
return true ;
}
else {
return false ;
}
}
__device__
bool IsValidAdhPairForNotInitPhase(const double& dist ) {
if (dist > restLenECMAdhSpringGPU){
return true ;
}
else {
return false ;
}
}
__device__
double CalAdhECM(const double& dist ) {
return (kAdhECMGPU*(dist-restLenECMAdhSpringGPU));
// in the function IsValid pair, distance already checked to be greater than neutral length
}
__device__
double CalAdhEnergy(const double& dist ) {
return (0.5*kAdhECMGPU*(dist-restLenECMAdhSpringGPU)*(dist-restLenECMAdhSpringGPU));
// in the function IsValid pair, distance already checked to be greater than neutral length
}
EType SceECM:: ConvertStringToEType(string eNodeRead) {
if (eNodeRead=="perip") {
return perip ;
}
else if (eNodeRead=="bc2") {
return bc2 ;
}
else if (eNodeRead=="excm") {
return excm ;
}
else {
cout << "Error in defining type of external nodes" << endl ;
return excm ;// To just return something to avoid compiler complain
}
}
SceECM::SceECM() {
eCMRemoved=false ;
}
void SceECM::Initialize(uint maxAllNodePerCellECM, uint maxMembrNodePerCellECM, uint maxTotalNodesECM, int freqPlotData, string uniqueSymbolOutput) {
maxAllNodePerCell=maxAllNodePerCellECM ;
maxMembrNodePerCell= maxMembrNodePerCellECM ;
maxTotalNodes=maxTotalNodesECM ; //Ali
this->freqPlotData=freqPlotData ;
this->uniqueSymbolOutput=uniqueSymbolOutput ;
std::fstream readCoord_ECM ;
std::fstream readInput_ECM ;
int numberNodes_ECM ;
double tmpPosX_ECM,tmpPosY_ECM ;
vector<double> posXIni_ECM,posYIni_ECM ;
vector <EType> eNodeVec ;
readCoord_ECM.open("./resources/coordinate_ECM21.txt") ;
if (readCoord_ECM.is_open()) {
cout << "ECM coordinates file opened successfully" <<endl ;
}
else {
cout << "ECM coordinates file is not opened successfully" << endl ;
}
string inputInfoText ;
string eNodeRead ;
readCoord_ECM>>numberNodes_ECM ;
for (int i=0 ; i<numberNodes_ECM ; i++){
readCoord_ECM>>tmpPosX_ECM>>tmpPosY_ECM>>eNodeRead ;
posXIni_ECM.push_back(tmpPosX_ECM) ;
posYIni_ECM.push_back(tmpPosY_ECM) ;
EType eNode=ConvertStringToEType(eNodeRead) ;
eNodeVec.push_back(eNode) ;
}
readInput_ECM.open("./resources/ECM_input.txt") ;
if (readInput_ECM.is_open()) {
cout << "ECM Mech input opened successfully" <<endl ;
}
else {
cout << "ECM Mech input is not opened successfully" << endl ;
}
readInput_ECM>> inputInfoText ;
for (int i=0 ; i<5; i++) {
readInput_ECM>> mechPara_ECM.sceInterCellCPU_ECM[i] ; //=39.0 ;
}
// readInput_ECM>>restLenECMSpring ;
// readInput_ECM>>eCMLinSpringStiff ;
readInput_ECM>>restLenECMAdhSpring ;
readInput_ECM>>maxLenECMAdhSpring ;
readInput_ECM>>kAdhECM ;
//for ( int i=0 ; i<4 ; i++) {
// readInput_ECM>>mechPara_ECM.wLCParaCPU_ECM[i] ;
// }
std::fstream secondInput_ECM ;
std:: string secondInputInfo ; //dummy
std::string secondInputFileName = "./resources/ECM_" + uniqueSymbolOutput + "input.cfg";
secondInput_ECM.open(secondInputFileName.c_str()) ;
if (secondInput_ECM.is_open()) {
cout << "Second ECM Mech input opened successfully" <<endl ;
}
else {
cout << "Second ECM Mech input is not opened successfully" << endl ;
}
secondInput_ECM>>secondInputInfo ; // just for information no use in the code
secondInput_ECM>>stiffnessECMBasal ;
secondInput_ECM>>stiffnessECMBC ;
secondInput_ECM>>stiffnessECMPerip ;
secondInput_ECM>>lknotECMBasal ;
secondInput_ECM>>lknotECMBC ;
secondInput_ECM>>lknotECMPerip ;
cout <<" stiffness of ECM at the basal side is="<<stiffnessECMBasal <<endl ;
cout <<" stiffness of ECM at boundary is="<<stiffnessECMBC<<endl ;
cout <<" stiffness of ECM peripodial side is="<<stiffnessECMPerip<<endl ;
cout <<" rest len basal ECM is="<<lknotECMBasal<<endl ;
cout <<" rest len boundary ECM is= "<<lknotECMBC<<endl ;
cout << "rest len peripodial ECM is=" <<lknotECMPerip <<endl ;
cout<< "number of ECM nodes is"<< numberNodes_ECM <<endl ;
//for (int i=0 ; i<posXIni_ECM.size() ; i++){
// cout << "ECM nodes read in cpu"<<endl;
// cout << posXIni_ECM[i] <<", "<<posYIni_ECM[i]<<", " << eNodeVec[i] <<endl; ;
//}
for (int i=0 ; i<5; i++) {
cout <<"Morse parameter number"<<i<<" is " <<mechPara_ECM.sceInterCellCPU_ECM[i]<<endl ;
}
//cout <<"rest length of ECM spring is "<<restLenECMSpring<<endl ;
// cout <<"ECM spring stiffness is "<<eCMLinSpringStiff<<endl ;
cout <<"ECM Membrane neutral adhesion length is "<<restLenECMAdhSpring<<endl ;
cout <<"ECM Membrane max adhesion length is "<<maxLenECMAdhSpring<<endl ;
cout <<"ECM Membrane adhesion stiffness is "<<kAdhECM<<endl ;
cout << "ECM only applies adhesvie force" << endl ;
//for ( int i=0 ; i<4 ; i++) {
// cout<<"wLC parameter "<< i << " is "<<mechPara_ECM.wLCParaCPU_ECM[i]<<endl ; ;
//}
cudaMemcpyToSymbol(sceInterCell_ECM,mechPara_ECM.sceInterCellCPU_ECM
,5*sizeof(double));
//cudaMemcpyToSymbol(wLCPara_ECM,mechPara_ECM.wLCParaCPU_ECM
// ,4*sizeof(double));
cudaMemcpyToSymbol(restLenECMAdhSpringGPU, &restLenECMAdhSpring,sizeof(double));
cudaMemcpyToSymbol(maxLenECMAdhSpringGPU, &maxLenECMAdhSpring,sizeof(double));
cudaMemcpyToSymbol(kAdhECMGPU, &kAdhECM,sizeof(double));
cudaMemcpyToSymbol(stiffnessECMPeripGPU, &stiffnessECMPerip,sizeof(double));
cudaMemcpyToSymbol(stiffnessECMBCGPU, &stiffnessECMBC,sizeof(double));
cudaMemcpyToSymbol(stiffnessECMBasalGPU, &stiffnessECMBasal,sizeof(double));
cudaMemcpyToSymbol(lknotECMPeripGPU, & lknotECMPerip,sizeof(double));
cudaMemcpyToSymbol(lknotECMBCGPU, & lknotECMBC,sizeof(double));
cudaMemcpyToSymbol(lknotECMBasalGPU, & lknotECMBasal,sizeof(double));
counter=100000 ; //large number
lastPrintECM=1000000 ; // large number
outputFrameECM=0 ;
numNodesECM= numberNodes_ECM ; //(eCMMaxX-eCMMinX)/eCMMinDist ;
indexECM.resize(numNodesECM,0) ;
peripORexcm.resize(numNodesECM,perip) ;
nodeECMLocX.resize(numNodesECM,0.0) ;
nodeECMLocY.resize(numNodesECM,0.0) ;
cellNeighborId.resize(numNodesECM,-1) ;
stiffLevel.resize(numNodesECM) ;
sponLen.resize(numNodesECM) ;
linSpringForceECMX.resize(numNodesECM,0.0);
linSpringForceECMY.resize(numNodesECM,0.0);
linSpringAvgTension.resize(numNodesECM,0.0);
linSpringEnergy.resize(numNodesECM,0.0);
morseEnergy.resize(numNodesECM,0.0);
adhEnergy.resize(numNodesECM,0.0);
bendSpringForceECMX.resize(numNodesECM,0.0);
bendSpringForceECMY.resize(numNodesECM,0.0);
memMorseForceECMX.resize(numNodesECM,0.0);
memMorseForceECMY.resize(numNodesECM,0.0);
fBendCenterX.resize(numNodesECM,0.0);
fBendCenterY.resize(numNodesECM,0.0);
fBendLeftX.resize(numNodesECM,0.0);
fBendLeftY.resize(numNodesECM,0.0);
fBendRightX.resize(numNodesECM,0.0);
fBendRightY.resize(numNodesECM,0.0);
totalForceECMX.resize(numNodesECM,0.0);
totalForceECMY.resize(numNodesECM,0.0);
//memNodeType.resize(maxTotalNodes,notAssigned1) ;
thrust::sequence (indexECM.begin(),indexECM.begin()+numNodesECM);
//thrust::fill (peripORexcm.begin(),peripORexcm.begin()+604,excm );
//thrust::fill (peripORexcm.begin()+1166,peripORexcm.end(),excm );
//thrust::fill (peripORexcm.begin(),peripORexcm.begin()+int(numNodesECM/2),excm );
//thrust::fill (peripORexcm.begin(),peripORexcm.begin()+int(numNodesECM/2),excm );
thrust::copy(posXIni_ECM.begin(),posXIni_ECM.end(),nodeECMLocX.begin()) ;
thrust::copy(posYIni_ECM.begin(),posYIni_ECM.end(),nodeECMLocY.begin()) ;
thrust::copy(eNodeVec.begin(),eNodeVec.end(),peripORexcm.begin()) ;
//cout << "GPU level initial coordinates and type of external nodes are: " << endl ;
//for (int i=0; i<nodeECMLocX.size() ; i++) {
// cout<< nodeECMLocX[i]<<", "<<nodeECMLocY[i]<<", "<<peripORexcm[i] << endl;
//}
PrintECM(0.0) ;
std::string cSVFileName = "./ECMFolder/EnergyExport_" + uniqueSymbolOutput + ".CSV";
ofstream EnergyExport ;
EnergyExport.open(cSVFileName.c_str());
EnergyExport <<"Time,"<<"TotalMorseEnergyECM," << "TotalAdhEnergyECM,"<<"TotalLinSpringEnergy,"<<"TotalEnergy, " <<"TotalEnergyDerivative"<< std::endl;
} //initilaization function finished
void SceECM:: ApplyECMConstrain(int currentActiveCellCount, int totalNodeCountForActiveCellsECM, double curTime, double dt, double Damp_Coef, bool cellPolar, bool subCellPolar, bool isInitPhase){
if (eCMRemoved) {
PrintECMRemoved(curTime);
return ;
}
#ifdef debugModeECM
cudaEvent_t start1, start2, start3, start4, start5, start6, start7, start8, stop;
float elapsedTime1, elapsedTime2, elapsedTime3, elapsedTime4, elapsedTime5, elapsedTime6, elapsedTime7 , elapsedTime8 ;
cudaEventCreate(&start1);
cudaEventCreate(&start2);
cudaEventCreate(&start3);
cudaEventCreate(&start4);
cudaEventCreate(&start5);
cudaEventCreate(&start6);
cudaEventCreate(&start7);
cudaEventCreate(&start8);
cudaEventCreate(&stop);
cudaEventRecord(start1, 0);
#endif
thrust::counting_iterator<int> iBegin(0) ;
nodeDeviceTmpLocX.resize(totalNodeCountForActiveCellsECM,0.0) ;
nodeDeviceTmpLocY.resize(totalNodeCountForActiveCellsECM,0.0) ;
//isBasalMemNode.resize(totalNodeCountForActiveCellsECM,false) ;
adhPairECM_Cell.resize(totalNodeCountForActiveCellsECM,-1) ;
morseEnergyCell.resize(totalNodeCountForActiveCellsECM,0.0);
adhEnergyCell.resize(totalNodeCountForActiveCellsECM,0.0);
thrust::copy(nodesPointerECM->getInfoVecs().nodeLocX.begin(),nodesPointerECM->getInfoVecs().nodeLocX.begin()+totalNodeCountForActiveCellsECM,nodeDeviceTmpLocX.begin()) ;
thrust::copy(nodesPointerECM->getInfoVecs().nodeLocY.begin(),nodesPointerECM->getInfoVecs().nodeLocY.begin()+totalNodeCountForActiveCellsECM,nodeDeviceTmpLocY.begin()) ;
//cout << " max all node per cell in ECM module is " << maxAllNodePerCell << endl ;
//cout<< "max membrane node per cell in ECM module is " << maxMembrNodePerCell<< endl ;
//cout<< "I am in ECM module and dt is: " << dt << endl ;
#ifdef debugModeECM
cudaEventRecord(start2, 0);
cudaEventSynchronize(start2);
cudaEventElapsedTime(&elapsedTime1, start1, start2);
#endif
double eCMBendStiff=6.0 ; // need to be an input
//if (cellPolar) {eCMLinSpringStiff=100 ; }
//if (subCellPolar) {eCMLinSpringStiff=100 ; }
//cout << "test to make sure ECM class reads cells class variables "<< cellsPointerECM->getCellInfoVecs().basalLocX[0] << endl ;
//cout << "test to make sure ECM class reads cells class variables "<< cellsPointerECM->getCellInfoVecs().basalLocY[0] << endl ;
double* nodeECMLocXAddr= thrust::raw_pointer_cast (
&nodeECMLocX[0]) ;
double* nodeECMLocYAddr= thrust::raw_pointer_cast (
&nodeECMLocY[0]) ;
EType* peripORexcmAddr= thrust::raw_pointer_cast (
&peripORexcm[0]) ;
// move the nodes of epithelial cells
//// find the closest ECM node to each each cell //
int numCells = cellsPointerECM->getCellInfoVecs().basalLocX.size() ;
counter ++ ;
if (counter>=100 || curTime<(100*dt)) {
counter=0 ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
cellsPointerECM->getCellInfoVecs().basalLocX.begin(),
cellsPointerECM->getCellInfoVecs().basalLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
cellsPointerECM->getCellInfoVecs().basalLocX.begin(),
cellsPointerECM->getCellInfoVecs().basalLocY.begin()))+numCells,
cellsPointerECM->getCellInfoVecs().eCMNeighborId.begin(),
FindECMNeighborPerCell(nodeECMLocXAddr,nodeECMLocYAddr,numNodesECM ));
double * basalCellLocXAddr= thrust::raw_pointer_cast ( & ( cellsPointerECM->getCellInfoVecs().basalLocX[0]) ) ;
double * basalCellLocYAddr= thrust::raw_pointer_cast ( & ( cellsPointerECM->getCellInfoVecs().basalLocY[0]) ) ;
// int numCells = cellsPointerECM->getCellInfoVecs().basalLocX.size() ;
//cout << " Number of cells in ECM class is equal to " << numCells << endl;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin()))+numNodesECM,
cellNeighborId.begin(),
FindCellNeighborPerECMNode(basalCellLocXAddr,basalCellLocYAddr, numCells));
}
thrust::counting_iterator<int> iBegin2(0) ;
//////////////////////////////////////////
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
make_permutation_iterator(
cellsPointerECM->getCellInfoVecs().eCMNeighborId.begin(),
make_transform_iterator(iBegin2,
DivideFunctor2(
maxAllNodePerCell))),
make_transform_iterator (iBegin,
DivideFunctor2(maxAllNodePerCell)),
make_transform_iterator (iBegin,
ModuloFunctor2(maxAllNodePerCell)),
nodesPointerECM->getInfoVecs().nodeLocX.begin(),
nodesPointerECM->getInfoVecs().nodeLocY.begin(),
nodesPointerECM->getInfoVecs().nodeIsActive.begin(),
nodesPointerECM->getInfoVecs().memNodeType1.begin()
)),
thrust::make_zip_iterator (
thrust:: make_tuple (
make_permutation_iterator(
cellsPointerECM->getCellInfoVecs().eCMNeighborId.begin(),
make_transform_iterator(iBegin2,
DivideFunctor2(
maxAllNodePerCell))),
make_transform_iterator (iBegin,
DivideFunctor2(maxAllNodePerCell)),
make_transform_iterator (iBegin,
ModuloFunctor2(maxAllNodePerCell)),
nodesPointerECM->getInfoVecs().nodeLocX.begin(),
nodesPointerECM->getInfoVecs().nodeLocY.begin(),
nodesPointerECM->getInfoVecs().nodeIsActive.begin(),
nodesPointerECM->getInfoVecs().memNodeType1.begin()
))+totalNodeCountForActiveCellsECM,
thrust::make_zip_iterator (
thrust::make_tuple (
nodesPointerECM->getInfoVecs().nodeLocX.begin(),
nodesPointerECM->getInfoVecs().nodeLocY.begin(),
adhPairECM_Cell.begin(),
morseEnergyCell.begin(),
adhEnergyCell.begin())),
MoveNodes2_Cell(nodeECMLocXAddr,nodeECMLocYAddr,maxMembrNodePerCell,numNodesECM,dt,Damp_Coef,isInitPhase,peripORexcmAddr,curTime,currentActiveCellCount));
#ifdef debugModeECM
cudaEventRecord(start3, 0);
cudaEventSynchronize(start3);
cudaEventElapsedTime(&elapsedTime2, start2, start3);
#endif
/* To reduce computational cost
energyECM.totalMorseEnergyCellECM = thrust::reduce( morseEnergyCell.begin(),morseEnergyCell.begin()+totalNodeCountForActiveCellsECM,(double) 0.0, thrust::plus<double>() );
energyECM.totalAdhEnergyCellECM = thrust::reduce( adhEnergyCell.begin() ,adhEnergyCell.begin() +totalNodeCountForActiveCellsECM,(double) 0.0, thrust::plus<double>() );
*/
bool* nodeIsActiveAddr= thrust::raw_pointer_cast (
& (nodesPointerECM->getInfoVecs().nodeIsActive[0])) ;
int * adhPairECM_CellAddr= thrust::raw_pointer_cast (
&adhPairECM_Cell[0]) ;
thrust:: transform (peripORexcm.begin(), peripORexcm.begin()+numNodesECM,
thrust::make_zip_iterator (thrust::make_tuple (
stiffLevel.begin(),
sponLen.begin() ))
,MechProp(isInitPhase));
double* stiffLevelAddr=thrust::raw_pointer_cast (
&stiffLevel[0]) ;
double* sponLenAddr =thrust::raw_pointer_cast (
&sponLen[0]) ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
linSpringForceECMX.begin(),
linSpringForceECMY.begin(),
linSpringAvgTension.begin(),
linSpringEnergy.begin())),
LinSpringForceECM(numNodesECM,nodeECMLocXAddr,nodeECMLocYAddr,stiffLevelAddr,sponLenAddr));
//////////////////////////////////// find the closest Cell to each ECM node ///////////
///////////////////////////////////
//cout << " I am after FindCellNeighbor functor" << endl ;
#ifdef debugModeECM
cudaEventRecord(start4, 0);
cudaEventSynchronize(start4);
cudaEventElapsedTime(&elapsedTime3, start3, start4);
#endif
//energyECM.totalLinSpringEnergyECM = 0.5 * ( thrust::reduce( linSpringEnergy.begin(),linSpringEnergy.begin()+numNodesECM,(double) 0.0, thrust::plus<double>() ));
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
fBendCenterX.begin(),
fBendCenterY.begin(),
fBendLeftX.begin(),
fBendLeftY.begin(),
fBendRightX.begin(),
fBendRightY.begin())),
CalBendECM(nodeECMLocXAddr,nodeECMLocYAddr,numNodesECM,eCMBendStiff));
#ifdef debugModeECM
cudaEventRecord(start5, 0);
cudaEventSynchronize(start5);
cudaEventElapsedTime(&elapsedTime4, start4, start5);
#endif
double* fBendLeftXAddr= thrust::raw_pointer_cast (
&fBendLeftX[0]) ;
double* fBendLeftYAddr= thrust::raw_pointer_cast (
&fBendLeftY[0]) ;
double* fBendRightXAddr= thrust::raw_pointer_cast (
&fBendRightX[0]) ;
double* fBendRightYAddr= thrust::raw_pointer_cast (
&fBendRightY[0]) ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
fBendCenterX.begin(),
fBendCenterY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
fBendCenterX.begin(),
fBendCenterY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
bendSpringForceECMX.begin(),
bendSpringForceECMY.begin())),
SumBendForce(fBendLeftXAddr,fBendLeftYAddr,fBendRightXAddr,fBendRightYAddr,numNodesECM));
#ifdef debugModeECM
cudaEventRecord(start6, 0);
cudaEventSynchronize(start6);
cudaEventElapsedTime(&elapsedTime5, start5, start6);
#endif
//to make sure it is based on the distance used for action force calculation.
double* nodeCellLocXAddr= thrust::raw_pointer_cast (
&nodeDeviceTmpLocX[0]) ;
double* nodeCellLocYAddr= thrust::raw_pointer_cast (
&nodeDeviceTmpLocY[0]) ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin(),
cellNeighborId.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
indexECM.begin(),
nodeECMLocX.begin(),
nodeECMLocY.begin(),
cellNeighborId.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
memMorseForceECMX.begin(),
memMorseForceECMY.begin(),
morseEnergy.begin(),
adhEnergy.begin())),
MorseAndAdhForceECM(numCells,maxAllNodePerCell,maxMembrNodePerCell,nodeCellLocXAddr,nodeCellLocYAddr,nodeIsActiveAddr,adhPairECM_CellAddr));
//cout << " I am after MorseAndAdhForceECM functor" << endl ;
#ifdef debugModeECM
cudaEventRecord(start7, 0);
cudaEventSynchronize(start7);
cudaEventElapsedTime(&elapsedTime6, start6, start7);
#endif
/* To reduce computational cost
energyECM.totalMorseEnergyECMCell = thrust::reduce( morseEnergy.begin(),morseEnergy.begin()+numNodesECM,(double) 0.0, thrust::plus<double>() );
energyECM.totalAdhEnergyECMCell = thrust::reduce( adhEnergy.begin() ,adhEnergy.begin() +numNodesECM,(double) 0.0, thrust::plus<double>() );
*/
double dummy=0.0 ;
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
linSpringForceECMX.begin(),
linSpringForceECMY.begin(),
bendSpringForceECMX.begin(),
bendSpringForceECMY.begin(),
memMorseForceECMX.begin(),
memMorseForceECMY.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
linSpringForceECMX.begin(),
linSpringForceECMY.begin(),
bendSpringForceECMX.begin(),
bendSpringForceECMY.begin(),
memMorseForceECMX.begin(),
memMorseForceECMY.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
totalForceECMX.begin(),
totalForceECMY.begin())),
TotalECMForceCompute(dummy));
#ifdef debugModeECM
cudaEventRecord(start8, 0);
cudaEventSynchronize(start8);
cudaEventElapsedTime(&elapsedTime7, start7, start8);
#endif
double Damp_CoefECM=Damp_Coef ;
double Damp_CoefPerip=Damp_Coef ;
// move the nodes of ECM
thrust:: transform (
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin(),
totalForceECMX.begin(),
totalForceECMY.begin(),
indexECM.begin(),
peripORexcm.begin())),
thrust::make_zip_iterator (
thrust:: make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin(),
totalForceECMX.begin(),
totalForceECMY.begin(),
indexECM.begin(),
peripORexcm.begin()))+numNodesECM,
thrust::make_zip_iterator (
thrust::make_tuple (
nodeECMLocX.begin(),
nodeECMLocY.begin())),
MoveNodeECM(dt,Damp_CoefECM,Damp_CoefPerip,numNodesECM,curTime));
/* To reduce computational cost
cout << "total Morse energy for cell-ECM is= "<< energyECM.totalMorseEnergyCellECM << endl ;
cout << "total Morse energy for ECM-cell is= "<< energyECM.totalMorseEnergyECMCell << endl ;
cout << "total adhesion energy for cell-ECM is= "<< energyECM.totalAdhEnergyCellECM << endl ;
cout << "total adhesion energy for ECM-cell is= "<< energyECM.totalAdhEnergyECMCell << endl ;
//assert (abs (energyECM.totalMorseEnergyCellECM-energyECM.totalMorseEnergyECMCell)<1.0) ;
//assert (abs (energyECM.totalAdhEnergyCellECM- energyECM.totalAdhEnergyECMCell) <1.0) ;
if ( (abs (energyECM.totalMorseEnergyCellECM-energyECM.totalMorseEnergyECMCell)>1.0) ||
(abs (energyECM.totalAdhEnergyCellECM- energyECM.totalAdhEnergyECMCell) >1.0)
) {
cout << "Warning: Action and reaction forces in the ECM do not match each other" << endl ;
}
*/
# ifdef debugModeECM
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&elapsedTime8, start8, stop);
std::cout << "time 1 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime1 << endl ;
std::cout << "time 2 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime2 << endl ;
std::cout << "time 3 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime3 << endl ;
std::cout << "time 4 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime4 << endl ;
std::cout << "time 5 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime5 << endl ;
std::cout << "time 6 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime6 << endl ;
std::cout << "time 7 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime7 << endl ;
std::cout << "time 8 spent in ECM module for moving the membrane node of cells and ECM nodes are: " << elapsedTime8 << endl ;
#endif
PrintECM(curTime);
}
void SceECM:: PrintECM(double curTime) {
lastPrintECM=lastPrintECM+1 ;
if (lastPrintECM>=freqPlotData) {
outputFrameECM++ ;
lastPrintECM=0 ;
cout << " I am in regular print function" << endl ;
// First ECM output file for paraview //
std::string vtkFileName = "./ECMFolder/ECM_" + uniqueSymbolOutput +patch::to_string(outputFrameECM-1) + ".vtk";
ofstream ECMOut;
ECMOut.open(vtkFileName.c_str());
ECMOut<< "# vtk DataFile Version 3.0" << endl;
ECMOut<< "Result for paraview 2d code" << endl;
ECMOut << "ASCII" << endl;
ECMOut << "DATASET UNSTRUCTURED_GRID" << std::endl;
ECMOut << "POINTS " << nodeECMLocX.size() << " float" << std::endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut << nodeECMLocX[i] << " " << nodeECMLocY[i] << " "
<< 0.0 << std::endl;
}
ECMOut<< std::endl;
ECMOut<< "CELLS " << nodeECMLocX.size()<< " " << 3 *nodeECMLocX.size()<< std::endl;
for (uint i = 0; i < (nodeECMLocX.size()-1); i++) {
ECMOut << 2 << " " << indexECM[i] << " "
<< indexECM[i+1] << std::endl;
}
ECMOut << 2 << " " << indexECM[nodeECMLocX.size()-1] << " "<< indexECM[0] << std::endl; //last point to the first point
ECMOut << "CELL_TYPES " << nodeECMLocX.size()<< endl;
for (uint i = 0; i < nodeECMLocX.size() ; i++) {
ECMOut << "3" << endl;
}
ECMOut << "POINT_DATA "<<nodeECMLocX.size() <<endl ;
ECMOut << "SCALARS Avg_Tension " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<linSpringAvgTension[i] <<endl ;
}
ECMOut << "SCALARS Node_Type " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<peripORexcm[i] <<endl ;
}
ECMOut.close();
// second output file for curvature estimation //
std::string txtFileName = "./ECMFolder/ECMLocationExport_" + uniqueSymbolOutput+ patch::to_string(outputFrameECM-1) + ".txt";
ofstream ECMLocationExport ;
ECMLocationExport.open(txtFileName.c_str());
//ECMExport << "ECM pouch coordinates" << std::endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
// if (peripORexcm[i]==excm) {
ECMLocationExport<< nodeECMLocX[i] << " " << nodeECMLocY[i] << " " << 0.0 << " "<< peripORexcm[i]<<std::endl;
// }
}
//ECMExport << "ECM lumen side coordinates" << std::endl;
// for (uint i = 0; i < nodeECMLocX.size(); i++) {
// if (peripORexcm[i]==perip) {
// ECMLocationExport << nodeECMLocX[i] << " " << nodeECMLocY[i] << " "
// << 0.0 << std::endl;
// }
// }
ECMLocationExport.close();
//Third write file for ECM
txtFileName = "./ECMFolder/ECMTensionExport_" + uniqueSymbolOutput+ patch::to_string(outputFrameECM-1) + ".txt";
ofstream ECMTensionExport ;
ECMTensionExport.open(txtFileName.c_str());
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMTensionExport<< linSpringAvgTension[i]<< " " << peripORexcm[i]<< std::endl;
}
ECMTensionExport.close();
///
//Fourth write file for ECM
energyECM.totalEnergyECMOld=energyECM.totalEnergyECM ;
energyECM.totalEnergyECM= energyECM.totalMorseEnergyECMCell
+ energyECM.totalAdhEnergyECMCell
+ energyECM.totalLinSpringEnergyECM ;
std::string cSVFileName = "./ECMFolder/EnergyExport_" + uniqueSymbolOutput+ ".CSV";
ofstream EnergyExport ;
EnergyExport.open(cSVFileName.c_str(),ofstream::app);
//EnergyExport <<"totalMorseEnergyCell " << "totalAdhEnergyCell "<< "totalMorseEnergy "<<"totalAdhEnergy "<< "totalLinSpringEnergy " << std::endl;
EnergyExport <<curTime<<","<<energyECM.totalMorseEnergyECMCell << "," << energyECM.totalAdhEnergyECMCell<< "," << energyECM.totalLinSpringEnergyECM <<"," << energyECM.totalEnergyECM <<","<<energyECM.totalEnergyPrimeECM <<std::endl;
}
}
// This is just to create a file to be able to generate the movie with consisten frames
void SceECM:: PrintECMRemoved(double curTime) {
lastPrintECM=lastPrintECM+1 ;
if (lastPrintECM>=freqPlotData) {
outputFrameECM++ ;
lastPrintECM=0 ;
cout << " I am in ECM removed print function" << endl ;
// First ECM output file for paraview //
std::string vtkFileName = "./ECMFolder/ECM_" + uniqueSymbolOutput +patch::to_string(outputFrameECM-1) + ".vtk";
ofstream ECMOut;
ECMOut.open(vtkFileName.c_str());
ECMOut<< "# vtk DataFile Version 3.0" << endl;
ECMOut<< "Result for paraview 2d code" << endl;
ECMOut << "ASCII" << endl;
ECMOut << "DATASET UNSTRUCTURED_GRID" << std::endl;
ECMOut << "POINTS " << nodeECMLocX.size() << " float" << std::endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut << -500.0 << " " << -500.0 << " "
<< 0.0 << std::endl; // Just out of domain
}
ECMOut<< std::endl;
ECMOut<< "CELLS " << nodeECMLocX.size()<< " " << 3 *nodeECMLocX.size()<< std::endl;
for (uint i = 0; i < (nodeECMLocX.size()-1); i++) {
ECMOut << 2 << " " << indexECM[i] << " "
<< indexECM[i+1] << std::endl;
}
ECMOut << 2 << " " << indexECM[nodeECMLocX.size()-1] << " "<< indexECM[0] << std::endl; //last point to the first point
ECMOut << "CELL_TYPES " << nodeECMLocX.size()<< endl;
for (uint i = 0; i < nodeECMLocX.size() ; i++) {
ECMOut << "3" << endl;
}
ECMOut << "POINT_DATA "<<nodeECMLocX.size() <<endl ;
ECMOut << "SCALARS Avg_Tension " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<linSpringAvgTension[i] <<endl ;
}
ECMOut << "SCALARS Node_Type " << "float"<< endl;
ECMOut << "LOOKUP_TABLE " << "default"<< endl;
for (uint i = 0; i < nodeECMLocX.size(); i++) {
ECMOut<<peripORexcm[i] <<endl ;
}
ECMOut.close();
}
}
|
00fb62d11037ef4b8bedf11c731040a95d20457a.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/shuffle_channel_op.h"
#include "paddle/fluid/platform/device/gpu/gpu_info.h"
#include "paddle/fluid/platform/device/gpu/gpu_primitives.h"
namespace paddle {
namespace operators {
using Tensor = phi::DenseTensor;
static constexpr int kNumCUDAThreads = 512;
static constexpr int kNumMaximumNumBlocks = 4096;
static inline int NumBlocks(const int N) {
return ::min((N + kNumCUDAThreads - 1) / kNumCUDAThreads,
kNumMaximumNumBlocks);
}
template <typename T>
__global__ void ShuffleChannel(const int nthreads,
const int feature_map_size,
T* output,
const T* input,
int group_row,
int group_column,
int len) {
int index = blockIdx.x * blockDim.x + threadIdx.x;
int offset = blockDim.x * gridDim.x;
for (size_t ii = index; ii < nthreads; ii += offset) {
const int n = index / group_row / group_column / len;
const int i = (index / group_column / len) % group_row;
const int j = index / len % group_column;
const int k = index - (n * feature_map_size + (i * group_column + j) * len);
T* p_o = output + n * feature_map_size + (j * group_row + i) * len;
p_o[k] = input[index];
}
}
template <typename DeviceContext, typename T>
class ShuffleChannelOpCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
auto* input = ctx.Input<phi::DenseTensor>("X");
auto* output = ctx.Output<phi::DenseTensor>("Out");
int group = ctx.Attr<int>("group");
auto input_dims = input->dims();
auto num = input_dims[0];
auto channel = input_dims[1];
auto height = input_dims[2];
auto weight = input_dims[3];
auto feature_map_size = channel * height * weight;
auto sp_sz = height * weight;
int group_row = group;
int group_column = channel / group_row;
// count is the product of NCHW same as numel()
int count = num * group_column * group_row * sp_sz;
int blocks = NumBlocks(output->numel());
int threads = kNumCUDAThreads;
const T* input_data = input->data<T>();
T* output_data = output->mutable_data<T>(ctx.GetPlace());
hipLaunchKernelGGL(( ShuffleChannel<T>)
, dim3(blocks), dim3(threads), 0, ctx.cuda_device_context().stream(),
count,
feature_map_size,
output_data,
input_data,
group_row,
group_column,
sp_sz);
}
};
template <typename DeviceContext, typename T>
class ShuffleChannelGradOpCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
auto* output_grad =
ctx.Input<phi::DenseTensor>(framework::GradVarName("Out"));
auto* input_grad =
ctx.Output<phi::DenseTensor>(framework::GradVarName("X"));
int group = ctx.Attr<int>("group");
const auto& input_dims = input_grad->dims();
auto num = input_dims[0];
auto channel = input_dims[1];
auto height = input_dims[2];
auto weight = input_dims[3];
auto feature_map_size = channel * height * weight;
auto sp_sz = height * weight;
int group_row = group;
int group_column = channel / group_row;
T* input_grad_data = input_grad->mutable_data<T>(ctx.GetPlace());
const T* output_grad_data = output_grad->data<T>();
int blocks = NumBlocks(output_grad->numel());
int threads = kNumCUDAThreads;
int count = num * group_column * group_row * sp_sz;
hipLaunchKernelGGL(( ShuffleChannel<T>)
, dim3(blocks), dim3(threads), 0, ctx.cuda_device_context().stream(),
count,
feature_map_size,
input_grad_data,
output_grad_data,
group_row,
group_column,
sp_sz);
}
};
} // namespace operators
} // namespace paddle
namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL(
shuffle_channel,
ops::ShuffleChannelOpCUDAKernel<phi::GPUContext, float>,
ops::ShuffleChannelOpCUDAKernel<phi::GPUContext, double>);
REGISTER_OP_CUDA_KERNEL(
shuffle_channel_grad,
ops::ShuffleChannelGradOpCUDAKernel<phi::GPUContext, float>,
ops::ShuffleChannelGradOpCUDAKernel<phi::GPUContext, double>);
| 00fb62d11037ef4b8bedf11c731040a95d20457a.cu | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/shuffle_channel_op.h"
#include "paddle/fluid/platform/device/gpu/gpu_info.h"
#include "paddle/fluid/platform/device/gpu/gpu_primitives.h"
namespace paddle {
namespace operators {
using Tensor = phi::DenseTensor;
static constexpr int kNumCUDAThreads = 512;
static constexpr int kNumMaximumNumBlocks = 4096;
static inline int NumBlocks(const int N) {
return std::min((N + kNumCUDAThreads - 1) / kNumCUDAThreads,
kNumMaximumNumBlocks);
}
template <typename T>
__global__ void ShuffleChannel(const int nthreads,
const int feature_map_size,
T* output,
const T* input,
int group_row,
int group_column,
int len) {
int index = blockIdx.x * blockDim.x + threadIdx.x;
int offset = blockDim.x * gridDim.x;
for (size_t ii = index; ii < nthreads; ii += offset) {
const int n = index / group_row / group_column / len;
const int i = (index / group_column / len) % group_row;
const int j = index / len % group_column;
const int k = index - (n * feature_map_size + (i * group_column + j) * len);
T* p_o = output + n * feature_map_size + (j * group_row + i) * len;
p_o[k] = input[index];
}
}
template <typename DeviceContext, typename T>
class ShuffleChannelOpCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
auto* input = ctx.Input<phi::DenseTensor>("X");
auto* output = ctx.Output<phi::DenseTensor>("Out");
int group = ctx.Attr<int>("group");
auto input_dims = input->dims();
auto num = input_dims[0];
auto channel = input_dims[1];
auto height = input_dims[2];
auto weight = input_dims[3];
auto feature_map_size = channel * height * weight;
auto sp_sz = height * weight;
int group_row = group;
int group_column = channel / group_row;
// count is the product of NCHW same as numel()
int count = num * group_column * group_row * sp_sz;
int blocks = NumBlocks(output->numel());
int threads = kNumCUDAThreads;
const T* input_data = input->data<T>();
T* output_data = output->mutable_data<T>(ctx.GetPlace());
ShuffleChannel<T>
<<<blocks, threads, 0, ctx.cuda_device_context().stream()>>>(
count,
feature_map_size,
output_data,
input_data,
group_row,
group_column,
sp_sz);
}
};
template <typename DeviceContext, typename T>
class ShuffleChannelGradOpCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
auto* output_grad =
ctx.Input<phi::DenseTensor>(framework::GradVarName("Out"));
auto* input_grad =
ctx.Output<phi::DenseTensor>(framework::GradVarName("X"));
int group = ctx.Attr<int>("group");
const auto& input_dims = input_grad->dims();
auto num = input_dims[0];
auto channel = input_dims[1];
auto height = input_dims[2];
auto weight = input_dims[3];
auto feature_map_size = channel * height * weight;
auto sp_sz = height * weight;
int group_row = group;
int group_column = channel / group_row;
T* input_grad_data = input_grad->mutable_data<T>(ctx.GetPlace());
const T* output_grad_data = output_grad->data<T>();
int blocks = NumBlocks(output_grad->numel());
int threads = kNumCUDAThreads;
int count = num * group_column * group_row * sp_sz;
ShuffleChannel<T>
<<<blocks, threads, 0, ctx.cuda_device_context().stream()>>>(
count,
feature_map_size,
input_grad_data,
output_grad_data,
group_row,
group_column,
sp_sz);
}
};
} // namespace operators
} // namespace paddle
namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL(
shuffle_channel,
ops::ShuffleChannelOpCUDAKernel<phi::GPUContext, float>,
ops::ShuffleChannelOpCUDAKernel<phi::GPUContext, double>);
REGISTER_OP_CUDA_KERNEL(
shuffle_channel_grad,
ops::ShuffleChannelGradOpCUDAKernel<phi::GPUContext, float>,
ops::ShuffleChannelGradOpCUDAKernel<phi::GPUContext, double>);
|
4b492418c77d1b88185c321dc85e1723f4505ac1.hip | // !!! This is a file automatically generated by hipify!!!
/***********************************************************************************
Implementing Breadth first search on CUDA using algorithm given in HiPC'07
paper "Accelerating Large Graph Algorithms on the GPU using CUDA"
Copyright (c) 2008 International Institute of Information Technology - Hyderabad.
All rights reserved.
Permission to use, copy, modify and distribute this software and its documentation for
educational purpose is hereby granted without fee, provided that the above copyright
notice and this permission notice appear in all copies of this software and that you do
not sell the software.
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,EXPRESS, IMPLIED OR
OTHERWISE.
Created by Pawan Harish.
************************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <hip/hip_runtime.h>
#define MAX_THREADS_PER_BLOCK 512
int no_of_nodes;
int edge_list_size;
FILE *fp;
//Structure to hold a node information
struct Node
{
int starting;
int no_of_edges;
};
#include <kernel.cu>
#include <kernel2.cu>
void BFSGraph(int argc, char** argv);
////////////////////////////////////////////////////////////////////////////////
// Main Program
////////////////////////////////////////////////////////////////////////////////
int main( int argc, char** argv)
{
no_of_nodes=0;
edge_list_size=0;
BFSGraph( argc, argv);
}
void Usage(int argc, char**argv){
fprintf(stderr,"Usage: %s <input_file>\n", argv[0]);
}
////////////////////////////////////////////////////////////////////////////////
//Apply BFS on a Graph using CUDA
////////////////////////////////////////////////////////////////////////////////
void BFSGraph( int argc, char** argv)
{
char *input_f;
if(argc!=2){
Usage(argc, argv);
exit(0);
}
input_f = argv[1];
printf("Reading File\n");
//Read in Graph from a file
fp = fopen(input_f,"r");
if(!fp)
{
printf("Error Reading graph file\n");
return;
}
int source = 0;
fscanf(fp,"%d",&no_of_nodes);
int num_of_blocks = 1;
int num_of_threads_per_block = no_of_nodes;
//Make execution Parameters according to the number of nodes
//Distribute threads across multiple Blocks if necessary
if(no_of_nodes>MAX_THREADS_PER_BLOCK)
{
num_of_blocks = (int)ceil(no_of_nodes/(double)MAX_THREADS_PER_BLOCK);
num_of_threads_per_block = MAX_THREADS_PER_BLOCK;
}
// allocate host memory
Node* h_graph_nodes = (Node*) malloc(sizeof(Node)*no_of_nodes);
bool *h_graph_mask = (bool*) malloc(sizeof(bool)*no_of_nodes);
bool *h_updating_graph_mask = (bool*) malloc(sizeof(bool)*no_of_nodes);
bool *h_graph_visited = (bool*) malloc(sizeof(bool)*no_of_nodes);
int start, edgeno;
// initalize the memory
for( unsigned int i = 0; i < no_of_nodes; i++)
{
fscanf(fp,"%d %d",&start,&edgeno);
h_graph_nodes[i].starting = start;
h_graph_nodes[i].no_of_edges = edgeno;
h_graph_mask[i]=false;
h_updating_graph_mask[i]=false;
h_graph_visited[i]=false;
}
//read the source node from the file
fscanf(fp,"%d",&source);
source=0;
//set the source node as true in the mask
h_graph_mask[source]=true;
h_graph_visited[source]=true;
fscanf(fp,"%d",&edge_list_size);
int id,cost;
int* h_graph_edges = (int*) malloc(sizeof(int)*edge_list_size);
for(int i=0; i < edge_list_size ; i++)
{
fscanf(fp,"%d",&id);
fscanf(fp,"%d",&cost);
h_graph_edges[i] = id;
}
if(fp)
fclose(fp);
printf("Read File\n");
//Copy the Node list to device memory
Node* d_graph_nodes;
hipMalloc( (void**) &d_graph_nodes, sizeof(Node)*no_of_nodes) ;
hipMemcpy( d_graph_nodes, h_graph_nodes, sizeof(Node)*no_of_nodes, hipMemcpyHostToDevice) ;
//Copy the Edge List to device Memory
int* d_graph_edges;
hipMalloc( (void**) &d_graph_edges, sizeof(int)*edge_list_size) ;
hipMemcpy( d_graph_edges, h_graph_edges, sizeof(int)*edge_list_size, hipMemcpyHostToDevice) ;
//Copy the Mask to device memory
bool* d_graph_mask;
hipMalloc( (void**) &d_graph_mask, sizeof(bool)*no_of_nodes) ;
hipMemcpy( d_graph_mask, h_graph_mask, sizeof(bool)*no_of_nodes, hipMemcpyHostToDevice) ;
bool* d_updating_graph_mask;
hipMalloc( (void**) &d_updating_graph_mask, sizeof(bool)*no_of_nodes) ;
hipMemcpy( d_updating_graph_mask, h_updating_graph_mask, sizeof(bool)*no_of_nodes, hipMemcpyHostToDevice) ;
//Copy the Visited nodes array to device memory
bool* d_graph_visited;
hipMalloc( (void**) &d_graph_visited, sizeof(bool)*no_of_nodes) ;
hipMemcpy( d_graph_visited, h_graph_visited, sizeof(bool)*no_of_nodes, hipMemcpyHostToDevice) ;
// allocate mem for the result on host side
int* h_cost = (int*) malloc( sizeof(int)*no_of_nodes);
for(int i=0;i<no_of_nodes;i++)
h_cost[i]=-1;
h_cost[source]=0;
// allocate device memory for result
int* d_cost;
hipMalloc( (void**) &d_cost, sizeof(int)*no_of_nodes);
hipMemcpy( d_cost, h_cost, sizeof(int)*no_of_nodes, hipMemcpyHostToDevice) ;
//make a bool to check if the execution is over
bool *d_over;
hipMalloc( (void**) &d_over, sizeof(bool));
printf("Copied Everything to GPU memory\n");
// setup execution parameters
dim3 grid( num_of_blocks, 1, 1);
dim3 threads( num_of_threads_per_block, 1, 1);
int k=0;
printf("Start traversing the tree\n");
bool stop;
//Call the Kernel untill all the elements of Frontier are not false
do
{
//if no thread changes this value then the loop stops
stop=false;
hipMemcpy( d_over, &stop, sizeof(bool), hipMemcpyHostToDevice) ;
hipLaunchKernelGGL(( Kernel), dim3(grid), dim3(threads), 0 , 0, d_graph_nodes, d_graph_edges, d_graph_mask, d_updating_graph_mask, d_graph_visited, d_cost, no_of_nodes);
// check if kernel execution generated and error
hipLaunchKernelGGL(( Kernel2), dim3(grid), dim3(threads), 0 , 0, d_graph_mask, d_updating_graph_mask, d_graph_visited, d_over, no_of_nodes);
// check if kernel execution generated and error
hipMemcpy( &stop, d_over, sizeof(bool), hipMemcpyDeviceToHost) ;
k++;
}
while(stop);
printf("Kernel Executed %d times\n",k);
// copy result from device to host
hipMemcpy( h_cost, d_cost, sizeof(int)*no_of_nodes, hipMemcpyDeviceToHost) ;
//Store the result into a file
#ifdef DUMPOUT
FILE *fpo = fopen("result.txt","w");
for(int i=0;i<no_of_nodes;i++)
fprintf(fpo,"%d) cost:%d\n",i,h_cost[i]);
fclose(fpo);
printf("Result stored in result.txt\n");
#endif
// cleanup memory
free( h_graph_nodes);
free( h_graph_edges);
free( h_graph_mask);
free( h_updating_graph_mask);
free( h_graph_visited);
free( h_cost);
hipFree(d_graph_nodes);
hipFree(d_graph_edges);
hipFree(d_graph_mask);
hipFree(d_updating_graph_mask);
hipFree(d_graph_visited);
hipFree(d_cost);
}
| 4b492418c77d1b88185c321dc85e1723f4505ac1.cu | /***********************************************************************************
Implementing Breadth first search on CUDA using algorithm given in HiPC'07
paper "Accelerating Large Graph Algorithms on the GPU using CUDA"
Copyright (c) 2008 International Institute of Information Technology - Hyderabad.
All rights reserved.
Permission to use, copy, modify and distribute this software and its documentation for
educational purpose is hereby granted without fee, provided that the above copyright
notice and this permission notice appear in all copies of this software and that you do
not sell the software.
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,EXPRESS, IMPLIED OR
OTHERWISE.
Created by Pawan Harish.
************************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cuda.h>
#define MAX_THREADS_PER_BLOCK 512
int no_of_nodes;
int edge_list_size;
FILE *fp;
//Structure to hold a node information
struct Node
{
int starting;
int no_of_edges;
};
#include <kernel.cu>
#include <kernel2.cu>
void BFSGraph(int argc, char** argv);
////////////////////////////////////////////////////////////////////////////////
// Main Program
////////////////////////////////////////////////////////////////////////////////
int main( int argc, char** argv)
{
no_of_nodes=0;
edge_list_size=0;
BFSGraph( argc, argv);
}
void Usage(int argc, char**argv){
fprintf(stderr,"Usage: %s <input_file>\n", argv[0]);
}
////////////////////////////////////////////////////////////////////////////////
//Apply BFS on a Graph using CUDA
////////////////////////////////////////////////////////////////////////////////
void BFSGraph( int argc, char** argv)
{
char *input_f;
if(argc!=2){
Usage(argc, argv);
exit(0);
}
input_f = argv[1];
printf("Reading File\n");
//Read in Graph from a file
fp = fopen(input_f,"r");
if(!fp)
{
printf("Error Reading graph file\n");
return;
}
int source = 0;
fscanf(fp,"%d",&no_of_nodes);
int num_of_blocks = 1;
int num_of_threads_per_block = no_of_nodes;
//Make execution Parameters according to the number of nodes
//Distribute threads across multiple Blocks if necessary
if(no_of_nodes>MAX_THREADS_PER_BLOCK)
{
num_of_blocks = (int)ceil(no_of_nodes/(double)MAX_THREADS_PER_BLOCK);
num_of_threads_per_block = MAX_THREADS_PER_BLOCK;
}
// allocate host memory
Node* h_graph_nodes = (Node*) malloc(sizeof(Node)*no_of_nodes);
bool *h_graph_mask = (bool*) malloc(sizeof(bool)*no_of_nodes);
bool *h_updating_graph_mask = (bool*) malloc(sizeof(bool)*no_of_nodes);
bool *h_graph_visited = (bool*) malloc(sizeof(bool)*no_of_nodes);
int start, edgeno;
// initalize the memory
for( unsigned int i = 0; i < no_of_nodes; i++)
{
fscanf(fp,"%d %d",&start,&edgeno);
h_graph_nodes[i].starting = start;
h_graph_nodes[i].no_of_edges = edgeno;
h_graph_mask[i]=false;
h_updating_graph_mask[i]=false;
h_graph_visited[i]=false;
}
//read the source node from the file
fscanf(fp,"%d",&source);
source=0;
//set the source node as true in the mask
h_graph_mask[source]=true;
h_graph_visited[source]=true;
fscanf(fp,"%d",&edge_list_size);
int id,cost;
int* h_graph_edges = (int*) malloc(sizeof(int)*edge_list_size);
for(int i=0; i < edge_list_size ; i++)
{
fscanf(fp,"%d",&id);
fscanf(fp,"%d",&cost);
h_graph_edges[i] = id;
}
if(fp)
fclose(fp);
printf("Read File\n");
//Copy the Node list to device memory
Node* d_graph_nodes;
cudaMalloc( (void**) &d_graph_nodes, sizeof(Node)*no_of_nodes) ;
cudaMemcpy( d_graph_nodes, h_graph_nodes, sizeof(Node)*no_of_nodes, cudaMemcpyHostToDevice) ;
//Copy the Edge List to device Memory
int* d_graph_edges;
cudaMalloc( (void**) &d_graph_edges, sizeof(int)*edge_list_size) ;
cudaMemcpy( d_graph_edges, h_graph_edges, sizeof(int)*edge_list_size, cudaMemcpyHostToDevice) ;
//Copy the Mask to device memory
bool* d_graph_mask;
cudaMalloc( (void**) &d_graph_mask, sizeof(bool)*no_of_nodes) ;
cudaMemcpy( d_graph_mask, h_graph_mask, sizeof(bool)*no_of_nodes, cudaMemcpyHostToDevice) ;
bool* d_updating_graph_mask;
cudaMalloc( (void**) &d_updating_graph_mask, sizeof(bool)*no_of_nodes) ;
cudaMemcpy( d_updating_graph_mask, h_updating_graph_mask, sizeof(bool)*no_of_nodes, cudaMemcpyHostToDevice) ;
//Copy the Visited nodes array to device memory
bool* d_graph_visited;
cudaMalloc( (void**) &d_graph_visited, sizeof(bool)*no_of_nodes) ;
cudaMemcpy( d_graph_visited, h_graph_visited, sizeof(bool)*no_of_nodes, cudaMemcpyHostToDevice) ;
// allocate mem for the result on host side
int* h_cost = (int*) malloc( sizeof(int)*no_of_nodes);
for(int i=0;i<no_of_nodes;i++)
h_cost[i]=-1;
h_cost[source]=0;
// allocate device memory for result
int* d_cost;
cudaMalloc( (void**) &d_cost, sizeof(int)*no_of_nodes);
cudaMemcpy( d_cost, h_cost, sizeof(int)*no_of_nodes, cudaMemcpyHostToDevice) ;
//make a bool to check if the execution is over
bool *d_over;
cudaMalloc( (void**) &d_over, sizeof(bool));
printf("Copied Everything to GPU memory\n");
// setup execution parameters
dim3 grid( num_of_blocks, 1, 1);
dim3 threads( num_of_threads_per_block, 1, 1);
int k=0;
printf("Start traversing the tree\n");
bool stop;
//Call the Kernel untill all the elements of Frontier are not false
do
{
//if no thread changes this value then the loop stops
stop=false;
cudaMemcpy( d_over, &stop, sizeof(bool), cudaMemcpyHostToDevice) ;
Kernel<<< grid, threads, 0 >>>( d_graph_nodes, d_graph_edges, d_graph_mask, d_updating_graph_mask, d_graph_visited, d_cost, no_of_nodes);
// check if kernel execution generated and error
Kernel2<<< grid, threads, 0 >>>( d_graph_mask, d_updating_graph_mask, d_graph_visited, d_over, no_of_nodes);
// check if kernel execution generated and error
cudaMemcpy( &stop, d_over, sizeof(bool), cudaMemcpyDeviceToHost) ;
k++;
}
while(stop);
printf("Kernel Executed %d times\n",k);
// copy result from device to host
cudaMemcpy( h_cost, d_cost, sizeof(int)*no_of_nodes, cudaMemcpyDeviceToHost) ;
//Store the result into a file
#ifdef DUMPOUT
FILE *fpo = fopen("result.txt","w");
for(int i=0;i<no_of_nodes;i++)
fprintf(fpo,"%d) cost:%d\n",i,h_cost[i]);
fclose(fpo);
printf("Result stored in result.txt\n");
#endif
// cleanup memory
free( h_graph_nodes);
free( h_graph_edges);
free( h_graph_mask);
free( h_updating_graph_mask);
free( h_graph_visited);
free( h_cost);
cudaFree(d_graph_nodes);
cudaFree(d_graph_edges);
cudaFree(d_graph_mask);
cudaFree(d_updating_graph_mask);
cudaFree(d_graph_visited);
cudaFree(d_cost);
}
|
307fabdd6bd5623dc96ee80993a6c036befb26c0.hip | // !!! This is a file automatically generated by hipify!!!
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <hip/hip_runtime.h>
int *a, *b; // host data
int *c, *c2; // results
__global__ void vecAdd(int *A,int *B,int *C,int N)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < N)
{
C[i] = A[i] + B[i];
}
}
void vecAdd_h(int *A1,int *B1, int *C1, int N)
{
for(int i=0;i<N;i++)
C1[i] = A1[i] + B1[i];
}
int main(int argc,char **argv)
{
printf("Begin \n");
int n=10000000;
int nBytes = n*sizeof(int);
int block_size, block_no;
a = (int *)malloc(nBytes);
b = (int *)malloc(nBytes);
c = (int *)malloc(nBytes);
c2 = (int *)malloc(nBytes);
int *a_d,*b_d,*c_d;
block_size=4000;
block_no = n/block_size;
dim3 dimBlock(block_size,1,1);
dim3 dimGrid(block_no,1,1);
for(int i = 0; i < n; i++ ) {
a[i] = sin(i)*sin(i);
b[i] = cos(i)*cos(i);
}
printf("Allocating device memory on host..\n");
hipMalloc((void **)&a_d,n*sizeof(int));
hipMalloc((void **)&b_d,n*sizeof(int));
hipMalloc((void **)&c_d,n*sizeof(int));
printf("Copying to device..\n");
hipMemcpy(a_d,a,n*sizeof(int),hipMemcpyHostToDevice);
hipMemcpy(b_d,b,n*sizeof(int),hipMemcpyHostToDevice);
clock_t start_d=clock();
printf("Doing GPU Vector add\n");
hipLaunchKernelGGL(( vecAdd), dim3(block_no),dim3(block_size), 0, 0, a_d,b_d,c_d,n);
hipDeviceSynchronize();
clock_t end_d = clock();
clock_t start_h = clock();
printf("Doing CPU Vector add\n");
vecAdd_h(a,b,c2,n);
clock_t end_h = clock();
double time_d = (double)(end_d-start_d)/CLOCKS_PER_SEC;
double time_h = (double)(end_h-start_h)/CLOCKS_PER_SEC;
hipMemcpy(c,c_d,n*sizeof(int),hipMemcpyDeviceToHost);
printf("Number of elements: %d GPU Time: %f CPU Time: %f\n",n,time_d,time_h);
hipFree(a_d);
hipFree(b_d);
hipFree(c_d);
return 0;
} | 307fabdd6bd5623dc96ee80993a6c036befb26c0.cu | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <cuda.h>
int *a, *b; // host data
int *c, *c2; // results
__global__ void vecAdd(int *A,int *B,int *C,int N)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < N)
{
C[i] = A[i] + B[i];
}
}
void vecAdd_h(int *A1,int *B1, int *C1, int N)
{
for(int i=0;i<N;i++)
C1[i] = A1[i] + B1[i];
}
int main(int argc,char **argv)
{
printf("Begin \n");
int n=10000000;
int nBytes = n*sizeof(int);
int block_size, block_no;
a = (int *)malloc(nBytes);
b = (int *)malloc(nBytes);
c = (int *)malloc(nBytes);
c2 = (int *)malloc(nBytes);
int *a_d,*b_d,*c_d;
block_size=4000;
block_no = n/block_size;
dim3 dimBlock(block_size,1,1);
dim3 dimGrid(block_no,1,1);
for(int i = 0; i < n; i++ ) {
a[i] = sin(i)*sin(i);
b[i] = cos(i)*cos(i);
}
printf("Allocating device memory on host..\n");
cudaMalloc((void **)&a_d,n*sizeof(int));
cudaMalloc((void **)&b_d,n*sizeof(int));
cudaMalloc((void **)&c_d,n*sizeof(int));
printf("Copying to device..\n");
cudaMemcpy(a_d,a,n*sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(b_d,b,n*sizeof(int),cudaMemcpyHostToDevice);
clock_t start_d=clock();
printf("Doing GPU Vector add\n");
vecAdd<<<block_no,block_size>>>(a_d,b_d,c_d,n);
cudaThreadSynchronize();
clock_t end_d = clock();
clock_t start_h = clock();
printf("Doing CPU Vector add\n");
vecAdd_h(a,b,c2,n);
clock_t end_h = clock();
double time_d = (double)(end_d-start_d)/CLOCKS_PER_SEC;
double time_h = (double)(end_h-start_h)/CLOCKS_PER_SEC;
cudaMemcpy(c,c_d,n*sizeof(int),cudaMemcpyDeviceToHost);
printf("Number of elements: %d GPU Time: %f CPU Time: %f\n",n,time_d,time_h);
cudaFree(a_d);
cudaFree(b_d);
cudaFree(c_d);
return 0;
} |
93ba693281e2aded7f1b9a0a1ee4f53e76fd6c49.hip | // !!! This is a file automatically generated by hipify!!!
#include <iostream>
#include <random>
#include <cusolverDn.h>
#include <rocblas.h>
#include <hip/hip_runtime.h>
#include "transform_matrix.cu"
#include "cuda_inv.cu"
const float ZERO = 0;
const float ONE = 1;
const float MINUS_ONE = -1;
__device__ float _soft_threshold(float x, float thresh){
if(x>thresh){
return x - thresh;
}else if(x < -thresh){
return x + thresh;
}else{
return 0;
}
}
__global__ void
_uzh(float *Dw_t, float *h_k, float *z_k, float *sub_z_h_k, float threshold, int n)
{
int index = blockIdx.x * blockDim.x + threadIdx.x;
if(index>=n) return;
float dw = Dw_t[index];
float h = h_k[index];
float z = _soft_threshold(dw + h, threshold);
z_k[index] = z;
h += dw - z;
h_k[index] = h;
sub_z_h_k[index] = z - h;
}
void _update_z_h(float *Dw_t, float *h_k, float *z_k, float *sub_z_h_k, float threshold, int n)
{
hipLaunchKernelGGL(( _uzh), dim3(n / 32 + (n % 32 ? 1 : 0)), dim3(32), 0, 0, Dw_t, h_k, z_k, sub_z_h_k, threshold, n);
}
float _cost_function(float *X, float *y, float *w, float *z, float alpha, int n_samples, int n_features, hipblasHandle_t cublas_handle){
float loss_w, loss_z;
hipblasSgemv(cublas_handle, HIPBLAS_OP_T,
n_features, n_samples,
&ONE,
X, n_features,
w, 1,
&MINUS_ONE,
y,
1);
hipblasSnrm2(cublas_handle, n_samples, y, 1, &loss_w);
hipblasSasum(cublas_handle, n_features, z, 1, &loss_z);
hipDeviceSynchronize();
return loss_w / n_samples + alpha * loss_z;
}
int
_update(float *X, float *y_k, transform_matrix &D,
int n_samples, int n_features, int n_targets, int n,
float *coef_matrix, float *inv_Xy_k, float *inv_D,
float alpha, float rho, int max_iter, float tol,
hipblasHandle_t cublas_handle, float *w, int *n_iter)
{
// n_samples, n_features = X.shape
// n_samples, 1 = y_k
// n_features, 1 = w_k.shape
// n_features, 1 = inv_Xy_k.shape
float inv_n_samples = 1.0f / n_samples;
float threshold = alpha / rho;
float *w_k;
float *Dw_t;
float *z_k;
float *h_k;
float *sub_z_h_k;
float *cost_workspace_y;
int status = 0;
status+=hipMalloc(&cost_workspace_y, n_samples * sizeof(float));
status+=hipMalloc(&w_k, n_features * sizeof(float));
status+=hipMalloc(&Dw_t, n_features * sizeof(float));
status+=hipMalloc(&z_k, n_features * sizeof(float));
status+=hipMalloc(&h_k, n_features * sizeof(float));
status+=hipMalloc(&sub_z_h_k, n_features * sizeof(float));
status+=hipblasSgemv(cublas_handle, HIPBLAS_OP_N,
n_features, n_samples,
&inv_n_samples,
X, n_features,
y_k, 1,
&ZERO,
w_k,
1);
status+=hipDeviceSynchronize();
D(w_k, z_k, n_features);
status+=hipMemset(h_k, 0, n_features * sizeof(float));
status+=hipMemcpy(sub_z_h_k, z_k, n_features * sizeof(float), hipMemcpyDeviceToDevice);
status+=hipDeviceSynchronize();
status+=hipMemcpy(cost_workspace_y, y_k, n_samples * sizeof(float), hipMemcpyDeviceToDevice);
float cost = _cost_function(X, cost_workspace_y, w_k, z_k, alpha, n_samples, n_features, cublas_handle);
float pre_cost, gap;
int i;
for (i = 0; i < max_iter; ++i){
status+=hipMemcpy(w_k, inv_Xy_k, n_features * sizeof(float), hipMemcpyDeviceToDevice);
status+=hipblasSgemv(cublas_handle, HIPBLAS_OP_T,
n_features, n_features,
&ONE,
inv_D, n_features,
sub_z_h_k, 1,
&ONE,
w_k,
1);
status+=hipDeviceSynchronize();
D(w_k, Dw_t, n_features);
status+=hipDeviceSynchronize();
_update_z_h(Dw_t, h_k, z_k, sub_z_h_k, threshold, n_features);
status+=hipDeviceSynchronize();
pre_cost = cost;
status+=hipMemcpy(cost_workspace_y, y_k, n_samples * sizeof(float), hipMemcpyDeviceToDevice);
cost = _cost_function(X, cost_workspace_y, w_k, z_k, alpha, n_samples, n_features, cublas_handle);
gap = abs(cost - pre_cost);
if(gap < tol){
break;
}
}
n_iter[n] = i;
status+=hipMemcpy(w + n_features * n, w_k, n_features*sizeof(float), hipMemcpyDeviceToDevice);
status+=hipFree(cost_workspace_y);
status+=hipFree(w_k);
status+=hipFree(Dw_t);
status+=hipFree(z_k);
status+=hipFree(h_k);
status+=hipFree(sub_z_h_k);
return status;
}
int _admm(float *X, float *y, transform_matrix &D,
int n_samples, int n_features, int n_targets,
float alpha, float rho, float tol, int max_iter, float *w, int* n_iter)
{
// n_samples, n_features = X.shape
// n_features, n_features = coef_matrix.shape == inv_matrix.shape
// n_features, n_samples = inv_matrix_dot_X_T.shape
// n_samples, n_targets = y.shape
// n_features, n_targets = inv_Xy.shape
int status=0;
hipblasHandle_t cublas_handle;
status+=hipblasCreate(&cublas_handle);
float *w_t;
status+=hipMalloc(&w_t, n_features*n_targets*sizeof(float));
float *coef_matrix;
status+=hipMalloc(&coef_matrix, n_features * n_features * sizeof(float));
D.DTD(coef_matrix, n_features);
status+=hipDeviceSynchronize();
float inv_n_samples = 1.0f / n_samples;
status+=hipblasSgemm(cublas_handle, HIPBLAS_OP_N, HIPBLAS_OP_T,
n_features, n_features, n_samples,
&inv_n_samples,
X, n_features,
X, n_features,
&rho,
coef_matrix,
n_features);
float *inv_matrix;
status+=hipMalloc(&inv_matrix, sizeof(float) * n_features * n_features);
status+=hipDeviceSynchronize();
status+=inv(coef_matrix, inv_matrix, n_features);
status+=hipDeviceSynchronize();
float *inv_Xy, *inv_matrix_dot_X_T;
status+=hipMalloc(&inv_matrix_dot_X_T, n_features * n_samples * sizeof(float));
status+=hipMalloc(&inv_Xy, n_features * n_targets * sizeof(float));
status+=hipDeviceSynchronize();
status+=hipblasSgemm(cublas_handle, HIPBLAS_OP_T, HIPBLAS_OP_N,
n_samples, n_features, n_features,
&ONE,
X, n_features,
inv_matrix, n_features,
&ZERO,
inv_matrix_dot_X_T,
n_samples);
status+=hipDeviceSynchronize();
status+=hipblasSgemm(cublas_handle, HIPBLAS_OP_T, HIPBLAS_OP_T,
n_features, n_targets, n_samples,
&inv_n_samples,
inv_matrix_dot_X_T, n_samples,
y, n_targets,
&ZERO,
inv_Xy,
n_features);
float *inv_D;
status+=hipMalloc(&inv_D, n_features * n_features * sizeof(float));
D.D_B(inv_matrix, inv_D, n_features, rho);
status+=hipDeviceSynchronize();
for (int i = 0; i < n_targets;++i){
status+=_update(X, y, D,
n_samples, n_features, n_targets, i,
coef_matrix, inv_Xy + n_features * i, inv_D,
alpha, rho, max_iter, tol,
cublas_handle, w, n_iter);
}
status+=hipDeviceSynchronize();
status+=hipFree(w_t);
status+=hipFree(coef_matrix);
status+=hipFree(inv_matrix);
status+=hipFree(inv_matrix_dot_X_T);
status+=hipFree(inv_Xy);
status+=hipFree(inv_D);
status+=hipblasDestroy(cublas_handle);
return status;
}
| 93ba693281e2aded7f1b9a0a1ee4f53e76fd6c49.cu | #include <iostream>
#include <random>
#include <cusolverDn.h>
#include <cublas_v2.h>
#include <cuda_runtime.h>
#include "transform_matrix.cu"
#include "cuda_inv.cu"
const float ZERO = 0;
const float ONE = 1;
const float MINUS_ONE = -1;
__device__ float _soft_threshold(float x, float thresh){
if(x>thresh){
return x - thresh;
}else if(x < -thresh){
return x + thresh;
}else{
return 0;
}
}
__global__ void
_uzh(float *Dw_t, float *h_k, float *z_k, float *sub_z_h_k, float threshold, int n)
{
int index = blockIdx.x * blockDim.x + threadIdx.x;
if(index>=n) return;
float dw = Dw_t[index];
float h = h_k[index];
float z = _soft_threshold(dw + h, threshold);
z_k[index] = z;
h += dw - z;
h_k[index] = h;
sub_z_h_k[index] = z - h;
}
void _update_z_h(float *Dw_t, float *h_k, float *z_k, float *sub_z_h_k, float threshold, int n)
{
_uzh<<<n / 32 + (n % 32 ? 1 : 0), 32>>>(Dw_t, h_k, z_k, sub_z_h_k, threshold, n);
}
float _cost_function(float *X, float *y, float *w, float *z, float alpha, int n_samples, int n_features, cublasHandle_t cublas_handle){
float loss_w, loss_z;
cublasSgemv(cublas_handle, CUBLAS_OP_T,
n_features, n_samples,
&ONE,
X, n_features,
w, 1,
&MINUS_ONE,
y,
1);
cublasSnrm2(cublas_handle, n_samples, y, 1, &loss_w);
cublasSasum(cublas_handle, n_features, z, 1, &loss_z);
cudaDeviceSynchronize();
return loss_w / n_samples + alpha * loss_z;
}
int
_update(float *X, float *y_k, transform_matrix &D,
int n_samples, int n_features, int n_targets, int n,
float *coef_matrix, float *inv_Xy_k, float *inv_D,
float alpha, float rho, int max_iter, float tol,
cublasHandle_t cublas_handle, float *w, int *n_iter)
{
// n_samples, n_features = X.shape
// n_samples, 1 = y_k
// n_features, 1 = w_k.shape
// n_features, 1 = inv_Xy_k.shape
float inv_n_samples = 1.0f / n_samples;
float threshold = alpha / rho;
float *w_k;
float *Dw_t;
float *z_k;
float *h_k;
float *sub_z_h_k;
float *cost_workspace_y;
int status = 0;
status+=cudaMalloc(&cost_workspace_y, n_samples * sizeof(float));
status+=cudaMalloc(&w_k, n_features * sizeof(float));
status+=cudaMalloc(&Dw_t, n_features * sizeof(float));
status+=cudaMalloc(&z_k, n_features * sizeof(float));
status+=cudaMalloc(&h_k, n_features * sizeof(float));
status+=cudaMalloc(&sub_z_h_k, n_features * sizeof(float));
status+=cublasSgemv(cublas_handle, CUBLAS_OP_N,
n_features, n_samples,
&inv_n_samples,
X, n_features,
y_k, 1,
&ZERO,
w_k,
1);
status+=cudaDeviceSynchronize();
D(w_k, z_k, n_features);
status+=cudaMemset(h_k, 0, n_features * sizeof(float));
status+=cudaMemcpy(sub_z_h_k, z_k, n_features * sizeof(float), cudaMemcpyDeviceToDevice);
status+=cudaDeviceSynchronize();
status+=cudaMemcpy(cost_workspace_y, y_k, n_samples * sizeof(float), cudaMemcpyDeviceToDevice);
float cost = _cost_function(X, cost_workspace_y, w_k, z_k, alpha, n_samples, n_features, cublas_handle);
float pre_cost, gap;
int i;
for (i = 0; i < max_iter; ++i){
status+=cudaMemcpy(w_k, inv_Xy_k, n_features * sizeof(float), cudaMemcpyDeviceToDevice);
status+=cublasSgemv(cublas_handle, CUBLAS_OP_T,
n_features, n_features,
&ONE,
inv_D, n_features,
sub_z_h_k, 1,
&ONE,
w_k,
1);
status+=cudaDeviceSynchronize();
D(w_k, Dw_t, n_features);
status+=cudaDeviceSynchronize();
_update_z_h(Dw_t, h_k, z_k, sub_z_h_k, threshold, n_features);
status+=cudaDeviceSynchronize();
pre_cost = cost;
status+=cudaMemcpy(cost_workspace_y, y_k, n_samples * sizeof(float), cudaMemcpyDeviceToDevice);
cost = _cost_function(X, cost_workspace_y, w_k, z_k, alpha, n_samples, n_features, cublas_handle);
gap = abs(cost - pre_cost);
if(gap < tol){
break;
}
}
n_iter[n] = i;
status+=cudaMemcpy(w + n_features * n, w_k, n_features*sizeof(float), cudaMemcpyDeviceToDevice);
status+=cudaFree(cost_workspace_y);
status+=cudaFree(w_k);
status+=cudaFree(Dw_t);
status+=cudaFree(z_k);
status+=cudaFree(h_k);
status+=cudaFree(sub_z_h_k);
return status;
}
int _admm(float *X, float *y, transform_matrix &D,
int n_samples, int n_features, int n_targets,
float alpha, float rho, float tol, int max_iter, float *w, int* n_iter)
{
// n_samples, n_features = X.shape
// n_features, n_features = coef_matrix.shape == inv_matrix.shape
// n_features, n_samples = inv_matrix_dot_X_T.shape
// n_samples, n_targets = y.shape
// n_features, n_targets = inv_Xy.shape
int status=0;
cublasHandle_t cublas_handle;
status+=cublasCreate(&cublas_handle);
float *w_t;
status+=cudaMalloc(&w_t, n_features*n_targets*sizeof(float));
float *coef_matrix;
status+=cudaMalloc(&coef_matrix, n_features * n_features * sizeof(float));
D.DTD(coef_matrix, n_features);
status+=cudaDeviceSynchronize();
float inv_n_samples = 1.0f / n_samples;
status+=cublasSgemm(cublas_handle, CUBLAS_OP_N, CUBLAS_OP_T,
n_features, n_features, n_samples,
&inv_n_samples,
X, n_features,
X, n_features,
&rho,
coef_matrix,
n_features);
float *inv_matrix;
status+=cudaMalloc(&inv_matrix, sizeof(float) * n_features * n_features);
status+=cudaDeviceSynchronize();
status+=inv(coef_matrix, inv_matrix, n_features);
status+=cudaDeviceSynchronize();
float *inv_Xy, *inv_matrix_dot_X_T;
status+=cudaMalloc(&inv_matrix_dot_X_T, n_features * n_samples * sizeof(float));
status+=cudaMalloc(&inv_Xy, n_features * n_targets * sizeof(float));
status+=cudaDeviceSynchronize();
status+=cublasSgemm(cublas_handle, CUBLAS_OP_T, CUBLAS_OP_N,
n_samples, n_features, n_features,
&ONE,
X, n_features,
inv_matrix, n_features,
&ZERO,
inv_matrix_dot_X_T,
n_samples);
status+=cudaDeviceSynchronize();
status+=cublasSgemm(cublas_handle, CUBLAS_OP_T, CUBLAS_OP_T,
n_features, n_targets, n_samples,
&inv_n_samples,
inv_matrix_dot_X_T, n_samples,
y, n_targets,
&ZERO,
inv_Xy,
n_features);
float *inv_D;
status+=cudaMalloc(&inv_D, n_features * n_features * sizeof(float));
D.D_B(inv_matrix, inv_D, n_features, rho);
status+=cudaDeviceSynchronize();
for (int i = 0; i < n_targets;++i){
status+=_update(X, y, D,
n_samples, n_features, n_targets, i,
coef_matrix, inv_Xy + n_features * i, inv_D,
alpha, rho, max_iter, tol,
cublas_handle, w, n_iter);
}
status+=cudaDeviceSynchronize();
status+=cudaFree(w_t);
status+=cudaFree(coef_matrix);
status+=cudaFree(inv_matrix);
status+=cudaFree(inv_matrix_dot_X_T);
status+=cudaFree(inv_Xy);
status+=cudaFree(inv_D);
status+=cublasDestroy(cublas_handle);
return status;
}
|
ba236ec8cd31489f17ec13c08706ce99c4b41990.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <math.h>
#include <math_constants.h>
#include <opencv2/core/core.hpp>
#include <vector>
#include "caffe/layers/detectnet_transform_layer.hpp"
#include "caffe/util/detectnet_coverage.hpp"
#include "caffe/util/gpu_memory.hpp"
#include "caffe/util/math_functions.hpp"
namespace caffe {
// Calculate the location in the image from the loop index
__device__ void get_pixel_indices(const int loop_index,
const uint4 shape, int* x, int* y, int* n
) {
int idx = loop_index;
*n = idx / (shape.y * shape.x);
idx -= *n * shape.y * shape.x;
*y = idx / shape.x;
idx -= *y * shape.x;
*x = idx;
}
// https://www.cs.rit.edu/~ncs/color/t_convert.html
template <typename Dtype>
__device__ void convert_rgb_to_hsv(
Dtype r, Dtype g, Dtype b,
Dtype* h, Dtype* s, Dtype* v
) {
Dtype min_v = min(min(r, g), b);
Dtype max_v = max(max(r, g), b); // NOLINT(build/include_what_you_use)
Dtype delta = max_v - min_v;
if (max_v == 0 || delta == 0) {
*h = 0;
*s = 0;
*v = max_v;
return;
}
if (r == max_v) {
*h = (g - b) / delta;
} else if (g == max_v) {
*h = 2 + (b - r) / delta;
} else {
*h = 4 + (r - g) / delta;
}
*h *= 60;
if (h < 0) {
*h += 360;
}
*s = delta / max_v;
*v = max_v;
}
// https://www.cs.rit.edu/~ncs/color/t_convert.html
template <typename Dtype>
__device__ void convert_hsv_to_rgb(
Dtype h, Dtype s, Dtype v,
Dtype* r, Dtype* g, Dtype* b
) {
int i;
Dtype f, p, q, t;
if (s == 0) {
*r = v;
*g = v;
*b = v;
return;
}
h /= 60; // sector 0 to 5
i = floor(h);
f = h - i; // factorial part of h
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * (1 - f));
switch (i) {
case 0:
*r = v;
*g = t;
*b = p;
break;
case 1:
*r = q;
*g = v;
*b = p;
break;
case 2:
*r = p;
*g = v;
*b = t;
break;
case 3:
*r = p;
*g = q;
*b = v;
break;
case 4:
*r = t;
*g = p;
*b = v;
break;
default: // case 5:
*r = v;
*g = p;
*b = q;
break;
}
}
template <typename Dtype>
__global__ void color_transformations(
const Dtype* src_data, Dtype* dst_data,
const uint4 shape, const AugmentSelection* aug_data
) {
CUDA_KERNEL_LOOP(loop_index, shape.x * shape.y * shape.w) {
int x, y, n;
get_pixel_indices(loop_index, shape, &x, &y, &n);
// check what needs doing
const AugmentSelection& as = aug_data[n];
const bool doHueRotation = (abs(as.hue_rotation) > FLT_EPSILON);
const bool doDesaturation = (as.saturation < (1.0 - 1.0/UINT8_MAX));
// N*cs*hs*ws + H*ws + W
int index = n * shape.z * shape.y * shape.x + y * shape.x + x;
// hs*ws
const int channel_stride = shape.y * shape.x;
// read
Dtype r = src_data[index + 0 * channel_stride];
Dtype g = src_data[index + 1 * channel_stride];
Dtype b = src_data[index + 2 * channel_stride];
if (doHueRotation || doDesaturation) {
// transform
Dtype h, s, v;
convert_rgb_to_hsv(r, g, b, &h, &s, &v);
if (doHueRotation) {
h -= aug_data[n].hue_rotation;
}
if (doDesaturation) {
s *= aug_data[n].saturation;
}
convert_hsv_to_rgb(h, s, v, &r, &g, &b);
}
// write
dst_data[index + 0 * channel_stride] = r;
dst_data[index + 1 * channel_stride] = g;
dst_data[index + 2 * channel_stride] = b;
}
}
// Mean is WxHxC
// For each pixel in the current image, subtract the corresponding pixel
// from the mean image
template <typename Dtype>
__global__ void pixel_mean_subtraction(
Dtype* data, const Dtype* mean_data, const uint4 shape
) {
CUDA_KERNEL_LOOP(loop_index, shape.x * shape.y * shape.w) {
int x, y, n;
get_pixel_indices(loop_index, shape, &x, &y, &n);
for (int c = 0; c < shape.z; c++) {
// N*cs*hs*ws + C*hs*ws + H*ws + W
const int data_idx = (n * shape.z * shape.y * shape.x) +
(c * shape.y * shape.x) + (y * shape.x) + x;
// C*hs*ws + H*ws + W
const int mean_idx = (c * shape.y * shape.x) + (y * shape.x) + x;
data[data_idx] -= mean_data[mean_idx];
}
}
}
// Mean is 1x1xC
// For each pixel in the current image, subtract the mean pixel
template <typename Dtype>
__global__ void channel_mean_subtraction(
Dtype* data, const uint4 shape,
const Dtype mean_value1, const Dtype mean_value2, const Dtype mean_value3
) {
CUDA_KERNEL_LOOP(loop_index, shape.x * shape.y * shape.w) {
int x, y, n;
get_pixel_indices(loop_index, shape, &x, &y, &n);
// N*cs*hs*ws + C*hs*ws + H*ws + W
const int data_idx = (n * shape.z * shape.y * shape.x) +(y * shape.x) + x;
// hs*ws
const int channel_stride = shape.y * shape.x;
data[data_idx + 0 * channel_stride] -= mean_value1;
data[data_idx + 1 * channel_stride] -= mean_value2;
data[data_idx + 2 * channel_stride] -= mean_value3;
}
}
template <typename Dtype>
__device__ void rotate_point(
const Dtype ax, const Dtype ay, // original point
const Dtype cx, const Dtype cy, // center point
float angle,
Dtype* bx, Dtype* by // destination point
) {
const Dtype s = sin(angle);
const Dtype c = cos(angle);
// translate to origin
const Dtype tx = ax - cx;
const Dtype ty = ay - cy;
*bx = (tx * c) - (ty * s) + cx;
*by = (tx * s) + (ty * c) + cy;
}
template <typename Dtype>
__device__ Dtype get_value(
const Dtype* data, const uint4& shape,
const unsigned int n, const unsigned int c,
int y, int x
) {
// Replicate border for 1 pixel
if (x == -1) x = 0;
if (x == shape.x) x = shape.x - 1;
if (y == -1) y = 0;
if (y == shape.y) y = shape.y - 1;
if (x >= 0 && x < shape.x && y >= 0 && y < shape.y) {
// N*cs*hs*ws + C*hs*ws + H*ws + W
return data[(n * shape.z * shape.y * shape.x) +
(c * shape.y * shape.x) + (y * shape.x) + x];
} else {
return 0;
}
}
template <typename Dtype>
__device__ Dtype cubic_interpolation(const Dtype& d,
const Dtype& v1, const Dtype& v2, const Dtype& v3, const Dtype& v4
) {
// d is [0,1], marking the distance from v2 towards v3
return v2 + d * (
-2.0 * v1 - 3.0 * v2 + 6.0 * v3 - 1.0 * v4 + d * (
3.0 * v1 - 6.0 * v2 + 3.0 * v3 + 0.0 * v4 + d * (
-1.0 * v1 + 3.0 * v2 - 3.0 * v3 + 1.0 * v4))) / 6.0;
}
// Interpolate in 1D space
template <typename Dtype>
__device__ Dtype interpolate_x(
const Dtype* data, const uint4& shape,
const unsigned int n, const unsigned int c,
const int y, const Dtype x
) {
Dtype dx = x - floor(x);
return cubic_interpolation(dx,
get_value(data, shape, n, c, y, floor(x) - 1),
get_value(data, shape, n, c, y, floor(x)),
get_value(data, shape, n, c, y, ceil(x)),
get_value(data, shape, n, c, y, ceil(x) + 1));
}
// Interpolate in 2D space
template <typename Dtype>
__device__ Dtype interpolate_xy(
const Dtype* data, const uint4& shape,
const unsigned int n, const unsigned int c,
const Dtype y, const Dtype x
) {
Dtype dy = y - floor(y);
return cubic_interpolation(dy,
interpolate_x(data, shape, n, c, floor(y) - 1, x),
interpolate_x(data, shape, n, c, floor(y), x),
interpolate_x(data, shape, n, c, ceil(y), x),
interpolate_x(data, shape, n, c, ceil(y) + 1, x));
}
template <typename Dtype>
__global__ void spatial_transformations(
const Dtype* src_data, const uint4 src_shape,
const AugmentSelection* aug_data,
Dtype* dst_data, const uint4 dst_shape
) {
CUDA_KERNEL_LOOP(loop_index, dst_shape.x * dst_shape.y * dst_shape.w) {
int dst_x, dst_y, n;
get_pixel_indices(loop_index, dst_shape, &dst_x, &dst_y, &n);
const AugmentSelection& as = aug_data[n];
// calculate src pixel indices for this thread
Dtype x = dst_x;
Dtype y = dst_y;
// crop
x += as.crop_offset.x;
y += as.crop_offset.y;
// rotate
if (abs(as.rotation) > FLT_EPSILON) {
const Dtype w_before = as.scale.width - 1;
const Dtype h_before = as.scale.height - 1;
const float angle = as.rotation * CUDART_PI_F / 180.0f;
const Dtype w_after = abs(w_before * cos(angle)) +
abs(h_before * sin(angle));
const Dtype h_after = abs(w_before * sin(angle)) +
abs(h_before * cos(angle));
rotate_point(x, y, w_after / 2.0f, h_after / 2.0f,
-angle, &x, &y);
x -= (w_after - w_before) / 2.0f;
y -= (h_after - h_before) / 2.0f;
}
// scale
if (src_shape.x != as.scale.width) {
x *= Dtype(src_shape.x - 1) / (as.scale.width - 1);
}
if (src_shape.y != as.scale.height) {
y *= Dtype(src_shape.y - 1) / (as.scale.height - 1);
}
// flip
if (as.flip) {
x = (src_shape.x - x - 1.0);
}
for (int c = 0; c < dst_shape.z; c++) {
// N*cs*hs*ws + C*hs*ws + H*ws + W
const int dst_idx = (n * dst_shape.z * dst_shape.y * dst_shape.x) +
(c * dst_shape.y * dst_shape.x) + (dst_y * dst_shape.x) + dst_x;
dst_data[dst_idx] = interpolate_xy(src_data, src_shape, n, c, y, x);
}
}
}
template <typename Dtype>
void DetectNetTransformationLayer<Dtype>::Forward_gpu(
const vector<Blob*>& bottom,
const vector<Blob*>& top) {
const Dtype* bottom_data = bottom[0]->gpu_data<Dtype>();
Dtype* top_data = top[0]->mutable_gpu_data<Dtype>();
AugmentSelection* aug_data = reinterpret_cast<AugmentSelection*>(
gpu_workspace_augmentations_.data());
Dtype* tmp_data = reinterpret_cast<Dtype*>(
gpu_workspace_tmpdata_.data());
const uint4 bottom_shape = make_uint4(
bottom[0]->shape(3), // x = W
bottom[0]->shape(2), // y = H
bottom[0]->shape(1), // z = C
bottom[0]->shape(0)); // w = N
const int bottom_count = bottom[0]->count();
const int bottom_pixels = bottom_shape.x * bottom_shape.y * bottom_shape.w;
const uint4 top_shape = make_uint4(
top[0]->shape(3), // x = W
top[0]->shape(2), // y = H
top[0]->shape(1), // z = C
top[0]->shape(0)); // w = N
const int top_count = top[0]->count();
const int top_pixels = top_shape.x * top_shape.y * top_shape.w;
// Get current stream
hipStream_t stream = Caffe::thread_stream();
// Make augmentation selections for each image
vector<AugmentSelection> augmentations;
for (int i = 0; i < bottom_shape.w; i++) {
augmentations.push_back(get_augmentations(
cv::Point(bottom_shape.x, bottom_shape.y)));
}
// Copy augmentation selections to GPU
size_t aug_data_sz = sizeof(AugmentSelection) * augmentations.size();
caffe_gpu_memcpy(aug_data_sz, &augmentations[0], aug_data);
// Color transformations
// NOLINT_NEXT_LINE(whitespace/operators)
hipLaunchKernelGGL(( color_transformations), dim3(CAFFE_GET_BLOCKS(bottom_pixels)),
dim3(CAFFE_CUDA_NUM_THREADS), 0, stream, bottom_data, tmp_data, bottom_shape, aug_data);
CUDA_CHECK(hipStreamSynchronize(stream));
// Mean subtraction
if (t_param_.has_mean_file()) {
// NOLINT_NEXT_LINE(whitespace/operators)
hipLaunchKernelGGL(( pixel_mean_subtraction), dim3(CAFFE_GET_BLOCKS(bottom_pixels)),
dim3(CAFFE_CUDA_NUM_THREADS), 0, stream, tmp_data, mean_blob_.gpu_data(), bottom_shape);
} else if (t_param_.mean_value_size() != 0) {
CHECK_EQ(bottom_shape.z, 3) << "Data must have 3 channels when "
"using transform_param.mean_value.";
// NOLINT_NEXT_LINE(whitespace/operators)
hipLaunchKernelGGL(( channel_mean_subtraction), dim3(CAFFE_GET_BLOCKS(bottom_pixels)),
dim3(CAFFE_CUDA_NUM_THREADS), 0, stream, tmp_data, bottom_shape,
mean_values_[0] * UINT8_MAX,
mean_values_[1] * UINT8_MAX,
mean_values_[2] * UINT8_MAX);
}
// Spatial transformations
// NOLINT_NEXT_LINE(whitespace/operators)
hipLaunchKernelGGL(( spatial_transformations), dim3(CAFFE_GET_BLOCKS(top_pixels)),
dim3(CAFFE_CUDA_NUM_THREADS), 0, stream, tmp_data, bottom_shape, aug_data,
top_data, top_shape);
CUDA_CHECK(hipStreamSynchronize(stream));
// Use CPU to transform labels
const vector<vector<BboxLabel> > list_list_bboxes = blobToLabels(*bottom[1]);
for (size_t i = 0; i < bottom[1]->num(); i++) {
const vector<BboxLabel>& list_bboxes = list_list_bboxes[i];
Dtype* output_label = &top[1]->mutable_cpu_data<Dtype>()[
top[1]->offset(i, 0, 0, 0)
];
transform_label_cpu(list_bboxes, output_label, augmentations[i],
cv::Size(bottom_shape.x, bottom_shape.y));
}
}
INSTANTIATE_LAYER_GPU_FORWARD(DetectNetTransformationLayer);
} // namespace caffe
| ba236ec8cd31489f17ec13c08706ce99c4b41990.cu | #include <math.h>
#include <math_constants.h>
#include <opencv2/core/core.hpp>
#include <vector>
#include "caffe/layers/detectnet_transform_layer.hpp"
#include "caffe/util/detectnet_coverage.hpp"
#include "caffe/util/gpu_memory.hpp"
#include "caffe/util/math_functions.hpp"
namespace caffe {
// Calculate the location in the image from the loop index
__device__ void get_pixel_indices(const int loop_index,
const uint4 shape, int* x, int* y, int* n
) {
int idx = loop_index;
*n = idx / (shape.y * shape.x);
idx -= *n * shape.y * shape.x;
*y = idx / shape.x;
idx -= *y * shape.x;
*x = idx;
}
// https://www.cs.rit.edu/~ncs/color/t_convert.html
template <typename Dtype>
__device__ void convert_rgb_to_hsv(
Dtype r, Dtype g, Dtype b,
Dtype* h, Dtype* s, Dtype* v
) {
Dtype min_v = min(min(r, g), b);
Dtype max_v = max(max(r, g), b); // NOLINT(build/include_what_you_use)
Dtype delta = max_v - min_v;
if (max_v == 0 || delta == 0) {
*h = 0;
*s = 0;
*v = max_v;
return;
}
if (r == max_v) {
*h = (g - b) / delta;
} else if (g == max_v) {
*h = 2 + (b - r) / delta;
} else {
*h = 4 + (r - g) / delta;
}
*h *= 60;
if (h < 0) {
*h += 360;
}
*s = delta / max_v;
*v = max_v;
}
// https://www.cs.rit.edu/~ncs/color/t_convert.html
template <typename Dtype>
__device__ void convert_hsv_to_rgb(
Dtype h, Dtype s, Dtype v,
Dtype* r, Dtype* g, Dtype* b
) {
int i;
Dtype f, p, q, t;
if (s == 0) {
*r = v;
*g = v;
*b = v;
return;
}
h /= 60; // sector 0 to 5
i = floor(h);
f = h - i; // factorial part of h
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * (1 - f));
switch (i) {
case 0:
*r = v;
*g = t;
*b = p;
break;
case 1:
*r = q;
*g = v;
*b = p;
break;
case 2:
*r = p;
*g = v;
*b = t;
break;
case 3:
*r = p;
*g = q;
*b = v;
break;
case 4:
*r = t;
*g = p;
*b = v;
break;
default: // case 5:
*r = v;
*g = p;
*b = q;
break;
}
}
template <typename Dtype>
__global__ void color_transformations(
const Dtype* src_data, Dtype* dst_data,
const uint4 shape, const AugmentSelection* aug_data
) {
CUDA_KERNEL_LOOP(loop_index, shape.x * shape.y * shape.w) {
int x, y, n;
get_pixel_indices(loop_index, shape, &x, &y, &n);
// check what needs doing
const AugmentSelection& as = aug_data[n];
const bool doHueRotation = (abs(as.hue_rotation) > FLT_EPSILON);
const bool doDesaturation = (as.saturation < (1.0 - 1.0/UINT8_MAX));
// N*cs*hs*ws + H*ws + W
int index = n * shape.z * shape.y * shape.x + y * shape.x + x;
// hs*ws
const int channel_stride = shape.y * shape.x;
// read
Dtype r = src_data[index + 0 * channel_stride];
Dtype g = src_data[index + 1 * channel_stride];
Dtype b = src_data[index + 2 * channel_stride];
if (doHueRotation || doDesaturation) {
// transform
Dtype h, s, v;
convert_rgb_to_hsv(r, g, b, &h, &s, &v);
if (doHueRotation) {
h -= aug_data[n].hue_rotation;
}
if (doDesaturation) {
s *= aug_data[n].saturation;
}
convert_hsv_to_rgb(h, s, v, &r, &g, &b);
}
// write
dst_data[index + 0 * channel_stride] = r;
dst_data[index + 1 * channel_stride] = g;
dst_data[index + 2 * channel_stride] = b;
}
}
// Mean is WxHxC
// For each pixel in the current image, subtract the corresponding pixel
// from the mean image
template <typename Dtype>
__global__ void pixel_mean_subtraction(
Dtype* data, const Dtype* mean_data, const uint4 shape
) {
CUDA_KERNEL_LOOP(loop_index, shape.x * shape.y * shape.w) {
int x, y, n;
get_pixel_indices(loop_index, shape, &x, &y, &n);
for (int c = 0; c < shape.z; c++) {
// N*cs*hs*ws + C*hs*ws + H*ws + W
const int data_idx = (n * shape.z * shape.y * shape.x) +
(c * shape.y * shape.x) + (y * shape.x) + x;
// C*hs*ws + H*ws + W
const int mean_idx = (c * shape.y * shape.x) + (y * shape.x) + x;
data[data_idx] -= mean_data[mean_idx];
}
}
}
// Mean is 1x1xC
// For each pixel in the current image, subtract the mean pixel
template <typename Dtype>
__global__ void channel_mean_subtraction(
Dtype* data, const uint4 shape,
const Dtype mean_value1, const Dtype mean_value2, const Dtype mean_value3
) {
CUDA_KERNEL_LOOP(loop_index, shape.x * shape.y * shape.w) {
int x, y, n;
get_pixel_indices(loop_index, shape, &x, &y, &n);
// N*cs*hs*ws + C*hs*ws + H*ws + W
const int data_idx = (n * shape.z * shape.y * shape.x) +(y * shape.x) + x;
// hs*ws
const int channel_stride = shape.y * shape.x;
data[data_idx + 0 * channel_stride] -= mean_value1;
data[data_idx + 1 * channel_stride] -= mean_value2;
data[data_idx + 2 * channel_stride] -= mean_value3;
}
}
template <typename Dtype>
__device__ void rotate_point(
const Dtype ax, const Dtype ay, // original point
const Dtype cx, const Dtype cy, // center point
float angle,
Dtype* bx, Dtype* by // destination point
) {
const Dtype s = sin(angle);
const Dtype c = cos(angle);
// translate to origin
const Dtype tx = ax - cx;
const Dtype ty = ay - cy;
*bx = (tx * c) - (ty * s) + cx;
*by = (tx * s) + (ty * c) + cy;
}
template <typename Dtype>
__device__ Dtype get_value(
const Dtype* data, const uint4& shape,
const unsigned int n, const unsigned int c,
int y, int x
) {
// Replicate border for 1 pixel
if (x == -1) x = 0;
if (x == shape.x) x = shape.x - 1;
if (y == -1) y = 0;
if (y == shape.y) y = shape.y - 1;
if (x >= 0 && x < shape.x && y >= 0 && y < shape.y) {
// N*cs*hs*ws + C*hs*ws + H*ws + W
return data[(n * shape.z * shape.y * shape.x) +
(c * shape.y * shape.x) + (y * shape.x) + x];
} else {
return 0;
}
}
template <typename Dtype>
__device__ Dtype cubic_interpolation(const Dtype& d,
const Dtype& v1, const Dtype& v2, const Dtype& v3, const Dtype& v4
) {
// d is [0,1], marking the distance from v2 towards v3
return v2 + d * (
-2.0 * v1 - 3.0 * v2 + 6.0 * v3 - 1.0 * v4 + d * (
3.0 * v1 - 6.0 * v2 + 3.0 * v3 + 0.0 * v4 + d * (
-1.0 * v1 + 3.0 * v2 - 3.0 * v3 + 1.0 * v4))) / 6.0;
}
// Interpolate in 1D space
template <typename Dtype>
__device__ Dtype interpolate_x(
const Dtype* data, const uint4& shape,
const unsigned int n, const unsigned int c,
const int y, const Dtype x
) {
Dtype dx = x - floor(x);
return cubic_interpolation(dx,
get_value(data, shape, n, c, y, floor(x) - 1),
get_value(data, shape, n, c, y, floor(x)),
get_value(data, shape, n, c, y, ceil(x)),
get_value(data, shape, n, c, y, ceil(x) + 1));
}
// Interpolate in 2D space
template <typename Dtype>
__device__ Dtype interpolate_xy(
const Dtype* data, const uint4& shape,
const unsigned int n, const unsigned int c,
const Dtype y, const Dtype x
) {
Dtype dy = y - floor(y);
return cubic_interpolation(dy,
interpolate_x(data, shape, n, c, floor(y) - 1, x),
interpolate_x(data, shape, n, c, floor(y), x),
interpolate_x(data, shape, n, c, ceil(y), x),
interpolate_x(data, shape, n, c, ceil(y) + 1, x));
}
template <typename Dtype>
__global__ void spatial_transformations(
const Dtype* src_data, const uint4 src_shape,
const AugmentSelection* aug_data,
Dtype* dst_data, const uint4 dst_shape
) {
CUDA_KERNEL_LOOP(loop_index, dst_shape.x * dst_shape.y * dst_shape.w) {
int dst_x, dst_y, n;
get_pixel_indices(loop_index, dst_shape, &dst_x, &dst_y, &n);
const AugmentSelection& as = aug_data[n];
// calculate src pixel indices for this thread
Dtype x = dst_x;
Dtype y = dst_y;
// crop
x += as.crop_offset.x;
y += as.crop_offset.y;
// rotate
if (abs(as.rotation) > FLT_EPSILON) {
const Dtype w_before = as.scale.width - 1;
const Dtype h_before = as.scale.height - 1;
const float angle = as.rotation * CUDART_PI_F / 180.0f;
const Dtype w_after = abs(w_before * cos(angle)) +
abs(h_before * sin(angle));
const Dtype h_after = abs(w_before * sin(angle)) +
abs(h_before * cos(angle));
rotate_point(x, y, w_after / 2.0f, h_after / 2.0f,
-angle, &x, &y);
x -= (w_after - w_before) / 2.0f;
y -= (h_after - h_before) / 2.0f;
}
// scale
if (src_shape.x != as.scale.width) {
x *= Dtype(src_shape.x - 1) / (as.scale.width - 1);
}
if (src_shape.y != as.scale.height) {
y *= Dtype(src_shape.y - 1) / (as.scale.height - 1);
}
// flip
if (as.flip) {
x = (src_shape.x - x - 1.0);
}
for (int c = 0; c < dst_shape.z; c++) {
// N*cs*hs*ws + C*hs*ws + H*ws + W
const int dst_idx = (n * dst_shape.z * dst_shape.y * dst_shape.x) +
(c * dst_shape.y * dst_shape.x) + (dst_y * dst_shape.x) + dst_x;
dst_data[dst_idx] = interpolate_xy(src_data, src_shape, n, c, y, x);
}
}
}
template <typename Dtype>
void DetectNetTransformationLayer<Dtype>::Forward_gpu(
const vector<Blob*>& bottom,
const vector<Blob*>& top) {
const Dtype* bottom_data = bottom[0]->gpu_data<Dtype>();
Dtype* top_data = top[0]->mutable_gpu_data<Dtype>();
AugmentSelection* aug_data = reinterpret_cast<AugmentSelection*>(
gpu_workspace_augmentations_.data());
Dtype* tmp_data = reinterpret_cast<Dtype*>(
gpu_workspace_tmpdata_.data());
const uint4 bottom_shape = make_uint4(
bottom[0]->shape(3), // x = W
bottom[0]->shape(2), // y = H
bottom[0]->shape(1), // z = C
bottom[0]->shape(0)); // w = N
const int bottom_count = bottom[0]->count();
const int bottom_pixels = bottom_shape.x * bottom_shape.y * bottom_shape.w;
const uint4 top_shape = make_uint4(
top[0]->shape(3), // x = W
top[0]->shape(2), // y = H
top[0]->shape(1), // z = C
top[0]->shape(0)); // w = N
const int top_count = top[0]->count();
const int top_pixels = top_shape.x * top_shape.y * top_shape.w;
// Get current stream
cudaStream_t stream = Caffe::thread_stream();
// Make augmentation selections for each image
vector<AugmentSelection> augmentations;
for (int i = 0; i < bottom_shape.w; i++) {
augmentations.push_back(get_augmentations(
cv::Point(bottom_shape.x, bottom_shape.y)));
}
// Copy augmentation selections to GPU
size_t aug_data_sz = sizeof(AugmentSelection) * augmentations.size();
caffe_gpu_memcpy(aug_data_sz, &augmentations[0], aug_data);
// Color transformations
// NOLINT_NEXT_LINE(whitespace/operators)
color_transformations<<<CAFFE_GET_BLOCKS(bottom_pixels),
CAFFE_CUDA_NUM_THREADS, 0, stream>>>(bottom_data, tmp_data, bottom_shape, aug_data);
CUDA_CHECK(cudaStreamSynchronize(stream));
// Mean subtraction
if (t_param_.has_mean_file()) {
// NOLINT_NEXT_LINE(whitespace/operators)
pixel_mean_subtraction<<<CAFFE_GET_BLOCKS(bottom_pixels),
CAFFE_CUDA_NUM_THREADS, 0, stream>>>(tmp_data, mean_blob_.gpu_data(), bottom_shape);
} else if (t_param_.mean_value_size() != 0) {
CHECK_EQ(bottom_shape.z, 3) << "Data must have 3 channels when "
"using transform_param.mean_value.";
// NOLINT_NEXT_LINE(whitespace/operators)
channel_mean_subtraction<<<CAFFE_GET_BLOCKS(bottom_pixels),
CAFFE_CUDA_NUM_THREADS, 0, stream>>>(tmp_data, bottom_shape,
mean_values_[0] * UINT8_MAX,
mean_values_[1] * UINT8_MAX,
mean_values_[2] * UINT8_MAX);
}
// Spatial transformations
// NOLINT_NEXT_LINE(whitespace/operators)
spatial_transformations<<<CAFFE_GET_BLOCKS(top_pixels),
CAFFE_CUDA_NUM_THREADS, 0, stream>>>(tmp_data, bottom_shape, aug_data,
top_data, top_shape);
CUDA_CHECK(cudaStreamSynchronize(stream));
// Use CPU to transform labels
const vector<vector<BboxLabel> > list_list_bboxes = blobToLabels(*bottom[1]);
for (size_t i = 0; i < bottom[1]->num(); i++) {
const vector<BboxLabel>& list_bboxes = list_list_bboxes[i];
Dtype* output_label = &top[1]->mutable_cpu_data<Dtype>()[
top[1]->offset(i, 0, 0, 0)
];
transform_label_cpu(list_bboxes, output_label, augmentations[i],
cv::Size(bottom_shape.x, bottom_shape.y));
}
}
INSTANTIATE_LAYER_GPU_FORWARD(DetectNetTransformationLayer);
} // namespace caffe
|
4713188960d0f4f9cd6f9cb596b6546340e945ff.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__global__ void cuda_f32_to_int8_nomax(float* input_f32, size_t size, int8_t *output_int8, float multipler)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < size) output_int8[idx] = input_f32[idx] * multipler; // 7-bit (1-bit sign)
} | 4713188960d0f4f9cd6f9cb596b6546340e945ff.cu | #include "includes.h"
__global__ void cuda_f32_to_int8_nomax(float* input_f32, size_t size, int8_t *output_int8, float multipler)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < size) output_int8[idx] = input_f32[idx] * multipler; // 7-bit (1-bit sign)
} |
2acff6ee818c4ad7829a9010c59ea9e50968babb.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* Copyright 2008-2009 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ocuutil/thread.h"
#include "ocuutil/float_routines.h"
#include "ocustorage/grid3dops.h"
#include "ocuequation/sol_gradient3d.h"
template<typename T>
__global__ void Sol_Gradient3DDevice_subtract_grad(T *u, T *v, T *w, T *phi, T coefficient,
T invhx, T invhy, T invhz,
int xstride, int ystride,
int nx, int ny, int nz, int blocksInY, float invBlocksInY)
{
int blockIdxz = truncf(blockIdx.y * invBlocksInY);
int blockIdxy = blockIdx.y - __mul24(blockIdxz,blocksInY);
// transpose for coalescing since k is the fastest changing index
int k = __mul24(blockIdx.x,blockDim.x) + threadIdx.x;
int j = __mul24(blockIdxy ,blockDim.y) + threadIdx.y;
int i = __mul24(blockIdxz ,blockDim.z) + threadIdx.z;
if (i < nx && j < ny && k < nz) {
int idx = __mul24(i, xstride) + __mul24(j,ystride) + k;
T p_ijk = phi[idx];
u[idx] += coefficient * invhx * (p_ijk - phi[idx - xstride]);
v[idx] += coefficient * invhy * (p_ijk - phi[idx - ystride]);
w[idx] += coefficient * invhz * (p_ijk - phi[idx - 1 ]);
}
}
namespace ocu {
template<typename T>
Sol_Gradient3DDevice<T>::Sol_Gradient3DDevice()
{
_hx = _hy = _hz;
u = v = w = 0;
phi = 0;
coefficient = (T)-1;
}
template<typename T>
bool
Sol_Gradient3DDevice<T>::solve()
{
int tnx = phi->nz();
int tny = phi->ny();
int tnz = phi->nx();
int threadsInX = 16;
int threadsInY = 4;
int threadsInZ = 4;
int blocksInX = (tnx+threadsInX-1)/threadsInX;
int blocksInY = (tny+threadsInY-1)/threadsInY;
int blocksInZ = (tnz+threadsInZ-1)/threadsInZ;
dim3 Dg = dim3(blocksInX, blocksInY*blocksInZ);
dim3 Db = dim3(threadsInX, threadsInY, threadsInZ);
PreKernel();
hipLaunchKernelGGL(( Sol_Gradient3DDevice_subtract_grad), dim3(Dg), dim3(Db), 0, ThreadManager::get_compute_stream(), &u->at(0,0,0),&v->at(0,0,0),&w->at(0,0,0), &phi->at(0,0,0), coefficient,
(T)(1/_hx), (T)(1/_hy), (T)(1/_hz),
phi->xstride(), phi->ystride(),
phi->nx(), phi->ny(), phi->nz(), blocksInY, 1.0f / (float)blocksInY);
return PostKernelDim("Sol_Gradient3DDevice_subtract_grad", Dg, Db);
}
template<typename T>
bool
Sol_Gradient3DDevice<T>::initialize_storage(int nx, int ny, int nz, double hx, double hy, double hz,
Grid3DDevice<T> *u_val, Grid3DDevice<T> *v_val, Grid3DDevice<T> *w_val, Grid3DDevice<T> *phi_val)
{
u = u_val;
v = v_val;
w = w_val;
phi = phi_val;
if (!check_valid_mac_dimensions(*u_val, *v_val, *w_val, nx, ny, nz)) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - u,v,w grid dimensions mismatch\n");
return false;
}
if (phi_val->nx() != nx || phi_val->ny() != ny || phi_val->nz() != nz ||
!phi_val->check_layout_match(*u_val)) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - invalid dimensions for phi\n");
return false;
}
// since they all have the same layout, we only need to test u
if (u_val->gx() < 1 || u_val->gy() < 1 || u_val->gz() < 1) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - must have at least one ghost cell on all sides\n");
return false;
}
if (!check_float(hx) || !check_float(hy) || !check_float(hz)) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - garbage hx,hy,hz value\n");
return false;
}
_hx = hx;
_hy = hy;
_hz = hz;
return true;
}
template class Sol_Gradient3DDevice<float>;
#ifdef OCU_DOUBLESUPPORT
template class Sol_Gradient3DDevice<double>;
#endif
} // end namespace
| 2acff6ee818c4ad7829a9010c59ea9e50968babb.cu | /*
* Copyright 2008-2009 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ocuutil/thread.h"
#include "ocuutil/float_routines.h"
#include "ocustorage/grid3dops.h"
#include "ocuequation/sol_gradient3d.h"
template<typename T>
__global__ void Sol_Gradient3DDevice_subtract_grad(T *u, T *v, T *w, T *phi, T coefficient,
T invhx, T invhy, T invhz,
int xstride, int ystride,
int nx, int ny, int nz, int blocksInY, float invBlocksInY)
{
int blockIdxz = truncf(blockIdx.y * invBlocksInY);
int blockIdxy = blockIdx.y - __mul24(blockIdxz,blocksInY);
// transpose for coalescing since k is the fastest changing index
int k = __mul24(blockIdx.x,blockDim.x) + threadIdx.x;
int j = __mul24(blockIdxy ,blockDim.y) + threadIdx.y;
int i = __mul24(blockIdxz ,blockDim.z) + threadIdx.z;
if (i < nx && j < ny && k < nz) {
int idx = __mul24(i, xstride) + __mul24(j,ystride) + k;
T p_ijk = phi[idx];
u[idx] += coefficient * invhx * (p_ijk - phi[idx - xstride]);
v[idx] += coefficient * invhy * (p_ijk - phi[idx - ystride]);
w[idx] += coefficient * invhz * (p_ijk - phi[idx - 1 ]);
}
}
namespace ocu {
template<typename T>
Sol_Gradient3DDevice<T>::Sol_Gradient3DDevice()
{
_hx = _hy = _hz;
u = v = w = 0;
phi = 0;
coefficient = (T)-1;
}
template<typename T>
bool
Sol_Gradient3DDevice<T>::solve()
{
int tnx = phi->nz();
int tny = phi->ny();
int tnz = phi->nx();
int threadsInX = 16;
int threadsInY = 4;
int threadsInZ = 4;
int blocksInX = (tnx+threadsInX-1)/threadsInX;
int blocksInY = (tny+threadsInY-1)/threadsInY;
int blocksInZ = (tnz+threadsInZ-1)/threadsInZ;
dim3 Dg = dim3(blocksInX, blocksInY*blocksInZ);
dim3 Db = dim3(threadsInX, threadsInY, threadsInZ);
PreKernel();
Sol_Gradient3DDevice_subtract_grad<<<Dg, Db, 0, ThreadManager::get_compute_stream()>>>(&u->at(0,0,0),&v->at(0,0,0),&w->at(0,0,0), &phi->at(0,0,0), coefficient,
(T)(1/_hx), (T)(1/_hy), (T)(1/_hz),
phi->xstride(), phi->ystride(),
phi->nx(), phi->ny(), phi->nz(), blocksInY, 1.0f / (float)blocksInY);
return PostKernelDim("Sol_Gradient3DDevice_subtract_grad", Dg, Db);
}
template<typename T>
bool
Sol_Gradient3DDevice<T>::initialize_storage(int nx, int ny, int nz, double hx, double hy, double hz,
Grid3DDevice<T> *u_val, Grid3DDevice<T> *v_val, Grid3DDevice<T> *w_val, Grid3DDevice<T> *phi_val)
{
u = u_val;
v = v_val;
w = w_val;
phi = phi_val;
if (!check_valid_mac_dimensions(*u_val, *v_val, *w_val, nx, ny, nz)) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - u,v,w grid dimensions mismatch\n");
return false;
}
if (phi_val->nx() != nx || phi_val->ny() != ny || phi_val->nz() != nz ||
!phi_val->check_layout_match(*u_val)) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - invalid dimensions for phi\n");
return false;
}
// since they all have the same layout, we only need to test u
if (u_val->gx() < 1 || u_val->gy() < 1 || u_val->gz() < 1) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - must have at least one ghost cell on all sides\n");
return false;
}
if (!check_float(hx) || !check_float(hy) || !check_float(hz)) {
printf("[ERROR] Sol_Gradient3DDevice::initialize_storage - garbage hx,hy,hz value\n");
return false;
}
_hx = hx;
_hy = hy;
_hz = hz;
return true;
}
template class Sol_Gradient3DDevice<float>;
#ifdef OCU_DOUBLESUPPORT
template class Sol_Gradient3DDevice<double>;
#endif
} // end namespace
|
cc51f4f47f0044e20a89d2f6fc0651249a9fe697.hip | // !!! This is a file automatically generated by hipify!!!
#include <sys/types.h>
#include <dirent.h>
#include <iostream>
#include <hip/hip_runtime.h>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <string>
#include <cerrno>
#include <hipcub/hipcub.hpp>
#include "gputimer.h"
#include "stopwords.h"
using namespace std;
struct myVec
{
char a[4096];
int b;
};
struct posting
{
unsigned long long key;
int value;
};
__shared__ char sh_document[4097];
//__shared__ char sh_check[4097];
//__shared__ long sh_hash_val[4097];
__shared__ unsigned long long sh_tokens[4097];
__device__ int len(int i)
{
int len = 0;
for(;sh_tokens[i]==0;i++,len++);
return len;
}
__device__ __host__ unsigned long SDBM(const char* str, unsigned int length)
{
unsigned long hash = 0;
unsigned int i;
for(i = 0; i < length; ++str, i++)
{
hash = (*str) + (hash << 6) + (hash << 16) - hash;
}
return hash;
}
__device__ bool isAlpha(char ch)
{
if(((ch>='a')&&(ch<='z'))||((ch>='A')&&(ch<='Z')))
return true;
else
return false;
}
__global__ void map(myVec *text,posting *d_out,unsigned long long int *tell)
{
//copying the document to shared memory
int16_t t = threadIdx.x;
int i=0;
while((t<text[blockIdx.x].b)&&(t<4096))
{
sh_document[t] = text[blockIdx.x].a[t];
//sh_check[t] = 0;
sh_tokens[t] = 0;
//sh_hash_val[t] = 0;
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
sh_document[4096] = 0;
//sh_check[4096] = 0;
sh_tokens[4096] = 0;
//Tokenising the document
t = threadIdx.x;
i = 0;
while((t<text[blockIdx.x].b)&&(t<4097)&&(t!=0))
{
if((isAlpha(sh_document[t]))&&(t!=0))
{
/*if((sh_document[t]>=65)&&(sh_document[t]<=90))
sh_document[i] = sh_document[i] + 32;*/
if((!isAlpha(sh_document[t-1]))&&(sh_tokens[t-1]==0))
{
atomicAdd(&sh_tokens[t-1],t-1);
}
if(!isAlpha(sh_document[t+1])&&(t<4095)&&(sh_tokens[t+1]==0))
{
atomicAdd(&sh_tokens[t+1],t+1);
}
}
else if(t!=0)
{
if(!isAlpha(sh_document[t-1])&&!isAlpha(sh_document[t+1])&&(sh_tokens[t]==0))
{
atomicAdd(&sh_tokens[t],t);
}
}
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
// Creating the hash
t = threadIdx.x;
i = 0;
while((t<text[blockIdx.x].b)&&(t<4097)&&(t!=0))
{
if((sh_tokens[t]==0)&&(sh_tokens[t-1]!=0))
sh_tokens[t] = SDBM(&sh_document[t],len(t));
else
sh_tokens[t] = 0;
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
//Removing the stopwords
t = threadIdx.x;
i = 0;
while((t<4097))
{
if(sh_tokens[i]!=0)
for(int j=0;j<174;j++)
{
/*if(sh_tokens[i]==d_stopwords[j])
atomicSub(&sh_tokens[i],sh_tokens[i]);//*/
atomicCAS(&sh_tokens[i],d_stopwords[j],0);
}
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
/*//sorting algorithm
if(threadIdx.x==0)
{
for(int i = 0; i < 4097; i++)
{
for(int j = 0; j < 4097-i-1; j++)
{
if(sh_tokens[j]>sh_tokens[j+1])
{
unsigned long long temp = sh_tokens[j];
sh_tokens[j] = sh_tokens[j+1];
sh_tokens[j+1] = temp;
}
}
}
}//*/
//creating the postings
if(blockIdx.x<588){
t = threadIdx.x;
i = 0;
while(t<4097)
{
d_out[blockIdx.x*4097+t].key = sh_tokens[t];
d_out[blockIdx.x*4097+t].value = blockIdx.x;
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
}//*/
/*int count = 0;
unsigned long long t = ptr[threadIdx.x];
__syncthreads();
for(int i = 0; i < len; i++){
if(ptr[i]<t)
count++;
}
__syncthreads();
ptr[count] = t;
*/
/* -----------------------needed later---------------------------
t = threadIdx.x;
i=0;
while((t<text[blockIdx.x].b)&&(t<4097))
{
if((sh_tokens[t]==0)&&(sh_document[t] != '\n')){
sh_check[t] = sh_document[t];}
else if(sh_tokens[t-1]==0)
sh_check[t] = '\0';
else
sh_check[t] = '\0';
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
------------------------------------------------------------------------*/
///*--------------------------------------------for checking values in shared memory------------------------------
if((threadIdx.x==0)&&(blockIdx.x==0))
{
for(int i = 0; i < 4097;i++)
tell[i] = sh_tokens[i];
}
//-------------------------------------------------------------------------------------------------------------*/
}
void read_directory(const string& name, vector<string>& v)
{
DIR* dirp = opendir(name.c_str());
struct dirent * dp;
while ((dp = readdir(dirp)) != NULL) {
if(dp->d_name[0]=='.')
continue;
v.push_back(dp->d_name);
}
closedir(dirp);
}
string get_file_content(const char* filename)
{
ifstream in(filename, std::ios::in | std::ios::binary);
if (in)
{
std::string contents;
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
return(contents);
}
throw(errno);
}
int main(int argc,char** argv)
{
unsigned long long int count;
string path = "/home/aniket/out";
char ch='y';
unsigned long long int *tell;
int fileNumber;
posting *d_out;
myVec *d_fileContent;
vector<string> fileList;
vector<string> fileContent;
int *d_docId;
hipError_t ce;
//cout<<"Enter the path to dataset:\n";
//getline(cin,path);
read_directory(path,fileList);
//-----------------------------------------------to be use to debug problems with file lsiting-----------------------------
// for(vector<string>::iterator it=fileList.begin();it!=fileList.end();++it)
// {
// cout<<*it<<endl;
// }
//-------------------------------------------------------------------------------------------------------------------------
for(unsigned int i=0;i<fileList.size();i++)
fileContent.push_back(get_file_content((path+"/"+fileList[i]).c_str())); //skipped first two files
cout << "No of files copied "<<fileContent.size()<<endl;
hipMallocManaged((void**)&d_fileContent,(fileContent.size())*sizeof(myVec));
//hipMallocManaged((void**)&t,24576*sizeof(int));
hipMallocManaged((void**)&tell,4097*sizeof(unsigned long long int));
ce = hipMallocManaged((void**)&d_out, 4096*fileList.size()*sizeof(posting));
cout<<hipGetErrorString(ce)<<endl;
for(int i=0;i<fileContent.size();i++)
{
//d_fileContent[i].a = (char*)malloc(fileContent[i].size()*sizeof(char));
hipMallocManaged((void**)&tell[i],4096*sizeof(char));
d_fileContent[i].b = fileContent[i].size();
strcpy(d_fileContent[i].a,fileContent[i].c_str());
}
//hipMemcpyToSymbol(d_stopwords, stopword, 174*sizeof(unsigned long long));;
GpuTimer kernelTimer,sortTimer;
kernelTimer.Start();
hipLaunchKernelGGL(( map), dim3(fileContent.size()),dim3(128), 0, 0, d_fileContent,d_out,tell);
kernelTimer.Stop();
ce = hipDeviceSynchronize();
cout<<hipGetErrorString(ce)<<endl;
//--------------------------------------------------------For sorting-----------------------------------------------------
unsigned long long *d_keys_in; //array to hold the hashed terms
int *d_values_in; //array to hold the docId
unsigned long long *d_keys_out; //array to hold the sorted hashed terms
int *d_values_out; //array to hold the corrosponding docId
int num_items = 4096*fileList.size(); //Number of element to be sorted
void *d_temp_storage = NULL; //auxallary space required for the sorting algorithm
size_t temp_storage_bytes = 0; //Size of the auxallary storage
//Alocating spaces for the above variables
hipMallocManaged((void**)&d_values_out, num_items*sizeof(int));
hipMallocManaged((void**)&d_keys_out, num_items*sizeof(unsigned long long));
hipMallocManaged((void**)&d_values_in, num_items*sizeof(int));
hipMallocManaged((void**)&d_keys_in, num_items*sizeof(unsigned long long));
//copying the keys and values form the output of mapper to the input of array for sorting
for(unsigned long long i = 0; i < num_items; i++)
{
d_keys_in[i] = d_out[i].key;
d_values_in[i] = d_out[i].value;
}
hipcub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out, num_items);
//Alocating auxallary space
hipMalloc(&d_temp_storage, temp_storage_bytes);
sortTimer.Start();
hipcub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out, num_items);
hipDeviceSynchronize();//*/
sortTimer.Stop();
//------------------------------------------------------------------------------------------------------------------------
if(ce==hipSuccess)
cout<<"Index Created Sucessfully...!!"<<endl;
else
{
cout<<"Index creation failed: "<<endl;
exit(1);
}
/*-------------------------------------------------------to be used to check file content-----------------------------------
while (ch == 'y')
{
cout << "Enter the file number to be printed: " << endl;
cin >> fileNumber;
if (fileNumber < fileContent.size())
cout << d_fileContent[fileNumber].a;
cout << "Continue..?(y/n): ";
cin >> ch;
}
//---------------------------------------------------------------------------------------------------------------------------*/
//---------------------------------------------------------Printing the execution time----------------------------------------
cout<<"\nKernel Execution time: "<<kernelTimer.Elapsed()<<" ms"<<endl;
cout<<"\nSorting time: "<<sortTimer.Elapsed()<<" ms"<<endl;
cout<<"\n";
//----------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------performing the search operation-------------------------------------------
string term;
GpuTimer searchTimer;
cout<<"Enter the search term: ";
cin>>term;
//std::transform(term.begin(),term.end(),term.begin(),::tolower);
unsigned long long term_hash = SDBM(term.c_str(),term.size());
searchTimer.Start();
for(unsigned long long i = num_items/2; i < num_items; i++)
{
if(d_keys_out[i]==term_hash)
cout<<fileList[d_values_out[i]]<<endl;
}
searchTimer.Stop();
//----------------------------------------------------------------------------------------------------------------------------
/*for(int i=0;i<4096;i++)
{
cout<<d_out[4096*550+i].key<<" ";
}//*/
cout<<"\nSearch time: "<<searchTimer.Elapsed()<<" ms"<<endl;
//cout<<fileContent[0];
cout<<"\n";
hipFree(d_out);
hipFree(d_fileContent);
hipFree(d_values_in);
hipFree(d_keys_in);
hipFree(d_values_out);
hipFree(d_keys_out);
return 0;
}
| cc51f4f47f0044e20a89d2f6fc0651249a9fe697.cu | #include <sys/types.h>
#include <dirent.h>
#include <iostream>
#include <cuda.h>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <string>
#include <cerrno>
#include <cub/cub.cuh>
#include "gputimer.h"
#include "stopwords.h"
using namespace std;
struct myVec
{
char a[4096];
int b;
};
struct posting
{
unsigned long long key;
int value;
};
__shared__ char sh_document[4097];
//__shared__ char sh_check[4097];
//__shared__ long sh_hash_val[4097];
__shared__ unsigned long long sh_tokens[4097];
__device__ int len(int i)
{
int len = 0;
for(;sh_tokens[i]==0;i++,len++);
return len;
}
__device__ __host__ unsigned long SDBM(const char* str, unsigned int length)
{
unsigned long hash = 0;
unsigned int i;
for(i = 0; i < length; ++str, i++)
{
hash = (*str) + (hash << 6) + (hash << 16) - hash;
}
return hash;
}
__device__ bool isAlpha(char ch)
{
if(((ch>='a')&&(ch<='z'))||((ch>='A')&&(ch<='Z')))
return true;
else
return false;
}
__global__ void map(myVec *text,posting *d_out,unsigned long long int *tell)
{
//copying the document to shared memory
int16_t t = threadIdx.x;
int i=0;
while((t<text[blockIdx.x].b)&&(t<4096))
{
sh_document[t] = text[blockIdx.x].a[t];
//sh_check[t] = 0;
sh_tokens[t] = 0;
//sh_hash_val[t] = 0;
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
sh_document[4096] = 0;
//sh_check[4096] = 0;
sh_tokens[4096] = 0;
//Tokenising the document
t = threadIdx.x;
i = 0;
while((t<text[blockIdx.x].b)&&(t<4097)&&(t!=0))
{
if((isAlpha(sh_document[t]))&&(t!=0))
{
/*if((sh_document[t]>=65)&&(sh_document[t]<=90))
sh_document[i] = sh_document[i] + 32;*/
if((!isAlpha(sh_document[t-1]))&&(sh_tokens[t-1]==0))
{
atomicAdd(&sh_tokens[t-1],t-1);
}
if(!isAlpha(sh_document[t+1])&&(t<4095)&&(sh_tokens[t+1]==0))
{
atomicAdd(&sh_tokens[t+1],t+1);
}
}
else if(t!=0)
{
if(!isAlpha(sh_document[t-1])&&!isAlpha(sh_document[t+1])&&(sh_tokens[t]==0))
{
atomicAdd(&sh_tokens[t],t);
}
}
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
// Creating the hash
t = threadIdx.x;
i = 0;
while((t<text[blockIdx.x].b)&&(t<4097)&&(t!=0))
{
if((sh_tokens[t]==0)&&(sh_tokens[t-1]!=0))
sh_tokens[t] = SDBM(&sh_document[t],len(t));
else
sh_tokens[t] = 0;
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
//Removing the stopwords
t = threadIdx.x;
i = 0;
while((t<4097))
{
if(sh_tokens[i]!=0)
for(int j=0;j<174;j++)
{
/*if(sh_tokens[i]==d_stopwords[j])
atomicSub(&sh_tokens[i],sh_tokens[i]);//*/
atomicCAS(&sh_tokens[i],d_stopwords[j],0);
}
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
/*//sorting algorithm
if(threadIdx.x==0)
{
for(int i = 0; i < 4097; i++)
{
for(int j = 0; j < 4097-i-1; j++)
{
if(sh_tokens[j]>sh_tokens[j+1])
{
unsigned long long temp = sh_tokens[j];
sh_tokens[j] = sh_tokens[j+1];
sh_tokens[j+1] = temp;
}
}
}
}//*/
//creating the postings
if(blockIdx.x<588){
t = threadIdx.x;
i = 0;
while(t<4097)
{
d_out[blockIdx.x*4097+t].key = sh_tokens[t];
d_out[blockIdx.x*4097+t].value = blockIdx.x;
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
}//*/
/*int count = 0;
unsigned long long t = ptr[threadIdx.x];
__syncthreads();
for(int i = 0; i < len; i++){
if(ptr[i]<t)
count++;
}
__syncthreads();
ptr[count] = t;
*/
/* -----------------------needed later---------------------------
t = threadIdx.x;
i=0;
while((t<text[blockIdx.x].b)&&(t<4097))
{
if((sh_tokens[t]==0)&&(sh_document[t] != '\n')){
sh_check[t] = sh_document[t];}
else if(sh_tokens[t-1]==0)
sh_check[t] = '\0';
else
sh_check[t] = '\0';
i++;
t = i*blockDim.x+threadIdx.x;
}
__syncthreads();
------------------------------------------------------------------------*/
///*--------------------------------------------for checking values in shared memory------------------------------
if((threadIdx.x==0)&&(blockIdx.x==0))
{
for(int i = 0; i < 4097;i++)
tell[i] = sh_tokens[i];
}
//-------------------------------------------------------------------------------------------------------------*/
}
void read_directory(const string& name, vector<string>& v)
{
DIR* dirp = opendir(name.c_str());
struct dirent * dp;
while ((dp = readdir(dirp)) != NULL) {
if(dp->d_name[0]=='.')
continue;
v.push_back(dp->d_name);
}
closedir(dirp);
}
string get_file_content(const char* filename)
{
ifstream in(filename, std::ios::in | std::ios::binary);
if (in)
{
std::string contents;
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
return(contents);
}
throw(errno);
}
int main(int argc,char** argv)
{
unsigned long long int count;
string path = "/home/aniket/out";
char ch='y';
unsigned long long int *tell;
int fileNumber;
posting *d_out;
myVec *d_fileContent;
vector<string> fileList;
vector<string> fileContent;
int *d_docId;
cudaError_t ce;
//cout<<"Enter the path to dataset:\n";
//getline(cin,path);
read_directory(path,fileList);
//-----------------------------------------------to be use to debug problems with file lsiting-----------------------------
// for(vector<string>::iterator it=fileList.begin();it!=fileList.end();++it)
// {
// cout<<*it<<endl;
// }
//-------------------------------------------------------------------------------------------------------------------------
for(unsigned int i=0;i<fileList.size();i++)
fileContent.push_back(get_file_content((path+"/"+fileList[i]).c_str())); //skipped first two files
cout << "No of files copied "<<fileContent.size()<<endl;
cudaMallocManaged((void**)&d_fileContent,(fileContent.size())*sizeof(myVec));
//cudaMallocManaged((void**)&t,24576*sizeof(int));
cudaMallocManaged((void**)&tell,4097*sizeof(unsigned long long int));
ce = cudaMallocManaged((void**)&d_out, 4096*fileList.size()*sizeof(posting));
cout<<cudaGetErrorString(ce)<<endl;
for(int i=0;i<fileContent.size();i++)
{
//d_fileContent[i].a = (char*)malloc(fileContent[i].size()*sizeof(char));
cudaMallocManaged((void**)&tell[i],4096*sizeof(char));
d_fileContent[i].b = fileContent[i].size();
strcpy(d_fileContent[i].a,fileContent[i].c_str());
}
//cudaMemcpyToSymbol(d_stopwords, stopword, 174*sizeof(unsigned long long));;
GpuTimer kernelTimer,sortTimer;
kernelTimer.Start();
map<<<fileContent.size(),128>>>(d_fileContent,d_out,tell);
kernelTimer.Stop();
ce = cudaDeviceSynchronize();
cout<<cudaGetErrorString(ce)<<endl;
//--------------------------------------------------------For sorting-----------------------------------------------------
unsigned long long *d_keys_in; //array to hold the hashed terms
int *d_values_in; //array to hold the docId
unsigned long long *d_keys_out; //array to hold the sorted hashed terms
int *d_values_out; //array to hold the corrosponding docId
int num_items = 4096*fileList.size(); //Number of element to be sorted
void *d_temp_storage = NULL; //auxallary space required for the sorting algorithm
size_t temp_storage_bytes = 0; //Size of the auxallary storage
//Alocating spaces for the above variables
cudaMallocManaged((void**)&d_values_out, num_items*sizeof(int));
cudaMallocManaged((void**)&d_keys_out, num_items*sizeof(unsigned long long));
cudaMallocManaged((void**)&d_values_in, num_items*sizeof(int));
cudaMallocManaged((void**)&d_keys_in, num_items*sizeof(unsigned long long));
//copying the keys and values form the output of mapper to the input of array for sorting
for(unsigned long long i = 0; i < num_items; i++)
{
d_keys_in[i] = d_out[i].key;
d_values_in[i] = d_out[i].value;
}
cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out, num_items);
//Alocating auxallary space
cudaMalloc(&d_temp_storage, temp_storage_bytes);
sortTimer.Start();
cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out, num_items);
cudaDeviceSynchronize();//*/
sortTimer.Stop();
//------------------------------------------------------------------------------------------------------------------------
if(ce==cudaSuccess)
cout<<"Index Created Sucessfully...!!"<<endl;
else
{
cout<<"Index creation failed: "<<endl;
exit(1);
}
/*-------------------------------------------------------to be used to check file content-----------------------------------
while (ch == 'y')
{
cout << "Enter the file number to be printed: " << endl;
cin >> fileNumber;
if (fileNumber < fileContent.size())
cout << d_fileContent[fileNumber].a;
cout << "Continue..?(y/n): ";
cin >> ch;
}
//---------------------------------------------------------------------------------------------------------------------------*/
//---------------------------------------------------------Printing the execution time----------------------------------------
cout<<"\nKernel Execution time: "<<kernelTimer.Elapsed()<<" ms"<<endl;
cout<<"\nSorting time: "<<sortTimer.Elapsed()<<" ms"<<endl;
cout<<"\n";
//----------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------performing the search operation-------------------------------------------
string term;
GpuTimer searchTimer;
cout<<"Enter the search term: ";
cin>>term;
//std::transform(term.begin(),term.end(),term.begin(),::tolower);
unsigned long long term_hash = SDBM(term.c_str(),term.size());
searchTimer.Start();
for(unsigned long long i = num_items/2; i < num_items; i++)
{
if(d_keys_out[i]==term_hash)
cout<<fileList[d_values_out[i]]<<endl;
}
searchTimer.Stop();
//----------------------------------------------------------------------------------------------------------------------------
/*for(int i=0;i<4096;i++)
{
cout<<d_out[4096*550+i].key<<" ";
}//*/
cout<<"\nSearch time: "<<searchTimer.Elapsed()<<" ms"<<endl;
//cout<<fileContent[0];
cout<<"\n";
cudaFree(d_out);
cudaFree(d_fileContent);
cudaFree(d_values_in);
cudaFree(d_keys_in);
cudaFree(d_values_out);
cudaFree(d_keys_out);
return 0;
}
|
26eb2edb020ab845535ea7b79f0af47b6a55c47b.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__global__ void vectorAdd(const double *A, const double *B, double *C, int numElements)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < numElements)
{
C[i] = A[i] + B[i];
}
printf("threadIdx:(%d, %d, %d) blockIdx:(%d, %d, %d) blockDim:(%d, %d, %d) "
"gridDim:(%d, %d, %d)\n", threadIdx.x, threadIdx.y, threadIdx.z,
blockIdx.x, blockIdx.y, blockIdx.z, blockDim.x, blockDim.y, blockDim.z,
gridDim.x,gridDim.y,gridDim.z);
} | 26eb2edb020ab845535ea7b79f0af47b6a55c47b.cu | #include "includes.h"
__global__ void vectorAdd(const double *A, const double *B, double *C, int numElements)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < numElements)
{
C[i] = A[i] + B[i];
}
printf("threadIdx:(%d, %d, %d) blockIdx:(%d, %d, %d) blockDim:(%d, %d, %d) "
"gridDim:(%d, %d, %d)\n", threadIdx.x, threadIdx.y, threadIdx.z,
blockIdx.x, blockIdx.y, blockIdx.z, blockDim.x, blockDim.y, blockDim.z,
gridDim.x,gridDim.y,gridDim.z);
} |
a32fa56c03d66c96a7379f6cef341352b95d0e00.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/allclose_kernel.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/kernel_registry.h"
namespace phi {
template <typename T>
__global__ void AllcloseCUDAKernel(const T* in_data,
const T* other_data,
const double rtol,
const double atol,
bool equal_nan,
int num,
bool* out_data) {
unsigned int idx = threadIdx.x + blockIdx.x * blockDim.x;
bool val;
for (int i = idx; i < num; i += blockDim.x * gridDim.x) {
const T a = in_data[i], b = other_data[i];
if (isnan(a) || isnan(b)) {
val = equal_nan && isnan(a) == isnan(b);
} else {
T left = (a > b ? a - b : b - a);
T right = atol + (b > 0 ? rtol * b : (-rtol) * b);
T diff = (left > right ? left - right : right - left);
val = a == b || left <= right || diff <= 1e-15;
}
if (!val) *out_data = false;
}
}
template <typename T, typename Context>
void AllCloseKernel(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& y,
const Scalar& rtol,
const Scalar& atol,
bool equal_nan,
DenseTensor* out) {
PADDLE_ENFORCE_EQ(
rtol.dtype(),
DataType::FLOAT64,
phi::errors::InvalidArgument(
"Input (Rtol) type must be double, but get %s.", rtol.dtype()));
PADDLE_ENFORCE_EQ(
atol.dtype(),
DataType::FLOAT64,
phi::errors::InvalidArgument(
"Input (Atol) type must be double, but get %s.", atol.dtype()));
const T* in_data = x.data<T>();
const T* other_data = y.data<T>();
auto rtol_v = rtol.to<double>();
auto atol_v = atol.to<double>();
bool* out_data = dev_ctx.template Alloc<bool>(out);
int num = x.numel();
int block = 1024;
int grid = (block - 1 + num) / block;
grid = (grid > block) ? block : grid;
#ifdef PADDLE_WITH_HIP
hipMemset(out_data, true, sizeof(bool));
#else
hipMemset(out_data, true, sizeof(bool));
#endif
hipLaunchKernelGGL(( AllcloseCUDAKernel<T>), dim3(grid), dim3(block), 0, dev_ctx.stream(),
in_data, other_data, rtol_v, atol_v, equal_nan, num, out_data);
}
} // namespace phi
PD_REGISTER_KERNEL(
allclose, GPU, ALL_LAYOUT, phi::AllCloseKernel, float, double) {
kernel->OutputAt(0).SetDataType(phi::DataType::BOOL);
}
| a32fa56c03d66c96a7379f6cef341352b95d0e00.cu | // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/allclose_kernel.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/kernel_registry.h"
namespace phi {
template <typename T>
__global__ void AllcloseCUDAKernel(const T* in_data,
const T* other_data,
const double rtol,
const double atol,
bool equal_nan,
int num,
bool* out_data) {
unsigned int idx = threadIdx.x + blockIdx.x * blockDim.x;
bool val;
for (int i = idx; i < num; i += blockDim.x * gridDim.x) {
const T a = in_data[i], b = other_data[i];
if (isnan(a) || isnan(b)) {
val = equal_nan && isnan(a) == isnan(b);
} else {
T left = (a > b ? a - b : b - a);
T right = atol + (b > 0 ? rtol * b : (-rtol) * b);
T diff = (left > right ? left - right : right - left);
val = a == b || left <= right || diff <= 1e-15;
}
if (!val) *out_data = false;
}
}
template <typename T, typename Context>
void AllCloseKernel(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& y,
const Scalar& rtol,
const Scalar& atol,
bool equal_nan,
DenseTensor* out) {
PADDLE_ENFORCE_EQ(
rtol.dtype(),
DataType::FLOAT64,
phi::errors::InvalidArgument(
"Input (Rtol) type must be double, but get %s.", rtol.dtype()));
PADDLE_ENFORCE_EQ(
atol.dtype(),
DataType::FLOAT64,
phi::errors::InvalidArgument(
"Input (Atol) type must be double, but get %s.", atol.dtype()));
const T* in_data = x.data<T>();
const T* other_data = y.data<T>();
auto rtol_v = rtol.to<double>();
auto atol_v = atol.to<double>();
bool* out_data = dev_ctx.template Alloc<bool>(out);
int num = x.numel();
int block = 1024;
int grid = (block - 1 + num) / block;
grid = (grid > block) ? block : grid;
#ifdef PADDLE_WITH_HIP
hipMemset(out_data, true, sizeof(bool));
#else
cudaMemset(out_data, true, sizeof(bool));
#endif
AllcloseCUDAKernel<T><<<grid, block, 0, dev_ctx.stream()>>>(
in_data, other_data, rtol_v, atol_v, equal_nan, num, out_data);
}
} // namespace phi
PD_REGISTER_KERNEL(
allclose, GPU, ALL_LAYOUT, phi::AllCloseKernel, float, double) {
kernel->OutputAt(0).SetDataType(phi::DataType::BOOL);
}
|
944933d06fc20d00122c8a63d2f65a692354bcad.hip | // !!! This is a file automatically generated by hipify!!!
#include <ATen/Context.h>
#include <ATen/hip/HIPContext.h>
#include <ATen/Dispatch.h>
#include <ATen/NativeFunctions.h>
#include <ATen/hip/PinnedMemoryAllocator.h>
#include <ATen/hip/HIPApplyUtils.cuh>
#include <ATen/hip/detail/IndexUtils.cuh>
#include <ATen/native/LinearAlgebraUtils.h>
#include <ATen/native/hip/MiscUtils.h>
#include <ATen/native/Resize.h>
#include <ATen/native/BatchLinearAlgebra.h>
#include <ATen/native/hip/BatchLinearAlgebraLib.h>
#include <ATen/native/cpu/zmath.h>
#include <THH/THH.h> // for USE_MAGMA
#ifdef USE_MAGMA
#include <magma_types.h>
#include <magma_v2.h>
const bool use_magma_ = true;
#else
const bool use_magma_ = false;
#endif
namespace at {
namespace native {
#ifdef USE_MAGMA
template<class scalar_t>
void magmaSolve(
magma_int_t n, magma_int_t nrhs, scalar_t* dA, magma_int_t ldda,
magma_int_t* ipiv, scalar_t* dB, magma_int_t lddb, magma_int_t* info);
template<class scalar_t>
void magmaSolveBatched(
magma_int_t n, magma_int_t nrhs, scalar_t** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, scalar_t** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaLu(
magma_int_t m, magma_int_t n, scalar_t* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info);
template<class scalar_t>
void magmaLuBatched(
magma_int_t m, magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaLuNoPiv(
magma_int_t m, magma_int_t n, scalar_t* dA, magma_int_t ldda,
magma_int_t* info);
template<class scalar_t>
void magmaLuNoPivBatched(
magma_int_t m, magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
inline magma_int_t magmaGetriOptimalBlocksize(magma_int_t n);
template<class scalar_t>
void magmaGetri(
magma_int_t n, scalar_t* dA, magma_int_t ldda, magma_int_t* ipiv, scalar_t* dwork,
magma_int_t lwork, magma_int_t* info);
template<class scalar_t>
void magmaGetriBatched(
magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, scalar_t** dinvA_array, magma_int_t lddia,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaCholeskySolve(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, scalar_t* dA, magma_int_t ldda,
scalar_t* dB, magma_int_t lddb, magma_int_t* info);
template<class scalar_t>
void magmaCholeskySolveBatched(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, scalar_t** dA_array, magma_int_t ldda,
scalar_t** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaCholesky(
magma_uplo_t uplo, magma_int_t n, scalar_t* dA,
magma_int_t ldda, magma_int_t* info);
template<class scalar_t>
void magmaCholeskyBatched(
magma_uplo_t uplo, magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaTriangularSolveBatched(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
scalar_t** dA_array, magma_int_t ldda, scalar_t** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue);
template<class scalar_t>
inline magma_int_t magmaGeqrfOptimalBlocksize(magma_int_t m, magma_int_t n);
template<class scalar_t>
void magmaGeqrf(
magma_int_t m, magma_int_t n, scalar_t* dA, magma_int_t ldda,
scalar_t* tau, scalar_t* dT, magma_int_t* info, bool is_v2);
template<class scalar_t>
void magmaOrgqr(
magma_int_t m, magma_int_t n, magma_int_t k, scalar_t* dA,
magma_int_t ldda, scalar_t* tau, scalar_t* dT, magma_int_t nb, magma_int_t* info);
template<class scalar_t, class value_t=scalar_t>
void magmaSyevd(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, scalar_t* dA, magma_int_t ldda,
value_t* w, scalar_t* wA, magma_int_t ldwa, scalar_t* work, magma_int_t lwork, value_t* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info);
template<class scalar_t, class value_t=scalar_t>
void magmaEig(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n, scalar_t *A, magma_int_t lda,
scalar_t *w, scalar_t *VL, magma_int_t ldvl,
scalar_t *VR, magma_int_t ldvr, scalar_t *work, magma_int_t lwork,
value_t *rwork,
magma_int_t *info);
template<class scalar_t, class value_t=scalar_t>
void magmaSvd(
magma_vec_t jobz, magma_int_t m, magma_int_t n, scalar_t* A,
magma_int_t lda, value_t* s, scalar_t* U, magma_int_t ldu,
scalar_t* VT, magma_int_t ldvt, scalar_t* work, magma_int_t lwork,
value_t* rwork,
magma_int_t* iwork, magma_int_t* info);
template<class scalar_t>
void magmaLuSolve(
magma_int_t n, magma_int_t nrhs, scalar_t* dA, magma_int_t ldda, magma_int_t* ipiv,
scalar_t* dB, magma_int_t lddb, magma_int_t* info);
template<class scalar_t>
void magmaLuSolveBatched(
magma_int_t n, magma_int_t nrhs, scalar_t** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
scalar_t** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaGels(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
scalar_t* dA, magma_int_t ldda, scalar_t* dB, magma_int_t lddb,
scalar_t* hwork, magma_int_t lwork, magma_int_t* info);
template<>
void magmaSolve<double>(
magma_int_t n, magma_int_t nrhs, double* dA, magma_int_t ldda,
magma_int_t* ipiv, double* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgesv_gpu(n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSolve<float>(
magma_int_t n, magma_int_t nrhs, float* dA, magma_int_t ldda,
magma_int_t* ipiv, float* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgesv_gpu(n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSolve<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>* dA, magma_int_t ldda,
magma_int_t* ipiv, c10::complex<double>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgesv_gpu(n, nrhs,
reinterpret_cast<magmaDoubleComplex*>(dA), ldda, ipiv,
reinterpret_cast<magmaDoubleComplex*>(dB), lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSolve<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>* dA, magma_int_t ldda,
magma_int_t* ipiv, c10::complex<float>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgesv_gpu(n, nrhs,
reinterpret_cast<magmaFloatComplex*>(dA), ldda, ipiv,
reinterpret_cast<magmaFloatComplex*>(dB), lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSolveBatched<double>(
magma_int_t n, magma_int_t nrhs, double** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, double** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_dgesv_batched(n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSolveBatched<float>(
magma_int_t n, magma_int_t nrhs, float** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, float** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_sgesv_batched(n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSolveBatched<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, c10::complex<double>** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_zgesv_batched(n, nrhs,
reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, dipiv_array,
reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSolveBatched<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, c10::complex<float>** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_cgesv_batched(n, nrhs,
reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, dipiv_array,
reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLu<double>(
magma_int_t m, magma_int_t n, double* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetrf_gpu(m, n, dA, ldda, ipiv, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLu<float>(
magma_int_t m, magma_int_t n, float* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetrf_gpu(m, n, dA, ldda, ipiv, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLu<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetrf_gpu(m, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, ipiv, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLu<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetrf_gpu(m, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, ipiv, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuBatched<double>(
magma_int_t m, magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_dgetrf_batched(m, n, dA_array, ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuBatched<float>(
magma_int_t m, magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_sgetrf_batched(m, n, dA_array, ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuBatched<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_zgetrf_batched(m, n, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuBatched<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_cgetrf_batched(m, n, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPiv<double>(
magma_int_t m, magma_int_t n, double* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetrf_nopiv_gpu(m, n, dA, ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPiv<float>(
magma_int_t m, magma_int_t n, float* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetrf_nopiv_gpu(m, n, dA, ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPiv<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetrf_nopiv_gpu(m, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPiv<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetrf_nopiv_gpu(m, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPivBatched<double>(
magma_int_t m, magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_dgetrf_nopiv_batched(m, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPivBatched<float>(
magma_int_t m, magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_sgetrf_nopiv_batched(m, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPivBatched<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_zgetrf_nopiv_batched(m, n, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuNoPivBatched<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_cgetrf_nopiv_batched(m, n, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
inline magma_int_t magmaGetriOptimalBlocksize<double>(magma_int_t n) {
return magma_get_dgetri_nb(n);
}
template<>
inline magma_int_t magmaGetriOptimalBlocksize<float>(magma_int_t n) {
return magma_get_sgetri_nb(n);
}
template <>
inline magma_int_t magmaGetriOptimalBlocksize<c10::complex<double>>(
magma_int_t n) {
return magma_get_zgetri_nb(n);
}
template <>
inline magma_int_t magmaGetriOptimalBlocksize<c10::complex<float>>(
magma_int_t n) {
return magma_get_cgetri_nb(n);
}
template<>
void magmaGetri<double>(
magma_int_t n, double* dA, magma_int_t ldda, magma_int_t* ipiv, double* dwork,
magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetri_gpu(n, dA, ldda, ipiv, dwork, lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGetri<float>(
magma_int_t n, float* dA, magma_int_t ldda, magma_int_t* ipiv, float* dwork,
magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetri_gpu(n, dA, ldda, ipiv, dwork, lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaGetri<c10::complex<double>>(
magma_int_t n,
c10::complex<double>* dA,
magma_int_t ldda,
magma_int_t* ipiv,
c10::complex<double>* dwork,
magma_int_t lwork,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetri_gpu(
n,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
ipiv,
reinterpret_cast<magmaDoubleComplex*>(dwork),
lwork,
info);
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaGetri<c10::complex<float>>(
magma_int_t n,
c10::complex<float>* dA,
magma_int_t ldda,
magma_int_t* ipiv,
c10::complex<float>* dwork,
magma_int_t lwork,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetri_gpu(
n,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
ipiv,
reinterpret_cast<magmaFloatComplex*>(dwork),
lwork,
info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGetriBatched<double>(
magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, double** dinvA_array, magma_int_t lddia,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_dgetri_outofplace_batched(n, dA_array, ldda, ipiv_array, dinvA_array, lddia, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGetriBatched<float>(
magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, float** dinvA_array, magma_int_t lddia,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_sgetri_outofplace_batched(n, dA_array, ldda, ipiv_array, dinvA_array, lddia, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaGetriBatched<c10::complex<double>>(
magma_int_t n,
c10::complex<double>** dA_array,
magma_int_t ldda,
magma_int_t** ipiv_array,
c10::complex<double>** dinvA_array,
magma_int_t lddia,
magma_int_t* info_array,
magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_zgetri_outofplace_batched(
n,
reinterpret_cast<magmaDoubleComplex**>(dA_array),
ldda,
ipiv_array,
reinterpret_cast<magmaDoubleComplex**>(dinvA_array),
lddia,
info_array,
batchsize,
magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaGetriBatched<c10::complex<float>>(
magma_int_t n,
c10::complex<float>** dA_array,
magma_int_t ldda,
magma_int_t** ipiv_array,
c10::complex<float>** dinvA_array,
magma_int_t lddia,
magma_int_t* info_array,
magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_cgetri_outofplace_batched(
n,
reinterpret_cast<magmaFloatComplex**>(dA_array),
ldda,
ipiv_array,
reinterpret_cast<magmaFloatComplex**>(dinvA_array),
lddia,
info_array,
batchsize,
magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolve<double>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, double* dA, magma_int_t ldda,
double* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dpotrs_gpu(uplo, n, nrhs, dA, ldda, dB, lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolve<float>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, float* dA, magma_int_t ldda,
float* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_spotrs_gpu(uplo, n, nrhs, dA, ldda, dB, lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolve<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<double>* dA, magma_int_t ldda,
c10::complex<double>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zpotrs_gpu(uplo, n, nrhs,
reinterpret_cast<magmaDoubleComplex*>(dA), ldda,
reinterpret_cast<magmaDoubleComplex*>(dB), lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolve<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<float>* dA, magma_int_t ldda,
c10::complex<float>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cpotrs_gpu(uplo, n, nrhs,
reinterpret_cast<magmaFloatComplex*>(dA), ldda,
reinterpret_cast<magmaFloatComplex*>(dB), lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolveBatched<double>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, double** dA_array, magma_int_t ldda,
double** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_dpotrs_batched(uplo, n, nrhs, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolveBatched<float>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, float** dA_array, magma_int_t ldda,
float** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_spotrs_batched(uplo, n, nrhs, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolveBatched<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<double>** dA_array, magma_int_t ldda,
c10::complex<double>** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_zpotrs_batched(uplo, n, nrhs,
reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda,
reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskySolveBatched<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<float>** dA_array, magma_int_t ldda,
c10::complex<float>** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_cpotrs_batched(uplo, n, nrhs,
reinterpret_cast<magmaFloatComplex**>(dA_array), ldda,
reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholesky<double>(
magma_uplo_t uplo, magma_int_t n, double* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dpotrf_gpu(uplo, n, dA, ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholesky<float>(
magma_uplo_t uplo, magma_int_t n, float* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_spotrf_gpu(uplo, n, dA, ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholesky<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<double>* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zpotrf_gpu(uplo, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholesky<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<float>* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cpotrf_gpu(uplo, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskyBatched<double>(
magma_uplo_t uplo, magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_dpotrf_batched(uplo, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskyBatched<float>(
magma_uplo_t uplo, magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_spotrf_batched(uplo, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskyBatched<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_zpotrf_batched(uplo, n, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaCholeskyBatched<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_cpotrf_batched(uplo, n, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaTriangularSolveBatched<double>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
double** dA_array, magma_int_t ldda, double** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmablas_dtrsm_batched(MagmaLeft, uplo, trans, diag, m, n, 1, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaTriangularSolveBatched<float>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
float** dA_array, magma_int_t ldda, float** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmablas_strsm_batched(MagmaLeft, uplo, trans, diag, m, n, 1, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaTriangularSolveBatched<c10::complex<double>>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
c10::complex<double>** dA_array, magma_int_t ldda, c10::complex<double>** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmaDoubleComplex alpha({1, 0});
magmablas_ztrsm_batched(MagmaLeft, uplo, trans, diag, m, n, alpha,
reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda,
reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaTriangularSolveBatched<c10::complex<float>>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
c10::complex<float>** dA_array, magma_int_t ldda, c10::complex<float>** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmaFloatComplex alpha({1, 0});
magmablas_ctrsm_batched(MagmaLeft, uplo, trans, diag, m, n, alpha,
reinterpret_cast<magmaFloatComplex**>(dA_array), ldda,
reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
inline magma_int_t magmaGeqrfOptimalBlocksize<double>(magma_int_t m, magma_int_t n) {
return magma_get_dgeqrf_nb(m, n);
}
template<>
inline magma_int_t magmaGeqrfOptimalBlocksize<float>(magma_int_t m, magma_int_t n) {
return magma_get_sgeqrf_nb(m, n);
}
template <>
inline magma_int_t magmaGeqrfOptimalBlocksize<c10::complex<double>>(
magma_int_t m,
magma_int_t n) {
return magma_get_zgeqrf_nb(m, n);
}
template <>
inline magma_int_t magmaGeqrfOptimalBlocksize<c10::complex<float>>(
magma_int_t m,
magma_int_t n) {
return magma_get_cgeqrf_nb(m, n);
}
template<>
void magmaGeqrf<double>(
magma_int_t m, magma_int_t n, double* dA, magma_int_t ldda,
double* tau, double* dT, magma_int_t* info, bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_dgeqrf_gpu(m, n, dA, ldda, tau, dT, info);
} else {
magma_dgeqrf2_gpu(m, n, dA, ldda, tau, info);
}
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGeqrf<float>(
magma_int_t m, magma_int_t n, float* dA, magma_int_t ldda,
float* tau, float* dT, magma_int_t* info, bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_sgeqrf_gpu(m, n, dA, ldda, tau, dT, info);
} else {
magma_sgeqrf2_gpu(m, n, dA, ldda, tau, info);
}
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaGeqrf<c10::complex<double>>(
magma_int_t m,
magma_int_t n,
c10::complex<double>* dA,
magma_int_t ldda,
c10::complex<double>* tau,
c10::complex<double>* dT,
magma_int_t* info,
bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_zgeqrf_gpu(
m,
n,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
reinterpret_cast<magmaDoubleComplex*>(tau),
reinterpret_cast<magmaDoubleComplex*>(dT),
info);
} else {
magma_zgeqrf2_gpu(
m,
n,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
reinterpret_cast<magmaDoubleComplex*>(tau),
info);
}
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaGeqrf<c10::complex<float>>(
magma_int_t m,
magma_int_t n,
c10::complex<float>* dA,
magma_int_t ldda,
c10::complex<float>* tau,
c10::complex<float>* dT,
magma_int_t* info,
bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_cgeqrf_gpu(
m,
n,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
reinterpret_cast<magmaFloatComplex*>(tau),
reinterpret_cast<magmaFloatComplex*>(dT),
info);
} else {
magma_cgeqrf2_gpu(
m,
n,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
reinterpret_cast<magmaFloatComplex*>(tau),
info);
}
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaOrgqr<double>(
magma_int_t m, magma_int_t n, magma_int_t k, double* dA, magma_int_t ldda,
double* tau, double* dT, magma_int_t nb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dorgqr_gpu(m, n, k, dA, ldda, tau, dT, nb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaOrgqr<float>(
magma_int_t m, magma_int_t n, magma_int_t k, float* dA, magma_int_t ldda,
float* tau, float* dT, magma_int_t nb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sorgqr_gpu(m, n, k, dA, ldda, tau, dT, nb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaOrgqr<c10::complex<double>>(
magma_int_t m,
magma_int_t n,
magma_int_t k,
c10::complex<double>* dA,
magma_int_t ldda,
c10::complex<double>* tau,
c10::complex<double>* dT,
magma_int_t nb,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zungqr_gpu(
m,
n,
k,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
reinterpret_cast<magmaDoubleComplex*>(tau),
reinterpret_cast<magmaDoubleComplex*>(dT),
nb,
info);
AT_CUDA_CHECK(hipGetLastError());
}
template <>
void magmaOrgqr<c10::complex<float>>(
magma_int_t m,
magma_int_t n,
magma_int_t k,
c10::complex<float>* dA,
magma_int_t ldda,
c10::complex<float>* tau,
c10::complex<float>* dT,
magma_int_t nb,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cungqr_gpu(
m,
n,
k,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
reinterpret_cast<magmaFloatComplex*>(tau),
reinterpret_cast<magmaFloatComplex*>(dT),
nb,
info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSyevd<double>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, double* dA, magma_int_t ldda,
double* w, double* wA, magma_int_t ldwa, double* work, magma_int_t lwork, double* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
(void)rwork; // unused
(void)lrwork; // unused
MagmaStreamSyncGuard guard;
magma_dsyevd_gpu(jobz, uplo, n, dA, ldda, w, wA, ldwa, work, lwork, iwork, liwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSyevd<float>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, float* dA, magma_int_t ldda,
float* w, float* wA, magma_int_t ldwa, float* work, magma_int_t lwork, float* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
(void)rwork; // unused
(void)lrwork; // unused
MagmaStreamSyncGuard guard;
magma_ssyevd_gpu(jobz, uplo, n, dA, ldda, w, wA, ldwa, work, lwork, iwork, liwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSyevd<c10::complex<double>, double>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, c10::complex<double>* dA, magma_int_t ldda,
double* w, c10::complex<double>* wA, magma_int_t ldwa, c10::complex<double>* work, magma_int_t lwork, double* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zheevd_gpu(
jobz, uplo, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, w, reinterpret_cast<magmaDoubleComplex*>(wA),
ldwa, reinterpret_cast<magmaDoubleComplex*>(work), lwork, rwork, lrwork, iwork, liwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSyevd<c10::complex<float>, float>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, c10::complex<float>* dA, magma_int_t ldda,
float* w, c10::complex<float>* wA, magma_int_t ldwa, c10::complex<float>* work, magma_int_t lwork, float* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cheevd_gpu(
jobz, uplo, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, w, reinterpret_cast<magmaFloatComplex*>(wA),
ldwa, reinterpret_cast<magmaFloatComplex*>(work), lwork, rwork, lrwork, iwork, liwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaEig<double>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
double *A, magma_int_t lda,
double *w,
double *VL, magma_int_t ldvl,
double *VR, magma_int_t ldvr,
double *work, magma_int_t lwork,
double *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
// magma [sd]geev wants to separate output arrays: wr and wi for the real
// and imaginary parts
double *wr = w;
double *wi = w + n;
(void)rwork; // unused
magma_dgeev(jobvl, jobvr, n, A, lda, wr, wi, VL, ldvl, VR, ldvr, work, lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaEig<float>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
float *A, magma_int_t lda,
float *w,
float *VL, magma_int_t ldvl,
float *VR, magma_int_t ldvr,
float *work, magma_int_t lwork,
float *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
float *wr = w;
float *wi = w + n;
(void)rwork; // unused
magma_sgeev(jobvl, jobvr, n, A, lda, wr, wi, VL, ldvl, VR, ldvr, work, lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaEig<c10::complex<double>, double>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
c10::complex<double> *A, magma_int_t lda,
c10::complex<double> *w,
c10::complex<double> *VL, magma_int_t ldvl,
c10::complex<double> *VR, magma_int_t ldvr,
c10::complex<double> *work, magma_int_t lwork,
double *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
magma_zgeev(jobvl, jobvr, n,
reinterpret_cast<magmaDoubleComplex*>(A), lda,
reinterpret_cast<magmaDoubleComplex*>(w),
reinterpret_cast<magmaDoubleComplex*>(VL), ldvl,
reinterpret_cast<magmaDoubleComplex*>(VR), ldvr,
reinterpret_cast<magmaDoubleComplex*>(work), lwork,
rwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaEig<c10::complex<float>, float>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
c10::complex<float> *A, magma_int_t lda,
c10::complex<float> *w,
c10::complex<float> *VL, magma_int_t ldvl,
c10::complex<float> *VR, magma_int_t ldvr,
c10::complex<float> *work, magma_int_t lwork,
float *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
magma_cgeev(jobvl, jobvr, n,
reinterpret_cast<magmaFloatComplex*>(A), lda,
reinterpret_cast<magmaFloatComplex*>(w),
reinterpret_cast<magmaFloatComplex*>(VL), ldvl,
reinterpret_cast<magmaFloatComplex*>(VR), ldvr,
reinterpret_cast<magmaFloatComplex*>(work), lwork,
rwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSvd<double>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, double* A,
magma_int_t lda, double* s, double* U, magma_int_t ldu,
double* VT, magma_int_t ldvt, double* work, magma_int_t lwork,
double *rwork, magma_int_t* iwork, magma_int_t* info) {
(void)rwork; // unused
MagmaStreamSyncGuard guard;
magma_dgesdd(jobz, m, n, A, lda, s, U, ldu, VT, ldvt, work, lwork, iwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSvd<float>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, float* A,
magma_int_t lda, float* s, float* U, magma_int_t ldu,
float* VT, magma_int_t ldvt, float* work, magma_int_t lwork,
float* rwork, magma_int_t* iwork, magma_int_t* info) {
(void)rwork; // unused
MagmaStreamSyncGuard guard;
magma_sgesdd(jobz, m, n, A, lda, s, U, ldu, VT, ldvt, work, lwork, iwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSvd<c10::complex<float>, float>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, c10::complex<float>* A,
magma_int_t lda, float* s, c10::complex<float>* U, magma_int_t ldu,
c10::complex<float>* VT, magma_int_t ldvt, c10::complex<float>* work, magma_int_t lwork,
float *rwork, magma_int_t* iwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgesdd(jobz, m, n, reinterpret_cast<magmaFloatComplex*>(A), lda, s,
reinterpret_cast<magmaFloatComplex*>(U), ldu,
reinterpret_cast<magmaFloatComplex*>(VT), ldvt,
reinterpret_cast<magmaFloatComplex*>(work), lwork,
rwork, iwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaSvd<c10::complex<double>, double>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, c10::complex<double>* A,
magma_int_t lda, double* s, c10::complex<double>* U, magma_int_t ldu,
c10::complex<double>* VT, magma_int_t ldvt, c10::complex<double>* work, magma_int_t lwork,
double *rwork, magma_int_t* iwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgesdd(jobz, m, n, reinterpret_cast<magmaDoubleComplex*>(A), lda, s,
reinterpret_cast<magmaDoubleComplex*>(U), ldu,
reinterpret_cast<magmaDoubleComplex*>(VT), ldvt,
reinterpret_cast<magmaDoubleComplex*>(work), lwork,
rwork, iwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolve<double>(
magma_int_t n, magma_int_t nrhs, double* dA, magma_int_t ldda, magma_int_t* ipiv,
double* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetrs_gpu(MagmaNoTrans, n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolve<float>(
magma_int_t n, magma_int_t nrhs, float* dA, magma_int_t ldda, magma_int_t* ipiv,
float* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetrs_gpu(MagmaNoTrans, n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolve<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>* dA, magma_int_t ldda, magma_int_t* ipiv,
c10::complex<double>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetrs_gpu(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, ipiv, reinterpret_cast<magmaDoubleComplex*>(dB), lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolve<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>* dA, magma_int_t ldda, magma_int_t* ipiv,
c10::complex<float>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetrs_gpu(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaFloatComplex*>(dA), ldda, ipiv, reinterpret_cast<magmaFloatComplex*>(dB), lddb, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolveBatched<double>(
magma_int_t n, magma_int_t nrhs, double** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
double** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_dgetrs_batched(MagmaNoTrans, n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolveBatched<float>(
magma_int_t n, magma_int_t nrhs, float** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
float** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_sgetrs_batched(MagmaNoTrans, n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolveBatched<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
c10::complex<double>** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_zgetrs_batched(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, dipiv_array, reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaLuSolveBatched<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
c10::complex<float>** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_cgetrs_batched(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, dipiv_array, reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGels<float>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
float* dA, magma_int_t ldda, float* dB, magma_int_t lddb,
float* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgels_gpu(trans, m, n, nrhs,
dA, ldda, dB, lddb,
hwork, lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGels<double>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
double* dA, magma_int_t ldda, double* dB, magma_int_t lddb,
double* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgels_gpu(trans, m, n, nrhs,
dA, ldda, dB, lddb,
hwork, lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGels<c10::complex<float>>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
c10::complex<float>* dA, magma_int_t ldda, c10::complex<float>* dB, magma_int_t lddb,
c10::complex<float>* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgels_gpu(trans, m, n, nrhs,
reinterpret_cast<magmaFloatComplex*>(dA), ldda,
reinterpret_cast<magmaFloatComplex*>(dB), lddb,
reinterpret_cast<magmaFloatComplex*>(hwork), lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
template<>
void magmaGels<c10::complex<double>>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
c10::complex<double>* dA, magma_int_t ldda, c10::complex<double>* dB, magma_int_t lddb,
c10::complex<double>* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgels_gpu(trans, m, n, nrhs,
reinterpret_cast<magmaDoubleComplex*>(dA), ldda,
reinterpret_cast<magmaDoubleComplex*>(dB), lddb,
reinterpret_cast<magmaDoubleComplex*>(hwork), lwork, info);
AT_CUDA_CHECK(hipGetLastError());
}
#endif
#define ALLOCATE_ARRAY(name, type, size) \
auto storage_##name = pin_memory<type>(size); \
name = static_cast<type*>(storage_##name.data());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_solve(Tensor& b, Tensor& A, Tensor& infos) {
#ifndef USE_MAGMA
AT_ERROR("solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto A_data = A.data_ptr<scalar_t>();
auto b_data = b.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(A.size(-2), "A.size(-2)");
magma_int_t nrhs = magma_int_cast(b.size(-1), "b.size(-1)");
magma_int_t lda = ::max(magma_int_t{1}, n);
if (b.dim() == 2) {
auto ipiv = at::empty({n}, at::kInt);
infos = infos.to(at::kCPU); // magmaSolve requires infos tensor to live on CPU
magmaSolve<scalar_t>(n, nrhs, A_data, lda, ipiv.data_ptr<magma_int_t>(),
b_data, lda, infos.data_ptr<magma_int_t>());
} else {
auto infos_data = infos.data_ptr<magma_int_t>();
auto A_mat_stride = matrixStride(A);
auto b_mat_stride = matrixStride(b);
magma_int_t batch_size = magma_int_cast(batchCount(A), "batchCount");
magma_int_t* ipiv_data;
magma_int_t** ipiv_array;
scalar_t** A_array;
scalar_t** b_array;
ALLOCATE_ARRAY(ipiv_data, magma_int_t, batch_size * n);
ALLOCATE_ARRAY(ipiv_array, magma_int_t*, batch_size);
ALLOCATE_ARRAY(A_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
A_array[i] = &A_data[i * A_mat_stride];
b_array[i] = &b_data[i * b_mat_stride];
ipiv_array[i] = &ipiv_data[i * n];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** A_array_cur = &A_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magma_int_t** ipiv_array_cur = &ipiv_array[mini_idx];
magma_int_t* info_array_cur = &infos_data[mini_idx];
magmaSolveBatched<scalar_t>(
n, nrhs, A_array_cur, lda, ipiv_array_cur, b_array_cur, lda,
info_array_cur, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaSolveBatched<scalar_t>(
n, nrhs, &A_array[mini_idx], lda, &ipiv_array[mini_idx], &b_array[mini_idx], lda,
&infos_data[mini_idx], batch_size % batch_limit, magma_queue);
}
}
#endif
}
std::tuple<Tensor, Tensor> _solve_helper_cuda(const Tensor& self, const Tensor& A) {
auto self_working_copy = cloneBatchedColumnMajor(self);
auto A_working_copy = cloneBatchedColumnMajor(A);
// infos might not get filled for empty inputs therefore at::zeros is used instead of at::empty
auto infos = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt));
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "solve_cuda", [&]{
apply_solve<scalar_t>(self_working_copy, A_working_copy, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "solve_cuda");
} else {
singleCheckErrors(infos.item().toInt(), "solve_cuda");
}
return std::tuple<Tensor, Tensor>(self_working_copy, A_working_copy);
}
// This is a type dispatching helper function for 'apply_solve'
Tensor& _linalg_solve_out_helper_cuda(Tensor& result, Tensor& input, Tensor& infos) {
// 'result' and 'input' should be in column major order (it should be checked before calling this function)
// the content of 'result', 'input' and 'infos' is overwritten by 'apply_solve'
// 'result' should contain data of 'other' tensor (right-hand-side of the linear system of equations)
// 'input' should contain data of origianl 'input' tensor (left-hand-side of the linear system)
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "linalg_solve_out_cpu", [&]{
apply_solve<scalar_t>(result, input, infos);
});
return result;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inverse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
Computes the inverse of n-by-n matrix 'self', it is saved to 'self_inv'.
'infos' is an int Tensor containing error codes for each matrix in the batched input.
'infos_lu' is for holding magmaLU errors, and 'infos_getri' is for holding magmaGetri errors
For more information see MAGMA's documentation for GETRI and GETRF routines.
*/
template <typename scalar_t>
static void apply_batched_inverse(Tensor& self, Tensor& self_inv, Tensor& infos_lu, Tensor& infos_getri) {
#ifndef USE_MAGMA
AT_ERROR("inverse: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto self_data = self.data_ptr<scalar_t>();
auto self_mat_stride = matrixStride(self);
auto self_inv_data = self_inv.data_ptr<scalar_t>();
auto self_inv_mat_stride = matrixStride(self_inv);
auto infos_lu_data = infos_lu.data_ptr<magma_int_t>();
auto infos_getri_data = infos_getri.data_ptr<magma_int_t>();
magma_int_t batch_size = magma_int_cast(batchCount(self), "batchCount");
// MAGMA does not work with batch_size == 0, let's return early in this case
if (batch_size == 0) {
return;
}
magma_int_t n = magma_int_cast(self.size(-2), "self.size(-2)");
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t* ipiv_data;
magma_int_t** ipiv_array;
scalar_t** self_array;
scalar_t** self_inv_array;
ALLOCATE_ARRAY(ipiv_data, magma_int_t, batch_size * lda);
ALLOCATE_ARRAY(ipiv_array, magma_int_t*, batch_size);
ALLOCATE_ARRAY(self_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(self_inv_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
self_array[i] = &self_data[i * self_mat_stride];
self_inv_array[i] = &self_inv_data[i * self_inv_mat_stride];
ipiv_array[i] = &ipiv_data[i * n];
}
// magmaLuBatched leaves ipiv_data values unwritten for singular matrices.
// Initialize to avoid memory access violations inside magma kernels (gh-51930).
std::fill_n(ipiv_data, batch_size * n, 1);
MAGMAQueue magma_queue(self.get_device());
magmaLuBatched<scalar_t>(
n, n, self_array, lda, ipiv_array, infos_lu_data,
batch_size, magma_queue);
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** self_array_cur = &self_array[mini_idx];
scalar_t** self_inv_array_cur = &self_inv_array[mini_idx];
magma_int_t** ipiv_array_cur = &ipiv_array[mini_idx];
magma_int_t* info_array_cur_getri = &infos_getri_data[mini_idx];
magmaGetriBatched<scalar_t>(
n, self_array_cur, lda, ipiv_array_cur, self_inv_array_cur,
lda, info_array_cur_getri, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaGetriBatched<scalar_t>(
n, &self_array[mini_idx], lda, &ipiv_array[mini_idx], &self_inv_array[mini_idx],
lda, &infos_getri_data[mini_idx], batch_size % batch_limit, magma_queue);
}
#endif
}
template <typename scalar_t>
static void apply_single_inverse(Tensor& self, Tensor& infos_lu, Tensor& infos_getri) {
#ifndef USE_MAGMA
AT_ERROR("inverse: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto self_data = self.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(self.size(-2), "self.size(-2)");
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t lwork = n * magmaGetriOptimalBlocksize<scalar_t>(n);
// magmaLu and magmaGetri requires infos tensor to live on CPU
infos_lu = infos_lu.to(at::kCPU);
infos_getri = infos_getri.to(at::kCPU);
Tensor ipiv = at::empty({lda}, at::kInt);
Tensor dwork = at::empty({lwork}, self.options());
magmaLu<scalar_t>(n, n, self_data, lda, ipiv.data_ptr<magma_int_t>(), infos_lu.data_ptr<magma_int_t>());
magmaGetri<scalar_t>(
n, self_data, lda, ipiv.data_ptr<magma_int_t>(), dwork.data_ptr<scalar_t>(), lwork, infos_getri.data_ptr<magma_int_t>());
#endif
}
Tensor _inverse_helper_cuda_legacy(const Tensor& self) {
auto self_inv_working_copy = cloneBatchedColumnMajor(self);
if (self.dim() > 2) {
auto infos_lu = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt));
auto infos_getri = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt));
auto self_working_copy = cloneBatchedColumnMajor(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "inverse_cuda", [&]{
apply_batched_inverse<scalar_t>(
self_working_copy, self_inv_working_copy, infos_lu, infos_getri);
});
batchCheckErrors(infos_lu, "inverse_cuda");
batchCheckErrors(infos_getri, "inverse_cuda");
} else {
// magmaLu and magmaGetri requires infos tensor to live on CPU
auto infos_lu = at::zeros({1}, self.options().dtype(kInt).device(kCPU));
auto infos_getri = at::zeros({1}, self.options().dtype(kInt).device(kCPU));
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "inverse_cuda", [&]{
apply_single_inverse<scalar_t>(self_inv_working_copy, infos_lu, infos_getri);
});
singleCheckErrors(infos_lu.item().toInt(), "inverse_cuda");
singleCheckErrors(infos_getri.item().toInt(), "inverse_cuda");
}
return self_inv_working_copy;
}
Tensor _inverse_helper_cuda(const Tensor& self) {
#ifdef USE_CUSOLVER
if ((self.dim() == 2) || (/* self.dim() > 2 && */ batchCount(self) <= 2) || !use_magma_) {
return _inverse_helper_cuda_lib(self); // cusolver or cublas
} else {
return _inverse_helper_cuda_legacy(self); // magma-cuda
}
#else
return _inverse_helper_cuda_legacy(self); // magma-cuda
#endif
}
// This is a type dispatching helper function for 'apply_batched_inverse' and 'singleCheckErrors'
Tensor& _linalg_inv_out_helper_cuda_legacy(Tensor& result, Tensor& infos_lu, Tensor& infos_getri) {
// assuming result is in column major order and contains the matrices to invert
if (result.dim() > 2) {
auto input_working_copy = cloneBatchedColumnMajor(result);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "linalg_inv_out_cuda", [&]{
apply_batched_inverse<scalar_t>(
input_working_copy, result, infos_lu, infos_getri);
});
} else {
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "linalg_inv_out_cuda", [&]{
apply_single_inverse<scalar_t>(result, infos_lu, infos_getri);
});
}
return result;
}
// This is a MAGMA/cuSOLVER dispatching helper function
Tensor& _linalg_inv_out_helper_cuda(Tensor &result, Tensor& infos_lu, Tensor& infos_getri) {
// This function calculates the inverse matrix in-place
// result should be in column major order and contain matrices to invert
#ifdef USE_CUSOLVER
if ((result.dim() == 2) || (/* result.dim() > 2 && */ batchCount(result) <= 2) || !use_magma_) {
return _linalg_inv_out_helper_cuda_lib(result, infos_lu, infos_getri); // cusolver or cublas
} else {
return _linalg_inv_out_helper_cuda_legacy(result, infos_lu, infos_getri); // magma-cuda
}
#else
return _linalg_inv_out_helper_cuda_legacy(result, infos_lu, infos_getri); // magma-cuda
#endif
return result;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cholesky_solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_cholesky_solve(Tensor& b, Tensor& A, bool upper, int64_t& info) {
#ifndef USE_MAGMA
AT_ERROR("cholesky_solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
auto A_data = A.data_ptr<scalar_t>();
auto b_data = b.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(A.size(-2), "A.size(-2)");
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t nrhs = magma_int_cast(b.size(-1), "b.size(-1)");
int info_tmp = 0;
if (b.dim() == 2) {
magmaCholeskySolve<scalar_t>(uplo, n, nrhs, A_data, lda,
b_data, lda, &info_tmp);
info = info_tmp;
} else {
auto A_mat_stride = matrixStride(A);
auto b_mat_stride = matrixStride(b);
magma_int_t batch_size = magma_int_cast(batchCount(A), "batchCount");
scalar_t** A_array;
scalar_t** b_array;
ALLOCATE_ARRAY(A_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
A_array[i] = &A_data[i * A_mat_stride];
b_array[i] = &b_data[i * b_mat_stride];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** A_array_cur = &A_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magmaCholeskySolveBatched<scalar_t>(
uplo, n, nrhs, A_array_cur, lda, b_array_cur, lda,
info_tmp, batch_limit, magma_queue);
if (info_tmp != 0) {
break;
}
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0 && info_tmp == 0) {
magmaCholeskySolveBatched<scalar_t>(
uplo, n, nrhs, &A_array[mini_idx], lda, &b_array[mini_idx], lda,
info_tmp, batch_size % batch_limit, magma_queue);
}
info = info_tmp;
}
#endif
}
Tensor _cholesky_solve_helper_cuda(const Tensor& self, const Tensor& A, bool upper) {
int64_t info = 0;
auto self_working_copy = cloneBatchedColumnMajor(self);
auto A_working_copy = cloneBatchedColumnMajor(A);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "cholesky_solve_cuda", [&]{
apply_cholesky_solve<scalar_t>(self_working_copy, A_working_copy, upper, info);
});
TORCH_CHECK(info == 0, "MAGMA cholesky_solve : invalid argument: ", -info);
return self_working_copy;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cholesky ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_cholesky(Tensor& self, bool upper, std::vector<int64_t>& infos) {
#ifndef USE_MAGMA
AT_ERROR("cholesky: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
auto self_data = self.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(self.size(-2), "self.size(-2)");
auto lda = std::max<magma_int_t>(1, n);
if (self.dim() == 2) {
magma_int_t info = 0;
magmaCholesky<scalar_t>(uplo, n, self_data, lda, &info);
infos[0] = info;
} else {
auto self_mat_stride = matrixStride(self);
magma_int_t batch_size = magma_int_cast(batchCount(self), "batchCount");
magma_int_t* info_array;
scalar_t** self_array;
ALLOCATE_ARRAY(info_array, magma_int_t, batch_size);
ALLOCATE_ARRAY(self_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
self_array[i] = &self_data[i * self_mat_stride];
}
MAGMAQueue magma_queue(self.get_device());
int64_t batch_limit = self.is_complex() ? 65535 : 262140;
// Compute as many batches of 262140 possible
// 262140 is the size of the largest batch of matrices that can be run with
// violating maximum kernel configuration
// For complex input the batch limit is 65535 (determined experimentally, see https://github.com/pytorch/pytorch/pull/47047#discussion_r516086923 for more information)
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit cholesky calls
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** self_array_cur = &self_array[mini_idx];
magma_int_t* info_array_cur = &info_array[mini_idx];
magmaCholeskyBatched<scalar_t>(
uplo, n, self_array_cur, lda, info_array_cur, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaCholeskyBatched<scalar_t>(
uplo, n, &self_array[mini_idx], lda, &info_array[mini_idx], batch_size % batch_limit, magma_queue);
}
for (int64_t i = 0; i < batch_size; i++) {
infos[i] = info_array[i];
}
}
#endif
}
Tensor _cholesky_helper_cuda_magma(const Tensor& self, bool upper) {
std::vector<int64_t> infos(batchCount(self), 0);
Tensor result;
if (self.dim() > 2) {
// MAGMA's batched cholesky operator has an off-by-one error causing IMA
// (see https://github.com/pytorch/pytorch/issues/42666). This code is based
// on the #cloneBatchedColumnMajor function however it pads the input with
// one extra element utilizing the fact that the resize_as_ method preserves
// the storage even if it's larger than the new sizes. This way if MAGMA
// reads off bounds it will still be valid user memory.
const Tensor input = upper ? self : self.transpose(-1, -2);
result = at::empty(input.numel() + 1, input.options());
result.resize_as_(input).copy_(input).transpose_(-1, -2);
} else {
result = cloneBatchedColumnMajor(upper ? self.transpose(-1, -2) : self);
}
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(
self.scalar_type(), "cholesky_cuda", [&] {
apply_cholesky<scalar_t>(result, false, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "cholesky_cuda");
} else {
singleCheckErrors(infos[0], "cholesky_cuda");
}
return upper ? result.transpose_(-1, -2) : result;
}
// Todo: cusolverDnXpotrfBatched has some numerical issue and is not used
// here. Batched cholesky is dispatched to magma.
// We will switch to cusolverDnXpotrfBatched after the issue is fixed.
// See https://github.com/pytorch/pytorch/issues/53879.
Tensor _cholesky_helper_cuda(const Tensor& self, bool upper) {
#ifdef USE_CUSOLVER
if (batchCount(self) == 1 || !use_magma_) {
return _cholesky_helper_cuda_cusolver(self, upper);
}
else {
return _cholesky_helper_cuda_magma(self, upper);
}
#else
return _cholesky_helper_cuda_magma(self, upper);
#endif
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cholesky_inverse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
Computes the inverse of a symmetric (Hermitian) positive-definite matrix n-by-n matrix 'input' using the Cholesky solver
This is an in-place routine, content of 'input' is overwritten.
'infos' is an int Tensor containing error codes for each matrix in the batched input.
MAGMA requires 'infos' to reside in CPU memory.
For more information see MAGMA's documentation for POTRS routine.
*/
template <typename scalar_t>
static void apply_cholesky_inverse(Tensor& input, Tensor& infos, bool upper) {
#ifndef USE_MAGMA
TORCH_CHECK(false, "cholesky_inverse: MAGMA library not found in compilation. Please rebuild with MAGMA.");
#else
// magmaCholeskyInverse (magma_dpotri_gpu) is slow because internally
// it transfers data several times between GPU and CPU and calls lapack routine on CPU
// using magmaCholeskySolveBatched is a lot faster
// note that magmaCholeskySolve is also slow
// 'input' is modified in-place we need to clone it and replace with a diagonal matrix
// for apply_cholesky_solve
auto input_working_copy = cloneBatchedColumnMajor(input);
// 'input' tensor has to be a batch of diagonal matrix
input.fill_(0);
input.diagonal(/*offset=*/0, /*dim1=*/-2, /*dim2=*/-1).fill_(1);
Tensor result_u, input_u;
if (input.dim() == 2) {
// unsqueezing here so that the batched version is used
result_u = input.unsqueeze(0);
input_u = input_working_copy.unsqueeze(0);
} else {
result_u = input;
input_u = input_working_copy;
}
// magma's potrs_batched doesn't take matrix-wise array of ints as an 'info' argument
// it returns a single 'magma_int_t'
// if info = 0 the operation is successful, if info = -i, the i-th parameter had an illegal value.
int64_t info_tmp = 0;
apply_cholesky_solve<scalar_t>(result_u, input_u, upper, info_tmp);
infos.fill_(info_tmp);
#endif
}
// This is a type dispatching helper function for 'apply_cholesky_inverse'
Tensor& cholesky_inverse_kernel_impl(Tensor &result, Tensor& infos, bool upper) {
// This function calculates the inverse matrix in-place
// result should be in column major order and contain matrices to invert
// the content of result is overwritten by 'apply_cholesky_inverse'
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "cholesky_inverse_out_cuda", [&]{
apply_cholesky_inverse<scalar_t>(result, infos, upper);
});
return result;
}
REGISTER_DISPATCH(cholesky_inverse_stub, &cholesky_inverse_kernel_impl);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_lu(Tensor& self, Tensor& pivots, Tensor& infos, bool get_pivots) {
#ifndef USE_MAGMA
AT_ERROR("lu: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto self_data = self.data_ptr<scalar_t>();
magma_int_t m = magma_int_cast(self.size(-2), "m");
magma_int_t n = magma_int_cast(self.size(-1), "n");
magma_int_t k = ::min(m, n);
if (self.dim() == 2) {
// If `pivots` is defined, then we have to compute them.
// magmaLu and magmaLuNoPiv use a hybrid CPU-GPU algorithm to compute
// the partially-pivoted LU decomposition with / without pivots.
// The driver routines magma_(d/s)getrf_(nopiv_)gpu accepts a tensor on the CPU for pivots.
// The data is later copied back to the appropriate output tensor.
Tensor info_tmp = at::zeros({}, at::kInt);
if (get_pivots) {
Tensor piv_tmp = at::empty({k}, at::kInt);
magmaLu<scalar_t>(
m, n, self_data, m, piv_tmp.data_ptr<magma_int_t>(), info_tmp.data_ptr<magma_int_t>());
pivots.copy_(piv_tmp);
} else {
magmaLuNoPiv<scalar_t>(m, n, self_data, m, info_tmp.data_ptr<magma_int_t>());
}
infos.copy_(info_tmp);
} else {
auto self_matrix_stride = matrixStride(self);
magma_int_t batch_size = magma_int_cast(batchCount(self), "batchCount");
scalar_t** self_array;
ALLOCATE_ARRAY(self_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
self_array[i] = &self_data[i * self_matrix_stride];
}
MAGMAQueue magma_queue(self.get_device());
// Same comment as in the case of single matrix above.
if (get_pivots) {
auto pivots_data = pivots.data_ptr<magma_int_t>();
auto pivots_matrix_stride = pivots.size(-1);
magma_int_t** pivots_array;
ALLOCATE_ARRAY(pivots_array, magma_int_t*, batch_size);
for (int64_t i = 0; i < batch_size; i++) {
pivots_array[i] = &pivots_data[i * pivots_matrix_stride];
}
magmaLuBatched<scalar_t>(
m, n, self_array, m, pivots_array,
infos.data_ptr<magma_int_t>(), batch_size, magma_queue);
} else {
magmaLuNoPivBatched<scalar_t>(
m, n, self_array, m, infos.data_ptr<magma_int_t>(),
batch_size, magma_queue);
}
}
#endif
}
std::tuple<Tensor, Tensor, Tensor> _lu_with_info_cuda(const Tensor& self, bool pivot, bool check_errors) {
TORCH_CHECK(self.dim() >= 2,
"expected tensor with 2 or more dimensions, got size: ", self.sizes(),
" instead");
auto m = self.size(-2);
auto n = self.size(-1);
auto k = ::min(m, n);
auto req_size = self.sizes().vec();
req_size.pop_back();
req_size.back() = k;
Tensor pivots_tensor = at::arange(1, k + 1, self.options().dtype(at::kInt)).expand(req_size).contiguous();
req_size.pop_back();
auto infos_tensor = at::zeros(req_size, self.options().dtype(at::kInt));
Tensor self_working_copy;
if (self.numel() == 0) {
self_working_copy = at::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
} else {
self_working_copy = cloneBatchedColumnMajor(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "lu_cuda", [&]{
apply_lu<scalar_t>(self_working_copy, pivots_tensor, infos_tensor, pivot);
});
}
if (check_errors) {
if (self.dim() == 2) {
singleCheckErrors(infos_tensor.item<int64_t>(), "lu", /*allow_singular=*/true);
} else {
batchCheckErrors(infos_tensor, "lu", /*allow_singular=*/true);
}
}
return std::make_tuple(self_working_copy, pivots_tensor, infos_tensor);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ triangular_solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_triangular_solve_batched(Tensor& A, Tensor& b, bool upper, bool transpose, bool conjugate_transpose, bool unitriangular) {
#ifndef USE_MAGMA
AT_ERROR("triangular_solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
magma_trans_t trans = transpose ? MagmaTrans : MagmaNoTrans;
trans = conjugate_transpose ? MagmaConjTrans : trans;
magma_diag_t diag = unitriangular ? MagmaUnit : MagmaNonUnit;
auto A_data = A.data_ptr<scalar_t>();
auto b_data = b.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(A.size(-2), "A.size(-2)");
magma_int_t nrhs = magma_int_cast(b.size(-1), "b.size(-1)");
// magma returns early if m <= 0 || n <= 0 for magmaTriangularSolveBatched
// magmaTriangularSolve is calling cuBLAS and it prints
// ** On entry to DTRSM parameter number 9 had an illegal value
// so let's use proper lda parameter here
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t batch_size = magma_int_cast(batchCount(A), "batchCount");
auto A_mat_stride = matrixStride(A);
auto b_mat_stride = matrixStride(b);
scalar_t** A_array;
scalar_t** b_array;
ALLOCATE_ARRAY(A_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
A_array[i] = &A_data[i * A_mat_stride];
b_array[i] = &b_data[i * b_mat_stride];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit;
int64_t mini_idx; // this is outside the loop because it is used for the case batch_size % batch_limit != 0
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** A_array_cur = &A_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magmaTriangularSolveBatched<scalar_t>(
uplo, trans, diag, n, nrhs, A_array_cur,
lda, b_array_cur, lda, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaTriangularSolveBatched<scalar_t>(
uplo, trans, diag, n, nrhs, &A_array[mini_idx],
lda, &b_array[mini_idx], lda, batch_size % batch_limit, magma_queue);
}
#endif
}
void triangular_solve_batched_magma(Tensor& A, Tensor& B, Tensor& infos, bool upper, bool transpose, bool conjugate_transpose, bool unitriangular) {
(void)infos; // unused
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(A.scalar_type(), "triangular_solve_cuda", [&]{
apply_triangular_solve_batched<scalar_t>(A, B, upper, transpose, conjugate_transpose, unitriangular);
});
}
void triangular_solve_kernel(Tensor& A, Tensor& B, Tensor& infos, bool upper, bool transpose, bool conjugate_transpose, bool unitriangular) {
// For batches smaller than 8 and matrix sizes larger than 64x64 cuBLAS forloop is faster than batched version
if (batchCount(A) <= 8 && A.size(-1) >= 64) {
triangular_solve_cublas(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
} else {
#ifndef USE_MAGMA
triangular_solve_batched_cublas(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
#else
// cuBLAS batched is faster than MAGMA batched up until 512x512, after that MAGMA is faster
if (A.size(-1) <= 512) {
triangular_solve_batched_cublas(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
} else {
triangular_solve_batched_magma(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
}
#endif // USE_MAGMA
}
}
REGISTER_DISPATCH(triangular_solve_stub, &triangular_solve_kernel);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ orgqr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tensor& orgqr_kernel_impl(Tensor& result, const Tensor& tau, Tensor& infos, int64_t n_columns) {
// TODO: It is possible to implement efficient batched orgqr for small tau (tau.size(-1) <= 32)
// using MAGMA, however it fails on Windows because of some illegal memory reads inside MAGMA.
// See discussions in https://github.com/pytorch/pytorch/pull/51348 for comparison of cuSOLVER-MAGMA
// and Windows failure.
// For reference here is the MAGMA-based implementation: https://gist.github.com/IvanYashchuk/2db50002c9d3c1462ff769e6410ad983
#if defined(USE_CUSOLVER)
return orgqr_helper_cuda_lib(result, tau, infos, n_columns); // cusolver
#else
TORCH_CHECK(false, "Calling torch.orgqr on a CUDA tensor requires compiling ",
"PyTorch with cuSOLVER. Please use PyTorch built with cuSOLVER support.");
#endif
}
REGISTER_DISPATCH(orgqr_stub, &orgqr_kernel_impl);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ qr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_qr(Tensor& Q, Tensor& R, int64_t q_size_minus_2, int64_t r_size_minus_1, int64_t n_columns,
bool compute_q, std::vector<int64_t>& infos) {
#ifndef USE_MAGMA
AT_ERROR("qr: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_int_t m = magma_int_cast(q_size_minus_2, "Q.size(-2)");
magma_int_t n = magma_int_cast(r_size_minus_1, "R.size(-1)");
auto r_data = R.data_ptr<scalar_t>();
auto r_matrix_stride = matrixStride(R);
magma_int_t k = m < n ? m : n;
magma_int_t nb = magmaGeqrfOptimalBlocksize<scalar_t>(m, n);
int64_t batch_size = batchCount(R);
// magmaGeqrf uses a hybrid CPU-GPU algorithm to compute the elementary reflectors.
// The driver routine magma_(d/s)geqrf2_gpu accepts a tensor on the CPU for elementary reflectors.
Tensor tau = at::empty({k}, Q.options().device(at::kCPU));
Tensor work = at::empty({(2 * k + magma_roundup(n, 32)) * nb}, R.options());
scalar_t* tau_data = tau.data_ptr<scalar_t>();
scalar_t* work_data = work.data_ptr<scalar_t>();
// This phase computes R (the raw version)
// This uses MAGMA's ?geqrf2_gpu function
magma_int_t info = 0;
for (int64_t i = 0; i < batch_size; i++) {
scalar_t* r_working_ptr = &r_data[i * r_matrix_stride];
magmaGeqrf<scalar_t>(m, n, r_working_ptr, m, tau_data, work_data, &info, /*is_v2=*/true);
infos[i] = info;
if (info != 0) {
return;
}
}
if (!compute_q) {
// this is for mode='r'
return;
}
// This phase computes Q (the raw version)
// We require to perform ?geqrf_gpu again due to this bug in MAGMA:
// - ?geqrf_gpu allows fast computation of Q via ?orgqr_gpu, but doesn't give R properly.
// - ?geqrf2_gpu gives correct R, but doesn't allow computation of Q via ?orgqr_gpu
// Refer to the below link for more details:
// http://icl.cs.utk.edu/magma/forum/viewtopic.php?f=2&t=1015&p=2800&hilit=geqrf_gpu#p2800
auto q_data = Q.data_ptr<scalar_t>();
auto q_matrix_stride = matrixStride(Q);
for (int64_t i = 0; i < batch_size; i++) {
scalar_t* q_working_ptr = &q_data[i * q_matrix_stride];
magmaGeqrf<scalar_t>(m, n, q_working_ptr, m, tau_data, work_data, &info, /*is_v2=*/false);
infos[i] = info;
if (info != 0) {
return;
}
magmaOrgqr<scalar_t>(m, n_columns, k, q_working_ptr, m, tau_data, work_data, nb, &info);
infos[i] = info;
if (info != 0) {
return;
}
}
#endif
}
std::tuple<Tensor,Tensor> _linalg_qr_helper_cuda(const Tensor& self, std::string mode) {
bool compute_q, reduced;
std::tie(compute_q, reduced) = _parse_qr_mode(mode);
std::vector<int64_t> infos(batchCount(self), 0);
// Setup input geometry and inputs for apply_qr
std::vector<int64_t> q_sizes, q_strides;
int64_t n_columns_q;
std::tie(q_sizes, q_strides, n_columns_q) = _compute_geometry_for_Q(self, reduced);
Tensor q_working_copy, r_working_copy;
// If there are no elements, then we simply return a pair of tensors of required dimensions
if (self.numel() == 0) {
int64_t n = self.size(-1);
r_working_copy = at::empty({n_columns_q, n}, self.options());
if (compute_q) {
int64_t n_rows_q = q_sizes[self.dim() - 2];
q_working_copy = at::eye(n_rows_q, n_columns_q, self.options());
} else {
q_working_copy = at::empty({0}, self.options());
}
return std::make_tuple(q_working_copy, r_working_copy);
}
if (compute_q) {
q_working_copy = at::empty_strided(q_sizes, q_strides, self.options());
q_working_copy.narrow(-1, 0, self.size(-1)).copy_(self);
} else {
q_working_copy = at::empty({0}, self.options());
}
r_working_copy = cloneBatchedColumnMajor(self);
int64_t m = q_sizes[self.dim() - 2];
int64_t n = r_working_copy.size(-1);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "qr_cuda", [&]{
apply_qr<scalar_t>(q_working_copy, r_working_copy, m, n, n_columns_q, compute_q, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "qr_cuda");
} else {
singleCheckErrors(infos[0], "qr_cuda");
}
if (compute_q) {
q_working_copy = q_working_copy.narrow(-1, 0, n_columns_q);
}
r_working_copy = r_working_copy.narrow(-2, 0, n_columns_q).triu();
return std::make_tuple(q_working_copy, r_working_copy);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ symeig ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_magma_eigh(Tensor& values, Tensor& vectors, Tensor& infos, bool upper, bool compute_eigenvectors) {
#ifndef USE_MAGMA
TORCH_CHECK(
false,
"Calling torch.linalg.eigh/eigvalsh on a CUDA tensor requires compiling ",
"PyTorch with MAGMA. Please use PyTorch built with MAGMA support.");
#else
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(values.device() == kCPU);
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(infos.device() == kCPU);
using value_t = typename c10::scalar_value_type<scalar_t>::type;
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
magma_vec_t jobz = compute_eigenvectors ? MagmaVec : MagmaNoVec;
magma_int_t n = magma_int_cast(vectors.size(-1), "n");
auto lda = std::max<magma_int_t>(1, n);
auto batch_size = batchCount(vectors);
auto vectors_stride = matrixStride(vectors);
auto values_stride = values.size(-1);
auto vectors_data = vectors.data_ptr<scalar_t>();
auto values_data = values.data_ptr<value_t>();
auto infos_data = infos.data_ptr<magma_int_t>();
scalar_t* wA;
ALLOCATE_ARRAY(wA, scalar_t, lda * lda);
// Run once, first to get the optimum work sizes.
// Since we deal with batches of matrices with the same dimensions, doing this outside
// the loop saves (batch_size - 1) workspace queries which would provide the same result
// and (batch_size - 1) calls to allocate and deallocate workspace using at::empty()
magma_int_t lwork = -1;
scalar_t wkopt;
magma_int_t liwork = -1;
magma_int_t iwkopt;
magma_int_t lrwork = -1;
value_t rwkopt;
magmaSyevd<scalar_t, value_t>(jobz, uplo, n, vectors_data, lda, values_data,
wA, lda, &wkopt, lwork, &rwkopt, lrwork, &iwkopt, liwork, infos_data);
scalar_t* work;
magma_int_t* iwork;
lwork = magma_int_cast(std::max<int64_t>(1, real_impl<scalar_t, value_t>(wkopt)), "work_size");
liwork = magma_int_cast(std::max<int64_t>(1, iwkopt), "iwork_size");
ALLOCATE_ARRAY(work, scalar_t, lwork);
ALLOCATE_ARRAY(iwork, magma_int_t, liwork);
value_t* rwork = nullptr;
c10::Storage storage_rwork;
if (vectors.is_complex()) {
lrwork = magma_int_cast(std::max<int64_t>(1, rwkopt), "rwork_size");
storage_rwork = pin_memory<value_t>(lrwork);
rwork = static_cast<value_t*>(storage_rwork.data());
}
for (decltype(batch_size) i = 0; i < batch_size; i++) {
scalar_t* vectors_working_ptr = &vectors_data[i * vectors_stride];
value_t* values_working_ptr = &values_data[i * values_stride];
magma_int_t* info_working_ptr = &infos_data[i];
magmaSyevd<scalar_t, value_t>(jobz, uplo, n, vectors_working_ptr, lda, values_working_ptr,
wA, lda, work, lwork, rwork, lrwork, iwork, liwork, info_working_ptr);
// The current behaviour for Linear Algebra functions to raise an error if something goes wrong
// or input doesn't satisfy some requirement
// therefore return early since further computations will be wasted anyway
if (*info_working_ptr != 0) {
return;
}
}
#endif
}
std::tuple<Tensor, Tensor> _symeig_helper_cuda(const Tensor& self, bool eigenvectors, bool upper) {
Tensor infos = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt).device(at::kCPU));
auto eigvals_shape = IntArrayRef(self.sizes().data(), self.dim()-1); // self.shape[:-1]
ScalarType real_dtype = toValueType(self.scalar_type());
// magmaSyevd uses a hybrid CPU-GPU algorithm to compute the eigenvalues and eigenvectors.
// The driver routine magma_(d/s)syev_gpu accepts a tensor on the CPU for eigvalenvalues.
// The data is later moved to the appropriate device.
// In the case where self.numel() == 0, we just return an empty tensor of
// dimensions on the CUDA (to avoid the unnecessary "to(at::kCUDA)")
auto eigvals_working_copy = self.numel() == 0
? at::empty(eigvals_shape, self.options().dtype(real_dtype))
: at::empty(eigvals_shape, self.options().dtype(real_dtype).device(at::kCPU));
if (self.numel() == 0) {
return std::tuple<Tensor, Tensor>(eigvals_working_copy, at::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT));
}
auto self_working_copy = cloneBatchedColumnMajor(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "symeig_cuda", [&]{
apply_magma_eigh<scalar_t>(eigvals_working_copy, self_working_copy, infos, upper, eigenvectors);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "symeig_cuda");
} else {
singleCheckErrors(infos.item().toInt(), "symeig_cuda");
}
if (eigenvectors) {
return std::tuple<Tensor, Tensor>(eigvals_working_copy.to(self.device()), self_working_copy);
} else {
return std::tuple<Tensor, Tensor>(eigvals_working_copy.to(self.device()), at::empty({0}, self.options()));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linalg_eigh ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This is a type dispatch function for 'apply_magma_eigh'
// For small inputs result is computed on CPU
void linalg_eigh_magma(Tensor& eigenvalues, Tensor& eigenvectors, Tensor& infos, bool upper, bool compute_eigenvectors) {
// MAGMA just calls LAPACK for eigenvectors.size(-1) <= 128
// See https://bitbucket.org/icl/magma/src/e6fdca447bd402693e8b0b950a898b6879bbcc41/src/zheevd_gpu.cpp?at=master#lines-258
// in addition lda is ignored breaking 0x0 inputs
if (eigenvectors.size(-1) > 128) {
// MAGMA requires eigenvalues and infos tensors to reside on CPU
Tensor eigenvalues_cpu = eigenvalues.to(kCPU);
infos = infos.to(kCPU);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(
eigenvectors.scalar_type(), "linalg_eigh_cpu", [&] {
apply_magma_eigh<scalar_t>(
eigenvalues_cpu, eigenvectors, infos, upper, compute_eigenvectors);
});
// Transfer computed by MAGMA results from CPU to GPU
eigenvalues.copy_(eigenvalues_cpu);
} else { // eigenvectors.size(-1) <= 128
// transfer to CPU, compute the result and copy back to GPU
// this is faster than going through MAGMA that does the same
Tensor eigenvalues_cpu = at::empty_like(eigenvalues, eigenvalues.options().device(kCPU));
if (compute_eigenvectors) {
Tensor eigenvectors_cpu = at::empty_like(eigenvectors, eigenvectors.options().device(kCPU));
at::linalg_eigh_out(eigenvalues_cpu, eigenvectors_cpu, eigenvectors.to(kCPU), upper ? "U" : "L");
eigenvectors.copy_(eigenvectors_cpu);
} else {
at::linalg_eigvalsh_out(eigenvalues_cpu, eigenvectors.to(kCPU), upper ? "U" : "L");
}
eigenvalues.copy_(eigenvalues_cpu);
}
}
void linalg_eigh_kernel(Tensor& eigenvalues, Tensor& eigenvectors, Tensor& infos, bool upper, bool compute_eigenvectors) {
#if defined(USE_CUSOLVER)
linalg_eigh_cusolver(eigenvalues, eigenvectors, infos, upper, compute_eigenvectors);
#else
linalg_eigh_magma(eigenvalues, eigenvectors, infos, upper, compute_eigenvectors);
#endif
}
REGISTER_DISPATCH(linalg_eigh_stub, &linalg_eigh_kernel);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eig ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// magmaEig uses a hybrid CPU-GPU algorithm, which takes and return CPU
// memory. So, we accept a GPU tensor, copy it to CPU memory, and later copy
// the returned values from CPU to GPU. See also magmaSymeig, which uses a
// similar approach.
template <typename scalar_t>
static void apply_eig(const Tensor& self, bool eigenvectors, Tensor& out_eigvals, Tensor& out_eigvecs,
int64_t *info_ptr) {
#ifndef USE_MAGMA
TORCH_CHECK(false, "Calling torch.eig on a CUDA tensor requires compiling PyTorch with MAGMA. "
"Either transfer the tensor to the CPU before calling torch.eig or recompile with MAGMA.");
#else
TORCH_INTERNAL_ASSERT(self.device() == at::kCPU, "Internal error: apply_eig needs a CPU tensor");
using value_t = typename c10::scalar_value_type<scalar_t>::type;
magma_vec_t jobvr = eigenvectors ? MagmaVec : MagmaNoVec;
magma_int_t n = magma_int_cast(self.size(-1), "n");
auto self_data = self.data_ptr<scalar_t>();
auto out_eigvals_data = out_eigvals.data_ptr<scalar_t>();
scalar_t *wr = out_eigvals_data;
scalar_t *vr_data = NULL;
magma_int_t ldvr = 1;
if (jobvr == MagmaVec)
{
vr_data = out_eigvecs.data_ptr<scalar_t>();
ldvr = n;
}
value_t *rwork_data = nullptr;
if (isComplexType(at::typeMetaToScalarType(self.dtype()))) {
ALLOCATE_ARRAY(rwork_data, value_t, n*2);
}
if (n > 0) {
// call magmaEig once to get the optimal size of work_data
scalar_t wkopt;
magma_int_t info;
magmaEig<scalar_t, value_t>(MagmaNoVec, jobvr, n, self_data, n, wr, NULL, 1, vr_data, ldvr, &wkopt, -1, rwork_data, &info);
magma_int_t lwork = static_cast<magma_int_t>(real_impl<scalar_t, value_t>(wkopt));
// call it a 2nd time to to the actual work
scalar_t *work_data = nullptr;
ALLOCATE_ARRAY(work_data, scalar_t, lwork);
magmaEig<scalar_t, value_t>(MagmaNoVec, jobvr, n, self_data, n, wr, NULL, 1, vr_data, ldvr, work_data, lwork, rwork_data, &info);
*info_ptr = info;
}
#endif
}
/*
* Internal helper; like eig_cuda but:
* 1. assume that self is a square matrix of side "n"
* 2. return CPU tensors (because this is what magmaEig returns), which will be copied to GPU memory
* by the caller
*/
std::tuple<Tensor, Tensor> eig_kernel_impl(const Tensor& self, bool& eigenvectors) {
int64_t n = self.size(-1);
// copy self to pinned CPU memory
auto self_working_copy = at::empty_strided(
{n, n}, // square matrix
{1, n}, // column-ordered, as magmaEig expects
at::TensorOptions(at::kCPU).dtype(self.dtype()).pinned_memory(true));
self_working_copy.copy_(self);
// tensors holding the results. We use empty_strided to make them column-ordered
auto options = self.options().device(at::kCPU).memory_format(LEGACY_CONTIGUOUS_MEMORY_FORMAT);
Tensor out_eigvals;
if (isComplexType(at::typeMetaToScalarType(self.dtype()))) {
out_eigvals = at::empty({n}, options);
} else {
out_eigvals = at::empty_strided({n, 2}, {1, n}, options);
}
auto out_eigvecs = eigenvectors
? at::empty_strided({n, n}, {1, n}, options)
: Tensor();
int64_t info;
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "eig_cuda", [&]{
apply_eig<scalar_t>(self_working_copy, eigenvectors, out_eigvals, out_eigvecs, &info);
});
singleCheckErrors(info, "eig_cuda");
return std::tuple<Tensor, Tensor>(out_eigvals, out_eigvecs);
}
REGISTER_DISPATCH(eig_stub, &eig_kernel_impl);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ svd ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename scalar_t>
static void apply_svd(Tensor& self, Tensor& U, Tensor& S, Tensor& VT,
char jobchar, std::vector<int64_t>& infos) {
#ifndef USE_MAGMA
AT_ERROR("svd: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
using value_t = typename c10::scalar_value_type<scalar_t>::type;
auto self_data = self.data_ptr<scalar_t>();
auto U_data = U.data_ptr<scalar_t>();
auto S_data = S.data_ptr<value_t>();
auto VT_data = VT.data_ptr<scalar_t>();
auto self_stride = matrixStride(self);
auto U_stride = matrixStride(U);
auto S_stride = S.size(-1);
auto VT_stride = matrixStride(VT);
auto batchsize = batchCount(self);
magma_vec_t jobz = jobchar == 'A' ? MagmaAllVec : (jobchar == 'S' ? MagmaSomeVec : MagmaNoVec);
magma_int_t m = magma_int_cast(self.size(-2), "m");
magma_int_t n = magma_int_cast(self.size(-1), "n");
auto lda = std::max<magma_int_t>(1, m);
auto ldvt = std::max<magma_int_t>(1, n);
auto mn = ::min(m, n);
c10::Storage storage_rwork;
value_t* rwork = nullptr;
magma_int_t* iwork;
ALLOCATE_ARRAY(iwork, magma_int_t, 8 * mn);
if (isComplexType(at::typeMetaToScalarType(self.dtype()))) {
auto lrwork = computeLRWorkDim(jobchar, m, n);
storage_rwork = pin_memory<value_t>(lrwork);
rwork = static_cast<value_t*>(storage_rwork.data());
}
magma_int_t info = 0;
// Run once, first to get the optimum work size.
// Since we deal with batches of matrices with the same dimensions, doing this outside
// the loop saves (batch_size - 1) workspace queries which would provide the same result
// and (batch_size - 1) calls to allocate and deallocate workspace using at::empty()
magma_int_t lwork = -1;
scalar_t wkopt = 1; // MAGMA might not set the value for the optimal workspace therefore use 1 as the default value
magmaSvd<scalar_t, value_t>(jobz, m, n, self_data, lda, S_data, U_data, lda, VT_data, ldvt, &wkopt, lwork, rwork, iwork, &info);
lwork = magma_int_cast(real_impl<scalar_t, value_t>(wkopt), "work_size");
scalar_t* work;
ALLOCATE_ARRAY(work, scalar_t, lwork);
for (int64_t i = 0; i < batchsize; i++) {
scalar_t* self_working_ptr = &self_data[i * self_stride];
value_t* S_working_ptr = &S_data[i * S_stride];
scalar_t* U_working_ptr = &U_data[i * U_stride];
scalar_t* VT_working_ptr = &VT_data[i * VT_stride];
// Compute S, U (optionally), VT (optionally)
magmaSvd<scalar_t, value_t>(jobz, m, n, self_working_ptr, lda,
S_working_ptr, U_working_ptr, lda, VT_working_ptr, ldvt, work, lwork, rwork, iwork, &info);
infos[i] = info;
if (info != 0) {
return;
}
}
#endif
}
std::tuple<Tensor, Tensor, Tensor> _svd_helper_cuda_legacy(const Tensor& self, bool some, bool compute_uv) {
std::vector<int64_t> infos(batchCount(self), 0);
int64_t m = self.size(-2), n = self.size(-1);
int64_t k = ::min(m, n);
char jobchar = compute_uv ? (some ? 'S' : 'A') : 'N';
Tensor U_working_copy, S_working_copy, VT_working_copy;
std::tie(U_working_copy, S_working_copy, VT_working_copy) = _create_U_S_VT(self, some, compute_uv);
// The input matrix, U, S and VT have to reside in pinned memory.
// Additionally, the input and U have to be in column major format.
// _create_U_S_VT takes care of a part of these requirements (for U, S and VT)
// For the input matrix, this requirements are being taken care of below.
// Specify strides
auto self_col_major_strides = at::detail::defaultStrides(self.sizes());
self_col_major_strides[self.dim() - 2] = 1;
self_col_major_strides[self.dim() - 1] = m;
// Create strided tensor in pinned memory
auto self_working_copy = at::empty_strided(self.sizes(), self_col_major_strides,
at::TensorOptions(at::kCPU).dtype(self.dtype()).pinned_memory(true));
self_working_copy.copy_(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "svd_cuda", [&] {
apply_svd<scalar_t>(self_working_copy, U_working_copy, S_working_copy, VT_working_copy, jobchar, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "svd_cuda");
} else {
singleCheckErrors(infos[0], "svd_cuda");
}
U_working_copy = same_stride_to(U_working_copy, self.options());
S_working_copy = same_stride_to(S_working_copy, S_working_copy.options().device(self.device()));
VT_working_copy = same_stride_to(VT_working_copy, self.options());
if (!compute_uv) {
VT_working_copy.zero_();
U_working_copy.zero_();
}
if (some) {
VT_working_copy = VT_working_copy.narrow(-2, 0, k);
}
// so far we have computed VT, but torch.svd returns V instead. Adjust accordingly.
// Note that the 'apply_svd' routine returns VT = V^T (for real inputs) or VT = V^H (for complex inputs), not V.
VT_working_copy = VT_working_copy.conj();
VT_working_copy.transpose_(-2, -1);
return std::make_tuple(U_working_copy, S_working_copy, VT_working_copy);
}
std::tuple<Tensor, Tensor, Tensor> _svd_helper_cuda(const Tensor& self, bool some, bool compute_uv) {
#ifdef USE_CUSOLVER
return _svd_helper_cuda_lib(self, some, compute_uv);
#else
return _svd_helper_cuda_legacy(self, some, compute_uv);
#endif
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lu_solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_lu_solve(Tensor& b, const Tensor& lu, const Tensor& pivots, int64_t& info) {
#ifndef USE_MAGMA
AT_ERROR("lu_solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto b_data = b.data_ptr<scalar_t>();
auto lu_data = lu.data_ptr<scalar_t>();
auto n = lu.size(-2);
auto nrhs = b.size(-1);
int info_tmp = 0;
if (b.dim() == 2) {
Tensor pivots_tmp = pivots.cpu();
magmaLuSolve<scalar_t>(n, nrhs, lu_data, n, pivots_tmp.data_ptr<magma_int_t>(), b_data, n, &info_tmp);
info = info_tmp;
} else {
auto pivots_data = pivots.data_ptr<magma_int_t>();
auto b_stride = matrixStride(b);
auto lu_stride = matrixStride(lu);
auto pivots_stride = pivots.size(-1);
magma_int_t batch_size = magma_int_cast(batchCount(b), "batchCount");
magma_int_t** pivots_array;
scalar_t** lu_array;
scalar_t** b_array;
ALLOCATE_ARRAY(pivots_array, magma_int_t*, batch_size);
ALLOCATE_ARRAY(lu_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
for (int64_t i = 0; i < batch_size; i++) {
pivots_array[i] = &pivots_data[i * pivots_stride];
b_array[i] = &b_data[i * b_stride];
lu_array[i] = &lu_data[i * lu_stride];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** lu_array_cur = &lu_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magma_int_t** pivots_array_cur = &pivots_array[mini_idx];
magmaLuSolveBatched<scalar_t>(
n, nrhs, lu_array_cur, n, pivots_array_cur, b_array_cur, n,
info_tmp, batch_limit, magma_queue);
if (info_tmp != 0) {
break;
}
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0 && info_tmp == 0) {
magmaLuSolveBatched<scalar_t>(
n, nrhs, &lu_array[mini_idx], n, &pivots_array[mini_idx], &b_array[mini_idx], n,
info_tmp, batch_size % batch_limit, magma_queue);
}
info = info_tmp;
}
#endif
}
Tensor _lu_solve_helper_cuda(const Tensor& self, const Tensor& LU_data, const Tensor& LU_pivots) {
int64_t info = 0;
auto self_working_copy = cloneBatchedColumnMajor(self);
auto LU_data_working_copy = cloneBatchedColumnMajor(LU_data);
auto LU_pivots_working_copy = LU_pivots.is_contiguous() ? LU_pivots : LU_pivots.contiguous();
if (self.numel() == 0 || LU_data.numel() == 0) {
return at::zeros_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "lu_solve_cuda", [&]{
apply_lu_solve<scalar_t>(self_working_copy, LU_data_working_copy, LU_pivots_working_copy, info);
});
TORCH_CHECK(info == 0, "MAGMA lu_solve : invalid argument: ", -info);
return self_working_copy;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lstsq ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tensor& _lstsq_helper_cuda(
Tensor& b, Tensor& rank, Tensor& singular_values, Tensor& infos, const Tensor& a, double cond, std::string driver_name) {
#ifndef USE_MAGMA
TORCH_CHECK(false, "torch.linalg.lstsq: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(a.scalar_type(), "torch.linalg.lstsq_cuda", [&] {
auto trans = MagmaNoTrans;
auto m = magma_int_cast(a.size(-2), "m");
auto n = magma_int_cast(a.size(-1), "n");
auto nrhs = magma_int_cast(b.size(-1), "nrhs");
auto ldda = std::max<magma_int_t>(1, m);
auto lddb = std::max<magma_int_t>(1, ::max(m, n));
auto nb = magmaGeqrfOptimalBlocksize<scalar_t>(m, n);
auto lwork = (m - n + nb) * (nrhs + nb) + nrhs * nb;
Tensor hwork = at::empty({static_cast<int64_t>(lwork)}, a.scalar_type());
auto* hwork_ptr = hwork.data_ptr<scalar_t>();
// MAGMA requires infos tensor to live on CPU
infos = infos.to(at::kCPU);
auto infos_data = infos.data_ptr<magma_int_t>();
batch_iterator_with_broadcasting<scalar_t>(a, b,
[&](scalar_t* a_working_ptr, scalar_t* b_working_ptr,
int64_t a_linear_batch_idx) {
magma_int_t* infos_working_ptr = &infos_data[a_linear_batch_idx];
magmaGels<scalar_t>(trans, m, n, nrhs,
a_working_ptr, ldda, b_working_ptr, lddb,
hwork_ptr, lwork, infos_working_ptr);
}
);
});
return b;
#endif
}
}} // namespace at::native
#undef ALLOCATE_ARRAY
| 944933d06fc20d00122c8a63d2f65a692354bcad.cu | #include <ATen/Context.h>
#include <ATen/cuda/CUDAContext.h>
#include <ATen/Dispatch.h>
#include <ATen/NativeFunctions.h>
#include <ATen/cuda/PinnedMemoryAllocator.h>
#include <ATen/cuda/CUDAApplyUtils.cuh>
#include <ATen/cuda/detail/IndexUtils.cuh>
#include <ATen/native/LinearAlgebraUtils.h>
#include <ATen/native/cuda/MiscUtils.h>
#include <ATen/native/Resize.h>
#include <ATen/native/BatchLinearAlgebra.h>
#include <ATen/native/cuda/BatchLinearAlgebraLib.h>
#include <ATen/native/cpu/zmath.h>
#include <THC/THC.h> // for USE_MAGMA
#ifdef USE_MAGMA
#include <magma_types.h>
#include <magma_v2.h>
const bool use_magma_ = true;
#else
const bool use_magma_ = false;
#endif
namespace at {
namespace native {
#ifdef USE_MAGMA
template<class scalar_t>
void magmaSolve(
magma_int_t n, magma_int_t nrhs, scalar_t* dA, magma_int_t ldda,
magma_int_t* ipiv, scalar_t* dB, magma_int_t lddb, magma_int_t* info);
template<class scalar_t>
void magmaSolveBatched(
magma_int_t n, magma_int_t nrhs, scalar_t** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, scalar_t** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaLu(
magma_int_t m, magma_int_t n, scalar_t* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info);
template<class scalar_t>
void magmaLuBatched(
magma_int_t m, magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaLuNoPiv(
magma_int_t m, magma_int_t n, scalar_t* dA, magma_int_t ldda,
magma_int_t* info);
template<class scalar_t>
void magmaLuNoPivBatched(
magma_int_t m, magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
inline magma_int_t magmaGetriOptimalBlocksize(magma_int_t n);
template<class scalar_t>
void magmaGetri(
magma_int_t n, scalar_t* dA, magma_int_t ldda, magma_int_t* ipiv, scalar_t* dwork,
magma_int_t lwork, magma_int_t* info);
template<class scalar_t>
void magmaGetriBatched(
magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, scalar_t** dinvA_array, magma_int_t lddia,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaCholeskySolve(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, scalar_t* dA, magma_int_t ldda,
scalar_t* dB, magma_int_t lddb, magma_int_t* info);
template<class scalar_t>
void magmaCholeskySolveBatched(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, scalar_t** dA_array, magma_int_t ldda,
scalar_t** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaCholesky(
magma_uplo_t uplo, magma_int_t n, scalar_t* dA,
magma_int_t ldda, magma_int_t* info);
template<class scalar_t>
void magmaCholeskyBatched(
magma_uplo_t uplo, magma_int_t n, scalar_t** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaTriangularSolveBatched(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
scalar_t** dA_array, magma_int_t ldda, scalar_t** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue);
template<class scalar_t>
inline magma_int_t magmaGeqrfOptimalBlocksize(magma_int_t m, magma_int_t n);
template<class scalar_t>
void magmaGeqrf(
magma_int_t m, magma_int_t n, scalar_t* dA, magma_int_t ldda,
scalar_t* tau, scalar_t* dT, magma_int_t* info, bool is_v2);
template<class scalar_t>
void magmaOrgqr(
magma_int_t m, magma_int_t n, magma_int_t k, scalar_t* dA,
magma_int_t ldda, scalar_t* tau, scalar_t* dT, magma_int_t nb, magma_int_t* info);
template<class scalar_t, class value_t=scalar_t>
void magmaSyevd(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, scalar_t* dA, magma_int_t ldda,
value_t* w, scalar_t* wA, magma_int_t ldwa, scalar_t* work, magma_int_t lwork, value_t* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info);
template<class scalar_t, class value_t=scalar_t>
void magmaEig(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n, scalar_t *A, magma_int_t lda,
scalar_t *w, scalar_t *VL, magma_int_t ldvl,
scalar_t *VR, magma_int_t ldvr, scalar_t *work, magma_int_t lwork,
value_t *rwork,
magma_int_t *info);
template<class scalar_t, class value_t=scalar_t>
void magmaSvd(
magma_vec_t jobz, magma_int_t m, magma_int_t n, scalar_t* A,
magma_int_t lda, value_t* s, scalar_t* U, magma_int_t ldu,
scalar_t* VT, magma_int_t ldvt, scalar_t* work, magma_int_t lwork,
value_t* rwork,
magma_int_t* iwork, magma_int_t* info);
template<class scalar_t>
void magmaLuSolve(
magma_int_t n, magma_int_t nrhs, scalar_t* dA, magma_int_t ldda, magma_int_t* ipiv,
scalar_t* dB, magma_int_t lddb, magma_int_t* info);
template<class scalar_t>
void magmaLuSolveBatched(
magma_int_t n, magma_int_t nrhs, scalar_t** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
scalar_t** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue);
template<class scalar_t>
void magmaGels(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
scalar_t* dA, magma_int_t ldda, scalar_t* dB, magma_int_t lddb,
scalar_t* hwork, magma_int_t lwork, magma_int_t* info);
template<>
void magmaSolve<double>(
magma_int_t n, magma_int_t nrhs, double* dA, magma_int_t ldda,
magma_int_t* ipiv, double* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgesv_gpu(n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSolve<float>(
magma_int_t n, magma_int_t nrhs, float* dA, magma_int_t ldda,
magma_int_t* ipiv, float* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgesv_gpu(n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSolve<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>* dA, magma_int_t ldda,
magma_int_t* ipiv, c10::complex<double>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgesv_gpu(n, nrhs,
reinterpret_cast<magmaDoubleComplex*>(dA), ldda, ipiv,
reinterpret_cast<magmaDoubleComplex*>(dB), lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSolve<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>* dA, magma_int_t ldda,
magma_int_t* ipiv, c10::complex<float>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgesv_gpu(n, nrhs,
reinterpret_cast<magmaFloatComplex*>(dA), ldda, ipiv,
reinterpret_cast<magmaFloatComplex*>(dB), lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSolveBatched<double>(
magma_int_t n, magma_int_t nrhs, double** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, double** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_dgesv_batched(n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSolveBatched<float>(
magma_int_t n, magma_int_t nrhs, float** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, float** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_sgesv_batched(n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSolveBatched<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, c10::complex<double>** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_zgesv_batched(n, nrhs,
reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, dipiv_array,
reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSolveBatched<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t** dipiv_array, c10::complex<float>** dB_array, magma_int_t lddb,
magma_int_t* dinfo_array, magma_int_t batch_count, const MAGMAQueue& magma_queue) {
magma_cgesv_batched(n, nrhs,
reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, dipiv_array,
reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, dinfo_array, batch_count, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLu<double>(
magma_int_t m, magma_int_t n, double* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetrf_gpu(m, n, dA, ldda, ipiv, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLu<float>(
magma_int_t m, magma_int_t n, float* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetrf_gpu(m, n, dA, ldda, ipiv, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLu<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetrf_gpu(m, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, ipiv, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLu<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>* dA, magma_int_t ldda,
magma_int_t* ipiv, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetrf_gpu(m, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, ipiv, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuBatched<double>(
magma_int_t m, magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_dgetrf_batched(m, n, dA_array, ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuBatched<float>(
magma_int_t m, magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_sgetrf_batched(m, n, dA_array, ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuBatched<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_zgetrf_batched(m, n, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuBatched<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, magma_int_t* info_array, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_cgetrf_batched(m, n, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, ipiv_array, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPiv<double>(
magma_int_t m, magma_int_t n, double* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetrf_nopiv_gpu(m, n, dA, ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPiv<float>(
magma_int_t m, magma_int_t n, float* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetrf_nopiv_gpu(m, n, dA, ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPiv<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetrf_nopiv_gpu(m, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPiv<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>* dA, magma_int_t ldda,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetrf_nopiv_gpu(m, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPivBatched<double>(
magma_int_t m, magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_dgetrf_nopiv_batched(m, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPivBatched<float>(
magma_int_t m, magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_sgetrf_nopiv_batched(m, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPivBatched<c10::complex<double>>(
magma_int_t m, magma_int_t n, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_zgetrf_nopiv_batched(m, n, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuNoPivBatched<c10::complex<float>>(
magma_int_t m, magma_int_t n, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_cgetrf_nopiv_batched(m, n, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
inline magma_int_t magmaGetriOptimalBlocksize<double>(magma_int_t n) {
return magma_get_dgetri_nb(n);
}
template<>
inline magma_int_t magmaGetriOptimalBlocksize<float>(magma_int_t n) {
return magma_get_sgetri_nb(n);
}
template <>
inline magma_int_t magmaGetriOptimalBlocksize<c10::complex<double>>(
magma_int_t n) {
return magma_get_zgetri_nb(n);
}
template <>
inline magma_int_t magmaGetriOptimalBlocksize<c10::complex<float>>(
magma_int_t n) {
return magma_get_cgetri_nb(n);
}
template<>
void magmaGetri<double>(
magma_int_t n, double* dA, magma_int_t ldda, magma_int_t* ipiv, double* dwork,
magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetri_gpu(n, dA, ldda, ipiv, dwork, lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGetri<float>(
magma_int_t n, float* dA, magma_int_t ldda, magma_int_t* ipiv, float* dwork,
magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetri_gpu(n, dA, ldda, ipiv, dwork, lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaGetri<c10::complex<double>>(
magma_int_t n,
c10::complex<double>* dA,
magma_int_t ldda,
magma_int_t* ipiv,
c10::complex<double>* dwork,
magma_int_t lwork,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetri_gpu(
n,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
ipiv,
reinterpret_cast<magmaDoubleComplex*>(dwork),
lwork,
info);
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaGetri<c10::complex<float>>(
magma_int_t n,
c10::complex<float>* dA,
magma_int_t ldda,
magma_int_t* ipiv,
c10::complex<float>* dwork,
magma_int_t lwork,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetri_gpu(
n,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
ipiv,
reinterpret_cast<magmaFloatComplex*>(dwork),
lwork,
info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGetriBatched<double>(
magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, double** dinvA_array, magma_int_t lddia,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_dgetri_outofplace_batched(n, dA_array, ldda, ipiv_array, dinvA_array, lddia, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGetriBatched<float>(
magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t** ipiv_array, float** dinvA_array, magma_int_t lddia,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_sgetri_outofplace_batched(n, dA_array, ldda, ipiv_array, dinvA_array, lddia, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaGetriBatched<c10::complex<double>>(
magma_int_t n,
c10::complex<double>** dA_array,
magma_int_t ldda,
magma_int_t** ipiv_array,
c10::complex<double>** dinvA_array,
magma_int_t lddia,
magma_int_t* info_array,
magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_zgetri_outofplace_batched(
n,
reinterpret_cast<magmaDoubleComplex**>(dA_array),
ldda,
ipiv_array,
reinterpret_cast<magmaDoubleComplex**>(dinvA_array),
lddia,
info_array,
batchsize,
magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaGetriBatched<c10::complex<float>>(
magma_int_t n,
c10::complex<float>** dA_array,
magma_int_t ldda,
magma_int_t** ipiv_array,
c10::complex<float>** dinvA_array,
magma_int_t lddia,
magma_int_t* info_array,
magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magma_cgetri_outofplace_batched(
n,
reinterpret_cast<magmaFloatComplex**>(dA_array),
ldda,
ipiv_array,
reinterpret_cast<magmaFloatComplex**>(dinvA_array),
lddia,
info_array,
batchsize,
magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolve<double>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, double* dA, magma_int_t ldda,
double* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dpotrs_gpu(uplo, n, nrhs, dA, ldda, dB, lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolve<float>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, float* dA, magma_int_t ldda,
float* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_spotrs_gpu(uplo, n, nrhs, dA, ldda, dB, lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolve<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<double>* dA, magma_int_t ldda,
c10::complex<double>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zpotrs_gpu(uplo, n, nrhs,
reinterpret_cast<magmaDoubleComplex*>(dA), ldda,
reinterpret_cast<magmaDoubleComplex*>(dB), lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolve<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<float>* dA, magma_int_t ldda,
c10::complex<float>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cpotrs_gpu(uplo, n, nrhs,
reinterpret_cast<magmaFloatComplex*>(dA), ldda,
reinterpret_cast<magmaFloatComplex*>(dB), lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolveBatched<double>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, double** dA_array, magma_int_t ldda,
double** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_dpotrs_batched(uplo, n, nrhs, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolveBatched<float>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, float** dA_array, magma_int_t ldda,
float** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_spotrs_batched(uplo, n, nrhs, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolveBatched<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<double>** dA_array, magma_int_t ldda,
c10::complex<double>** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_zpotrs_batched(uplo, n, nrhs,
reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda,
reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskySolveBatched<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, c10::complex<float>** dA_array, magma_int_t ldda,
c10::complex<float>** dB_array, magma_int_t lddb, magma_int_t& info, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_cpotrs_batched(uplo, n, nrhs,
reinterpret_cast<magmaFloatComplex**>(dA_array), ldda,
reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholesky<double>(
magma_uplo_t uplo, magma_int_t n, double* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dpotrf_gpu(uplo, n, dA, ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholesky<float>(
magma_uplo_t uplo, magma_int_t n, float* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_spotrf_gpu(uplo, n, dA, ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholesky<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<double>* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zpotrf_gpu(uplo, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholesky<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<float>* dA,
magma_int_t ldda, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cpotrf_gpu(uplo, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskyBatched<double>(
magma_uplo_t uplo, magma_int_t n, double** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_dpotrf_batched(uplo, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskyBatched<float>(
magma_uplo_t uplo, magma_int_t n, float** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_spotrf_batched(uplo, n, dA_array, ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskyBatched<c10::complex<double>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<double>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_zpotrf_batched(uplo, n, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaCholeskyBatched<c10::complex<float>>(
magma_uplo_t uplo, magma_int_t n, c10::complex<float>** dA_array, magma_int_t ldda,
magma_int_t* info_array, magma_int_t batchsize, const MAGMAQueue& magma_queue) {
magma_cpotrf_batched(uplo, n, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, info_array, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaTriangularSolveBatched<double>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
double** dA_array, magma_int_t ldda, double** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmablas_dtrsm_batched(MagmaLeft, uplo, trans, diag, m, n, 1, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaTriangularSolveBatched<float>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
float** dA_array, magma_int_t ldda, float** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmablas_strsm_batched(MagmaLeft, uplo, trans, diag, m, n, 1, dA_array, ldda, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaTriangularSolveBatched<c10::complex<double>>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
c10::complex<double>** dA_array, magma_int_t ldda, c10::complex<double>** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmaDoubleComplex alpha({1, 0});
magmablas_ztrsm_batched(MagmaLeft, uplo, trans, diag, m, n, alpha,
reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda,
reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaTriangularSolveBatched<c10::complex<float>>(
magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n,
c10::complex<float>** dA_array, magma_int_t ldda, c10::complex<float>** dB_array, magma_int_t lddb, magma_int_t batchsize,
const MAGMAQueue& magma_queue) {
magmaFloatComplex alpha({1, 0});
magmablas_ctrsm_batched(MagmaLeft, uplo, trans, diag, m, n, alpha,
reinterpret_cast<magmaFloatComplex**>(dA_array), ldda,
reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
inline magma_int_t magmaGeqrfOptimalBlocksize<double>(magma_int_t m, magma_int_t n) {
return magma_get_dgeqrf_nb(m, n);
}
template<>
inline magma_int_t magmaGeqrfOptimalBlocksize<float>(magma_int_t m, magma_int_t n) {
return magma_get_sgeqrf_nb(m, n);
}
template <>
inline magma_int_t magmaGeqrfOptimalBlocksize<c10::complex<double>>(
magma_int_t m,
magma_int_t n) {
return magma_get_zgeqrf_nb(m, n);
}
template <>
inline magma_int_t magmaGeqrfOptimalBlocksize<c10::complex<float>>(
magma_int_t m,
magma_int_t n) {
return magma_get_cgeqrf_nb(m, n);
}
template<>
void magmaGeqrf<double>(
magma_int_t m, magma_int_t n, double* dA, magma_int_t ldda,
double* tau, double* dT, magma_int_t* info, bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_dgeqrf_gpu(m, n, dA, ldda, tau, dT, info);
} else {
magma_dgeqrf2_gpu(m, n, dA, ldda, tau, info);
}
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGeqrf<float>(
magma_int_t m, magma_int_t n, float* dA, magma_int_t ldda,
float* tau, float* dT, magma_int_t* info, bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_sgeqrf_gpu(m, n, dA, ldda, tau, dT, info);
} else {
magma_sgeqrf2_gpu(m, n, dA, ldda, tau, info);
}
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaGeqrf<c10::complex<double>>(
magma_int_t m,
magma_int_t n,
c10::complex<double>* dA,
magma_int_t ldda,
c10::complex<double>* tau,
c10::complex<double>* dT,
magma_int_t* info,
bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_zgeqrf_gpu(
m,
n,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
reinterpret_cast<magmaDoubleComplex*>(tau),
reinterpret_cast<magmaDoubleComplex*>(dT),
info);
} else {
magma_zgeqrf2_gpu(
m,
n,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
reinterpret_cast<magmaDoubleComplex*>(tau),
info);
}
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaGeqrf<c10::complex<float>>(
magma_int_t m,
magma_int_t n,
c10::complex<float>* dA,
magma_int_t ldda,
c10::complex<float>* tau,
c10::complex<float>* dT,
magma_int_t* info,
bool is_v2) {
MagmaStreamSyncGuard guard;
if (!is_v2) {
magma_cgeqrf_gpu(
m,
n,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
reinterpret_cast<magmaFloatComplex*>(tau),
reinterpret_cast<magmaFloatComplex*>(dT),
info);
} else {
magma_cgeqrf2_gpu(
m,
n,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
reinterpret_cast<magmaFloatComplex*>(tau),
info);
}
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaOrgqr<double>(
magma_int_t m, magma_int_t n, magma_int_t k, double* dA, magma_int_t ldda,
double* tau, double* dT, magma_int_t nb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dorgqr_gpu(m, n, k, dA, ldda, tau, dT, nb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaOrgqr<float>(
magma_int_t m, magma_int_t n, magma_int_t k, float* dA, magma_int_t ldda,
float* tau, float* dT, magma_int_t nb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sorgqr_gpu(m, n, k, dA, ldda, tau, dT, nb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaOrgqr<c10::complex<double>>(
magma_int_t m,
magma_int_t n,
magma_int_t k,
c10::complex<double>* dA,
magma_int_t ldda,
c10::complex<double>* tau,
c10::complex<double>* dT,
magma_int_t nb,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zungqr_gpu(
m,
n,
k,
reinterpret_cast<magmaDoubleComplex*>(dA),
ldda,
reinterpret_cast<magmaDoubleComplex*>(tau),
reinterpret_cast<magmaDoubleComplex*>(dT),
nb,
info);
AT_CUDA_CHECK(cudaGetLastError());
}
template <>
void magmaOrgqr<c10::complex<float>>(
magma_int_t m,
magma_int_t n,
magma_int_t k,
c10::complex<float>* dA,
magma_int_t ldda,
c10::complex<float>* tau,
c10::complex<float>* dT,
magma_int_t nb,
magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cungqr_gpu(
m,
n,
k,
reinterpret_cast<magmaFloatComplex*>(dA),
ldda,
reinterpret_cast<magmaFloatComplex*>(tau),
reinterpret_cast<magmaFloatComplex*>(dT),
nb,
info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSyevd<double>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, double* dA, magma_int_t ldda,
double* w, double* wA, magma_int_t ldwa, double* work, magma_int_t lwork, double* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
(void)rwork; // unused
(void)lrwork; // unused
MagmaStreamSyncGuard guard;
magma_dsyevd_gpu(jobz, uplo, n, dA, ldda, w, wA, ldwa, work, lwork, iwork, liwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSyevd<float>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, float* dA, magma_int_t ldda,
float* w, float* wA, magma_int_t ldwa, float* work, magma_int_t lwork, float* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
(void)rwork; // unused
(void)lrwork; // unused
MagmaStreamSyncGuard guard;
magma_ssyevd_gpu(jobz, uplo, n, dA, ldda, w, wA, ldwa, work, lwork, iwork, liwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSyevd<c10::complex<double>, double>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, c10::complex<double>* dA, magma_int_t ldda,
double* w, c10::complex<double>* wA, magma_int_t ldwa, c10::complex<double>* work, magma_int_t lwork, double* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zheevd_gpu(
jobz, uplo, n, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, w, reinterpret_cast<magmaDoubleComplex*>(wA),
ldwa, reinterpret_cast<magmaDoubleComplex*>(work), lwork, rwork, lrwork, iwork, liwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSyevd<c10::complex<float>, float>(
magma_vec_t jobz, magma_uplo_t uplo, magma_int_t n, c10::complex<float>* dA, magma_int_t ldda,
float* w, c10::complex<float>* wA, magma_int_t ldwa, c10::complex<float>* work, magma_int_t lwork, float* rwork,
magma_int_t lrwork, magma_int_t* iwork, magma_int_t liwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cheevd_gpu(
jobz, uplo, n, reinterpret_cast<magmaFloatComplex*>(dA), ldda, w, reinterpret_cast<magmaFloatComplex*>(wA),
ldwa, reinterpret_cast<magmaFloatComplex*>(work), lwork, rwork, lrwork, iwork, liwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaEig<double>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
double *A, magma_int_t lda,
double *w,
double *VL, magma_int_t ldvl,
double *VR, magma_int_t ldvr,
double *work, magma_int_t lwork,
double *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
// magma [sd]geev wants to separate output arrays: wr and wi for the real
// and imaginary parts
double *wr = w;
double *wi = w + n;
(void)rwork; // unused
magma_dgeev(jobvl, jobvr, n, A, lda, wr, wi, VL, ldvl, VR, ldvr, work, lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaEig<float>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
float *A, magma_int_t lda,
float *w,
float *VL, magma_int_t ldvl,
float *VR, magma_int_t ldvr,
float *work, magma_int_t lwork,
float *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
float *wr = w;
float *wi = w + n;
(void)rwork; // unused
magma_sgeev(jobvl, jobvr, n, A, lda, wr, wi, VL, ldvl, VR, ldvr, work, lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaEig<c10::complex<double>, double>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
c10::complex<double> *A, magma_int_t lda,
c10::complex<double> *w,
c10::complex<double> *VL, magma_int_t ldvl,
c10::complex<double> *VR, magma_int_t ldvr,
c10::complex<double> *work, magma_int_t lwork,
double *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
magma_zgeev(jobvl, jobvr, n,
reinterpret_cast<magmaDoubleComplex*>(A), lda,
reinterpret_cast<magmaDoubleComplex*>(w),
reinterpret_cast<magmaDoubleComplex*>(VL), ldvl,
reinterpret_cast<magmaDoubleComplex*>(VR), ldvr,
reinterpret_cast<magmaDoubleComplex*>(work), lwork,
rwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaEig<c10::complex<float>, float>(
magma_vec_t jobvl, magma_vec_t jobvr, magma_int_t n,
c10::complex<float> *A, magma_int_t lda,
c10::complex<float> *w,
c10::complex<float> *VL, magma_int_t ldvl,
c10::complex<float> *VR, magma_int_t ldvr,
c10::complex<float> *work, magma_int_t lwork,
float *rwork,
magma_int_t *info) {
MagmaStreamSyncGuard guard;
magma_cgeev(jobvl, jobvr, n,
reinterpret_cast<magmaFloatComplex*>(A), lda,
reinterpret_cast<magmaFloatComplex*>(w),
reinterpret_cast<magmaFloatComplex*>(VL), ldvl,
reinterpret_cast<magmaFloatComplex*>(VR), ldvr,
reinterpret_cast<magmaFloatComplex*>(work), lwork,
rwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSvd<double>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, double* A,
magma_int_t lda, double* s, double* U, magma_int_t ldu,
double* VT, magma_int_t ldvt, double* work, magma_int_t lwork,
double *rwork, magma_int_t* iwork, magma_int_t* info) {
(void)rwork; // unused
MagmaStreamSyncGuard guard;
magma_dgesdd(jobz, m, n, A, lda, s, U, ldu, VT, ldvt, work, lwork, iwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSvd<float>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, float* A,
magma_int_t lda, float* s, float* U, magma_int_t ldu,
float* VT, magma_int_t ldvt, float* work, magma_int_t lwork,
float* rwork, magma_int_t* iwork, magma_int_t* info) {
(void)rwork; // unused
MagmaStreamSyncGuard guard;
magma_sgesdd(jobz, m, n, A, lda, s, U, ldu, VT, ldvt, work, lwork, iwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSvd<c10::complex<float>, float>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, c10::complex<float>* A,
magma_int_t lda, float* s, c10::complex<float>* U, magma_int_t ldu,
c10::complex<float>* VT, magma_int_t ldvt, c10::complex<float>* work, magma_int_t lwork,
float *rwork, magma_int_t* iwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgesdd(jobz, m, n, reinterpret_cast<magmaFloatComplex*>(A), lda, s,
reinterpret_cast<magmaFloatComplex*>(U), ldu,
reinterpret_cast<magmaFloatComplex*>(VT), ldvt,
reinterpret_cast<magmaFloatComplex*>(work), lwork,
rwork, iwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaSvd<c10::complex<double>, double>(
magma_vec_t jobz, magma_int_t m, magma_int_t n, c10::complex<double>* A,
magma_int_t lda, double* s, c10::complex<double>* U, magma_int_t ldu,
c10::complex<double>* VT, magma_int_t ldvt, c10::complex<double>* work, magma_int_t lwork,
double *rwork, magma_int_t* iwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgesdd(jobz, m, n, reinterpret_cast<magmaDoubleComplex*>(A), lda, s,
reinterpret_cast<magmaDoubleComplex*>(U), ldu,
reinterpret_cast<magmaDoubleComplex*>(VT), ldvt,
reinterpret_cast<magmaDoubleComplex*>(work), lwork,
rwork, iwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolve<double>(
magma_int_t n, magma_int_t nrhs, double* dA, magma_int_t ldda, magma_int_t* ipiv,
double* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgetrs_gpu(MagmaNoTrans, n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolve<float>(
magma_int_t n, magma_int_t nrhs, float* dA, magma_int_t ldda, magma_int_t* ipiv,
float* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgetrs_gpu(MagmaNoTrans, n, nrhs, dA, ldda, ipiv, dB, lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolve<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>* dA, magma_int_t ldda, magma_int_t* ipiv,
c10::complex<double>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgetrs_gpu(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaDoubleComplex*>(dA), ldda, ipiv, reinterpret_cast<magmaDoubleComplex*>(dB), lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolve<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>* dA, magma_int_t ldda, magma_int_t* ipiv,
c10::complex<float>* dB, magma_int_t lddb, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgetrs_gpu(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaFloatComplex*>(dA), ldda, ipiv, reinterpret_cast<magmaFloatComplex*>(dB), lddb, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolveBatched<double>(
magma_int_t n, magma_int_t nrhs, double** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
double** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_dgetrs_batched(MagmaNoTrans, n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolveBatched<float>(
magma_int_t n, magma_int_t nrhs, float** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
float** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_sgetrs_batched(MagmaNoTrans, n, nrhs, dA_array, ldda, dipiv_array, dB_array, lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolveBatched<c10::complex<double>>(
magma_int_t n, magma_int_t nrhs, c10::complex<double>** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
c10::complex<double>** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_zgetrs_batched(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaDoubleComplex**>(dA_array), ldda, dipiv_array, reinterpret_cast<magmaDoubleComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaLuSolveBatched<c10::complex<float>>(
magma_int_t n, magma_int_t nrhs, c10::complex<float>** dA_array, magma_int_t ldda, magma_int_t** dipiv_array,
c10::complex<float>** dB_array, magma_int_t lddb, magma_int_t& info,
magma_int_t batchsize, const MAGMAQueue& magma_queue) {
info = magma_cgetrs_batched(MagmaNoTrans, n, nrhs, reinterpret_cast<magmaFloatComplex**>(dA_array), ldda, dipiv_array, reinterpret_cast<magmaFloatComplex**>(dB_array), lddb, batchsize, magma_queue.get_queue());
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGels<float>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
float* dA, magma_int_t ldda, float* dB, magma_int_t lddb,
float* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_sgels_gpu(trans, m, n, nrhs,
dA, ldda, dB, lddb,
hwork, lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGels<double>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
double* dA, magma_int_t ldda, double* dB, magma_int_t lddb,
double* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_dgels_gpu(trans, m, n, nrhs,
dA, ldda, dB, lddb,
hwork, lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGels<c10::complex<float>>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
c10::complex<float>* dA, magma_int_t ldda, c10::complex<float>* dB, magma_int_t lddb,
c10::complex<float>* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_cgels_gpu(trans, m, n, nrhs,
reinterpret_cast<magmaFloatComplex*>(dA), ldda,
reinterpret_cast<magmaFloatComplex*>(dB), lddb,
reinterpret_cast<magmaFloatComplex*>(hwork), lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
template<>
void magmaGels<c10::complex<double>>(
magma_trans_t trans, magma_int_t m, magma_int_t n, magma_int_t nrhs,
c10::complex<double>* dA, magma_int_t ldda, c10::complex<double>* dB, magma_int_t lddb,
c10::complex<double>* hwork, magma_int_t lwork, magma_int_t* info) {
MagmaStreamSyncGuard guard;
magma_zgels_gpu(trans, m, n, nrhs,
reinterpret_cast<magmaDoubleComplex*>(dA), ldda,
reinterpret_cast<magmaDoubleComplex*>(dB), lddb,
reinterpret_cast<magmaDoubleComplex*>(hwork), lwork, info);
AT_CUDA_CHECK(cudaGetLastError());
}
#endif
#define ALLOCATE_ARRAY(name, type, size) \
auto storage_##name = pin_memory<type>(size); \
name = static_cast<type*>(storage_##name.data());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_solve(Tensor& b, Tensor& A, Tensor& infos) {
#ifndef USE_MAGMA
AT_ERROR("solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto A_data = A.data_ptr<scalar_t>();
auto b_data = b.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(A.size(-2), "A.size(-2)");
magma_int_t nrhs = magma_int_cast(b.size(-1), "b.size(-1)");
magma_int_t lda = std::max(magma_int_t{1}, n);
if (b.dim() == 2) {
auto ipiv = at::empty({n}, at::kInt);
infos = infos.to(at::kCPU); // magmaSolve requires infos tensor to live on CPU
magmaSolve<scalar_t>(n, nrhs, A_data, lda, ipiv.data_ptr<magma_int_t>(),
b_data, lda, infos.data_ptr<magma_int_t>());
} else {
auto infos_data = infos.data_ptr<magma_int_t>();
auto A_mat_stride = matrixStride(A);
auto b_mat_stride = matrixStride(b);
magma_int_t batch_size = magma_int_cast(batchCount(A), "batchCount");
magma_int_t* ipiv_data;
magma_int_t** ipiv_array;
scalar_t** A_array;
scalar_t** b_array;
ALLOCATE_ARRAY(ipiv_data, magma_int_t, batch_size * n);
ALLOCATE_ARRAY(ipiv_array, magma_int_t*, batch_size);
ALLOCATE_ARRAY(A_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
A_array[i] = &A_data[i * A_mat_stride];
b_array[i] = &b_data[i * b_mat_stride];
ipiv_array[i] = &ipiv_data[i * n];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** A_array_cur = &A_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magma_int_t** ipiv_array_cur = &ipiv_array[mini_idx];
magma_int_t* info_array_cur = &infos_data[mini_idx];
magmaSolveBatched<scalar_t>(
n, nrhs, A_array_cur, lda, ipiv_array_cur, b_array_cur, lda,
info_array_cur, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaSolveBatched<scalar_t>(
n, nrhs, &A_array[mini_idx], lda, &ipiv_array[mini_idx], &b_array[mini_idx], lda,
&infos_data[mini_idx], batch_size % batch_limit, magma_queue);
}
}
#endif
}
std::tuple<Tensor, Tensor> _solve_helper_cuda(const Tensor& self, const Tensor& A) {
auto self_working_copy = cloneBatchedColumnMajor(self);
auto A_working_copy = cloneBatchedColumnMajor(A);
// infos might not get filled for empty inputs therefore at::zeros is used instead of at::empty
auto infos = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt));
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "solve_cuda", [&]{
apply_solve<scalar_t>(self_working_copy, A_working_copy, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "solve_cuda");
} else {
singleCheckErrors(infos.item().toInt(), "solve_cuda");
}
return std::tuple<Tensor, Tensor>(self_working_copy, A_working_copy);
}
// This is a type dispatching helper function for 'apply_solve'
Tensor& _linalg_solve_out_helper_cuda(Tensor& result, Tensor& input, Tensor& infos) {
// 'result' and 'input' should be in column major order (it should be checked before calling this function)
// the content of 'result', 'input' and 'infos' is overwritten by 'apply_solve'
// 'result' should contain data of 'other' tensor (right-hand-side of the linear system of equations)
// 'input' should contain data of origianl 'input' tensor (left-hand-side of the linear system)
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "linalg_solve_out_cpu", [&]{
apply_solve<scalar_t>(result, input, infos);
});
return result;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inverse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
Computes the inverse of n-by-n matrix 'self', it is saved to 'self_inv'.
'infos' is an int Tensor containing error codes for each matrix in the batched input.
'infos_lu' is for holding magmaLU errors, and 'infos_getri' is for holding magmaGetri errors
For more information see MAGMA's documentation for GETRI and GETRF routines.
*/
template <typename scalar_t>
static void apply_batched_inverse(Tensor& self, Tensor& self_inv, Tensor& infos_lu, Tensor& infos_getri) {
#ifndef USE_MAGMA
AT_ERROR("inverse: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto self_data = self.data_ptr<scalar_t>();
auto self_mat_stride = matrixStride(self);
auto self_inv_data = self_inv.data_ptr<scalar_t>();
auto self_inv_mat_stride = matrixStride(self_inv);
auto infos_lu_data = infos_lu.data_ptr<magma_int_t>();
auto infos_getri_data = infos_getri.data_ptr<magma_int_t>();
magma_int_t batch_size = magma_int_cast(batchCount(self), "batchCount");
// MAGMA does not work with batch_size == 0, let's return early in this case
if (batch_size == 0) {
return;
}
magma_int_t n = magma_int_cast(self.size(-2), "self.size(-2)");
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t* ipiv_data;
magma_int_t** ipiv_array;
scalar_t** self_array;
scalar_t** self_inv_array;
ALLOCATE_ARRAY(ipiv_data, magma_int_t, batch_size * lda);
ALLOCATE_ARRAY(ipiv_array, magma_int_t*, batch_size);
ALLOCATE_ARRAY(self_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(self_inv_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
self_array[i] = &self_data[i * self_mat_stride];
self_inv_array[i] = &self_inv_data[i * self_inv_mat_stride];
ipiv_array[i] = &ipiv_data[i * n];
}
// magmaLuBatched leaves ipiv_data values unwritten for singular matrices.
// Initialize to avoid memory access violations inside magma kernels (gh-51930).
std::fill_n(ipiv_data, batch_size * n, 1);
MAGMAQueue magma_queue(self.get_device());
magmaLuBatched<scalar_t>(
n, n, self_array, lda, ipiv_array, infos_lu_data,
batch_size, magma_queue);
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** self_array_cur = &self_array[mini_idx];
scalar_t** self_inv_array_cur = &self_inv_array[mini_idx];
magma_int_t** ipiv_array_cur = &ipiv_array[mini_idx];
magma_int_t* info_array_cur_getri = &infos_getri_data[mini_idx];
magmaGetriBatched<scalar_t>(
n, self_array_cur, lda, ipiv_array_cur, self_inv_array_cur,
lda, info_array_cur_getri, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaGetriBatched<scalar_t>(
n, &self_array[mini_idx], lda, &ipiv_array[mini_idx], &self_inv_array[mini_idx],
lda, &infos_getri_data[mini_idx], batch_size % batch_limit, magma_queue);
}
#endif
}
template <typename scalar_t>
static void apply_single_inverse(Tensor& self, Tensor& infos_lu, Tensor& infos_getri) {
#ifndef USE_MAGMA
AT_ERROR("inverse: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto self_data = self.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(self.size(-2), "self.size(-2)");
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t lwork = n * magmaGetriOptimalBlocksize<scalar_t>(n);
// magmaLu and magmaGetri requires infos tensor to live on CPU
infos_lu = infos_lu.to(at::kCPU);
infos_getri = infos_getri.to(at::kCPU);
Tensor ipiv = at::empty({lda}, at::kInt);
Tensor dwork = at::empty({lwork}, self.options());
magmaLu<scalar_t>(n, n, self_data, lda, ipiv.data_ptr<magma_int_t>(), infos_lu.data_ptr<magma_int_t>());
magmaGetri<scalar_t>(
n, self_data, lda, ipiv.data_ptr<magma_int_t>(), dwork.data_ptr<scalar_t>(), lwork, infos_getri.data_ptr<magma_int_t>());
#endif
}
Tensor _inverse_helper_cuda_legacy(const Tensor& self) {
auto self_inv_working_copy = cloneBatchedColumnMajor(self);
if (self.dim() > 2) {
auto infos_lu = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt));
auto infos_getri = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt));
auto self_working_copy = cloneBatchedColumnMajor(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "inverse_cuda", [&]{
apply_batched_inverse<scalar_t>(
self_working_copy, self_inv_working_copy, infos_lu, infos_getri);
});
batchCheckErrors(infos_lu, "inverse_cuda");
batchCheckErrors(infos_getri, "inverse_cuda");
} else {
// magmaLu and magmaGetri requires infos tensor to live on CPU
auto infos_lu = at::zeros({1}, self.options().dtype(kInt).device(kCPU));
auto infos_getri = at::zeros({1}, self.options().dtype(kInt).device(kCPU));
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "inverse_cuda", [&]{
apply_single_inverse<scalar_t>(self_inv_working_copy, infos_lu, infos_getri);
});
singleCheckErrors(infos_lu.item().toInt(), "inverse_cuda");
singleCheckErrors(infos_getri.item().toInt(), "inverse_cuda");
}
return self_inv_working_copy;
}
Tensor _inverse_helper_cuda(const Tensor& self) {
#ifdef USE_CUSOLVER
if ((self.dim() == 2) || (/* self.dim() > 2 && */ batchCount(self) <= 2) || !use_magma_) {
return _inverse_helper_cuda_lib(self); // cusolver or cublas
} else {
return _inverse_helper_cuda_legacy(self); // magma-cuda
}
#else
return _inverse_helper_cuda_legacy(self); // magma-cuda
#endif
}
// This is a type dispatching helper function for 'apply_batched_inverse' and 'singleCheckErrors'
Tensor& _linalg_inv_out_helper_cuda_legacy(Tensor& result, Tensor& infos_lu, Tensor& infos_getri) {
// assuming result is in column major order and contains the matrices to invert
if (result.dim() > 2) {
auto input_working_copy = cloneBatchedColumnMajor(result);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "linalg_inv_out_cuda", [&]{
apply_batched_inverse<scalar_t>(
input_working_copy, result, infos_lu, infos_getri);
});
} else {
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "linalg_inv_out_cuda", [&]{
apply_single_inverse<scalar_t>(result, infos_lu, infos_getri);
});
}
return result;
}
// This is a MAGMA/cuSOLVER dispatching helper function
Tensor& _linalg_inv_out_helper_cuda(Tensor &result, Tensor& infos_lu, Tensor& infos_getri) {
// This function calculates the inverse matrix in-place
// result should be in column major order and contain matrices to invert
#ifdef USE_CUSOLVER
if ((result.dim() == 2) || (/* result.dim() > 2 && */ batchCount(result) <= 2) || !use_magma_) {
return _linalg_inv_out_helper_cuda_lib(result, infos_lu, infos_getri); // cusolver or cublas
} else {
return _linalg_inv_out_helper_cuda_legacy(result, infos_lu, infos_getri); // magma-cuda
}
#else
return _linalg_inv_out_helper_cuda_legacy(result, infos_lu, infos_getri); // magma-cuda
#endif
return result;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cholesky_solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_cholesky_solve(Tensor& b, Tensor& A, bool upper, int64_t& info) {
#ifndef USE_MAGMA
AT_ERROR("cholesky_solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
auto A_data = A.data_ptr<scalar_t>();
auto b_data = b.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(A.size(-2), "A.size(-2)");
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t nrhs = magma_int_cast(b.size(-1), "b.size(-1)");
int info_tmp = 0;
if (b.dim() == 2) {
magmaCholeskySolve<scalar_t>(uplo, n, nrhs, A_data, lda,
b_data, lda, &info_tmp);
info = info_tmp;
} else {
auto A_mat_stride = matrixStride(A);
auto b_mat_stride = matrixStride(b);
magma_int_t batch_size = magma_int_cast(batchCount(A), "batchCount");
scalar_t** A_array;
scalar_t** b_array;
ALLOCATE_ARRAY(A_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
A_array[i] = &A_data[i * A_mat_stride];
b_array[i] = &b_data[i * b_mat_stride];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** A_array_cur = &A_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magmaCholeskySolveBatched<scalar_t>(
uplo, n, nrhs, A_array_cur, lda, b_array_cur, lda,
info_tmp, batch_limit, magma_queue);
if (info_tmp != 0) {
break;
}
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0 && info_tmp == 0) {
magmaCholeskySolveBatched<scalar_t>(
uplo, n, nrhs, &A_array[mini_idx], lda, &b_array[mini_idx], lda,
info_tmp, batch_size % batch_limit, magma_queue);
}
info = info_tmp;
}
#endif
}
Tensor _cholesky_solve_helper_cuda(const Tensor& self, const Tensor& A, bool upper) {
int64_t info = 0;
auto self_working_copy = cloneBatchedColumnMajor(self);
auto A_working_copy = cloneBatchedColumnMajor(A);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "cholesky_solve_cuda", [&]{
apply_cholesky_solve<scalar_t>(self_working_copy, A_working_copy, upper, info);
});
TORCH_CHECK(info == 0, "MAGMA cholesky_solve : invalid argument: ", -info);
return self_working_copy;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cholesky ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_cholesky(Tensor& self, bool upper, std::vector<int64_t>& infos) {
#ifndef USE_MAGMA
AT_ERROR("cholesky: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
auto self_data = self.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(self.size(-2), "self.size(-2)");
auto lda = std::max<magma_int_t>(1, n);
if (self.dim() == 2) {
magma_int_t info = 0;
magmaCholesky<scalar_t>(uplo, n, self_data, lda, &info);
infos[0] = info;
} else {
auto self_mat_stride = matrixStride(self);
magma_int_t batch_size = magma_int_cast(batchCount(self), "batchCount");
magma_int_t* info_array;
scalar_t** self_array;
ALLOCATE_ARRAY(info_array, magma_int_t, batch_size);
ALLOCATE_ARRAY(self_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
self_array[i] = &self_data[i * self_mat_stride];
}
MAGMAQueue magma_queue(self.get_device());
int64_t batch_limit = self.is_complex() ? 65535 : 262140;
// Compute as many batches of 262140 possible
// 262140 is the size of the largest batch of matrices that can be run with
// violating maximum kernel configuration
// For complex input the batch limit is 65535 (determined experimentally, see https://github.com/pytorch/pytorch/pull/47047#discussion_r516086923 for more information)
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit cholesky calls
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** self_array_cur = &self_array[mini_idx];
magma_int_t* info_array_cur = &info_array[mini_idx];
magmaCholeskyBatched<scalar_t>(
uplo, n, self_array_cur, lda, info_array_cur, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaCholeskyBatched<scalar_t>(
uplo, n, &self_array[mini_idx], lda, &info_array[mini_idx], batch_size % batch_limit, magma_queue);
}
for (int64_t i = 0; i < batch_size; i++) {
infos[i] = info_array[i];
}
}
#endif
}
Tensor _cholesky_helper_cuda_magma(const Tensor& self, bool upper) {
std::vector<int64_t> infos(batchCount(self), 0);
Tensor result;
if (self.dim() > 2) {
// MAGMA's batched cholesky operator has an off-by-one error causing IMA
// (see https://github.com/pytorch/pytorch/issues/42666). This code is based
// on the #cloneBatchedColumnMajor function however it pads the input with
// one extra element utilizing the fact that the resize_as_ method preserves
// the storage even if it's larger than the new sizes. This way if MAGMA
// reads off bounds it will still be valid user memory.
const Tensor input = upper ? self : self.transpose(-1, -2);
result = at::empty(input.numel() + 1, input.options());
result.resize_as_(input).copy_(input).transpose_(-1, -2);
} else {
result = cloneBatchedColumnMajor(upper ? self.transpose(-1, -2) : self);
}
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(
self.scalar_type(), "cholesky_cuda", [&] {
apply_cholesky<scalar_t>(result, false, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "cholesky_cuda");
} else {
singleCheckErrors(infos[0], "cholesky_cuda");
}
return upper ? result.transpose_(-1, -2) : result;
}
// Todo: cusolverDnXpotrfBatched has some numerical issue and is not used
// here. Batched cholesky is dispatched to magma.
// We will switch to cusolverDnXpotrfBatched after the issue is fixed.
// See https://github.com/pytorch/pytorch/issues/53879.
Tensor _cholesky_helper_cuda(const Tensor& self, bool upper) {
#ifdef USE_CUSOLVER
if (batchCount(self) == 1 || !use_magma_) {
return _cholesky_helper_cuda_cusolver(self, upper);
}
else {
return _cholesky_helper_cuda_magma(self, upper);
}
#else
return _cholesky_helper_cuda_magma(self, upper);
#endif
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cholesky_inverse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
Computes the inverse of a symmetric (Hermitian) positive-definite matrix n-by-n matrix 'input' using the Cholesky solver
This is an in-place routine, content of 'input' is overwritten.
'infos' is an int Tensor containing error codes for each matrix in the batched input.
MAGMA requires 'infos' to reside in CPU memory.
For more information see MAGMA's documentation for POTRS routine.
*/
template <typename scalar_t>
static void apply_cholesky_inverse(Tensor& input, Tensor& infos, bool upper) {
#ifndef USE_MAGMA
TORCH_CHECK(false, "cholesky_inverse: MAGMA library not found in compilation. Please rebuild with MAGMA.");
#else
// magmaCholeskyInverse (magma_dpotri_gpu) is slow because internally
// it transfers data several times between GPU and CPU and calls lapack routine on CPU
// using magmaCholeskySolveBatched is a lot faster
// note that magmaCholeskySolve is also slow
// 'input' is modified in-place we need to clone it and replace with a diagonal matrix
// for apply_cholesky_solve
auto input_working_copy = cloneBatchedColumnMajor(input);
// 'input' tensor has to be a batch of diagonal matrix
input.fill_(0);
input.diagonal(/*offset=*/0, /*dim1=*/-2, /*dim2=*/-1).fill_(1);
Tensor result_u, input_u;
if (input.dim() == 2) {
// unsqueezing here so that the batched version is used
result_u = input.unsqueeze(0);
input_u = input_working_copy.unsqueeze(0);
} else {
result_u = input;
input_u = input_working_copy;
}
// magma's potrs_batched doesn't take matrix-wise array of ints as an 'info' argument
// it returns a single 'magma_int_t'
// if info = 0 the operation is successful, if info = -i, the i-th parameter had an illegal value.
int64_t info_tmp = 0;
apply_cholesky_solve<scalar_t>(result_u, input_u, upper, info_tmp);
infos.fill_(info_tmp);
#endif
}
// This is a type dispatching helper function for 'apply_cholesky_inverse'
Tensor& cholesky_inverse_kernel_impl(Tensor &result, Tensor& infos, bool upper) {
// This function calculates the inverse matrix in-place
// result should be in column major order and contain matrices to invert
// the content of result is overwritten by 'apply_cholesky_inverse'
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(result.scalar_type(), "cholesky_inverse_out_cuda", [&]{
apply_cholesky_inverse<scalar_t>(result, infos, upper);
});
return result;
}
REGISTER_DISPATCH(cholesky_inverse_stub, &cholesky_inverse_kernel_impl);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_lu(Tensor& self, Tensor& pivots, Tensor& infos, bool get_pivots) {
#ifndef USE_MAGMA
AT_ERROR("lu: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto self_data = self.data_ptr<scalar_t>();
magma_int_t m = magma_int_cast(self.size(-2), "m");
magma_int_t n = magma_int_cast(self.size(-1), "n");
magma_int_t k = std::min(m, n);
if (self.dim() == 2) {
// If `pivots` is defined, then we have to compute them.
// magmaLu and magmaLuNoPiv use a hybrid CPU-GPU algorithm to compute
// the partially-pivoted LU decomposition with / without pivots.
// The driver routines magma_(d/s)getrf_(nopiv_)gpu accepts a tensor on the CPU for pivots.
// The data is later copied back to the appropriate output tensor.
Tensor info_tmp = at::zeros({}, at::kInt);
if (get_pivots) {
Tensor piv_tmp = at::empty({k}, at::kInt);
magmaLu<scalar_t>(
m, n, self_data, m, piv_tmp.data_ptr<magma_int_t>(), info_tmp.data_ptr<magma_int_t>());
pivots.copy_(piv_tmp);
} else {
magmaLuNoPiv<scalar_t>(m, n, self_data, m, info_tmp.data_ptr<magma_int_t>());
}
infos.copy_(info_tmp);
} else {
auto self_matrix_stride = matrixStride(self);
magma_int_t batch_size = magma_int_cast(batchCount(self), "batchCount");
scalar_t** self_array;
ALLOCATE_ARRAY(self_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
self_array[i] = &self_data[i * self_matrix_stride];
}
MAGMAQueue magma_queue(self.get_device());
// Same comment as in the case of single matrix above.
if (get_pivots) {
auto pivots_data = pivots.data_ptr<magma_int_t>();
auto pivots_matrix_stride = pivots.size(-1);
magma_int_t** pivots_array;
ALLOCATE_ARRAY(pivots_array, magma_int_t*, batch_size);
for (int64_t i = 0; i < batch_size; i++) {
pivots_array[i] = &pivots_data[i * pivots_matrix_stride];
}
magmaLuBatched<scalar_t>(
m, n, self_array, m, pivots_array,
infos.data_ptr<magma_int_t>(), batch_size, magma_queue);
} else {
magmaLuNoPivBatched<scalar_t>(
m, n, self_array, m, infos.data_ptr<magma_int_t>(),
batch_size, magma_queue);
}
}
#endif
}
std::tuple<Tensor, Tensor, Tensor> _lu_with_info_cuda(const Tensor& self, bool pivot, bool check_errors) {
TORCH_CHECK(self.dim() >= 2,
"expected tensor with 2 or more dimensions, got size: ", self.sizes(),
" instead");
auto m = self.size(-2);
auto n = self.size(-1);
auto k = std::min(m, n);
auto req_size = self.sizes().vec();
req_size.pop_back();
req_size.back() = k;
Tensor pivots_tensor = at::arange(1, k + 1, self.options().dtype(at::kInt)).expand(req_size).contiguous();
req_size.pop_back();
auto infos_tensor = at::zeros(req_size, self.options().dtype(at::kInt));
Tensor self_working_copy;
if (self.numel() == 0) {
self_working_copy = at::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
} else {
self_working_copy = cloneBatchedColumnMajor(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "lu_cuda", [&]{
apply_lu<scalar_t>(self_working_copy, pivots_tensor, infos_tensor, pivot);
});
}
if (check_errors) {
if (self.dim() == 2) {
singleCheckErrors(infos_tensor.item<int64_t>(), "lu", /*allow_singular=*/true);
} else {
batchCheckErrors(infos_tensor, "lu", /*allow_singular=*/true);
}
}
return std::make_tuple(self_working_copy, pivots_tensor, infos_tensor);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ triangular_solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_triangular_solve_batched(Tensor& A, Tensor& b, bool upper, bool transpose, bool conjugate_transpose, bool unitriangular) {
#ifndef USE_MAGMA
AT_ERROR("triangular_solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
magma_trans_t trans = transpose ? MagmaTrans : MagmaNoTrans;
trans = conjugate_transpose ? MagmaConjTrans : trans;
magma_diag_t diag = unitriangular ? MagmaUnit : MagmaNonUnit;
auto A_data = A.data_ptr<scalar_t>();
auto b_data = b.data_ptr<scalar_t>();
magma_int_t n = magma_int_cast(A.size(-2), "A.size(-2)");
magma_int_t nrhs = magma_int_cast(b.size(-1), "b.size(-1)");
// magma returns early if m <= 0 || n <= 0 for magmaTriangularSolveBatched
// magmaTriangularSolve is calling cuBLAS and it prints
// ** On entry to DTRSM parameter number 9 had an illegal value
// so let's use proper lda parameter here
magma_int_t lda = std::max<magma_int_t>(1, n);
magma_int_t batch_size = magma_int_cast(batchCount(A), "batchCount");
auto A_mat_stride = matrixStride(A);
auto b_mat_stride = matrixStride(b);
scalar_t** A_array;
scalar_t** b_array;
ALLOCATE_ARRAY(A_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
// Set up the created arrays
for (int64_t i = 0; i < batch_size; i++) {
A_array[i] = &A_data[i * A_mat_stride];
b_array[i] = &b_data[i * b_mat_stride];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit;
int64_t mini_idx; // this is outside the loop because it is used for the case batch_size % batch_limit != 0
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** A_array_cur = &A_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magmaTriangularSolveBatched<scalar_t>(
uplo, trans, diag, n, nrhs, A_array_cur,
lda, b_array_cur, lda, batch_limit, magma_queue);
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0) {
magmaTriangularSolveBatched<scalar_t>(
uplo, trans, diag, n, nrhs, &A_array[mini_idx],
lda, &b_array[mini_idx], lda, batch_size % batch_limit, magma_queue);
}
#endif
}
void triangular_solve_batched_magma(Tensor& A, Tensor& B, Tensor& infos, bool upper, bool transpose, bool conjugate_transpose, bool unitriangular) {
(void)infos; // unused
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(A.scalar_type(), "triangular_solve_cuda", [&]{
apply_triangular_solve_batched<scalar_t>(A, B, upper, transpose, conjugate_transpose, unitriangular);
});
}
void triangular_solve_kernel(Tensor& A, Tensor& B, Tensor& infos, bool upper, bool transpose, bool conjugate_transpose, bool unitriangular) {
// For batches smaller than 8 and matrix sizes larger than 64x64 cuBLAS forloop is faster than batched version
if (batchCount(A) <= 8 && A.size(-1) >= 64) {
triangular_solve_cublas(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
} else {
#ifndef USE_MAGMA
triangular_solve_batched_cublas(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
#else
// cuBLAS batched is faster than MAGMA batched up until 512x512, after that MAGMA is faster
if (A.size(-1) <= 512) {
triangular_solve_batched_cublas(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
} else {
triangular_solve_batched_magma(A, B, infos, upper, transpose, conjugate_transpose, unitriangular);
}
#endif // USE_MAGMA
}
}
REGISTER_DISPATCH(triangular_solve_stub, &triangular_solve_kernel);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ orgqr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tensor& orgqr_kernel_impl(Tensor& result, const Tensor& tau, Tensor& infos, int64_t n_columns) {
// TODO: It is possible to implement efficient batched orgqr for small tau (tau.size(-1) <= 32)
// using MAGMA, however it fails on Windows because of some illegal memory reads inside MAGMA.
// See discussions in https://github.com/pytorch/pytorch/pull/51348 for comparison of cuSOLVER-MAGMA
// and Windows failure.
// For reference here is the MAGMA-based implementation: https://gist.github.com/IvanYashchuk/2db50002c9d3c1462ff769e6410ad983
#if defined(USE_CUSOLVER)
return orgqr_helper_cuda_lib(result, tau, infos, n_columns); // cusolver
#else
TORCH_CHECK(false, "Calling torch.orgqr on a CUDA tensor requires compiling ",
"PyTorch with cuSOLVER. Please use PyTorch built with cuSOLVER support.");
#endif
}
REGISTER_DISPATCH(orgqr_stub, &orgqr_kernel_impl);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ qr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_qr(Tensor& Q, Tensor& R, int64_t q_size_minus_2, int64_t r_size_minus_1, int64_t n_columns,
bool compute_q, std::vector<int64_t>& infos) {
#ifndef USE_MAGMA
AT_ERROR("qr: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
magma_int_t m = magma_int_cast(q_size_minus_2, "Q.size(-2)");
magma_int_t n = magma_int_cast(r_size_minus_1, "R.size(-1)");
auto r_data = R.data_ptr<scalar_t>();
auto r_matrix_stride = matrixStride(R);
magma_int_t k = m < n ? m : n;
magma_int_t nb = magmaGeqrfOptimalBlocksize<scalar_t>(m, n);
int64_t batch_size = batchCount(R);
// magmaGeqrf uses a hybrid CPU-GPU algorithm to compute the elementary reflectors.
// The driver routine magma_(d/s)geqrf2_gpu accepts a tensor on the CPU for elementary reflectors.
Tensor tau = at::empty({k}, Q.options().device(at::kCPU));
Tensor work = at::empty({(2 * k + magma_roundup(n, 32)) * nb}, R.options());
scalar_t* tau_data = tau.data_ptr<scalar_t>();
scalar_t* work_data = work.data_ptr<scalar_t>();
// This phase computes R (the raw version)
// This uses MAGMA's ?geqrf2_gpu function
magma_int_t info = 0;
for (int64_t i = 0; i < batch_size; i++) {
scalar_t* r_working_ptr = &r_data[i * r_matrix_stride];
magmaGeqrf<scalar_t>(m, n, r_working_ptr, m, tau_data, work_data, &info, /*is_v2=*/true);
infos[i] = info;
if (info != 0) {
return;
}
}
if (!compute_q) {
// this is for mode='r'
return;
}
// This phase computes Q (the raw version)
// We require to perform ?geqrf_gpu again due to this bug in MAGMA:
// - ?geqrf_gpu allows fast computation of Q via ?orgqr_gpu, but doesn't give R properly.
// - ?geqrf2_gpu gives correct R, but doesn't allow computation of Q via ?orgqr_gpu
// Refer to the below link for more details:
// http://icl.cs.utk.edu/magma/forum/viewtopic.php?f=2&t=1015&p=2800&hilit=geqrf_gpu#p2800
auto q_data = Q.data_ptr<scalar_t>();
auto q_matrix_stride = matrixStride(Q);
for (int64_t i = 0; i < batch_size; i++) {
scalar_t* q_working_ptr = &q_data[i * q_matrix_stride];
magmaGeqrf<scalar_t>(m, n, q_working_ptr, m, tau_data, work_data, &info, /*is_v2=*/false);
infos[i] = info;
if (info != 0) {
return;
}
magmaOrgqr<scalar_t>(m, n_columns, k, q_working_ptr, m, tau_data, work_data, nb, &info);
infos[i] = info;
if (info != 0) {
return;
}
}
#endif
}
std::tuple<Tensor,Tensor> _linalg_qr_helper_cuda(const Tensor& self, std::string mode) {
bool compute_q, reduced;
std::tie(compute_q, reduced) = _parse_qr_mode(mode);
std::vector<int64_t> infos(batchCount(self), 0);
// Setup input geometry and inputs for apply_qr
std::vector<int64_t> q_sizes, q_strides;
int64_t n_columns_q;
std::tie(q_sizes, q_strides, n_columns_q) = _compute_geometry_for_Q(self, reduced);
Tensor q_working_copy, r_working_copy;
// If there are no elements, then we simply return a pair of tensors of required dimensions
if (self.numel() == 0) {
int64_t n = self.size(-1);
r_working_copy = at::empty({n_columns_q, n}, self.options());
if (compute_q) {
int64_t n_rows_q = q_sizes[self.dim() - 2];
q_working_copy = at::eye(n_rows_q, n_columns_q, self.options());
} else {
q_working_copy = at::empty({0}, self.options());
}
return std::make_tuple(q_working_copy, r_working_copy);
}
if (compute_q) {
q_working_copy = at::empty_strided(q_sizes, q_strides, self.options());
q_working_copy.narrow(-1, 0, self.size(-1)).copy_(self);
} else {
q_working_copy = at::empty({0}, self.options());
}
r_working_copy = cloneBatchedColumnMajor(self);
int64_t m = q_sizes[self.dim() - 2];
int64_t n = r_working_copy.size(-1);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "qr_cuda", [&]{
apply_qr<scalar_t>(q_working_copy, r_working_copy, m, n, n_columns_q, compute_q, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "qr_cuda");
} else {
singleCheckErrors(infos[0], "qr_cuda");
}
if (compute_q) {
q_working_copy = q_working_copy.narrow(-1, 0, n_columns_q);
}
r_working_copy = r_working_copy.narrow(-2, 0, n_columns_q).triu();
return std::make_tuple(q_working_copy, r_working_copy);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ symeig ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_magma_eigh(Tensor& values, Tensor& vectors, Tensor& infos, bool upper, bool compute_eigenvectors) {
#ifndef USE_MAGMA
TORCH_CHECK(
false,
"Calling torch.linalg.eigh/eigvalsh on a CUDA tensor requires compiling ",
"PyTorch with MAGMA. Please use PyTorch built with MAGMA support.");
#else
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(values.device() == kCPU);
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(infos.device() == kCPU);
using value_t = typename c10::scalar_value_type<scalar_t>::type;
magma_uplo_t uplo = upper ? MagmaUpper : MagmaLower;
magma_vec_t jobz = compute_eigenvectors ? MagmaVec : MagmaNoVec;
magma_int_t n = magma_int_cast(vectors.size(-1), "n");
auto lda = std::max<magma_int_t>(1, n);
auto batch_size = batchCount(vectors);
auto vectors_stride = matrixStride(vectors);
auto values_stride = values.size(-1);
auto vectors_data = vectors.data_ptr<scalar_t>();
auto values_data = values.data_ptr<value_t>();
auto infos_data = infos.data_ptr<magma_int_t>();
scalar_t* wA;
ALLOCATE_ARRAY(wA, scalar_t, lda * lda);
// Run once, first to get the optimum work sizes.
// Since we deal with batches of matrices with the same dimensions, doing this outside
// the loop saves (batch_size - 1) workspace queries which would provide the same result
// and (batch_size - 1) calls to allocate and deallocate workspace using at::empty()
magma_int_t lwork = -1;
scalar_t wkopt;
magma_int_t liwork = -1;
magma_int_t iwkopt;
magma_int_t lrwork = -1;
value_t rwkopt;
magmaSyevd<scalar_t, value_t>(jobz, uplo, n, vectors_data, lda, values_data,
wA, lda, &wkopt, lwork, &rwkopt, lrwork, &iwkopt, liwork, infos_data);
scalar_t* work;
magma_int_t* iwork;
lwork = magma_int_cast(std::max<int64_t>(1, real_impl<scalar_t, value_t>(wkopt)), "work_size");
liwork = magma_int_cast(std::max<int64_t>(1, iwkopt), "iwork_size");
ALLOCATE_ARRAY(work, scalar_t, lwork);
ALLOCATE_ARRAY(iwork, magma_int_t, liwork);
value_t* rwork = nullptr;
c10::Storage storage_rwork;
if (vectors.is_complex()) {
lrwork = magma_int_cast(std::max<int64_t>(1, rwkopt), "rwork_size");
storage_rwork = pin_memory<value_t>(lrwork);
rwork = static_cast<value_t*>(storage_rwork.data());
}
for (decltype(batch_size) i = 0; i < batch_size; i++) {
scalar_t* vectors_working_ptr = &vectors_data[i * vectors_stride];
value_t* values_working_ptr = &values_data[i * values_stride];
magma_int_t* info_working_ptr = &infos_data[i];
magmaSyevd<scalar_t, value_t>(jobz, uplo, n, vectors_working_ptr, lda, values_working_ptr,
wA, lda, work, lwork, rwork, lrwork, iwork, liwork, info_working_ptr);
// The current behaviour for Linear Algebra functions to raise an error if something goes wrong
// or input doesn't satisfy some requirement
// therefore return early since further computations will be wasted anyway
if (*info_working_ptr != 0) {
return;
}
}
#endif
}
std::tuple<Tensor, Tensor> _symeig_helper_cuda(const Tensor& self, bool eigenvectors, bool upper) {
Tensor infos = at::zeros({std::max<int64_t>(1, batchCount(self))}, self.options().dtype(kInt).device(at::kCPU));
auto eigvals_shape = IntArrayRef(self.sizes().data(), self.dim()-1); // self.shape[:-1]
ScalarType real_dtype = toValueType(self.scalar_type());
// magmaSyevd uses a hybrid CPU-GPU algorithm to compute the eigenvalues and eigenvectors.
// The driver routine magma_(d/s)syev_gpu accepts a tensor on the CPU for eigvalenvalues.
// The data is later moved to the appropriate device.
// In the case where self.numel() == 0, we just return an empty tensor of
// dimensions on the CUDA (to avoid the unnecessary "to(at::kCUDA)")
auto eigvals_working_copy = self.numel() == 0
? at::empty(eigvals_shape, self.options().dtype(real_dtype))
: at::empty(eigvals_shape, self.options().dtype(real_dtype).device(at::kCPU));
if (self.numel() == 0) {
return std::tuple<Tensor, Tensor>(eigvals_working_copy, at::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT));
}
auto self_working_copy = cloneBatchedColumnMajor(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "symeig_cuda", [&]{
apply_magma_eigh<scalar_t>(eigvals_working_copy, self_working_copy, infos, upper, eigenvectors);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "symeig_cuda");
} else {
singleCheckErrors(infos.item().toInt(), "symeig_cuda");
}
if (eigenvectors) {
return std::tuple<Tensor, Tensor>(eigvals_working_copy.to(self.device()), self_working_copy);
} else {
return std::tuple<Tensor, Tensor>(eigvals_working_copy.to(self.device()), at::empty({0}, self.options()));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linalg_eigh ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This is a type dispatch function for 'apply_magma_eigh'
// For small inputs result is computed on CPU
void linalg_eigh_magma(Tensor& eigenvalues, Tensor& eigenvectors, Tensor& infos, bool upper, bool compute_eigenvectors) {
// MAGMA just calls LAPACK for eigenvectors.size(-1) <= 128
// See https://bitbucket.org/icl/magma/src/e6fdca447bd402693e8b0b950a898b6879bbcc41/src/zheevd_gpu.cpp?at=master#lines-258
// in addition lda is ignored breaking 0x0 inputs
if (eigenvectors.size(-1) > 128) {
// MAGMA requires eigenvalues and infos tensors to reside on CPU
Tensor eigenvalues_cpu = eigenvalues.to(kCPU);
infos = infos.to(kCPU);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(
eigenvectors.scalar_type(), "linalg_eigh_cpu", [&] {
apply_magma_eigh<scalar_t>(
eigenvalues_cpu, eigenvectors, infos, upper, compute_eigenvectors);
});
// Transfer computed by MAGMA results from CPU to GPU
eigenvalues.copy_(eigenvalues_cpu);
} else { // eigenvectors.size(-1) <= 128
// transfer to CPU, compute the result and copy back to GPU
// this is faster than going through MAGMA that does the same
Tensor eigenvalues_cpu = at::empty_like(eigenvalues, eigenvalues.options().device(kCPU));
if (compute_eigenvectors) {
Tensor eigenvectors_cpu = at::empty_like(eigenvectors, eigenvectors.options().device(kCPU));
at::linalg_eigh_out(eigenvalues_cpu, eigenvectors_cpu, eigenvectors.to(kCPU), upper ? "U" : "L");
eigenvectors.copy_(eigenvectors_cpu);
} else {
at::linalg_eigvalsh_out(eigenvalues_cpu, eigenvectors.to(kCPU), upper ? "U" : "L");
}
eigenvalues.copy_(eigenvalues_cpu);
}
}
void linalg_eigh_kernel(Tensor& eigenvalues, Tensor& eigenvectors, Tensor& infos, bool upper, bool compute_eigenvectors) {
#if defined(USE_CUSOLVER)
linalg_eigh_cusolver(eigenvalues, eigenvectors, infos, upper, compute_eigenvectors);
#else
linalg_eigh_magma(eigenvalues, eigenvectors, infos, upper, compute_eigenvectors);
#endif
}
REGISTER_DISPATCH(linalg_eigh_stub, &linalg_eigh_kernel);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eig ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// magmaEig uses a hybrid CPU-GPU algorithm, which takes and return CPU
// memory. So, we accept a GPU tensor, copy it to CPU memory, and later copy
// the returned values from CPU to GPU. See also magmaSymeig, which uses a
// similar approach.
template <typename scalar_t>
static void apply_eig(const Tensor& self, bool eigenvectors, Tensor& out_eigvals, Tensor& out_eigvecs,
int64_t *info_ptr) {
#ifndef USE_MAGMA
TORCH_CHECK(false, "Calling torch.eig on a CUDA tensor requires compiling PyTorch with MAGMA. "
"Either transfer the tensor to the CPU before calling torch.eig or recompile with MAGMA.");
#else
TORCH_INTERNAL_ASSERT(self.device() == at::kCPU, "Internal error: apply_eig needs a CPU tensor");
using value_t = typename c10::scalar_value_type<scalar_t>::type;
magma_vec_t jobvr = eigenvectors ? MagmaVec : MagmaNoVec;
magma_int_t n = magma_int_cast(self.size(-1), "n");
auto self_data = self.data_ptr<scalar_t>();
auto out_eigvals_data = out_eigvals.data_ptr<scalar_t>();
scalar_t *wr = out_eigvals_data;
scalar_t *vr_data = NULL;
magma_int_t ldvr = 1;
if (jobvr == MagmaVec)
{
vr_data = out_eigvecs.data_ptr<scalar_t>();
ldvr = n;
}
value_t *rwork_data = nullptr;
if (isComplexType(at::typeMetaToScalarType(self.dtype()))) {
ALLOCATE_ARRAY(rwork_data, value_t, n*2);
}
if (n > 0) {
// call magmaEig once to get the optimal size of work_data
scalar_t wkopt;
magma_int_t info;
magmaEig<scalar_t, value_t>(MagmaNoVec, jobvr, n, self_data, n, wr, NULL, 1, vr_data, ldvr, &wkopt, -1, rwork_data, &info);
magma_int_t lwork = static_cast<magma_int_t>(real_impl<scalar_t, value_t>(wkopt));
// call it a 2nd time to to the actual work
scalar_t *work_data = nullptr;
ALLOCATE_ARRAY(work_data, scalar_t, lwork);
magmaEig<scalar_t, value_t>(MagmaNoVec, jobvr, n, self_data, n, wr, NULL, 1, vr_data, ldvr, work_data, lwork, rwork_data, &info);
*info_ptr = info;
}
#endif
}
/*
* Internal helper; like eig_cuda but:
* 1. assume that self is a square matrix of side "n"
* 2. return CPU tensors (because this is what magmaEig returns), which will be copied to GPU memory
* by the caller
*/
std::tuple<Tensor, Tensor> eig_kernel_impl(const Tensor& self, bool& eigenvectors) {
int64_t n = self.size(-1);
// copy self to pinned CPU memory
auto self_working_copy = at::empty_strided(
{n, n}, // square matrix
{1, n}, // column-ordered, as magmaEig expects
at::TensorOptions(at::kCPU).dtype(self.dtype()).pinned_memory(true));
self_working_copy.copy_(self);
// tensors holding the results. We use empty_strided to make them column-ordered
auto options = self.options().device(at::kCPU).memory_format(LEGACY_CONTIGUOUS_MEMORY_FORMAT);
Tensor out_eigvals;
if (isComplexType(at::typeMetaToScalarType(self.dtype()))) {
out_eigvals = at::empty({n}, options);
} else {
out_eigvals = at::empty_strided({n, 2}, {1, n}, options);
}
auto out_eigvecs = eigenvectors
? at::empty_strided({n, n}, {1, n}, options)
: Tensor();
int64_t info;
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "eig_cuda", [&]{
apply_eig<scalar_t>(self_working_copy, eigenvectors, out_eigvals, out_eigvecs, &info);
});
singleCheckErrors(info, "eig_cuda");
return std::tuple<Tensor, Tensor>(out_eigvals, out_eigvecs);
}
REGISTER_DISPATCH(eig_stub, &eig_kernel_impl);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ svd ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename scalar_t>
static void apply_svd(Tensor& self, Tensor& U, Tensor& S, Tensor& VT,
char jobchar, std::vector<int64_t>& infos) {
#ifndef USE_MAGMA
AT_ERROR("svd: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
using value_t = typename c10::scalar_value_type<scalar_t>::type;
auto self_data = self.data_ptr<scalar_t>();
auto U_data = U.data_ptr<scalar_t>();
auto S_data = S.data_ptr<value_t>();
auto VT_data = VT.data_ptr<scalar_t>();
auto self_stride = matrixStride(self);
auto U_stride = matrixStride(U);
auto S_stride = S.size(-1);
auto VT_stride = matrixStride(VT);
auto batchsize = batchCount(self);
magma_vec_t jobz = jobchar == 'A' ? MagmaAllVec : (jobchar == 'S' ? MagmaSomeVec : MagmaNoVec);
magma_int_t m = magma_int_cast(self.size(-2), "m");
magma_int_t n = magma_int_cast(self.size(-1), "n");
auto lda = std::max<magma_int_t>(1, m);
auto ldvt = std::max<magma_int_t>(1, n);
auto mn = std::min(m, n);
c10::Storage storage_rwork;
value_t* rwork = nullptr;
magma_int_t* iwork;
ALLOCATE_ARRAY(iwork, magma_int_t, 8 * mn);
if (isComplexType(at::typeMetaToScalarType(self.dtype()))) {
auto lrwork = computeLRWorkDim(jobchar, m, n);
storage_rwork = pin_memory<value_t>(lrwork);
rwork = static_cast<value_t*>(storage_rwork.data());
}
magma_int_t info = 0;
// Run once, first to get the optimum work size.
// Since we deal with batches of matrices with the same dimensions, doing this outside
// the loop saves (batch_size - 1) workspace queries which would provide the same result
// and (batch_size - 1) calls to allocate and deallocate workspace using at::empty()
magma_int_t lwork = -1;
scalar_t wkopt = 1; // MAGMA might not set the value for the optimal workspace therefore use 1 as the default value
magmaSvd<scalar_t, value_t>(jobz, m, n, self_data, lda, S_data, U_data, lda, VT_data, ldvt, &wkopt, lwork, rwork, iwork, &info);
lwork = magma_int_cast(real_impl<scalar_t, value_t>(wkopt), "work_size");
scalar_t* work;
ALLOCATE_ARRAY(work, scalar_t, lwork);
for (int64_t i = 0; i < batchsize; i++) {
scalar_t* self_working_ptr = &self_data[i * self_stride];
value_t* S_working_ptr = &S_data[i * S_stride];
scalar_t* U_working_ptr = &U_data[i * U_stride];
scalar_t* VT_working_ptr = &VT_data[i * VT_stride];
// Compute S, U (optionally), VT (optionally)
magmaSvd<scalar_t, value_t>(jobz, m, n, self_working_ptr, lda,
S_working_ptr, U_working_ptr, lda, VT_working_ptr, ldvt, work, lwork, rwork, iwork, &info);
infos[i] = info;
if (info != 0) {
return;
}
}
#endif
}
std::tuple<Tensor, Tensor, Tensor> _svd_helper_cuda_legacy(const Tensor& self, bool some, bool compute_uv) {
std::vector<int64_t> infos(batchCount(self), 0);
int64_t m = self.size(-2), n = self.size(-1);
int64_t k = std::min(m, n);
char jobchar = compute_uv ? (some ? 'S' : 'A') : 'N';
Tensor U_working_copy, S_working_copy, VT_working_copy;
std::tie(U_working_copy, S_working_copy, VT_working_copy) = _create_U_S_VT(self, some, compute_uv);
// The input matrix, U, S and VT have to reside in pinned memory.
// Additionally, the input and U have to be in column major format.
// _create_U_S_VT takes care of a part of these requirements (for U, S and VT)
// For the input matrix, this requirements are being taken care of below.
// Specify strides
auto self_col_major_strides = at::detail::defaultStrides(self.sizes());
self_col_major_strides[self.dim() - 2] = 1;
self_col_major_strides[self.dim() - 1] = m;
// Create strided tensor in pinned memory
auto self_working_copy = at::empty_strided(self.sizes(), self_col_major_strides,
at::TensorOptions(at::kCPU).dtype(self.dtype()).pinned_memory(true));
self_working_copy.copy_(self);
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "svd_cuda", [&] {
apply_svd<scalar_t>(self_working_copy, U_working_copy, S_working_copy, VT_working_copy, jobchar, infos);
});
if (self.dim() > 2) {
batchCheckErrors(infos, "svd_cuda");
} else {
singleCheckErrors(infos[0], "svd_cuda");
}
U_working_copy = same_stride_to(U_working_copy, self.options());
S_working_copy = same_stride_to(S_working_copy, S_working_copy.options().device(self.device()));
VT_working_copy = same_stride_to(VT_working_copy, self.options());
if (!compute_uv) {
VT_working_copy.zero_();
U_working_copy.zero_();
}
if (some) {
VT_working_copy = VT_working_copy.narrow(-2, 0, k);
}
// so far we have computed VT, but torch.svd returns V instead. Adjust accordingly.
// Note that the 'apply_svd' routine returns VT = V^T (for real inputs) or VT = V^H (for complex inputs), not V.
VT_working_copy = VT_working_copy.conj();
VT_working_copy.transpose_(-2, -1);
return std::make_tuple(U_working_copy, S_working_copy, VT_working_copy);
}
std::tuple<Tensor, Tensor, Tensor> _svd_helper_cuda(const Tensor& self, bool some, bool compute_uv) {
#ifdef USE_CUSOLVER
return _svd_helper_cuda_lib(self, some, compute_uv);
#else
return _svd_helper_cuda_legacy(self, some, compute_uv);
#endif
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lu_solve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename scalar_t>
static void apply_lu_solve(Tensor& b, const Tensor& lu, const Tensor& pivots, int64_t& info) {
#ifndef USE_MAGMA
AT_ERROR("lu_solve: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
auto b_data = b.data_ptr<scalar_t>();
auto lu_data = lu.data_ptr<scalar_t>();
auto n = lu.size(-2);
auto nrhs = b.size(-1);
int info_tmp = 0;
if (b.dim() == 2) {
Tensor pivots_tmp = pivots.cpu();
magmaLuSolve<scalar_t>(n, nrhs, lu_data, n, pivots_tmp.data_ptr<magma_int_t>(), b_data, n, &info_tmp);
info = info_tmp;
} else {
auto pivots_data = pivots.data_ptr<magma_int_t>();
auto b_stride = matrixStride(b);
auto lu_stride = matrixStride(lu);
auto pivots_stride = pivots.size(-1);
magma_int_t batch_size = magma_int_cast(batchCount(b), "batchCount");
magma_int_t** pivots_array;
scalar_t** lu_array;
scalar_t** b_array;
ALLOCATE_ARRAY(pivots_array, magma_int_t*, batch_size);
ALLOCATE_ARRAY(lu_array, scalar_t*, batch_size);
ALLOCATE_ARRAY(b_array, scalar_t*, batch_size);
for (int64_t i = 0; i < batch_size; i++) {
pivots_array[i] = &pivots_data[i * pivots_stride];
b_array[i] = &b_data[i * b_stride];
lu_array[i] = &lu_data[i * lu_stride];
}
MAGMAQueue magma_queue(b.get_device());
constexpr int64_t batch_limit = 65535;
// Compute as many batches of 65535 possible
// The number of "mini"-batches are floor(batch_size / batch_limit)
// and these cover floor(batch_size / batch_limit) * batch_limit matrix solves
int64_t mini_batches = batch_size / batch_limit, mini_idx;
for (mini_idx = 0; mini_idx < mini_batches * batch_limit; mini_idx += batch_limit) {
scalar_t** lu_array_cur = &lu_array[mini_idx];
scalar_t** b_array_cur = &b_array[mini_idx];
magma_int_t** pivots_array_cur = &pivots_array[mini_idx];
magmaLuSolveBatched<scalar_t>(
n, nrhs, lu_array_cur, n, pivots_array_cur, b_array_cur, n,
info_tmp, batch_limit, magma_queue);
if (info_tmp != 0) {
break;
}
}
// Compute whatever is left = batch_size - floor(batch_size / batch_limit) * batch_limit
// which concisely is equal to batch_size % batch_limit
if (batch_size % batch_limit != 0 && info_tmp == 0) {
magmaLuSolveBatched<scalar_t>(
n, nrhs, &lu_array[mini_idx], n, &pivots_array[mini_idx], &b_array[mini_idx], n,
info_tmp, batch_size % batch_limit, magma_queue);
}
info = info_tmp;
}
#endif
}
Tensor _lu_solve_helper_cuda(const Tensor& self, const Tensor& LU_data, const Tensor& LU_pivots) {
int64_t info = 0;
auto self_working_copy = cloneBatchedColumnMajor(self);
auto LU_data_working_copy = cloneBatchedColumnMajor(LU_data);
auto LU_pivots_working_copy = LU_pivots.is_contiguous() ? LU_pivots : LU_pivots.contiguous();
if (self.numel() == 0 || LU_data.numel() == 0) {
return at::zeros_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(self.scalar_type(), "lu_solve_cuda", [&]{
apply_lu_solve<scalar_t>(self_working_copy, LU_data_working_copy, LU_pivots_working_copy, info);
});
TORCH_CHECK(info == 0, "MAGMA lu_solve : invalid argument: ", -info);
return self_working_copy;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lstsq ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tensor& _lstsq_helper_cuda(
Tensor& b, Tensor& rank, Tensor& singular_values, Tensor& infos, const Tensor& a, double cond, std::string driver_name) {
#ifndef USE_MAGMA
TORCH_CHECK(false, "torch.linalg.lstsq: MAGMA library not found in "
"compilation. Please rebuild with MAGMA.");
#else
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES(a.scalar_type(), "torch.linalg.lstsq_cuda", [&] {
auto trans = MagmaNoTrans;
auto m = magma_int_cast(a.size(-2), "m");
auto n = magma_int_cast(a.size(-1), "n");
auto nrhs = magma_int_cast(b.size(-1), "nrhs");
auto ldda = std::max<magma_int_t>(1, m);
auto lddb = std::max<magma_int_t>(1, std::max(m, n));
auto nb = magmaGeqrfOptimalBlocksize<scalar_t>(m, n);
auto lwork = (m - n + nb) * (nrhs + nb) + nrhs * nb;
Tensor hwork = at::empty({static_cast<int64_t>(lwork)}, a.scalar_type());
auto* hwork_ptr = hwork.data_ptr<scalar_t>();
// MAGMA requires infos tensor to live on CPU
infos = infos.to(at::kCPU);
auto infos_data = infos.data_ptr<magma_int_t>();
batch_iterator_with_broadcasting<scalar_t>(a, b,
[&](scalar_t* a_working_ptr, scalar_t* b_working_ptr,
int64_t a_linear_batch_idx) {
magma_int_t* infos_working_ptr = &infos_data[a_linear_batch_idx];
magmaGels<scalar_t>(trans, m, n, nrhs,
a_working_ptr, ldda, b_working_ptr, lddb,
hwork_ptr, lwork, infos_working_ptr);
}
);
});
return b;
#endif
}
}} // namespace at::native
#undef ALLOCATE_ARRAY
|
6b9a860c20a5a0bf1ee5d3ca3c0ac1976e84a267.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
__global__ void stdp_kernel(
float *weight, int weight_size_0, int weight_size_1, int weight_size_2, int weight_size_3,
float *output_spike, int output_spike_size_0, int output_spike_size_1,
int output_spike_size_2, int output_spike_size_3,
float *history, float *weight_update)
// Each thread is for an element in output_spike in the form:
// (batch_id, channel_id, height_id, width_id) = (blockIdx.x, threadIdx.x, blockIdx.y, blockIdx.z).
// Note that grid is 3D and block is 1D; this to make the channel the fastest dimension as across
// the channel the history patch block is accessed is same.
// IMPORTANT: Number of channels MUST BE LESS than maximum thread limit.
// Note: All 'id's refer to numpy indices and 'index'/'linear_idx' refer to linear memory index.
const int offset = weight_size_2 / 2;
const int batch_id = blockIdx.x;
const int channel_id = threadIdx.x;
const int height_id = blockIdx.y;
const int width_id = blockIdx.z;
/*
// some constants
output_spike_size_1_2_3 = output_spike_size_1 * output_spike_size_2 * output_spike_size_3;
output_spike_size_2_3 = output_spike_size_2 * output_spike_size_3;
output_spike_size_3 = output_spike_size_3; // = gridDim.z;
weight_size_0_1_2_3 = weight_size_0 * weight_size_1 * weight_size_2 * weight_size_3;
weight_size_1_2_3 = weight_size_1 * weight_size_2 * weight_size_3;
weight_size_2_3 = weight_size_2 * weight_size_3;
weight_size_1 = weight_size_1
weight_size_3 = weight_size_3
*/
const int linear_idx = (batch_id * (output_spike_size_1 * output_spike_size_2 * output_spike_size_3)) \
+ (channel_id * (output_spike_size_2 * output_spike_size_3)) \
+ (height_id * (output_spike_size_3)) \
+ width_id;
if (output_spike[linear_idx] != 1.0f)
return;
const int filter_index = channel_id * (weight_size_1 * weight_size_2 * weight_size_3);
const int delta_index_const = batch_id * (weight_size_0 * weight_size_1 * weight_size_2 * weight_size_3);
float input_tmp;
int w_index, deltaW_index;
int filter_2d_index, filter_1d_index;
int history_1d_index, history_pivot, history_index, history_index1, history_index2;
for (int l = 0; l < weight_size_1; l++)
{
history_pivot = (batch_id * (weight_size_1 * output_spike_size_2 * output_spike_size_3)) \
+ (l * (output_spike_size_2 * output_spike_size_3));
filter_2d_index = filter_index + (l * weight_size_2 * weight_size_3);
for (int i = 0; i < weight_size_2; i++)
{
filter_1d_index = filter_2d_index + (i * weight_size_3);
history_index1 = height_id + i - offset;
if (history_index1 < 0 || history_index1 >= output_spike_size_2)
continue;
history_1d_index = history_pivot + (history_index1 * output_spike_size_3);
for (int j = 0; j < weight_size_3; j++)
{
w_index = filter_1d_index + j;
deltaW_index = delta_index_const + w_index;
history_index2 = width_id + j - offset;
if (history_index2 < 0 || history_index2 >= output_spike_size_3)
continue;
history_index = history_1d_index + history_index2;
input_tmp = history[history_index];
//weight_update[deltaW_index] = deltaW_index;
weight_update[deltaW_index] = (weight[w_index] * (1-weight[w_index])) \
* ((input_tmp != 0.0f) - (input_tmp == 0.0f));
}
}
}
}
| 6b9a860c20a5a0bf1ee5d3ca3c0ac1976e84a267.cu | __global__ void stdp_kernel(
float *weight, int weight_size_0, int weight_size_1, int weight_size_2, int weight_size_3,
float *output_spike, int output_spike_size_0, int output_spike_size_1,
int output_spike_size_2, int output_spike_size_3,
float *history, float *weight_update)
// Each thread is for an element in output_spike in the form:
// (batch_id, channel_id, height_id, width_id) = (blockIdx.x, threadIdx.x, blockIdx.y, blockIdx.z).
// Note that grid is 3D and block is 1D; this to make the channel the fastest dimension as across
// the channel the history patch block is accessed is same.
// IMPORTANT: Number of channels MUST BE LESS than maximum thread limit.
// Note: All 'id's refer to numpy indices and 'index'/'linear_idx' refer to linear memory index.
const int offset = weight_size_2 / 2;
const int batch_id = blockIdx.x;
const int channel_id = threadIdx.x;
const int height_id = blockIdx.y;
const int width_id = blockIdx.z;
/*
// some constants
output_spike_size_1_2_3 = output_spike_size_1 * output_spike_size_2 * output_spike_size_3;
output_spike_size_2_3 = output_spike_size_2 * output_spike_size_3;
output_spike_size_3 = output_spike_size_3; // = gridDim.z;
weight_size_0_1_2_3 = weight_size_0 * weight_size_1 * weight_size_2 * weight_size_3;
weight_size_1_2_3 = weight_size_1 * weight_size_2 * weight_size_3;
weight_size_2_3 = weight_size_2 * weight_size_3;
weight_size_1 = weight_size_1
weight_size_3 = weight_size_3
*/
const int linear_idx = (batch_id * (output_spike_size_1 * output_spike_size_2 * output_spike_size_3)) \
+ (channel_id * (output_spike_size_2 * output_spike_size_3)) \
+ (height_id * (output_spike_size_3)) \
+ width_id;
if (output_spike[linear_idx] != 1.0f)
return;
const int filter_index = channel_id * (weight_size_1 * weight_size_2 * weight_size_3);
const int delta_index_const = batch_id * (weight_size_0 * weight_size_1 * weight_size_2 * weight_size_3);
float input_tmp;
int w_index, deltaW_index;
int filter_2d_index, filter_1d_index;
int history_1d_index, history_pivot, history_index, history_index1, history_index2;
for (int l = 0; l < weight_size_1; l++)
{
history_pivot = (batch_id * (weight_size_1 * output_spike_size_2 * output_spike_size_3)) \
+ (l * (output_spike_size_2 * output_spike_size_3));
filter_2d_index = filter_index + (l * weight_size_2 * weight_size_3);
for (int i = 0; i < weight_size_2; i++)
{
filter_1d_index = filter_2d_index + (i * weight_size_3);
history_index1 = height_id + i - offset;
if (history_index1 < 0 || history_index1 >= output_spike_size_2)
continue;
history_1d_index = history_pivot + (history_index1 * output_spike_size_3);
for (int j = 0; j < weight_size_3; j++)
{
w_index = filter_1d_index + j;
deltaW_index = delta_index_const + w_index;
history_index2 = width_id + j - offset;
if (history_index2 < 0 || history_index2 >= output_spike_size_3)
continue;
history_index = history_1d_index + history_index2;
input_tmp = history[history_index];
//weight_update[deltaW_index] = deltaW_index;
weight_update[deltaW_index] = (weight[w_index] * (1-weight[w_index])) \
* ((input_tmp != 0.0f) - (input_tmp == 0.0f));
}
}
}
}
|
0f9e436bc0ec2c60b053193223f63729bb3f6966.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__global__ void kernel(int* d_vec, int n) {
int tid = threadIdx.x;
if(threadIdx.x < n) {
int i = d_vec[tid];
d_vec[tid] = i > 5 ? -i : i;
}
} | 0f9e436bc0ec2c60b053193223f63729bb3f6966.cu | #include "includes.h"
__global__ void kernel(int* d_vec, int n) {
int tid = threadIdx.x;
if(threadIdx.x < n) {
int i = d_vec[tid];
d_vec[tid] = i > 5 ? -i : i;
}
} |
06ed6bc4a14c8f7ce5f141ab16ef2d232b43519c.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__global__ void cu_interpolation(const float* src, float* dst, const int colssrc, const int colsdst, const int _stride, const int n){
int tid = threadIdx.x + blockIdx.x * blockDim.x;
int stride = blockDim.x * gridDim.x;
while(tid < n){
int csrc = tid % colssrc;
int rsrc = tid / colssrc;
int rdst = rsrc * _stride;
int cdst = csrc * _stride;
dst[rdst * colsdst + cdst] = src[tid];
tid += stride;
}
} | 06ed6bc4a14c8f7ce5f141ab16ef2d232b43519c.cu | #include "includes.h"
__global__ void cu_interpolation(const float* src, float* dst, const int colssrc, const int colsdst, const int _stride, const int n){
int tid = threadIdx.x + blockIdx.x * blockDim.x;
int stride = blockDim.x * gridDim.x;
while(tid < n){
int csrc = tid % colssrc;
int rsrc = tid / colssrc;
int rdst = rsrc * _stride;
int cdst = csrc * _stride;
dst[rdst * colsdst + cdst] = src[tid];
tid += stride;
}
} |
9c2c14d3f7c494cfc12f05e3e654c1dc527aacf4.hip | // !!! This is a file automatically generated by hipify!!!
#include <primitiv/config.h>
#include <primitiv/devices/cuda/device.h>
#include <primitiv/devices/cuda/ops/common.h>
#include <primitiv/internal/cuda/utils.h>
namespace primitiv {
namespace devices {
void CUDA::random_normal_impl(float mean, float sd, Tensor &y) {
std::size_t size = y.shape().size();
if (size % 2 != 0) {
std::size_t capacity = y.allocated_size() / sizeof(float);
if (capacity <= size) {
PRIMITIV_THROW_ERROR(
"Could not generate " << size
<< " + 1 random values. capacity: " << capacity);
}
++size;
}
CUDA_CALL(::hipSetDevice(dev_id_));
CURAND_CALL(::hiprandGenerateNormal(
state_->hiprand.get(), MDATA(y), size, mean, sd));
}
} // namespace devices
} // namespace primitiv
| 9c2c14d3f7c494cfc12f05e3e654c1dc527aacf4.cu | #include <primitiv/config.h>
#include <primitiv/devices/cuda/device.h>
#include <primitiv/devices/cuda/ops/common.h>
#include <primitiv/internal/cuda/utils.h>
namespace primitiv {
namespace devices {
void CUDA::random_normal_impl(float mean, float sd, Tensor &y) {
std::size_t size = y.shape().size();
if (size % 2 != 0) {
std::size_t capacity = y.allocated_size() / sizeof(float);
if (capacity <= size) {
PRIMITIV_THROW_ERROR(
"Could not generate " << size
<< " + 1 random values. capacity: " << capacity);
}
++size;
}
CUDA_CALL(::cudaSetDevice(dev_id_));
CURAND_CALL(::curandGenerateNormal(
state_->curand.get(), MDATA(y), size, mean, sd));
}
} // namespace devices
} // namespace primitiv
|
bb24fc10828d36d3b4225564856df430fc236a04.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* Description:
* this function finds the min along the innermost dimension
* Nd input, (N-1)d output, (N-1)d argmin
*/
__global__ void min_output(float *input, float *output, float *indices,
long nrows, long ncols)
{
// output offset:
long o = threadIdx.x + blockDim.x * blockIdx.x;
if (o >= nrows) return;
// input offset:
long i = o * ncols;
// move pointers
input = input + i;
// compute min:
float min = input[0];
long argmin = 0;
long ii;
for (ii=1; ii<ncols; ii++) {
float val = input[ii];
if (val < min) {
min = val;
argmin = ii;
}
}
// store
output[o] = min;
indices[o] = argmin+1;
}
__global__ void min_gradInput(float *input, float *output, float *indices,
long nrows, long ncols)
{
// output offset:
long o = threadIdx.x + blockDim.x * blockIdx.x;
if (o >= nrows) return;
// input offset:
long i = o * ncols;
// bprop min gradient:
long idx = indices[o]-1;
input[i+idx] = output[o];
}
static int cunn_Min_updateOutput(lua_State *L)
{
THCudaTensor *input = (THCudaTensor *)luaT_checkudata(L, 2, "torch.CudaTensor");
int dimension = luaT_getfieldcheckint(L, 1, "dimension")-1;
THCudaTensor *indices = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "indices", "torch.CudaTensor");
THCudaTensor *output = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "output", "torch.CudaTensor");
luaL_argcheck(L, dimension >= 0 && dimension < input->nDimension, 2, "dimension out of range");
luaL_argcheck(L, dimension == input->nDimension-1, 2, "only supported dimension is innermost (CUDA kernel only)");
input = THCudaTensor_newContiguous(input);
THLongStorage *dim = THLongStorage_newWithSize(input->nDimension);
long i;
for(i = 0; i < input->nDimension; i++)
dim->data[i] = input->size[i];
dim->data[dimension] = 1;
THCudaTensor_resize(output, dim, NULL);
THCudaTensor_resize(indices, dim, NULL);
THLongStorage_free(dim);
float *input_data = THCudaTensor_data(input);
float *output_data = THCudaTensor_data(output);
float *indices_data = THCudaTensor_data(indices);
long nrows = THCudaTensor_nElement(output);
long ncols = input->size[dimension];
// cuda blocks & threads:
long nthreads = 256;
long nblocks = ceil((float)nrows / nthreads);
dim3 blocks(nblocks);
dim3 threads(nthreads);
// kernel:
hipLaunchKernelGGL(( min_output) , dim3(blocks), dim3(threads), 0, 0, input_data, output_data, indices_data, nrows, ncols);
// check for errors
hipError_t err = hipGetLastError();
if (err != hipSuccess) {
printf("error in Min.updateOutput: %s\n", hipGetErrorString(err));
THError("aborting");
}
// final cut:
THCudaTensor_free(input);
THCudaTensor_select(output, NULL, dimension, 0);
return 1;
}
static int cunn_Min_updateGradInput(lua_State *L)
{
THCudaTensor *input = (THCudaTensor *)luaT_checkudata(L, 2, "torch.CudaTensor");
THCudaTensor *gradOutput = (THCudaTensor *)luaT_checkudata(L, 3, "torch.CudaTensor");
THCudaTensor *indices = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "indices", "torch.CudaTensor");
int dimension = luaT_getfieldcheckint(L, 1, "dimension")-1;
THCudaTensor *gradInput = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "gradInput", "torch.CudaTensor");
THCudaTensor_resizeAs(gradInput, input);
THCudaTensor_zero(gradInput);
float *gradInput_data = THCudaTensor_data(gradInput);
float *gradOutput_data = THCudaTensor_data(gradOutput);
float *indices_data = THCudaTensor_data(indices);
long nrows = THCudaTensor_nElement(gradOutput);
long ncols = gradInput->size[dimension];
// cuda blocks & threads:
long nthreads = 256;
long nblocks = ceil((float)nrows / nthreads);
dim3 blocks(nblocks);
dim3 threads(nthreads);
// kernel:
hipLaunchKernelGGL(( min_gradInput) , dim3(blocks), dim3(threads), 0, 0, gradInput_data, gradOutput_data, indices_data, nrows, ncols);
// check for errors
hipError_t err = hipGetLastError();
if (err != hipSuccess) {
printf("error in Min.updateOutput: %s\n", hipGetErrorString(err));
THError("aborting");
}
return 1;
}
static const struct luaL_Reg cunn_Min__ [] = {
{"Min_updateOutput", cunn_Min_updateOutput},
{"Min_updateGradInput", cunn_Min_updateGradInput},
{NULL, NULL}
};
static void cunn_Min_init(lua_State *L)
{
luaT_pushmetatable(L, "torch.CudaTensor");
luaT_registeratname(L, cunn_Min__, "nn");
lua_pop(L,1);
}
| bb24fc10828d36d3b4225564856df430fc236a04.cu |
/*
* Description:
* this function finds the min along the innermost dimension
* Nd input, (N-1)d output, (N-1)d argmin
*/
__global__ void min_output(float *input, float *output, float *indices,
long nrows, long ncols)
{
// output offset:
long o = threadIdx.x + blockDim.x * blockIdx.x;
if (o >= nrows) return;
// input offset:
long i = o * ncols;
// move pointers
input = input + i;
// compute min:
float min = input[0];
long argmin = 0;
long ii;
for (ii=1; ii<ncols; ii++) {
float val = input[ii];
if (val < min) {
min = val;
argmin = ii;
}
}
// store
output[o] = min;
indices[o] = argmin+1;
}
__global__ void min_gradInput(float *input, float *output, float *indices,
long nrows, long ncols)
{
// output offset:
long o = threadIdx.x + blockDim.x * blockIdx.x;
if (o >= nrows) return;
// input offset:
long i = o * ncols;
// bprop min gradient:
long idx = indices[o]-1;
input[i+idx] = output[o];
}
static int cunn_Min_updateOutput(lua_State *L)
{
THCudaTensor *input = (THCudaTensor *)luaT_checkudata(L, 2, "torch.CudaTensor");
int dimension = luaT_getfieldcheckint(L, 1, "dimension")-1;
THCudaTensor *indices = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "indices", "torch.CudaTensor");
THCudaTensor *output = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "output", "torch.CudaTensor");
luaL_argcheck(L, dimension >= 0 && dimension < input->nDimension, 2, "dimension out of range");
luaL_argcheck(L, dimension == input->nDimension-1, 2, "only supported dimension is innermost (CUDA kernel only)");
input = THCudaTensor_newContiguous(input);
THLongStorage *dim = THLongStorage_newWithSize(input->nDimension);
long i;
for(i = 0; i < input->nDimension; i++)
dim->data[i] = input->size[i];
dim->data[dimension] = 1;
THCudaTensor_resize(output, dim, NULL);
THCudaTensor_resize(indices, dim, NULL);
THLongStorage_free(dim);
float *input_data = THCudaTensor_data(input);
float *output_data = THCudaTensor_data(output);
float *indices_data = THCudaTensor_data(indices);
long nrows = THCudaTensor_nElement(output);
long ncols = input->size[dimension];
// cuda blocks & threads:
long nthreads = 256;
long nblocks = ceil((float)nrows / nthreads);
dim3 blocks(nblocks);
dim3 threads(nthreads);
// kernel:
min_output <<<blocks, threads>>> (input_data, output_data, indices_data, nrows, ncols);
// check for errors
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess) {
printf("error in Min.updateOutput: %s\n", cudaGetErrorString(err));
THError("aborting");
}
// final cut:
THCudaTensor_free(input);
THCudaTensor_select(output, NULL, dimension, 0);
return 1;
}
static int cunn_Min_updateGradInput(lua_State *L)
{
THCudaTensor *input = (THCudaTensor *)luaT_checkudata(L, 2, "torch.CudaTensor");
THCudaTensor *gradOutput = (THCudaTensor *)luaT_checkudata(L, 3, "torch.CudaTensor");
THCudaTensor *indices = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "indices", "torch.CudaTensor");
int dimension = luaT_getfieldcheckint(L, 1, "dimension")-1;
THCudaTensor *gradInput = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "gradInput", "torch.CudaTensor");
THCudaTensor_resizeAs(gradInput, input);
THCudaTensor_zero(gradInput);
float *gradInput_data = THCudaTensor_data(gradInput);
float *gradOutput_data = THCudaTensor_data(gradOutput);
float *indices_data = THCudaTensor_data(indices);
long nrows = THCudaTensor_nElement(gradOutput);
long ncols = gradInput->size[dimension];
// cuda blocks & threads:
long nthreads = 256;
long nblocks = ceil((float)nrows / nthreads);
dim3 blocks(nblocks);
dim3 threads(nthreads);
// kernel:
min_gradInput <<<blocks, threads>>> (gradInput_data, gradOutput_data, indices_data, nrows, ncols);
// check for errors
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess) {
printf("error in Min.updateOutput: %s\n", cudaGetErrorString(err));
THError("aborting");
}
return 1;
}
static const struct luaL_Reg cunn_Min__ [] = {
{"Min_updateOutput", cunn_Min_updateOutput},
{"Min_updateGradInput", cunn_Min_updateGradInput},
{NULL, NULL}
};
static void cunn_Min_init(lua_State *L)
{
luaT_pushmetatable(L, "torch.CudaTensor");
luaT_registeratname(L, cunn_Min__, "nn");
lua_pop(L,1);
}
|
decdea677bd6710f4feb529ec7113062404d909d.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <stdio.h>
/*
#define TRACE_DX
#define TRACE_DZ
#define TRACE_DIFFLUX_UX
#define TRACE_DIFFLUX_UY
#define TRACE_DIFFLUX_UZ
#define TRACE_DIFFLUX_E
#define TRACE_UPDATE_RHO
#define TRACE_UPDATE_E
#define TRACE_UPDATE_U
#define TRACE_UPDATE_U_ALT
*/
#define RADIUS 4
#define TYPE double
#define CACHE_LINE_SIZE 128
#ifdef UNROLL
#define OUTER_UNROLL #pragma unroll 9
#else
#define OUTER_UNROLL //#pragma unroll 9
#endif
#ifndef TILE_DIMX
#define TILE_DIMX 32
#endif
#ifndef TILE_DIMY
#define TILE_DIMY 8
#endif
#ifndef LDG
#define __ldg( X ) (*(X))
#endif
__constant__ TYPE c_first[RADIUS+1];
__constant__ TYPE c_second[RADIUS+1];
#define ONE_THIRD (1./3.)
#define TWO_THIRDS (2./3.)
#define FOUR_THIRDS (4./3.)
void process_error( const hipError_t &error, char *string=0, bool verbose=false )
{
if( error != hipSuccess || verbose )
{
int current_gpu = -1;
hipGetDevice( ¤t_gpu );
printf( "GPU %d: ", current_gpu );
if( string )
printf( string );
printf( ": %s\n", hipGetErrorString( error ) );
}
if( error != hipSuccess )
exit(-1);
}
inline __device__ void advance( TYPE *field, const int num_points )
{
#pragma unroll
for(int i=0; i<num_points-1; i++)
field[i] = field[i+1];
}
#ifdef TRACE_UPDATE_RHO
template<int tile_dimx, int tile_dimy, int radius>
__global__ void update_rho_single_pass(
TYPE* g_rho,
const TYPE* g_ux, const TYPE* g_uy, const TYPE* g_uz,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
TYPE queue[2*radius+1];
#pragma unroll
for( int i=1; i<diameter; i++ )
{
queue[i] = __ldg( &g_uz[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue, diameter );
queue[diameter-1] = __ldg( &g_uz[idx_in] );
TYPE del_momenta = 0;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
del_momenta += c_first[i] * ( __ldg( &g_ux[idx_out+i] ) - __ldg( &g_ux[idx_out-i] )
+ __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_uy[idx_out-i*nx_pad] )
+ queue[radius+i] - queue[radius-i] );
}
g_rho[idx_out] = __ldg( &g_rho[idx_out] ) - delta_t * del_momenta;
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#ifdef TRACE_DX
template<int tile_dimx, int tile_dimy, int radius>
__global__ void first_derivative_x( TYPE* g_deriv, TYPE *g_field,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx = iy * nx_pad + ix;
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
TYPE deriv = c_first[0] * __ldg( &g_field[idx] );
#pragma unroll
for( int i=1; i<=radius; i++ )
deriv += c_first[i] * ( __ldg( &g_field[idx+i] ) - __ldg( &g_field[idx-i] ) );
g_deriv[idx] = deriv;
idx += stride;
}
}
#endif
#ifdef TRACE_DZ
template<int tile_dimx, int tile_dimy, int radius>
__global__ void first_derivative_z( TYPE* g_deriv, TYPE *g_field,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
TYPE queue[2*radius+1];
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue[i] = __ldg( &g_field[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue, 2*radius+1 );
queue[2*radius] = __ldg( &g_field[idx_in] );
TYPE deriv = c_first[0] * queue[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
deriv += c_first[i] * ( queue[radius+i] - queue[radius-i] );
g_deriv[idx_out] = deriv;
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_UX
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_momentum_x( TYPE* g_difflux, TYPE *g_vx, TYPE *g_vy_y, TYPE *g_vz_z,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_vx[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_vx[i] = __ldg( &g_vx[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_vx, 2*radius+1 );
queue_vx[2*radius] = __ldg( &g_vx[idx_in] );
TYPE vx_xx, vx_yy, vx_zz, vy_xy, vz_xz;
vx_xx = vx_yy = vx_zz = c_second[0] * queue_vx[radius];
vy_xy = c_first[0] * __ldg( &g_vy_y[idx_out] ); // probably can be replaced with 0
vz_xz = c_first[0] * __ldg( &g_vz_z[idx_out] ); // probably can be replaced with 0
#pragma unroll
for( int i=1; i<=radius; i++ )
{
vx_xx += c_second[i] * ( __ldg( &g_vx[idx_out+i] ) + __ldg( &g_vx[idx_out-i] ) );
vx_yy += c_second[i] * ( __ldg( &g_vx[idx_out+i*nx_pad] ) + __ldg( &g_vx[idx_out-i*nx_pad] ) );
vx_zz += c_second[i] * ( queue_vx[radius+i] + queue_vx[radius-i] );
vy_xy += c_first[i] * ( __ldg( &g_vy_y[idx_out+i] ) - __ldg( &g_vy_y[idx_out-i] ) );
vz_xz += c_first[i] * ( __ldg( &g_vz_z[idx_out+i] ) - __ldg( &g_vz_z[idx_out-i] ) );
}
g_difflux[idx_out] = FOUR_THIRDS * vx_xx + vx_yy + vx_zz + ONE_THIRD * ( vy_xy + vz_xz );
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_UY
// difflux for momentum in y
// march in the y dimension
// maintain 3 register-queues and 1 smem array
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_momentum_y_Q( TYPE* g_difflux, TYPE *g_vy, TYPE *g_vx_x, TYPE *g_vz_z,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_vy[2*radius+1], queue_vx_x[2*radius+1], queue_vz_z[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iz = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad;
int idx_out = iz * (nx_pad*ny_pad) + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_vy[i] = __ldg( &g_vy[idx_in] );
queue_vx_x[i] = __ldg( &g_vx_x[idx_in] );
queue_vz_z[i] = __ldg( &g_vz_z[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iy=0; iy<ny; iy++ )
{
advance( queue_vy, 2*radius+1 );
queue_vy[2*radius] = __ldg( &g_vy[idx_in] );
advance( queue_vx_x, 2*radius+1 );
queue_vx_x[2*radius] = __ldg( &g_vx_x[idx_in] );
advance( queue_vz_z, 2*radius+1 );
queue_vz_z[2*radius] = __ldg( &g_vz_z[idx_in] );
TYPE vy_xx, vy_yy, vy_zz, vx_xy, vz_yz;
vy_xx = vy_yy = vy_zz = c_second[0] * queue_vy[radius];
vx_xy = c_first[0] * queue_vx_x[radius];
vz_yz = c_first[0] * queue_vz_z[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
{
vy_xx += c_second[i] * ( __ldg( &g_vy[idx_out+i] ) + __ldg( &g_vy[idx_out-i] ) );
vy_yy += c_second[i] * ( __ldg( &g_vy[idx_out+i*nx_pad*ny_pad] ) + __ldg( &g_vy[idx_out-i*nx_pad*ny_pad] ) );
vy_zz += c_second[i] * ( queue_vy[radius+i] + queue_vy[radius-i] );
vx_xy += c_first[i] * ( queue_vx_x[radius+i] - queue_vx_x[radius-i] );
vz_yz += c_first[i] * ( queue_vz_z[radius+i] - queue_vz_z[radius-i] );
}
g_difflux[idx_out] = vy_xx + FOUR_THIRDS * vy_yy + vy_zz + ONE_THIRD * ( vx_xy + vz_yz );
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_UZ
// difflux for momentum in z
// march in the z dimension
// maintain 3 register-queues and 1 smem array
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_momentum_z_Q( TYPE* g_difflux, TYPE *g_vz, TYPE *g_vx_x, TYPE *g_vy_y,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_vz[2*radius+1];
TYPE queue_vx_x[2*radius+1];
TYPE queue_vy_y[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_vz[i] = __ldg( &g_vz[idx_in] );
queue_vx_x[i] = __ldg( &g_vx_x[idx_in] );
queue_vy_y[i] = __ldg( &g_vy_y[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_vz, 2*radius+1 );
queue_vz[2*radius] = __ldg( &g_vz[idx_in] );
advance( queue_vx_x, 2*radius+1 );
queue_vx_x[2*radius] = __ldg( &g_vx_x[idx_in] );
advance( queue_vy_y, 2*radius+1 );
queue_vy_y[2*radius] = __ldg( &g_vy_y[idx_in] );
TYPE vz_xx, vz_yy, vz_zz, vx_xz, vy_yz;
vz_xx = vz_yy = vz_zz = c_second[0] * queue_vz[radius];
vx_xz = c_first[0] * queue_vx_x[radius];
vy_yz = c_first[0] * queue_vy_y[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
{
vz_xx += c_second[i] * ( __ldg( &g_vz[idx_out+i] ) + __ldg( &g_vz[idx_out-i] ) );
vz_yy += c_second[i] * ( queue_vz[radius+i] + queue_vz[radius-i] );
vz_zz += c_second[i] * ( __ldg( &g_vz[idx_out+i*nx_pad] ) + __ldg( &g_vz[idx_out-i*nx_pad] ) );
vx_xz += c_first[i] * ( queue_vx_x[radius+i] - queue_vx_x[radius-i] );
vy_yz += c_first[i] * ( queue_vy_y[radius+i] - queue_vy_y[radius-i] );
}
g_difflux[idx_out] = vz_xx + vz_yy + FOUR_THIRDS * vz_zz + ONE_THIRD * ( vx_xz + vy_yz );
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_E
// difflux of energy
// marches in z
// reads 3 velocities and 3 components of momentum-difflux from gmem
// computes 3 temperature derivatives and 9 velocity derivatives on the fly
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_energy_4q(
TYPE *g_difflux,
const TYPE alam, const TYPE eta,
TYPE *g_T,
TYPE *g_vx, TYPE *g_vy, TYPE *g_vz,
TYPE *g_difflux_x, TYPE *g_difflux_y, TYPE *g_difflux_z,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_T[2*radius+1];
TYPE queue_vx[2*radius+1], queue_vy[2*radius+1], queue_vz[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad*ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_T[i] = __ldg( &g_T[idx_in] );
queue_vx[i] = __ldg( &g_vx[idx_in] );
queue_vy[i] = __ldg( &g_vy[idx_in] );
queue_vz[i] = __ldg( &g_vz[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_T, 2*radius+1 );
queue_T[2*radius] = __ldg( &g_T[idx_in] );
advance( queue_vx, 2*radius+1 );
queue_vx[2*radius] = __ldg( &g_vx[idx_in] );
advance( queue_vy, 2*radius+1 );
queue_vy[2*radius] = __ldg( &g_vy[idx_in] );
advance( queue_vz, 2*radius+1 );
queue_vz[2*radius] = __ldg( &g_vz[idx_in] );
TYPE vx_x=0, vx_y=0, vx_z=0;
TYPE vy_x=0, vy_y=0, vy_z=0;
TYPE vz_x=0, vz_y=0, vz_z=0;
TYPE laplacian_T = 3 * c_second[0] * queue_T[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
{
laplacian_T += c_second[i] * ( queue_T[radius+i] + queue_T[radius-i] +
__ldg( &g_T[idx_out+i] ) + __ldg( &g_T[idx_out-i] ) +
__ldg( &g_T[idx_out+i*nx_pad] ) + __ldg( &g_T[idx_out-i*nx_pad] ) );
vx_x += c_first[i] * ( __ldg( &g_vx[idx_out+i] ) - __ldg( &g_vx[idx_out-i] ) );
vx_y += c_first[i] * ( __ldg( &g_vx[idx_out+i*nx_pad] ) - __ldg( &g_vx[idx_out-i*nx_pad] ) );
vx_z += c_first[i] * ( queue_vx[radius+i] - queue_vx[radius-i] );
vy_x += c_first[i] * ( __ldg( &g_vy[idx_out+i] ) - __ldg( &g_vy[idx_out-i] ) );
vy_y += c_first[i] * ( __ldg( &g_vy[idx_out+i*nx_pad] ) - __ldg( &g_vy[idx_out-i*nx_pad] ) );
vy_z += c_first[i] * ( queue_vy[radius+i] - queue_vy[radius-i] );
vz_x += c_first[i] * ( __ldg( &g_vz[idx_out+i] ) - __ldg( &g_vz[idx_out-i] ) );
vz_y += c_first[i] * ( __ldg( &g_vz[idx_out+i*nx_pad] ) - __ldg( &g_vz[idx_out-i*nx_pad] ) );
vz_z += c_first[i] * ( queue_vz[radius+i] - queue_vz[radius-i] );
}
TYPE divu = TWO_THIRDS * ( vx_x + vy_y + vz_z );
TYPE tauxx = 2 * vx_x - divu;
TYPE tauyy = 2 * vy_y - divu;
TYPE tauzz = 2 * vz_z - divu;
TYPE tauxy = vx_y + vy_x;
TYPE tauxz = vx_z + vz_x;
TYPE tauyz = vy_z + vz_y;
TYPE mechwork = tauxx*vx_x + tauyy*vy_y + tauzz*vz_z +
tauxy*tauxy + tauxz*tauxz + tauyz*tauyz;
mechwork = eta * mechwork +
__ldg( &g_difflux_x[idx_out] ) * __ldg( &g_vx[idx_out] ) +
__ldg( &g_difflux_y[idx_out] ) * __ldg( &g_vy[idx_out] ) +
__ldg( &g_difflux_z[idx_out] ) * __ldg( &g_vz[idx_out] );
g_difflux[idx_out] = alam * laplacian_T + mechwork;
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_UPDATE_E
// 2 queues (redundant reads of rE)
// all LDGs use index arithmetic and array notation
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void update_rE(
TYPE *g_rE,
const TYPE *g_p,
const TYPE *g_vx, const TYPE *g_vy, const TYPE *g_vz,
const TYPE *g_difflux_E,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
TYPE queue_vz[2*radius+1];
TYPE queue_rE_p[2*radius+1];
#pragma unroll
for( int i=1; i<diameter; i++ )
{
queue_rE_p[i] = __ldg( &g_rE[idx_in] ) + __ldg( &g_p[idx_in] );
queue_vz[i] = __ldg( &g_vz[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_rE_p, diameter );
queue_rE_p[diameter-1] = __ldg( &g_rE[idx_in]) + __ldg( &g_p[idx_in] );
advance( queue_vz, diameter );
queue_vz[diameter-1] = __ldg( &g_vz[idx_in] );
TYPE rEp_vx_x = 0;
TYPE rEp_vy_y = 0;
TYPE rEp_vz_z = 0;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
rEp_vx_x += c_first[i] * ( __ldg( &g_vx[idx_out+i] ) * ( __ldg( &g_rE[idx_out+i] ) + __ldg( &g_p[idx_out+i] ) ) -
__ldg( &g_vx[idx_out-i] ) * ( __ldg( &g_rE[idx_out-i] ) + __ldg( &g_p[idx_out-i] ) ) );
rEp_vy_y += c_first[i] * ( __ldg( &g_vx[idx_out+i*nx_pad] ) * ( __ldg( &g_rE[idx_out+i*nx_pad] ) + __ldg( &g_p[idx_out+i*nx_pad] ) ) -
__ldg( &g_vx[idx_out-i*nx_pad] ) * ( __ldg( &g_rE[idx_out-i*nx_pad] ) + __ldg( &g_p[idx_out-i*nx_pad] ) ) );
rEp_vz_z += c_first[i] * ( queue_rE_p[radius+i]*queue_vz[radius+i] - queue_rE_p[radius-i]*queue_vz[radius-i] );
}
g_rE[idx_out] = __ldg( &g_rE[idx_out] ) + delta_t * ( __ldg( &g_difflux_E[idx_out] ) - ( rEp_vx_x + rEp_vy_y + rEp_vz_z ) );
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#ifdef TRACE_UPDATE_U
// updates all 3 momentum components
// computes all 3 hypterm components, reads momenta and density
// 4 shared memory arrays
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void update_xyz_m4s(
TYPE *g_ux, TYPE *g_uy, TYPE *g_uz,
const TYPE *g_rho, const TYPE *g_p,
const TYPE *g_difflux_x, const TYPE *g_difflux_y, const TYPE *g_difflux_z,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE l_ux[2*radius+1], l_uy[2*radius+1], l_uz[2*radius+1], l_rho[2*radius+1], l_p[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
#pragma unroll
for( int i=1; i<diameter; i++ )
{
l_ux[i] = __ldg( &g_ux[idx_in] );
l_uy[i] = __ldg( &g_uy[idx_in] );
l_uz[i] = __ldg( &g_uz[idx_in] );
l_rho[i] = __ldg( &g_rho[idx_in] );
l_p[i] = __ldg( &g_p[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( l_ux, diameter );
l_ux[diameter-1] = __ldg( &g_ux[idx_in] );
advance( l_uy, diameter );
l_uy[diameter-1] = __ldg( &g_uy[idx_in] );
advance( l_uz, diameter );
l_uz[diameter-1] = __ldg( &g_uz[idx_in] );
advance( l_rho, diameter );
l_rho[diameter-1] = __ldg( &g_rho[idx_in] );
advance( l_p, diameter );
l_p[diameter-1] = __ldg( &g_p[idx_in] );
TYPE hypterm_x=0.f, hypterm_y=0.f, hypterm_z=0.f;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
hypterm_x += c_first[i] * (
( __ldg( &g_rho[idx_out+i] ) *__ldg( &g_ux[idx_out+i] ) * __ldg( &g_ux[idx_out+i] ) - __ldg( &g_rho[idx_out-i] )*__ldg( &g_ux[idx_out-i] )*__ldg( &g_ux[idx_out-i] ) ) + // x-deriv of rho-ux-ux product
( __ldg( &g_rho[idx_out+i*nx_pad] ) * __ldg( &g_ux[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] )*__ldg( &g_ux[idx_out-i*nx_pad] )*__ldg( &g_uy[idx_out-i*nx_pad] ) ) + // y-deriv of rho-ux-uy product
( l_rho[radius+i] * l_ux[radius+i] * l_uz[radius+i] - l_rho[radius-i]*l_ux[radius-i]*l_uz[radius-i] ) + // z-deriv of rho-ux-uz product
( __ldg( &g_p[idx_out+i] ) - __ldg( &g_p[idx_out-i] ) ) // x-deriv of pressure
);
hypterm_y += c_first[i] * (
( __ldg( &g_rho[idx_out+i] ) * __ldg( &g_ux[idx_out+i] ) * __ldg( &g_uy[idx_out+i] ) - __ldg( &g_rho[idx_out-i] ) *__ldg( &g_ux[idx_out-i] ) * __ldg( &g_uy[idx_out-i] ) ) + // x-deriv of rho-ux-uy product
( __ldg( &g_rho[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] ) *__ldg( &g_uy[idx_out-i*nx_pad] ) * __ldg( &g_uy[idx_out-i*nx_pad] ) ) + // y-deriv of rho-uy-uy product
( l_rho[radius+i]*l_uy[radius+i]*l_uz[radius+i] - l_rho[radius-i]*l_uy[radius-i]*l_uz[radius-i] ) + // z-deriv of rho-uy-uz product
( __ldg( &g_p[idx_out+i*nx_pad] ) - __ldg( &g_p[idx_out-i*nx_pad] ) ) // y-deriv of pressure
);
hypterm_z += c_first[i] * (
( __ldg( &g_rho[idx_out+i] ) * __ldg( &g_ux[idx_out+i] ) * __ldg( &g_uz[idx_out+i] ) - __ldg( &g_rho[idx_out-i] ) * __ldg( &g_ux[idx_out-i] ) * __ldg( &g_uz[idx_out-i] ) ) + // x-deriv of rho-ux-uz product
( __ldg( &g_rho[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) * __ldg( &g_uz[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] ) * __ldg( &g_uy[idx_out-i*nx_pad] ) * __ldg( &g_uz[idx_out-i*nx_pad] ) ) + // y-deriv of rho-uy-uz product
( l_rho[radius+i]*l_uz[radius+i]*l_uz[radius+i] - l_rho[radius-i]*l_uz[radius-i]*l_uz[radius-i] ) + // z-deriv of rho-uz-uz product
( l_p[radius+i] - l_p[radius-i] ) // z-deriv of pressure
);
}
g_ux[idx_out] = l_ux[radius] + __ldg( &g_difflux_x[idx_out] ) - delta_t * hypterm_x;
g_uy[idx_out] = l_uy[radius] + __ldg( &g_difflux_y[idx_out] ) - delta_t * hypterm_y;
g_uz[idx_out] = l_uz[radius] + __ldg( &g_difflux_z[idx_out] ) - delta_t * hypterm_z;
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#ifdef TRACE_UPDATE_U_ALT
// updates all 3 momentum components
// computes all 3 hypterm components, reads momenta and density
// 4 shared memory arrays
// computes all derivatives first, then applies product rule
//
template<int tile_dimx, int tile_dimy, int radius>
//__launch_bounds__(256,2)
__global__ void update_xyz_m4s_p(
TYPE *g_ux, TYPE *g_uy, TYPE *g_uz,
const TYPE *g_rho, const TYPE *g_p,
const TYPE *g_difflux_x, const TYPE *g_difflux_y, const TYPE *g_difflux_z,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE l_ux[2*radius+1], l_uy[2*radius+1], l_uz[2*radius+1], l_rho[2*radius+1], l_p[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
#pragma unroll
for( int i=1; i<diameter; i++ )
{
l_ux[i] = __ldg( &g_ux[idx_in] );
l_uy[i] = __ldg( &g_uy[idx_in] );
l_uz[i] = __ldg( &g_uz[idx_in] );
l_rho[i] = __ldg( &g_rho[idx_in] );
l_p[i] = __ldg( &g_p[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
TYPE p_x=0, p_y=0, p_z=0;
advance( l_ux, diameter );
l_ux[diameter-1] = __ldg( &g_ux[idx_in] );
advance( l_uy, diameter );
l_uy[diameter-1] = __ldg( &g_uy[idx_in] );
advance( l_uz, diameter );
l_uz[diameter-1] = __ldg( &g_uz[idx_in] );
advance( l_rho, diameter );
l_rho[diameter-1] = __ldg( &g_rho[idx_in] );
advance( l_p, diameter );
l_p[diameter-1] = __ldg( &g_p[idx_in] );
////////////////////////////////////
// compute the x component
//
TYPE rho_x=0, rho_y=0, rho_z=0;
TYPE ux_x=0, ux_y=0, ux_z=0;
TYPE uy_x=0, uy_y=0, uy_z=0;
TYPE uz_x=0, uz_y=0, uz_z=0;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
rho_x += c_first[i] * ( __ldg( &g_rho[idx_out+i] ) - __ldg( &g_rho[idx_out-i] ) );
ux_x += c_first[i] * ( __ldg( &g_ux[idx_out+i] ) - __ldg( &g_ux[idx_out-i] ) );
uy_x += c_first[i] * ( __ldg( &g_uy[idx_out+i] ) - __ldg( &g_uy[idx_out-i] ) );
uz_x += c_first[i] * ( __ldg( &g_uz[idx_out+i] ) - __ldg( &g_uz[idx_out-i] ) );
p_x += c_first[i] * ( __ldg( &g_p[idx_out+i] ) - __ldg( &g_p[idx_out-i] ) );
rho_y += c_first[i] * ( __ldg( &g_rho[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] ) );
ux_y += c_first[i] * ( __ldg( &g_ux[idx_out+i*nx_pad] ) - __ldg( &g_ux[idx_out-i*nx_pad] ) );
uy_y += c_first[i] * ( __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_uy[idx_out-i*nx_pad] ) );
uz_y += c_first[i] * ( __ldg( &g_uz[idx_out+i*nx_pad] ) - __ldg( &g_uz[idx_out-i*nx_pad] ) );
p_y += c_first[i] * ( __ldg( &g_p[idx_out+i*nx_pad] ) - __ldg( &g_p[idx_out-i*nx_pad] ) );
rho_z += c_first[i] * ( l_rho[radius+i] - l_rho[radius-i] );
ux_z += c_first[i] * ( l_ux[radius+i] - l_ux[radius-i] );
uy_z += c_first[i] * ( l_uy[radius+i] - l_uy[radius-i] );
uz_z += c_first[i] * ( l_uz[radius+i] - l_uz[radius-i] );
p_z += c_first[i] * ( l_p[radius+i] - l_p[radius-i] );
}
TYPE hypterm_x = ( rho_x*l_ux[radius]*l_ux[radius] + 2*l_rho[radius]*ux_x*l_ux[radius] )
+ ( rho_y*l_ux[radius]*l_uy[radius] + l_rho[radius]*ux_y*l_uy[radius] + l_rho[radius]*l_ux[radius]*uy_y )
+ ( rho_z*l_ux[radius]*l_uz[radius] + l_rho[radius]*ux_z*l_uz[radius] + l_rho[radius]*l_ux[radius]*uz_z )
+ p_x;
//__threadfence_block();
TYPE hypterm_y = ( rho_x*l_ux[radius]*l_uy[radius] + l_rho[radius]*ux_x*l_uy[radius] + l_rho[radius]*l_ux[radius]*uy_x )
+ ( rho_y*l_uy[radius]*l_uy[radius] + 2*l_rho[radius]*uy_y*l_uy[radius] )
+ ( rho_z*l_uy[radius]*l_uz[radius] + l_rho[radius]*uy_z*l_uz[radius] + l_rho[radius]*l_uy[radius]*uz_z )
+ p_y;
//__threadfence_block();
TYPE hypterm_z = ( rho_x*l_ux[radius]*l_uz[radius] + l_rho[radius]*ux_x*l_uz[radius] + l_rho[radius]*l_ux[radius]*uz_x )
+ ( rho_y*l_uy[radius]*l_uz[radius] + l_rho[radius]*uy_y*l_uz[radius] + l_rho[radius]*l_uy[radius]*uz_y )
+ ( rho_z*l_uz[radius]*l_uz[radius] + 2*l_rho[radius]*uz_z*l_uz[radius] )
+ p_z;
g_ux[idx_out] = l_ux[radius] + __ldg( &g_difflux_x[idx_out] ) - delta_t * hypterm_x;
g_uy[idx_out] = l_uy[radius] + __ldg( &g_difflux_y[idx_out] ) - delta_t * hypterm_y;
g_uz[idx_out] = l_uz[radius] + __ldg( &g_difflux_z[idx_out] ) - delta_t * hypterm_z;
__syncthreads();
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#define NUM_VOLS 8
int main( int argc, char *argv[] )
{
int nx = 8*32;
int ny = 8*32;
int nz = 8*32;
int num_iterations = 1;
int gpu_id = 0;
/////////////////////////////////////////
// process command-line arguments
//
if( argc >= 4 )
{
nx = atoi( argv[1] );
ny = atoi( argv[2] );
nz = atoi( argv[3] );
}
if( argc >= 5 )
num_iterations = atoi( argv[4] );
if( argc >= 6 )
gpu_id = atoi( argv[5] );
TYPE delta_t = 0.01;
/////////////////////////////////////////
// create GPu context
//
hipError_t error = hipSuccess;
error = hipSetDevice( gpu_id );
process_error( error, "set device" );
hipDeviceProp_t prop;
error = hipGetDeviceProperties( &prop, gpu_id );
process_error( error, "get device properties" );
printf("%s\n", prop.name );
error = hipFree( 0 );
process_error( error, "create GPU context" );
printf( "%d %d %d %d\n", nx, ny, nz, num_iterations );
/////////////////////////////////////////
// allocate memory on GPU
//
TYPE *d_volumes[NUM_VOLS];
const int radius = 4;
const int cache_line_size_type = CACHE_LINE_SIZE / sizeof(TYPE);
size_t nx_pad = nx + 2 * radius;
size_t ny_pad = ny + 2 * radius;
size_t nz_pad = nz + 2 * radius;
nx_pad += cache_line_size_type - ( nx_pad % cache_line_size_type ); // make each row a multiple of cache-line size
size_t lead_pad = cache_line_size_type - radius;
size_t num_bytes_padded = ( lead_pad + nx_pad * ny_pad * nz_pad ) * sizeof( TYPE );
size_t num_bytes = nx * ny * nz * sizeof( TYPE );
int padding_to_first_output_cell = lead_pad + radius*nx_pad*ny_pad + radius*nx_pad + radius;
for( int i=0; i<NUM_VOLS; i++ )
{
error = hipMalloc( &d_volumes[i], num_bytes_padded );
char message[20];
sprintf( message, "allocate vol %d", i );
process_error( error, message );
d_volumes[i] += padding_to_first_output_cell;
}
printf( "%dx%dx%d %8.3f GB\n", nx_pad, ny_pad, nz_pad, (((float)NUM_VOLS)*num_bytes_padded)/(1024.f*1024.f*1024.f) );
// error = hipDeviceSetSharedMemConfig( hipSharedMemBankSizeEightByte );
// process_error( error, "set SMEM addressing mode to 8-byte" );
/*
hipEvent_t start, stop;
error = hipEventCreate( &start );
process_error( error, "create start event" );
error = hipEventCreate( &stop );
process_error( error, "create stop event" );
*/
float elapsed_time_ms=0.f, throughput_mcells=0.f;
#ifdef TRACE_UPDATE_RHO
{ // update rho, march in z, 4 volumes
TYPE *d_rho = d_volumes[0];
TYPE *d_momentum_x = d_volumes[1];
TYPE *d_momentum_y = d_volumes[2];
TYPE *d_momentum_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_rho_single_pass<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_rho, d_momentum_x, d_momentum_y, d_momentum_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "rho kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "rho", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DX
{ // derivative in x, march in z, 2 volumes
TYPE *d_vx_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( first_derivative_x<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_vx_x, d_vx,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "x kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "vx_x", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DZ
{ // derivative in z, march in z, 2 volumes
TYPE *d_vz_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( first_derivative_z<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_vz_z, d_vz,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "z kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "vz_z", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_UX
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy_y = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_momentum_x<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_x, d_vx, d_vy_y, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-x kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_x", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_UY
{ // difflux momentum-y, march in y, 4 volumes
TYPE *d_difflux_y = d_volumes[0];
TYPE *d_vy = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, nz/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_momentum_y_Q<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_y, d_vy, d_vx_x, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-yQ kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_yQ", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_UZ
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vy_y = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_momentum_z_Q<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_z, d_vz, d_vx_x, d_vy_y,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-zQ kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_zQ", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_E
{ // difflux energy, march in z, 8 volumes
TYPE *d_difflux_E = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy = d_volumes[2];
TYPE *d_vz = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_T = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
TYPE alam = 5.3;
TYPE eta = 7.1;
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_energy_4q<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_E,
alam, eta,
d_T,
d_vx, d_vy, d_vz,
d_difflux_x, d_difflux_y, d_difflux_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-E_4q kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_E_4q", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_UPDATE_E
{ // update energy, march in z, 6 volumes
TYPE *d_rE = d_volumes[0];
TYPE *d_p = d_volumes[1];
TYPE *d_vx = d_volumes[2];
TYPE *d_vy = d_volumes[3];
TYPE *d_vz = d_volumes[4];
TYPE *d_difflux_E = d_volumes[5];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_rE<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_rE,
d_p,
d_vx, d_vy, d_vz,
d_difflux_E,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "update-rE kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "update_rE", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_UPDATE_U
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_xyz_m4s<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "update-momentum m4s kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_UPDATE_U_ALT
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_xyz_m4s_p<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "update-momentum m4s kernel" );
/* error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4", elapsed_time_ms, throughput_mcells );
*/
}
#endif
/////////////////////////////////////////
// free GPU resources
//
for( int i=0; i<NUM_VOLS; i++ )
{
d_volumes[i] -= padding_to_first_output_cell;
error = hipFree( d_volumes[i] );
char message[20];
sprintf( message, "free vol %d", i );
process_error( error, message );
}
error = hipDeviceReset();
process_error( error, "destroy GPU context" );
return 0;
}
/*
#ifdef TRACE_UPDATE_RHO
{ // update rho, march in z, 4 volumes
TYPE *d_rho = d_volumes[0];
TYPE *d_momentum_x = d_volumes[1];
TYPE *d_momentum_y = d_volumes[2];
TYPE *d_momentum_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_rho_single_pass<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_rho, d_momentum_x, d_momentum_y, d_momentum_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "rho kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "rho", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DX
{ // derivative in x, march in z, 2 volumes
TYPE *d_vx_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( first_derivative_x<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_vx_x, d_vx,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "x kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "vx_x", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DZ
{ // derivative in z, march in z, 2 volumes
TYPE *d_vz_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( first_derivative_z<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_vz_z, d_vz,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "z kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "vz_z", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_UX
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy_y = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_momentum_x<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_x, d_vx, d_vy_y, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-x kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_x", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_UY
{ // difflux momentum-y, march in y, 4 volumes
TYPE *d_difflux_y = d_volumes[0];
TYPE *d_vy = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, nz/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_momentum_y_Q<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_y, d_vy, d_vx_x, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-yQ kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_yQ", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_UZ
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vy_y = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_momentum_z_Q<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_z, d_vz, d_vx_x, d_vy_y,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-zQ kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_zQ", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_E
{ // difflux energy, march in z, 8 volumes
TYPE *d_difflux_E = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy = d_volumes[2];
TYPE *d_vz = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_T = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
TYPE alam = 5.3;
TYPE eta = 7.1;
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( D_energy_4q<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_difflux_E,
alam, eta,
d_T,
d_vx, d_vy, d_vz,
d_difflux_x, d_difflux_y, d_difflux_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "difflux-E_4q kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_E_4q", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_UPDATE_E
{ // update energy, march in z, 6 volumes
TYPE *d_rE = d_volumes[0];
TYPE *d_p = d_volumes[1];
TYPE *d_vx = d_volumes[2];
TYPE *d_vy = d_volumes[3];
TYPE *d_vz = d_volumes[4];
TYPE *d_difflux_E = d_volumes[5];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_rE<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_rE,
d_p,
d_vx, d_vy, d_vz,
d_difflux_E,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "update-rE kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "update_rE", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_UPDATE_U
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_xyz_m4s<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "update-momentum m4s kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_UPDATE_U
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
hipEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
hipLaunchKernelGGL(( update_xyz_m4s_p<TILE_DIMX,TILE_DIMY,RADIUS>), dim3(grid),dim3(block), 0, 0,
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
hipEventRecord( stop, 0 );
hipDeviceSynchronize();
error = hipGetLastError();
process_error( error, "update-momentum m4s kernel" );
error = hipEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4_p", elapsed_time_ms, throughput_mcells );
}
#endif
/////////////////////////////////////////
// free GPU resources
//
for( int i=0; i<NUM_VOLS; i++ )
{
d_volumes[i] -= padding_to_first_output_cell;
error = hipFree( d_volumes[i] );
char message[20];
sprintf( message, "free vol %d", i );
process_error( error, message );
}
error = hipDeviceReset();
process_error( error, "destroy GPU context" );
return 0;
}
*/ | decdea677bd6710f4feb529ec7113062404d909d.cu | #include <stdio.h>
/*
#define TRACE_DX
#define TRACE_DZ
#define TRACE_DIFFLUX_UX
#define TRACE_DIFFLUX_UY
#define TRACE_DIFFLUX_UZ
#define TRACE_DIFFLUX_E
#define TRACE_UPDATE_RHO
#define TRACE_UPDATE_E
#define TRACE_UPDATE_U
#define TRACE_UPDATE_U_ALT
*/
#define RADIUS 4
#define TYPE double
#define CACHE_LINE_SIZE 128
#ifdef UNROLL
#define OUTER_UNROLL #pragma unroll 9
#else
#define OUTER_UNROLL //#pragma unroll 9
#endif
#ifndef TILE_DIMX
#define TILE_DIMX 32
#endif
#ifndef TILE_DIMY
#define TILE_DIMY 8
#endif
#ifndef LDG
#define __ldg( X ) (*(X))
#endif
__constant__ TYPE c_first[RADIUS+1];
__constant__ TYPE c_second[RADIUS+1];
#define ONE_THIRD (1./3.)
#define TWO_THIRDS (2./3.)
#define FOUR_THIRDS (4./3.)
void process_error( const cudaError_t &error, char *string=0, bool verbose=false )
{
if( error != cudaSuccess || verbose )
{
int current_gpu = -1;
cudaGetDevice( ¤t_gpu );
printf( "GPU %d: ", current_gpu );
if( string )
printf( string );
printf( ": %s\n", cudaGetErrorString( error ) );
}
if( error != cudaSuccess )
exit(-1);
}
inline __device__ void advance( TYPE *field, const int num_points )
{
#pragma unroll
for(int i=0; i<num_points-1; i++)
field[i] = field[i+1];
}
#ifdef TRACE_UPDATE_RHO
template<int tile_dimx, int tile_dimy, int radius>
__global__ void update_rho_single_pass(
TYPE* g_rho,
const TYPE* g_ux, const TYPE* g_uy, const TYPE* g_uz,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
TYPE queue[2*radius+1];
#pragma unroll
for( int i=1; i<diameter; i++ )
{
queue[i] = __ldg( &g_uz[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue, diameter );
queue[diameter-1] = __ldg( &g_uz[idx_in] );
TYPE del_momenta = 0;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
del_momenta += c_first[i] * ( __ldg( &g_ux[idx_out+i] ) - __ldg( &g_ux[idx_out-i] )
+ __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_uy[idx_out-i*nx_pad] )
+ queue[radius+i] - queue[radius-i] );
}
g_rho[idx_out] = __ldg( &g_rho[idx_out] ) - delta_t * del_momenta;
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#ifdef TRACE_DX
template<int tile_dimx, int tile_dimy, int radius>
__global__ void first_derivative_x( TYPE* g_deriv, TYPE *g_field,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx = iy * nx_pad + ix;
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
TYPE deriv = c_first[0] * __ldg( &g_field[idx] );
#pragma unroll
for( int i=1; i<=radius; i++ )
deriv += c_first[i] * ( __ldg( &g_field[idx+i] ) - __ldg( &g_field[idx-i] ) );
g_deriv[idx] = deriv;
idx += stride;
}
}
#endif
#ifdef TRACE_DZ
template<int tile_dimx, int tile_dimy, int radius>
__global__ void first_derivative_z( TYPE* g_deriv, TYPE *g_field,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
TYPE queue[2*radius+1];
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue[i] = __ldg( &g_field[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue, 2*radius+1 );
queue[2*radius] = __ldg( &g_field[idx_in] );
TYPE deriv = c_first[0] * queue[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
deriv += c_first[i] * ( queue[radius+i] - queue[radius-i] );
g_deriv[idx_out] = deriv;
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_UX
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_momentum_x( TYPE* g_difflux, TYPE *g_vx, TYPE *g_vy_y, TYPE *g_vz_z,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_vx[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_vx[i] = __ldg( &g_vx[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_vx, 2*radius+1 );
queue_vx[2*radius] = __ldg( &g_vx[idx_in] );
TYPE vx_xx, vx_yy, vx_zz, vy_xy, vz_xz;
vx_xx = vx_yy = vx_zz = c_second[0] * queue_vx[radius];
vy_xy = c_first[0] * __ldg( &g_vy_y[idx_out] ); // probably can be replaced with 0
vz_xz = c_first[0] * __ldg( &g_vz_z[idx_out] ); // probably can be replaced with 0
#pragma unroll
for( int i=1; i<=radius; i++ )
{
vx_xx += c_second[i] * ( __ldg( &g_vx[idx_out+i] ) + __ldg( &g_vx[idx_out-i] ) );
vx_yy += c_second[i] * ( __ldg( &g_vx[idx_out+i*nx_pad] ) + __ldg( &g_vx[idx_out-i*nx_pad] ) );
vx_zz += c_second[i] * ( queue_vx[radius+i] + queue_vx[radius-i] );
vy_xy += c_first[i] * ( __ldg( &g_vy_y[idx_out+i] ) - __ldg( &g_vy_y[idx_out-i] ) );
vz_xz += c_first[i] * ( __ldg( &g_vz_z[idx_out+i] ) - __ldg( &g_vz_z[idx_out-i] ) );
}
g_difflux[idx_out] = FOUR_THIRDS * vx_xx + vx_yy + vx_zz + ONE_THIRD * ( vy_xy + vz_xz );
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_UY
// difflux for momentum in y
// march in the y dimension
// maintain 3 register-queues and 1 smem array
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_momentum_y_Q( TYPE* g_difflux, TYPE *g_vy, TYPE *g_vx_x, TYPE *g_vz_z,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_vy[2*radius+1], queue_vx_x[2*radius+1], queue_vz_z[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iz = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad;
int idx_out = iz * (nx_pad*ny_pad) + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_vy[i] = __ldg( &g_vy[idx_in] );
queue_vx_x[i] = __ldg( &g_vx_x[idx_in] );
queue_vz_z[i] = __ldg( &g_vz_z[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iy=0; iy<ny; iy++ )
{
advance( queue_vy, 2*radius+1 );
queue_vy[2*radius] = __ldg( &g_vy[idx_in] );
advance( queue_vx_x, 2*radius+1 );
queue_vx_x[2*radius] = __ldg( &g_vx_x[idx_in] );
advance( queue_vz_z, 2*radius+1 );
queue_vz_z[2*radius] = __ldg( &g_vz_z[idx_in] );
TYPE vy_xx, vy_yy, vy_zz, vx_xy, vz_yz;
vy_xx = vy_yy = vy_zz = c_second[0] * queue_vy[radius];
vx_xy = c_first[0] * queue_vx_x[radius];
vz_yz = c_first[0] * queue_vz_z[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
{
vy_xx += c_second[i] * ( __ldg( &g_vy[idx_out+i] ) + __ldg( &g_vy[idx_out-i] ) );
vy_yy += c_second[i] * ( __ldg( &g_vy[idx_out+i*nx_pad*ny_pad] ) + __ldg( &g_vy[idx_out-i*nx_pad*ny_pad] ) );
vy_zz += c_second[i] * ( queue_vy[radius+i] + queue_vy[radius-i] );
vx_xy += c_first[i] * ( queue_vx_x[radius+i] - queue_vx_x[radius-i] );
vz_yz += c_first[i] * ( queue_vz_z[radius+i] - queue_vz_z[radius-i] );
}
g_difflux[idx_out] = vy_xx + FOUR_THIRDS * vy_yy + vy_zz + ONE_THIRD * ( vx_xy + vz_yz );
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_UZ
// difflux for momentum in z
// march in the z dimension
// maintain 3 register-queues and 1 smem array
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_momentum_z_Q( TYPE* g_difflux, TYPE *g_vz, TYPE *g_vx_x, TYPE *g_vy_y,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_vz[2*radius+1];
TYPE queue_vx_x[2*radius+1];
TYPE queue_vy_y[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_vz[i] = __ldg( &g_vz[idx_in] );
queue_vx_x[i] = __ldg( &g_vx_x[idx_in] );
queue_vy_y[i] = __ldg( &g_vy_y[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_vz, 2*radius+1 );
queue_vz[2*radius] = __ldg( &g_vz[idx_in] );
advance( queue_vx_x, 2*radius+1 );
queue_vx_x[2*radius] = __ldg( &g_vx_x[idx_in] );
advance( queue_vy_y, 2*radius+1 );
queue_vy_y[2*radius] = __ldg( &g_vy_y[idx_in] );
TYPE vz_xx, vz_yy, vz_zz, vx_xz, vy_yz;
vz_xx = vz_yy = vz_zz = c_second[0] * queue_vz[radius];
vx_xz = c_first[0] * queue_vx_x[radius];
vy_yz = c_first[0] * queue_vy_y[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
{
vz_xx += c_second[i] * ( __ldg( &g_vz[idx_out+i] ) + __ldg( &g_vz[idx_out-i] ) );
vz_yy += c_second[i] * ( queue_vz[radius+i] + queue_vz[radius-i] );
vz_zz += c_second[i] * ( __ldg( &g_vz[idx_out+i*nx_pad] ) + __ldg( &g_vz[idx_out-i*nx_pad] ) );
vx_xz += c_first[i] * ( queue_vx_x[radius+i] - queue_vx_x[radius-i] );
vy_yz += c_first[i] * ( queue_vy_y[radius+i] - queue_vy_y[radius-i] );
}
g_difflux[idx_out] = vz_xx + vz_yy + FOUR_THIRDS * vz_zz + ONE_THIRD * ( vx_xz + vy_yz );
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_DIFFLUX_E
// difflux of energy
// marches in z
// reads 3 velocities and 3 components of momentum-difflux from gmem
// computes 3 temperature derivatives and 9 velocity derivatives on the fly
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void D_energy_4q(
TYPE *g_difflux,
const TYPE alam, const TYPE eta,
TYPE *g_T,
TYPE *g_vx, TYPE *g_vy, TYPE *g_vz,
TYPE *g_difflux_x, TYPE *g_difflux_y, TYPE *g_difflux_z,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE queue_T[2*radius+1];
TYPE queue_vx[2*radius+1], queue_vy[2*radius+1], queue_vz[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int stride = nx_pad*ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * stride;
#pragma unroll
for( int i=1; i<2*radius+1; i++ )
{
queue_T[i] = __ldg( &g_T[idx_in] );
queue_vx[i] = __ldg( &g_vx[idx_in] );
queue_vy[i] = __ldg( &g_vy[idx_in] );
queue_vz[i] = __ldg( &g_vz[idx_in] );
idx_in += stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_T, 2*radius+1 );
queue_T[2*radius] = __ldg( &g_T[idx_in] );
advance( queue_vx, 2*radius+1 );
queue_vx[2*radius] = __ldg( &g_vx[idx_in] );
advance( queue_vy, 2*radius+1 );
queue_vy[2*radius] = __ldg( &g_vy[idx_in] );
advance( queue_vz, 2*radius+1 );
queue_vz[2*radius] = __ldg( &g_vz[idx_in] );
TYPE vx_x=0, vx_y=0, vx_z=0;
TYPE vy_x=0, vy_y=0, vy_z=0;
TYPE vz_x=0, vz_y=0, vz_z=0;
TYPE laplacian_T = 3 * c_second[0] * queue_T[radius];
#pragma unroll
for( int i=1; i<=radius; i++ )
{
laplacian_T += c_second[i] * ( queue_T[radius+i] + queue_T[radius-i] +
__ldg( &g_T[idx_out+i] ) + __ldg( &g_T[idx_out-i] ) +
__ldg( &g_T[idx_out+i*nx_pad] ) + __ldg( &g_T[idx_out-i*nx_pad] ) );
vx_x += c_first[i] * ( __ldg( &g_vx[idx_out+i] ) - __ldg( &g_vx[idx_out-i] ) );
vx_y += c_first[i] * ( __ldg( &g_vx[idx_out+i*nx_pad] ) - __ldg( &g_vx[idx_out-i*nx_pad] ) );
vx_z += c_first[i] * ( queue_vx[radius+i] - queue_vx[radius-i] );
vy_x += c_first[i] * ( __ldg( &g_vy[idx_out+i] ) - __ldg( &g_vy[idx_out-i] ) );
vy_y += c_first[i] * ( __ldg( &g_vy[idx_out+i*nx_pad] ) - __ldg( &g_vy[idx_out-i*nx_pad] ) );
vy_z += c_first[i] * ( queue_vy[radius+i] - queue_vy[radius-i] );
vz_x += c_first[i] * ( __ldg( &g_vz[idx_out+i] ) - __ldg( &g_vz[idx_out-i] ) );
vz_y += c_first[i] * ( __ldg( &g_vz[idx_out+i*nx_pad] ) - __ldg( &g_vz[idx_out-i*nx_pad] ) );
vz_z += c_first[i] * ( queue_vz[radius+i] - queue_vz[radius-i] );
}
TYPE divu = TWO_THIRDS * ( vx_x + vy_y + vz_z );
TYPE tauxx = 2 * vx_x - divu;
TYPE tauyy = 2 * vy_y - divu;
TYPE tauzz = 2 * vz_z - divu;
TYPE tauxy = vx_y + vy_x;
TYPE tauxz = vx_z + vz_x;
TYPE tauyz = vy_z + vz_y;
TYPE mechwork = tauxx*vx_x + tauyy*vy_y + tauzz*vz_z +
tauxy*tauxy + tauxz*tauxz + tauyz*tauyz;
mechwork = eta * mechwork +
__ldg( &g_difflux_x[idx_out] ) * __ldg( &g_vx[idx_out] ) +
__ldg( &g_difflux_y[idx_out] ) * __ldg( &g_vy[idx_out] ) +
__ldg( &g_difflux_z[idx_out] ) * __ldg( &g_vz[idx_out] );
g_difflux[idx_out] = alam * laplacian_T + mechwork;
idx_in += stride;
idx_out += stride;
}
}
#endif
#ifdef TRACE_UPDATE_E
// 2 queues (redundant reads of rE)
// all LDGs use index arithmetic and array notation
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void update_rE(
TYPE *g_rE,
const TYPE *g_p,
const TYPE *g_vx, const TYPE *g_vy, const TYPE *g_vz,
const TYPE *g_difflux_E,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
TYPE queue_vz[2*radius+1];
TYPE queue_rE_p[2*radius+1];
#pragma unroll
for( int i=1; i<diameter; i++ )
{
queue_rE_p[i] = __ldg( &g_rE[idx_in] ) + __ldg( &g_p[idx_in] );
queue_vz[i] = __ldg( &g_vz[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( queue_rE_p, diameter );
queue_rE_p[diameter-1] = __ldg( &g_rE[idx_in]) + __ldg( &g_p[idx_in] );
advance( queue_vz, diameter );
queue_vz[diameter-1] = __ldg( &g_vz[idx_in] );
TYPE rEp_vx_x = 0;
TYPE rEp_vy_y = 0;
TYPE rEp_vz_z = 0;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
rEp_vx_x += c_first[i] * ( __ldg( &g_vx[idx_out+i] ) * ( __ldg( &g_rE[idx_out+i] ) + __ldg( &g_p[idx_out+i] ) ) -
__ldg( &g_vx[idx_out-i] ) * ( __ldg( &g_rE[idx_out-i] ) + __ldg( &g_p[idx_out-i] ) ) );
rEp_vy_y += c_first[i] * ( __ldg( &g_vx[idx_out+i*nx_pad] ) * ( __ldg( &g_rE[idx_out+i*nx_pad] ) + __ldg( &g_p[idx_out+i*nx_pad] ) ) -
__ldg( &g_vx[idx_out-i*nx_pad] ) * ( __ldg( &g_rE[idx_out-i*nx_pad] ) + __ldg( &g_p[idx_out-i*nx_pad] ) ) );
rEp_vz_z += c_first[i] * ( queue_rE_p[radius+i]*queue_vz[radius+i] - queue_rE_p[radius-i]*queue_vz[radius-i] );
}
g_rE[idx_out] = __ldg( &g_rE[idx_out] ) + delta_t * ( __ldg( &g_difflux_E[idx_out] ) - ( rEp_vx_x + rEp_vy_y + rEp_vz_z ) );
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#ifdef TRACE_UPDATE_U
// updates all 3 momentum components
// computes all 3 hypterm components, reads momenta and density
// 4 shared memory arrays
//
template<int tile_dimx, int tile_dimy, int radius>
__global__ void update_xyz_m4s(
TYPE *g_ux, TYPE *g_uy, TYPE *g_uz,
const TYPE *g_rho, const TYPE *g_p,
const TYPE *g_difflux_x, const TYPE *g_difflux_y, const TYPE *g_difflux_z,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE l_ux[2*radius+1], l_uy[2*radius+1], l_uz[2*radius+1], l_rho[2*radius+1], l_p[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
#pragma unroll
for( int i=1; i<diameter; i++ )
{
l_ux[i] = __ldg( &g_ux[idx_in] );
l_uy[i] = __ldg( &g_uy[idx_in] );
l_uz[i] = __ldg( &g_uz[idx_in] );
l_rho[i] = __ldg( &g_rho[idx_in] );
l_p[i] = __ldg( &g_p[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
advance( l_ux, diameter );
l_ux[diameter-1] = __ldg( &g_ux[idx_in] );
advance( l_uy, diameter );
l_uy[diameter-1] = __ldg( &g_uy[idx_in] );
advance( l_uz, diameter );
l_uz[diameter-1] = __ldg( &g_uz[idx_in] );
advance( l_rho, diameter );
l_rho[diameter-1] = __ldg( &g_rho[idx_in] );
advance( l_p, diameter );
l_p[diameter-1] = __ldg( &g_p[idx_in] );
TYPE hypterm_x=0.f, hypterm_y=0.f, hypterm_z=0.f;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
hypterm_x += c_first[i] * (
( __ldg( &g_rho[idx_out+i] ) *__ldg( &g_ux[idx_out+i] ) * __ldg( &g_ux[idx_out+i] ) - __ldg( &g_rho[idx_out-i] )*__ldg( &g_ux[idx_out-i] )*__ldg( &g_ux[idx_out-i] ) ) + // x-deriv of rho-ux-ux product
( __ldg( &g_rho[idx_out+i*nx_pad] ) * __ldg( &g_ux[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] )*__ldg( &g_ux[idx_out-i*nx_pad] )*__ldg( &g_uy[idx_out-i*nx_pad] ) ) + // y-deriv of rho-ux-uy product
( l_rho[radius+i] * l_ux[radius+i] * l_uz[radius+i] - l_rho[radius-i]*l_ux[radius-i]*l_uz[radius-i] ) + // z-deriv of rho-ux-uz product
( __ldg( &g_p[idx_out+i] ) - __ldg( &g_p[idx_out-i] ) ) // x-deriv of pressure
);
hypterm_y += c_first[i] * (
( __ldg( &g_rho[idx_out+i] ) * __ldg( &g_ux[idx_out+i] ) * __ldg( &g_uy[idx_out+i] ) - __ldg( &g_rho[idx_out-i] ) *__ldg( &g_ux[idx_out-i] ) * __ldg( &g_uy[idx_out-i] ) ) + // x-deriv of rho-ux-uy product
( __ldg( &g_rho[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] ) *__ldg( &g_uy[idx_out-i*nx_pad] ) * __ldg( &g_uy[idx_out-i*nx_pad] ) ) + // y-deriv of rho-uy-uy product
( l_rho[radius+i]*l_uy[radius+i]*l_uz[radius+i] - l_rho[radius-i]*l_uy[radius-i]*l_uz[radius-i] ) + // z-deriv of rho-uy-uz product
( __ldg( &g_p[idx_out+i*nx_pad] ) - __ldg( &g_p[idx_out-i*nx_pad] ) ) // y-deriv of pressure
);
hypterm_z += c_first[i] * (
( __ldg( &g_rho[idx_out+i] ) * __ldg( &g_ux[idx_out+i] ) * __ldg( &g_uz[idx_out+i] ) - __ldg( &g_rho[idx_out-i] ) * __ldg( &g_ux[idx_out-i] ) * __ldg( &g_uz[idx_out-i] ) ) + // x-deriv of rho-ux-uz product
( __ldg( &g_rho[idx_out+i*nx_pad] ) * __ldg( &g_uy[idx_out+i*nx_pad] ) * __ldg( &g_uz[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] ) * __ldg( &g_uy[idx_out-i*nx_pad] ) * __ldg( &g_uz[idx_out-i*nx_pad] ) ) + // y-deriv of rho-uy-uz product
( l_rho[radius+i]*l_uz[radius+i]*l_uz[radius+i] - l_rho[radius-i]*l_uz[radius-i]*l_uz[radius-i] ) + // z-deriv of rho-uz-uz product
( l_p[radius+i] - l_p[radius-i] ) // z-deriv of pressure
);
}
g_ux[idx_out] = l_ux[radius] + __ldg( &g_difflux_x[idx_out] ) - delta_t * hypterm_x;
g_uy[idx_out] = l_uy[radius] + __ldg( &g_difflux_y[idx_out] ) - delta_t * hypterm_y;
g_uz[idx_out] = l_uz[radius] + __ldg( &g_difflux_z[idx_out] ) - delta_t * hypterm_z;
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#ifdef TRACE_UPDATE_U_ALT
// updates all 3 momentum components
// computes all 3 hypterm components, reads momenta and density
// 4 shared memory arrays
// computes all derivatives first, then applies product rule
//
template<int tile_dimx, int tile_dimy, int radius>
//__launch_bounds__(256,2)
__global__ void update_xyz_m4s_p(
TYPE *g_ux, TYPE *g_uy, TYPE *g_uz,
const TYPE *g_rho, const TYPE *g_p,
const TYPE *g_difflux_x, const TYPE *g_difflux_y, const TYPE *g_difflux_z,
const TYPE delta_t,
const int nx, const int ny, const int nz,
const int nx_pad, const int ny_pad, const int nz_pad )
{
TYPE l_ux[2*radius+1], l_uy[2*radius+1], l_uz[2*radius+1], l_rho[2*radius+1], l_p[2*radius+1];
int ix = blockIdx.x * tile_dimx + threadIdx.x;
int iy = blockIdx.y * tile_dimy + threadIdx.y;
int slice_stride = nx_pad * ny_pad;
int idx_out = iy * nx_pad + ix;
int idx_in = idx_out - radius * slice_stride;
const int diameter = 2*radius + 1;
#pragma unroll
for( int i=1; i<diameter; i++ )
{
l_ux[i] = __ldg( &g_ux[idx_in] );
l_uy[i] = __ldg( &g_uy[idx_in] );
l_uz[i] = __ldg( &g_uz[idx_in] );
l_rho[i] = __ldg( &g_rho[idx_in] );
l_p[i] = __ldg( &g_p[idx_in] );
idx_in += slice_stride;
}
OUTER_UNROLL
for( int iz=0; iz<nz; iz++ )
{
TYPE p_x=0, p_y=0, p_z=0;
advance( l_ux, diameter );
l_ux[diameter-1] = __ldg( &g_ux[idx_in] );
advance( l_uy, diameter );
l_uy[diameter-1] = __ldg( &g_uy[idx_in] );
advance( l_uz, diameter );
l_uz[diameter-1] = __ldg( &g_uz[idx_in] );
advance( l_rho, diameter );
l_rho[diameter-1] = __ldg( &g_rho[idx_in] );
advance( l_p, diameter );
l_p[diameter-1] = __ldg( &g_p[idx_in] );
////////////////////////////////////
// compute the x component
//
TYPE rho_x=0, rho_y=0, rho_z=0;
TYPE ux_x=0, ux_y=0, ux_z=0;
TYPE uy_x=0, uy_y=0, uy_z=0;
TYPE uz_x=0, uz_y=0, uz_z=0;
#pragma unroll
for( int i=1; i<=radius; i++ )
{
rho_x += c_first[i] * ( __ldg( &g_rho[idx_out+i] ) - __ldg( &g_rho[idx_out-i] ) );
ux_x += c_first[i] * ( __ldg( &g_ux[idx_out+i] ) - __ldg( &g_ux[idx_out-i] ) );
uy_x += c_first[i] * ( __ldg( &g_uy[idx_out+i] ) - __ldg( &g_uy[idx_out-i] ) );
uz_x += c_first[i] * ( __ldg( &g_uz[idx_out+i] ) - __ldg( &g_uz[idx_out-i] ) );
p_x += c_first[i] * ( __ldg( &g_p[idx_out+i] ) - __ldg( &g_p[idx_out-i] ) );
rho_y += c_first[i] * ( __ldg( &g_rho[idx_out+i*nx_pad] ) - __ldg( &g_rho[idx_out-i*nx_pad] ) );
ux_y += c_first[i] * ( __ldg( &g_ux[idx_out+i*nx_pad] ) - __ldg( &g_ux[idx_out-i*nx_pad] ) );
uy_y += c_first[i] * ( __ldg( &g_uy[idx_out+i*nx_pad] ) - __ldg( &g_uy[idx_out-i*nx_pad] ) );
uz_y += c_first[i] * ( __ldg( &g_uz[idx_out+i*nx_pad] ) - __ldg( &g_uz[idx_out-i*nx_pad] ) );
p_y += c_first[i] * ( __ldg( &g_p[idx_out+i*nx_pad] ) - __ldg( &g_p[idx_out-i*nx_pad] ) );
rho_z += c_first[i] * ( l_rho[radius+i] - l_rho[radius-i] );
ux_z += c_first[i] * ( l_ux[radius+i] - l_ux[radius-i] );
uy_z += c_first[i] * ( l_uy[radius+i] - l_uy[radius-i] );
uz_z += c_first[i] * ( l_uz[radius+i] - l_uz[radius-i] );
p_z += c_first[i] * ( l_p[radius+i] - l_p[radius-i] );
}
TYPE hypterm_x = ( rho_x*l_ux[radius]*l_ux[radius] + 2*l_rho[radius]*ux_x*l_ux[radius] )
+ ( rho_y*l_ux[radius]*l_uy[radius] + l_rho[radius]*ux_y*l_uy[radius] + l_rho[radius]*l_ux[radius]*uy_y )
+ ( rho_z*l_ux[radius]*l_uz[radius] + l_rho[radius]*ux_z*l_uz[radius] + l_rho[radius]*l_ux[radius]*uz_z )
+ p_x;
//__threadfence_block();
TYPE hypterm_y = ( rho_x*l_ux[radius]*l_uy[radius] + l_rho[radius]*ux_x*l_uy[radius] + l_rho[radius]*l_ux[radius]*uy_x )
+ ( rho_y*l_uy[radius]*l_uy[radius] + 2*l_rho[radius]*uy_y*l_uy[radius] )
+ ( rho_z*l_uy[radius]*l_uz[radius] + l_rho[radius]*uy_z*l_uz[radius] + l_rho[radius]*l_uy[radius]*uz_z )
+ p_y;
//__threadfence_block();
TYPE hypterm_z = ( rho_x*l_ux[radius]*l_uz[radius] + l_rho[radius]*ux_x*l_uz[radius] + l_rho[radius]*l_ux[radius]*uz_x )
+ ( rho_y*l_uy[radius]*l_uz[radius] + l_rho[radius]*uy_y*l_uz[radius] + l_rho[radius]*l_uy[radius]*uz_y )
+ ( rho_z*l_uz[radius]*l_uz[radius] + 2*l_rho[radius]*uz_z*l_uz[radius] )
+ p_z;
g_ux[idx_out] = l_ux[radius] + __ldg( &g_difflux_x[idx_out] ) - delta_t * hypterm_x;
g_uy[idx_out] = l_uy[radius] + __ldg( &g_difflux_y[idx_out] ) - delta_t * hypterm_y;
g_uz[idx_out] = l_uz[radius] + __ldg( &g_difflux_z[idx_out] ) - delta_t * hypterm_z;
__syncthreads();
idx_in += slice_stride;
idx_out += slice_stride;
}
}
#endif
#define NUM_VOLS 8
int main( int argc, char *argv[] )
{
int nx = 8*32;
int ny = 8*32;
int nz = 8*32;
int num_iterations = 1;
int gpu_id = 0;
/////////////////////////////////////////
// process command-line arguments
//
if( argc >= 4 )
{
nx = atoi( argv[1] );
ny = atoi( argv[2] );
nz = atoi( argv[3] );
}
if( argc >= 5 )
num_iterations = atoi( argv[4] );
if( argc >= 6 )
gpu_id = atoi( argv[5] );
TYPE delta_t = 0.01;
/////////////////////////////////////////
// create GPu context
//
cudaError_t error = cudaSuccess;
error = cudaSetDevice( gpu_id );
process_error( error, "set device" );
cudaDeviceProp prop;
error = cudaGetDeviceProperties( &prop, gpu_id );
process_error( error, "get device properties" );
printf("%s\n", prop.name );
error = cudaFree( 0 );
process_error( error, "create GPU context" );
printf( "%d %d %d %d\n", nx, ny, nz, num_iterations );
/////////////////////////////////////////
// allocate memory on GPU
//
TYPE *d_volumes[NUM_VOLS];
const int radius = 4;
const int cache_line_size_type = CACHE_LINE_SIZE / sizeof(TYPE);
size_t nx_pad = nx + 2 * radius;
size_t ny_pad = ny + 2 * radius;
size_t nz_pad = nz + 2 * radius;
nx_pad += cache_line_size_type - ( nx_pad % cache_line_size_type ); // make each row a multiple of cache-line size
size_t lead_pad = cache_line_size_type - radius;
size_t num_bytes_padded = ( lead_pad + nx_pad * ny_pad * nz_pad ) * sizeof( TYPE );
size_t num_bytes = nx * ny * nz * sizeof( TYPE );
int padding_to_first_output_cell = lead_pad + radius*nx_pad*ny_pad + radius*nx_pad + radius;
for( int i=0; i<NUM_VOLS; i++ )
{
error = cudaMalloc( &d_volumes[i], num_bytes_padded );
char message[20];
sprintf( message, "allocate vol %d", i );
process_error( error, message );
d_volumes[i] += padding_to_first_output_cell;
}
printf( "%dx%dx%d %8.3f GB\n", nx_pad, ny_pad, nz_pad, (((float)NUM_VOLS)*num_bytes_padded)/(1024.f*1024.f*1024.f) );
// error = cudaDeviceSetSharedMemConfig( cudaSharedMemBankSizeEightByte );
// process_error( error, "set SMEM addressing mode to 8-byte" );
/*
cudaEvent_t start, stop;
error = cudaEventCreate( &start );
process_error( error, "create start event" );
error = cudaEventCreate( &stop );
process_error( error, "create stop event" );
*/
float elapsed_time_ms=0.f, throughput_mcells=0.f;
#ifdef TRACE_UPDATE_RHO
{ // update rho, march in z, 4 volumes
TYPE *d_rho = d_volumes[0];
TYPE *d_momentum_x = d_volumes[1];
TYPE *d_momentum_y = d_volumes[2];
TYPE *d_momentum_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_rho_single_pass<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_rho, d_momentum_x, d_momentum_y, d_momentum_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "rho kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "rho", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DX
{ // derivative in x, march in z, 2 volumes
TYPE *d_vx_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
first_derivative_x<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_vx_x, d_vx,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "x kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "vx_x", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DZ
{ // derivative in z, march in z, 2 volumes
TYPE *d_vz_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
first_derivative_z<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_vz_z, d_vz,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "z kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "vz_z", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_UX
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy_y = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_momentum_x<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_x, d_vx, d_vy_y, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-x kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_x", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_UY
{ // difflux momentum-y, march in y, 4 volumes
TYPE *d_difflux_y = d_volumes[0];
TYPE *d_vy = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, nz/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_momentum_y_Q<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_y, d_vy, d_vx_x, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-yQ kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_yQ", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_UZ
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vy_y = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_momentum_z_Q<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_z, d_vz, d_vx_x, d_vy_y,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-zQ kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_zQ", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_DIFFLUX_E
{ // difflux energy, march in z, 8 volumes
TYPE *d_difflux_E = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy = d_volumes[2];
TYPE *d_vz = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_T = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
TYPE alam = 5.3;
TYPE eta = 7.1;
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_energy_4q<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_E,
alam, eta,
d_T,
d_vx, d_vy, d_vz,
d_difflux_x, d_difflux_y, d_difflux_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-E_4q kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "difflux_E_4q", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_UPDATE_E
{ // update energy, march in z, 6 volumes
TYPE *d_rE = d_volumes[0];
TYPE *d_p = d_volumes[1];
TYPE *d_vx = d_volumes[2];
TYPE *d_vy = d_volumes[3];
TYPE *d_vz = d_volumes[4];
TYPE *d_difflux_E = d_volumes[5];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_rE<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_rE,
d_p,
d_vx, d_vy, d_vz,
d_difflux_E,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "update-rE kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "update_rE", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_UPDATE_U
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_xyz_m4s<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "update-momentum m4s kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4", elapsed_time_ms, throughput_mcells );
*/
}
#endif
#ifdef TRACE_UPDATE_U_ALT
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
// cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_xyz_m4s_p<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
// cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "update-momentum m4s kernel" );
/* error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%15s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4", elapsed_time_ms, throughput_mcells );
*/
}
#endif
/////////////////////////////////////////
// free GPU resources
//
for( int i=0; i<NUM_VOLS; i++ )
{
d_volumes[i] -= padding_to_first_output_cell;
error = cudaFree( d_volumes[i] );
char message[20];
sprintf( message, "free vol %d", i );
process_error( error, message );
}
error = cudaDeviceReset();
process_error( error, "destroy GPU context" );
return 0;
}
/*
#ifdef TRACE_UPDATE_RHO
{ // update rho, march in z, 4 volumes
TYPE *d_rho = d_volumes[0];
TYPE *d_momentum_x = d_volumes[1];
TYPE *d_momentum_y = d_volumes[2];
TYPE *d_momentum_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_rho_single_pass<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_rho, d_momentum_x, d_momentum_y, d_momentum_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "rho kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "rho", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DX
{ // derivative in x, march in z, 2 volumes
TYPE *d_vx_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
first_derivative_x<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_vx_x, d_vx,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "x kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "vx_x", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DZ
{ // derivative in z, march in z, 2 volumes
TYPE *d_vz_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
first_derivative_z<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_vz_z, d_vz,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "z kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "vz_z", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_UX
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_x = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy_y = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_momentum_x<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_x, d_vx, d_vy_y, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-x kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_x", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_UY
{ // difflux momentum-y, march in y, 4 volumes
TYPE *d_difflux_y = d_volumes[0];
TYPE *d_vy = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vz_z = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, nz/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_momentum_y_Q<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_y, d_vy, d_vx_x, d_vz_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-yQ kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_yQ", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_UZ
{ // difflux momentum-x, march in z, 4 volumes
TYPE *d_difflux_z = d_volumes[0];
TYPE *d_vz = d_volumes[1];
TYPE *d_vx_x = d_volumes[2];
TYPE *d_vy_y = d_volumes[3];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_momentum_z_Q<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_z, d_vz, d_vx_x, d_vy_y,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-zQ kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_zQ", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_DIFFLUX_E
{ // difflux energy, march in z, 8 volumes
TYPE *d_difflux_E = d_volumes[0];
TYPE *d_vx = d_volumes[1];
TYPE *d_vy = d_volumes[2];
TYPE *d_vz = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_T = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
TYPE alam = 5.3;
TYPE eta = 7.1;
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
D_energy_4q<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_difflux_E,
alam, eta,
d_T,
d_vx, d_vy, d_vz,
d_difflux_x, d_difflux_y, d_difflux_z,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "difflux-E_4q kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "difflux_E_4q", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_UPDATE_E
{ // update energy, march in z, 6 volumes
TYPE *d_rE = d_volumes[0];
TYPE *d_p = d_volumes[1];
TYPE *d_vx = d_volumes[2];
TYPE *d_vy = d_volumes[3];
TYPE *d_vz = d_volumes[4];
TYPE *d_difflux_E = d_volumes[5];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_rE<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_rE,
d_p,
d_vx, d_vy, d_vz,
d_difflux_E,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "update-rE kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "update_rE", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_UPDATE_U
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_xyz_m4s<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "update-momentum m4s kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4", elapsed_time_ms, throughput_mcells );
}
#endif
#ifdef TRACE_UPDATE_U
{ // update momenta, march in z, 8 volumes
TYPE *d_ux = d_volumes[0];
TYPE *d_uy = d_volumes[1];
TYPE *d_uz = d_volumes[2];
TYPE *d_rho = d_volumes[3];
TYPE *d_difflux_x = d_volumes[4];
TYPE *d_difflux_y = d_volumes[5];
TYPE *d_difflux_z = d_volumes[6];
TYPE *d_p = d_volumes[7];
dim3 block( TILE_DIMX, TILE_DIMY );
dim3 grid( nx/block.x, ny/block.y );
cudaEventRecord( start, 0 );
for( int i=0; i<num_iterations; i++ )
{
update_xyz_m4s_p<TILE_DIMX,TILE_DIMY,RADIUS><<<grid,block>>>(
d_ux, d_uy, d_uz,
d_rho, d_p,
d_difflux_x, d_difflux_y, d_difflux_z,
delta_t,
nx, ny, nz,
nx_pad, ny_pad, nz_pad );
}
cudaEventRecord( stop, 0 );
cudaDeviceSynchronize();
error = cudaGetLastError();
process_error( error, "update-momentum m4s kernel" );
error = cudaEventElapsedTime( &elapsed_time_ms, start, stop );
process_error( error, "get kernel time" );
elapsed_time_ms /= num_iterations;
throughput_mcells = 1e-3f * nx*ny*nz / elapsed_time_ms;
printf( "%17s: %7.2f ms, %7.1f MC/s\n", "update_xyz_m4_p", elapsed_time_ms, throughput_mcells );
}
#endif
/////////////////////////////////////////
// free GPU resources
//
for( int i=0; i<NUM_VOLS; i++ )
{
d_volumes[i] -= padding_to_first_output_cell;
error = cudaFree( d_volumes[i] );
char message[20];
sprintf( message, "free vol %d", i );
process_error( error, message );
}
error = cudaDeviceReset();
process_error( error, "destroy GPU context" );
return 0;
}
*/ |
6dc0ab3751f9fddd2b19cef5b8289833ae0fc5aa.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* This sample implements a separable convolution
* of a 2D image with an arbitrary filter.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned int filter_radius;
#define FILTER_LENGTH (2 * filter_radius + 1)
#define ABS(val) ((val)<0.0 ? (-(val)) : (val))
#define accuracy 0.00005
#define ArraySize imageW * imageH
#define ERROR -1
#define SH_MEM_SIZE 32
#define NUMBLOCKS 4
typedef float dataType;
__constant__ dataType d_Filter[65536 / sizeof(dataType)];
// This checks for cuda errors
#define cudaErrorCheck() \
{ \
hipError_t error = hipGetLastError(); \
if (error != hipSuccess) \
{ \
printf("Cuda Error Found %s:%d: '%s'\n", __FILE__, __LINE__, hipGetErrorString(error)); \
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU); \
return (ERROR); \
} \
}
#define cudaCalloc(pointer, size, sizeOfElement) \
{ \
hipError_t err = hipMalloc(pointer, size * sizeOfElement); \
if (err != hipSuccess) \
{ \
printf("Error allocating memory on host: %s\n", hipGetErrorString(err)); \
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU); \
return (ERROR); \
} \
hipMemset(*pointer, 0.0, size *sizeOfElement); \
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Row Convolution Filter
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionRow(dataType *Input, dataType *Output, int filterR, int imageW)
{
dataType sum = 0;
int d, k;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
//int dimx = blockDim.x * gridDim.x + 2 * filterR;
//int idx = iy * dimx + ix;
int imageWithPaddingW = imageW + 2 * filterR;
for (k = -filterR; k <= filterR; k++){
d = ix + k;
//printf("ix=%d,iy=%d, k=%d, output_idx=%d, input_idx=%d\n", ix, iy, k, iy * imageWithPaddingW + ix, iy * imageWithPaddingW + d);
sum += Input[iy * imageWithPaddingW + d] * d_Filter[filterR - k];
Output[iy * imageWithPaddingW + ix] = sum;
}
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Column Convolution Filter
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionColumn(dataType *Input, dataType *Output, int filterR, int imageW, int imageH)
{
dataType sum = 0;
int d, k;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
//int dimx = blockDim.x * gridDim.x;
//int idx = iy * dimx + ix;
int imageWithPaddingW = imageW + 2 * filterR;
for (k = -filterR; k <= filterR; k++){
d = iy + k;
sum += Input[d * imageWithPaddingW + ix] * d_Filter[filterR - k];
Output[iy * imageWithPaddingW + ix] = sum;
}
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Row Convolution Filter using Shared Memory
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionRowSharedMem(dataType *Input, dataType *Output, int filterR, int imageW)
{
dataType sum = 0;
int d, k;
int tx = threadIdx.x;
int ty = threadIdx.y;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
int imageWithPaddingW = imageW + 2 * filterR;
//shared memory for Input
__shared__ dataType s_Input[SH_MEM_SIZE * SH_MEM_SIZE];
//collaboratively load tiles into __shared__
s_Input[ty * SH_MEM_SIZE + tx] = Input[iy * imageWithPaddingW + ix];
__syncthreads();
for (k = -filterR; k <= filterR; k++){
d = tx + k;
if (d >= 0 && d < SH_MEM_SIZE)
{
sum += s_Input[ty * SH_MEM_SIZE + d] * d_Filter[filterR - k];
}
else
{
sum += Input[iy * imageWithPaddingW + ix + k] * d_Filter[filterR - k];
}
}
Output[iy * imageWithPaddingW + ix] = sum; //There is no reason to do it for each iteration
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Column Convolution Filter using Shared Memory
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionColumnSharedMem(dataType *Input, dataType *Output, int filterR, int imageW, int imageH)
{
dataType sum = 0;
int d, k;
int tx = threadIdx.x;
int ty = threadIdx.y;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
int imageWithPaddingW = imageW + 2 * filterR;
//shared memory for Input
__shared__ dataType s_Input[SH_MEM_SIZE * SH_MEM_SIZE];
//collaboratively load tiles into __shared__
s_Input[ty * SH_MEM_SIZE + tx] = Input[iy * imageWithPaddingW + ix];
__syncthreads();
for (k = -filterR; k <= filterR; k++){
d = ty + k;
if (d >= 0 && d < SH_MEM_SIZE)
{
sum += s_Input[d * SH_MEM_SIZE + tx] * d_Filter[filterR - k];
}
else
{
sum += Input[(iy + k) * imageWithPaddingW + ix] * d_Filter[filterR - k];
}
}
Output[iy * imageWithPaddingW + ix] = sum; //No reason for each iteration
}
////////////////////////////////////////////////////////////////////////////////
// Reference row convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionRowCPU(dataType *h_Dst, dataType *h_Src, dataType *h_Filter,
int imageW, int imageH, int filterR) {
int x, y, k;
int imageWithPaddingW = imageW + 2 * filterR;
for (y = filterR; y < (imageH + filterR); y++) {
for (x = filterR; x < (imageW + filterR); x++) {
dataType sum = 0;
for (k = -filterR; k <= filterR; k++) {
int d = x + k;
sum += h_Src[y * imageWithPaddingW + d] * h_Filter[filterR - k];
}
h_Dst[y * imageWithPaddingW + x] = sum; //Only one time for each x & y
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Reference column convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionColumnCPU(dataType *h_Dst, dataType *h_Src, dataType *h_Filter,
int imageW, int imageH, int filterR) {
int x, y, k;
int imageWithPaddingW = imageW + 2 * filterR;
for (y = filterR; y < (imageH + filterR); y++) {
for (x = filterR; x < (imageW + filterR); x++) {
dataType sum = 0;
for (k = -filterR; k <= filterR; k++) {
int d = y + k;
//printf("x=%d, y=%d, output_idx=%d, input_idx=%d\n", x, y, y * imageWithPaddingW + x, y * imageWithPaddingW + d);
sum += h_Src[d * imageWithPaddingW + x] * h_Filter[filterR - k];
}
h_Dst[y * imageWithPaddingW + x] = sum; //Only one time for each x & y
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Free Alocated Host and Device Memory
////////////////////////////////////////////////////////////////////////////////
int freeMemory(dataType *h_Filter, dataType *h_Input, dataType *h_Buffer, dataType *h_OutputCPU, dataType *h_OutputGPU, dataType *d_Input, dataType *d_Buffer, dataType *d_OutputGPU)
{
hipError_t err;
// free all the allocated memory for the host
printf("Free host memory...\n");
if (h_OutputGPU != NULL){
free(h_OutputGPU);
}
if (h_OutputCPU != NULL){
free(h_OutputCPU);
}
if (h_Buffer != NULL){
free(h_Buffer);
}
if (h_Input != NULL){
free(h_Input);
}
if (h_Filter != NULL)
{
free(h_Filter);
}
//free all the allocated device (GPU) memory
printf("Free device memory...\n");
if (d_OutputGPU != NULL){
err = hipFree(d_OutputGPU);
if (err != hipSuccess)
{
printf("Error during hipFree (d_OutputGPU): %s\n", hipGetErrorString(err));
return (ERROR);
}
}
if (d_Buffer != NULL){
err = hipFree(d_Buffer);
if (err != hipSuccess)
{
printf("Error during hipFree (d_Buffer): %s\n", hipGetErrorString(err));
return (ERROR);
}
}
if (d_Input != NULL){
err = hipFree(d_Input);
if (err != hipSuccess)
{
printf("Error during hipFree (d_Input): %s\n", hipGetErrorString(err));
return (ERROR);
}
}
// Do a device reset just in case... Bgalte to sxolio otan ylopoihsete CUDA
printf("Reset Device\n");
err = hipDeviceReset();
if (err != hipSuccess){
printf("Error during hipDeviceReset: %s\n", hipGetErrorString(err));
return (ERROR);
}
return (0);
}
////////////////////////////////////////////////////////////////////////////////
// Main program
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
//pointers for the host
dataType
*h_Filter = NULL,
*h_Input = NULL,
*h_Buffer = NULL,
*h_OutputCPU = NULL,
*h_OutputGPU = NULL;
//pointers for the device
dataType
*d_Input = NULL,
*d_Buffer = NULL,
*d_OutputGPU = NULL;
int imageW; //image width = N
int imageH; //image height = N
unsigned int i, j, block_size, numberOfBlocks;
dataType diff = 0, max_diff = 0;
/*-------timing variables-------*/
struct timespec tv1, tv2;
hipError_t err;
hipEvent_t start;
hipEvent_t stop;
float elapsed;
/*------------------------------*/
/*------padding variables-------*/
int imageWithPaddingW, newImageSize;
/*------------------------------*/
printf("Enter filter radius : ");
scanf("%d", &filter_radius);
// Ta imageW, imageH ta dinei o xrhsths kai thewroume oti einai isa,
// dhladh imageW = imageH = N, opou to N to dinei o xrhsths.
// Gia aplothta thewroume tetragwnikes eikones.
printf("Enter image size. Should be a power of two and greater than %d : ", FILTER_LENGTH);
scanf("%d", &imageW);
imageH = imageW;
imageWithPaddingW = imageW + 2 * filter_radius;
newImageSize = imageWithPaddingW * imageWithPaddingW;
printf("Image Width x Height = %i x %i\n\n", imageW, imageH);
printf("Image Width x Height = %i x %i\n\n", imageWithPaddingW, imageWithPaddingW);
printf("Allocating and initializing host arrays...\n");
//Allocate host (CPU) memory
{
h_Filter = (dataType *)malloc(FILTER_LENGTH * sizeof(dataType));
if (h_Filter == NULL)
{
printf("Error allocating memory on host for h_Filter");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_Input = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_Input == NULL){
printf("Error allocating memory on host for h_Input");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_Buffer = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_Buffer == NULL){
printf("Error allocating memory on host for h_Buffer");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_OutputCPU = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_OutputCPU == NULL){
printf("Error allocating memory on host for h_OutputCPU");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_OutputGPU = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_OutputGPU == NULL){
printf("Error allocating memory on host for h_OutputGPU");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
// to 'h_Filter' apotelei to filtro me to opoio ginetai to convolution kai
// arxikopoieitai tuxaia. To 'h_Input' einai h eikona panw sthn opoia ginetai
// to convolution kai arxikopoieitai kai auth tuxaia.
}
printf("Allocate device (GPU) memory\n");
//Allocate device (GPU) memory
{
err = hipMalloc( (void**) &d_Input, newImageSize * sizeof(dataType) );
if (err != hipSuccess){
printf("Error allocating memory on host for d_Input: %s\n", hipGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
cudaCalloc((void**) &d_Buffer, newImageSize, sizeof(dataType));
cudaCalloc((void**) &d_OutputGPU, newImageSize, sizeof(dataType));
}
if (imageW < 32)
{
block_size = imageW;
numberOfBlocks = 1;
}
else
{
block_size = 32;
numberOfBlocks = imageW / block_size;
}
dim3 threadsPerBlock(block_size, block_size); //geometry for block
dim3 numBlocks(numberOfBlocks, numberOfBlocks); //geometry for grid
//Initializations
{
srand(200);
// Random initialization of h_Filter
for (i = 0; i < FILTER_LENGTH; i++) {
h_Filter[i] = (dataType)(rand() % 16);
}
// Random initialization of h_Input
for (i = filter_radius; i < (imageH + filter_radius); i++) {
for (j = filter_radius; j < (imageW + filter_radius); j++){
h_Input[i * imageWithPaddingW + j] = (dataType)rand() / ((dataType)RAND_MAX / 255) + (dataType)rand() / (dataType)RAND_MAX;
}
}
}
//CPU Computation
{
// To parakatw einai to kommati pou ekteleitai sthn CPU kai me vash auto prepei na ginei h sugrish me thn GPU.
printf("CPU computation is about to start...\n");
//Get the starting time
clock_gettime(CLOCK_MONOTONIC_RAW, &tv1);
convolutionRowCPU(h_Buffer, h_Input, h_Filter, imageW, imageH, filter_radius); // convolution kata grammes
convolutionColumnCPU(h_OutputCPU, h_Buffer, h_Filter, imageW, imageH, filter_radius); // convolution kata sthles
//Take the end time
clock_gettime(CLOCK_MONOTONIC_RAW, &tv2);
printf("CPU computation finished...\n");
}
//Calculate the duration of the CPU computation and report it
{
printf("\033[1;33m");
printf("CPU time = %10g seconds\n",
(double)(tv2.tv_nsec - tv1.tv_nsec) / 1000000000.0 +
(double)(tv2.tv_sec - tv1.tv_sec));
}
printf("\033[0m");
//Copy from host to device
{
hipEventCreate(&start);
hipEventCreate(&stop);
printf("Copy host memory to device\n");
hipEventRecord(start, 0);
//Copy host memory to device
err = hipMemcpyToSymbol(d_Filter, h_Filter, FILTER_LENGTH * sizeof(dataType));
if (err != hipSuccess)
{
printf("Error during hipMemcpyToSymbol of h_Filter to d_Filter: %s\n", hipGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
err = hipMemcpy(d_Input, h_Input, newImageSize * sizeof(dataType), hipMemcpyHostToDevice);
if (err != hipSuccess)
{
printf("Error during hipMemcpy of h_Input to d_Input: %s\n", hipGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
}
//GPU Computation
{
printf("GPU computation is about to start...\n");
//kernel for row convolution
//execute grid of numBlocks blocks of threadsPerBlock threads each
hipLaunchKernelGGL(( convolutionRowSharedMem) , dim3(numBlocks), dim3(threadsPerBlock) , 0, 0, d_Input, d_Buffer, filter_radius, imageW);
err = hipDeviceSynchronize();
if (err != hipSuccess){
printf ("Error during hipDeviceSynchronize: %s\n", hipGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
//Error Checking
cudaErrorCheck();
//kernel for column convolution
//execute grid of numBlocks blocks of threadsPerBlock threads each
hipLaunchKernelGGL(( convolutionColumnSharedMem) , dim3(numBlocks), dim3(threadsPerBlock) , 0, 0, d_Buffer, d_OutputGPU, filter_radius, imageW, imageH);
err = hipMemcpy(h_OutputGPU, d_OutputGPU, newImageSize * sizeof(dataType), hipMemcpyDeviceToHost);
if(err != hipSuccess){
printf("Error during hipMemcpy of d_OutputGPU to h_OutputGPU: %s\n", hipGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
//Error Checking
cudaErrorCheck();
hipEventRecord(stop, 0);
printf("GPU computation finished...\n");
}
//Execution Time of GPU
{
hipEventSynchronize(stop);
hipEventElapsedTime(&elapsed, start, stop);
printf("\033[1;35m");
printf("GPU time = %g ms\n", elapsed);
printf("\033[0m");
hipEventDestroy(start);
hipEventDestroy(stop);
}
//Compare the results from CPU and GPU
{
for (i = filter_radius; i < imageH + filter_radius; i++) {
for (j = filter_radius; j < imageW + filter_radius; j++) {
diff = ABS(h_OutputGPU[i * imageWithPaddingW + j] - h_OutputCPU[i * imageWithPaddingW + j]);
//printf("The difference between h_OutputCPU[%d]=%lf and h_OutputGPU[%d]=%lf is diff = %g\n", i * imageWithPaddingW + j, h_OutputCPU[i * imageWithPaddingW + j], i * imageWithPaddingW + j, h_OutputGPU[i * imageWithPaddingW + j], diff);
if (diff > max_diff) {
max_diff = diff;
}
if (diff > accuracy) {
//printf("\t|->ERROR: The difference between the values of h_OutputCPU and h_OutputGPU at index i = %u is bigger than the given accuracy.\n", i);
}
}
}
if (max_diff > accuracy)
{
printf("\033[1;31m");
printf("ERROR! Max difference between the values of h_OutputCPU and h_OutputGPU is max_diff = %g\n", max_diff);
}
else
{
printf("\033[1;32m");
printf("Max difference between the values of h_OutputCPU and h_OutputGPU is max_diff = %g\n", max_diff);
}
}
//Free allocated host and device memory
printf("\033[0m");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return 0;
}
| 6dc0ab3751f9fddd2b19cef5b8289833ae0fc5aa.cu | /*
* This sample implements a separable convolution
* of a 2D image with an arbitrary filter.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned int filter_radius;
#define FILTER_LENGTH (2 * filter_radius + 1)
#define ABS(val) ((val)<0.0 ? (-(val)) : (val))
#define accuracy 0.00005
#define ArraySize imageW * imageH
#define ERROR -1
#define SH_MEM_SIZE 32
#define NUMBLOCKS 4
typedef float dataType;
__constant__ dataType d_Filter[65536 / sizeof(dataType)];
// This checks for cuda errors
#define cudaErrorCheck() \
{ \
cudaError_t error = cudaGetLastError(); \
if (error != cudaSuccess) \
{ \
printf("Cuda Error Found %s:%d: '%s'\n", __FILE__, __LINE__, cudaGetErrorString(error)); \
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU); \
return (ERROR); \
} \
}
#define cudaCalloc(pointer, size, sizeOfElement) \
{ \
cudaError_t err = cudaMalloc(pointer, size * sizeOfElement); \
if (err != cudaSuccess) \
{ \
printf("Error allocating memory on host: %s\n", cudaGetErrorString(err)); \
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU); \
return (ERROR); \
} \
cudaMemset(*pointer, 0.0, size *sizeOfElement); \
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Row Convolution Filter
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionRow(dataType *Input, dataType *Output, int filterR, int imageW)
{
dataType sum = 0;
int d, k;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
//int dimx = blockDim.x * gridDim.x + 2 * filterR;
//int idx = iy * dimx + ix;
int imageWithPaddingW = imageW + 2 * filterR;
for (k = -filterR; k <= filterR; k++){
d = ix + k;
//printf("ix=%d,iy=%d, k=%d, output_idx=%d, input_idx=%d\n", ix, iy, k, iy * imageWithPaddingW + ix, iy * imageWithPaddingW + d);
sum += Input[iy * imageWithPaddingW + d] * d_Filter[filterR - k];
Output[iy * imageWithPaddingW + ix] = sum;
}
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Column Convolution Filter
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionColumn(dataType *Input, dataType *Output, int filterR, int imageW, int imageH)
{
dataType sum = 0;
int d, k;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
//int dimx = blockDim.x * gridDim.x;
//int idx = iy * dimx + ix;
int imageWithPaddingW = imageW + 2 * filterR;
for (k = -filterR; k <= filterR; k++){
d = iy + k;
sum += Input[d * imageWithPaddingW + ix] * d_Filter[filterR - k];
Output[iy * imageWithPaddingW + ix] = sum;
}
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Row Convolution Filter using Shared Memory
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionRowSharedMem(dataType *Input, dataType *Output, int filterR, int imageW)
{
dataType sum = 0;
int d, k;
int tx = threadIdx.x;
int ty = threadIdx.y;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
int imageWithPaddingW = imageW + 2 * filterR;
//shared memory for Input
__shared__ dataType s_Input[SH_MEM_SIZE * SH_MEM_SIZE];
//collaboratively load tiles into __shared__
s_Input[ty * SH_MEM_SIZE + tx] = Input[iy * imageWithPaddingW + ix];
__syncthreads();
for (k = -filterR; k <= filterR; k++){
d = tx + k;
if (d >= 0 && d < SH_MEM_SIZE)
{
sum += s_Input[ty * SH_MEM_SIZE + d] * d_Filter[filterR - k];
}
else
{
sum += Input[iy * imageWithPaddingW + ix + k] * d_Filter[filterR - k];
}
}
Output[iy * imageWithPaddingW + ix] = sum; //There is no reason to do it for each iteration
}
////////////////////////////////////////////////////////////////////////////////
// Kernel Column Convolution Filter using Shared Memory
////////////////////////////////////////////////////////////////////////////////
__global__ void convolutionColumnSharedMem(dataType *Input, dataType *Output, int filterR, int imageW, int imageH)
{
dataType sum = 0;
int d, k;
int tx = threadIdx.x;
int ty = threadIdx.y;
int ix = blockIdx.x * blockDim.x + threadIdx.x + filterR;
int iy = blockIdx.y * blockDim.y + threadIdx.y + filterR;
int imageWithPaddingW = imageW + 2 * filterR;
//shared memory for Input
__shared__ dataType s_Input[SH_MEM_SIZE * SH_MEM_SIZE];
//collaboratively load tiles into __shared__
s_Input[ty * SH_MEM_SIZE + tx] = Input[iy * imageWithPaddingW + ix];
__syncthreads();
for (k = -filterR; k <= filterR; k++){
d = ty + k;
if (d >= 0 && d < SH_MEM_SIZE)
{
sum += s_Input[d * SH_MEM_SIZE + tx] * d_Filter[filterR - k];
}
else
{
sum += Input[(iy + k) * imageWithPaddingW + ix] * d_Filter[filterR - k];
}
}
Output[iy * imageWithPaddingW + ix] = sum; //No reason for each iteration
}
////////////////////////////////////////////////////////////////////////////////
// Reference row convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionRowCPU(dataType *h_Dst, dataType *h_Src, dataType *h_Filter,
int imageW, int imageH, int filterR) {
int x, y, k;
int imageWithPaddingW = imageW + 2 * filterR;
for (y = filterR; y < (imageH + filterR); y++) {
for (x = filterR; x < (imageW + filterR); x++) {
dataType sum = 0;
for (k = -filterR; k <= filterR; k++) {
int d = x + k;
sum += h_Src[y * imageWithPaddingW + d] * h_Filter[filterR - k];
}
h_Dst[y * imageWithPaddingW + x] = sum; //Only one time for each x & y
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Reference column convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionColumnCPU(dataType *h_Dst, dataType *h_Src, dataType *h_Filter,
int imageW, int imageH, int filterR) {
int x, y, k;
int imageWithPaddingW = imageW + 2 * filterR;
for (y = filterR; y < (imageH + filterR); y++) {
for (x = filterR; x < (imageW + filterR); x++) {
dataType sum = 0;
for (k = -filterR; k <= filterR; k++) {
int d = y + k;
//printf("x=%d, y=%d, output_idx=%d, input_idx=%d\n", x, y, y * imageWithPaddingW + x, y * imageWithPaddingW + d);
sum += h_Src[d * imageWithPaddingW + x] * h_Filter[filterR - k];
}
h_Dst[y * imageWithPaddingW + x] = sum; //Only one time for each x & y
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Free Alocated Host and Device Memory
////////////////////////////////////////////////////////////////////////////////
int freeMemory(dataType *h_Filter, dataType *h_Input, dataType *h_Buffer, dataType *h_OutputCPU, dataType *h_OutputGPU, dataType *d_Input, dataType *d_Buffer, dataType *d_OutputGPU)
{
cudaError_t err;
// free all the allocated memory for the host
printf("Free host memory...\n");
if (h_OutputGPU != NULL){
free(h_OutputGPU);
}
if (h_OutputCPU != NULL){
free(h_OutputCPU);
}
if (h_Buffer != NULL){
free(h_Buffer);
}
if (h_Input != NULL){
free(h_Input);
}
if (h_Filter != NULL)
{
free(h_Filter);
}
//free all the allocated device (GPU) memory
printf("Free device memory...\n");
if (d_OutputGPU != NULL){
err = cudaFree(d_OutputGPU);
if (err != cudaSuccess)
{
printf("Error during cudaFree (d_OutputGPU): %s\n", cudaGetErrorString(err));
return (ERROR);
}
}
if (d_Buffer != NULL){
err = cudaFree(d_Buffer);
if (err != cudaSuccess)
{
printf("Error during cudaFree (d_Buffer): %s\n", cudaGetErrorString(err));
return (ERROR);
}
}
if (d_Input != NULL){
err = cudaFree(d_Input);
if (err != cudaSuccess)
{
printf("Error during cudaFree (d_Input): %s\n", cudaGetErrorString(err));
return (ERROR);
}
}
// Do a device reset just in case... Bgalte to sxolio otan ylopoihsete CUDA
printf("Reset Device\n");
err = cudaDeviceReset();
if (err != cudaSuccess){
printf("Error during cudaDeviceReset: %s\n", cudaGetErrorString(err));
return (ERROR);
}
return (0);
}
////////////////////////////////////////////////////////////////////////////////
// Main program
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
//pointers for the host
dataType
*h_Filter = NULL,
*h_Input = NULL,
*h_Buffer = NULL,
*h_OutputCPU = NULL,
*h_OutputGPU = NULL;
//pointers for the device
dataType
*d_Input = NULL,
*d_Buffer = NULL,
*d_OutputGPU = NULL;
int imageW; //image width = N
int imageH; //image height = N
unsigned int i, j, block_size, numberOfBlocks;
dataType diff = 0, max_diff = 0;
/*-------timing variables-------*/
struct timespec tv1, tv2;
cudaError_t err;
cudaEvent_t start;
cudaEvent_t stop;
float elapsed;
/*------------------------------*/
/*------padding variables-------*/
int imageWithPaddingW, newImageSize;
/*------------------------------*/
printf("Enter filter radius : ");
scanf("%d", &filter_radius);
// Ta imageW, imageH ta dinei o xrhsths kai thewroume oti einai isa,
// dhladh imageW = imageH = N, opou to N to dinei o xrhsths.
// Gia aplothta thewroume tetragwnikes eikones.
printf("Enter image size. Should be a power of two and greater than %d : ", FILTER_LENGTH);
scanf("%d", &imageW);
imageH = imageW;
imageWithPaddingW = imageW + 2 * filter_radius;
newImageSize = imageWithPaddingW * imageWithPaddingW;
printf("Image Width x Height = %i x %i\n\n", imageW, imageH);
printf("Image Width x Height = %i x %i\n\n", imageWithPaddingW, imageWithPaddingW);
printf("Allocating and initializing host arrays...\n");
//Allocate host (CPU) memory
{
h_Filter = (dataType *)malloc(FILTER_LENGTH * sizeof(dataType));
if (h_Filter == NULL)
{
printf("Error allocating memory on host for h_Filter");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_Input = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_Input == NULL){
printf("Error allocating memory on host for h_Input");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_Buffer = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_Buffer == NULL){
printf("Error allocating memory on host for h_Buffer");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_OutputCPU = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_OutputCPU == NULL){
printf("Error allocating memory on host for h_OutputCPU");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
h_OutputGPU = (dataType *)calloc(newImageSize, sizeof(dataType));
if (h_OutputGPU == NULL){
printf("Error allocating memory on host for h_OutputGPU");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
// to 'h_Filter' apotelei to filtro me to opoio ginetai to convolution kai
// arxikopoieitai tuxaia. To 'h_Input' einai h eikona panw sthn opoia ginetai
// to convolution kai arxikopoieitai kai auth tuxaia.
}
printf("Allocate device (GPU) memory\n");
//Allocate device (GPU) memory
{
err = cudaMalloc( (void**) &d_Input, newImageSize * sizeof(dataType) );
if (err != cudaSuccess){
printf("Error allocating memory on host for d_Input: %s\n", cudaGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
cudaCalloc((void**) &d_Buffer, newImageSize, sizeof(dataType));
cudaCalloc((void**) &d_OutputGPU, newImageSize, sizeof(dataType));
}
if (imageW < 32)
{
block_size = imageW;
numberOfBlocks = 1;
}
else
{
block_size = 32;
numberOfBlocks = imageW / block_size;
}
dim3 threadsPerBlock(block_size, block_size); //geometry for block
dim3 numBlocks(numberOfBlocks, numberOfBlocks); //geometry for grid
//Initializations
{
srand(200);
// Random initialization of h_Filter
for (i = 0; i < FILTER_LENGTH; i++) {
h_Filter[i] = (dataType)(rand() % 16);
}
// Random initialization of h_Input
for (i = filter_radius; i < (imageH + filter_radius); i++) {
for (j = filter_radius; j < (imageW + filter_radius); j++){
h_Input[i * imageWithPaddingW + j] = (dataType)rand() / ((dataType)RAND_MAX / 255) + (dataType)rand() / (dataType)RAND_MAX;
}
}
}
//CPU Computation
{
// To parakatw einai to kommati pou ekteleitai sthn CPU kai me vash auto prepei na ginei h sugrish me thn GPU.
printf("CPU computation is about to start...\n");
//Get the starting time
clock_gettime(CLOCK_MONOTONIC_RAW, &tv1);
convolutionRowCPU(h_Buffer, h_Input, h_Filter, imageW, imageH, filter_radius); // convolution kata grammes
convolutionColumnCPU(h_OutputCPU, h_Buffer, h_Filter, imageW, imageH, filter_radius); // convolution kata sthles
//Take the end time
clock_gettime(CLOCK_MONOTONIC_RAW, &tv2);
printf("CPU computation finished...\n");
}
//Calculate the duration of the CPU computation and report it
{
printf("\033[1;33m");
printf("CPU time = %10g seconds\n",
(double)(tv2.tv_nsec - tv1.tv_nsec) / 1000000000.0 +
(double)(tv2.tv_sec - tv1.tv_sec));
}
printf("\033[0m");
//Copy from host to device
{
cudaEventCreate(&start);
cudaEventCreate(&stop);
printf("Copy host memory to device\n");
cudaEventRecord(start, 0);
//Copy host memory to device
err = cudaMemcpyToSymbol(d_Filter, h_Filter, FILTER_LENGTH * sizeof(dataType));
if (err != cudaSuccess)
{
printf("Error during cudaMemcpyToSymbol of h_Filter to d_Filter: %s\n", cudaGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
err = cudaMemcpy(d_Input, h_Input, newImageSize * sizeof(dataType), cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
printf("Error during cudaMemcpy of h_Input to d_Input: %s\n", cudaGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
}
//GPU Computation
{
printf("GPU computation is about to start...\n");
//kernel for row convolution
//execute grid of numBlocks blocks of threadsPerBlock threads each
convolutionRowSharedMem <<< numBlocks, threadsPerBlock >>> (d_Input, d_Buffer, filter_radius, imageW);
err = cudaDeviceSynchronize();
if (err != cudaSuccess){
printf ("Error during cudaDeviceSynchronize: %s\n", cudaGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
//Error Checking
cudaErrorCheck();
//kernel for column convolution
//execute grid of numBlocks blocks of threadsPerBlock threads each
convolutionColumnSharedMem <<< numBlocks, threadsPerBlock >>> (d_Buffer, d_OutputGPU, filter_radius, imageW, imageH);
err = cudaMemcpy(h_OutputGPU, d_OutputGPU, newImageSize * sizeof(dataType), cudaMemcpyDeviceToHost);
if(err != cudaSuccess){
printf("Error during cudaMemcpy of d_OutputGPU to h_OutputGPU: %s\n", cudaGetErrorString(err));
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return (ERROR);
}
//Error Checking
cudaErrorCheck();
cudaEventRecord(stop, 0);
printf("GPU computation finished...\n");
}
//Execution Time of GPU
{
cudaEventSynchronize(stop);
cudaEventElapsedTime(&elapsed, start, stop);
printf("\033[1;35m");
printf("GPU time = %g ms\n", elapsed);
printf("\033[0m");
cudaEventDestroy(start);
cudaEventDestroy(stop);
}
//Compare the results from CPU and GPU
{
for (i = filter_radius; i < imageH + filter_radius; i++) {
for (j = filter_radius; j < imageW + filter_radius; j++) {
diff = ABS(h_OutputGPU[i * imageWithPaddingW + j] - h_OutputCPU[i * imageWithPaddingW + j]);
//printf("The difference between h_OutputCPU[%d]=%lf and h_OutputGPU[%d]=%lf is diff = %g\n", i * imageWithPaddingW + j, h_OutputCPU[i * imageWithPaddingW + j], i * imageWithPaddingW + j, h_OutputGPU[i * imageWithPaddingW + j], diff);
if (diff > max_diff) {
max_diff = diff;
}
if (diff > accuracy) {
//printf("\t|->ERROR: The difference between the values of h_OutputCPU and h_OutputGPU at index i = %u is bigger than the given accuracy.\n", i);
}
}
}
if (max_diff > accuracy)
{
printf("\033[1;31m");
printf("ERROR! Max difference between the values of h_OutputCPU and h_OutputGPU is max_diff = %g\n", max_diff);
}
else
{
printf("\033[1;32m");
printf("Max difference between the values of h_OutputCPU and h_OutputGPU is max_diff = %g\n", max_diff);
}
}
//Free allocated host and device memory
printf("\033[0m");
freeMemory(h_Filter, h_Input, h_Buffer, h_OutputCPU, h_OutputGPU, d_Input, d_Buffer, d_OutputGPU);
return 0;
}
|
85cc74ee5693941c1c13e5a5d556221cbc70fd90.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <stdio.h>
#include <omp.h>
__global__ void gpu3_row(int m, int n, int k_max, double *A, double *B, double *C) {
int i, j, k;
double sum1, sum2;
i = 2*(blockIdx.x * blockDim.x + threadIdx.x);
j = blockIdx.y * blockDim.y + threadIdx.y;
if(!(i >= m-1 || j >= n)){
sum1 = 0.0;
sum2 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
sum2 += A[(i+1)*k_max+k] * B[k*n+j];
}
C[i*n+j] = sum1;
C[(i+1)*n+j] = sum2;
}else if(!(i >= m || j >= n)){
sum1 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
}
C[i*n+j] = sum1;
}
}
__global__ void gpu3_column(int m, int n, int k_max, double *A, double *B, double *C) {
int i, j, k;
double sum1, sum2;
i = blockIdx.x * blockDim.x + threadIdx.x;
j = 2*(blockIdx.y * blockDim.y + threadIdx.y);
if(!(i >= m || j >= n-1)){
sum1 = 0.0;
sum2 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
sum2 += A[i*k_max+k] * B[k*n+(j+1)];
}
// printf("%f %f\n", sum1, sum2);
C[i*n+j] = sum1;
C[i*n+(j+1)] = sum2;
}else if(!(i >= m || j >= n)){
sum1 = 0.0;
//sum2 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
//sum2 += A[i*k_max+k] * B[k*n+(j+1)];
}
// printf("%f\n", sum1);
C[i*n+j] = sum1;
//C[i*n+(j+1)] = sum2;
}
}
extern "C" { __host__ void matmult_gpu3(int m, int n, int k, double *h_A, double *h_B, double *h_C){
double *d_A, *d_B, *d_C;
int devices;
hipGetDeviceCount(&devices);
int A_elems = m*k;
int B_elems = k*n;
int C_elems = m*n;
int size_A = A_elems*sizeof(double);
int size_B = B_elems*sizeof(double);
int size_C = C_elems*sizeof(double);
hipMalloc((void**)&d_A, size_A);
hipMalloc((void**)&d_B, size_B);
hipMalloc((void**)&d_C, size_C);
hipMemcpy(d_A, h_A, size_A, hipMemcpyHostToDevice);
hipMemcpy(d_B, h_B, size_B, hipMemcpyHostToDevice);
int blockx = 16;
int blocky = 16;
dim3 dimBlock(blockx,blocky,1);
//for column
int gridx = (m/blockx)+1;
int gridy = ((n/blocky)+1)/2 + 1;
//for row
//int gridx = ((m/blockx)+1)/2 + 1;
//int gridy = (n/blocky)+1;
dim3 dimGrid(gridx,gridy,1);
//for column
hipLaunchKernelGGL(( gpu3_column), dim3(dimGrid),dim3(dimBlock), 0, 0, m,n,k,d_A,d_B,d_C);
//for grid
//gpu3_row<<<dimGrid,dimBlock>>>(m,n,k,d_A,d_B,d_C);
hipDeviceSynchronize();
hipMemcpy(h_C, d_C, size_C, hipMemcpyDeviceToHost);
int i,j;
hipFree(d_A);
hipFree(d_B);
hipFree(d_C);
}
}
| 85cc74ee5693941c1c13e5a5d556221cbc70fd90.cu | #include <stdio.h>
#include <omp.h>
__global__ void gpu3_row(int m, int n, int k_max, double *A, double *B, double *C) {
int i, j, k;
double sum1, sum2;
i = 2*(blockIdx.x * blockDim.x + threadIdx.x);
j = blockIdx.y * blockDim.y + threadIdx.y;
if(!(i >= m-1 || j >= n)){
sum1 = 0.0;
sum2 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
sum2 += A[(i+1)*k_max+k] * B[k*n+j];
}
C[i*n+j] = sum1;
C[(i+1)*n+j] = sum2;
}else if(!(i >= m || j >= n)){
sum1 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
}
C[i*n+j] = sum1;
}
}
__global__ void gpu3_column(int m, int n, int k_max, double *A, double *B, double *C) {
int i, j, k;
double sum1, sum2;
i = blockIdx.x * blockDim.x + threadIdx.x;
j = 2*(blockIdx.y * blockDim.y + threadIdx.y);
if(!(i >= m || j >= n-1)){
sum1 = 0.0;
sum2 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
sum2 += A[i*k_max+k] * B[k*n+(j+1)];
}
// printf("%f %f\n", sum1, sum2);
C[i*n+j] = sum1;
C[i*n+(j+1)] = sum2;
}else if(!(i >= m || j >= n)){
sum1 = 0.0;
//sum2 = 0.0;
for(k = 0; k < k_max; k++){
sum1 += A[i*k_max+k] * B[k*n+j];
//sum2 += A[i*k_max+k] * B[k*n+(j+1)];
}
// printf("%f\n", sum1);
C[i*n+j] = sum1;
//C[i*n+(j+1)] = sum2;
}
}
extern "C" { __host__ void matmult_gpu3(int m, int n, int k, double *h_A, double *h_B, double *h_C){
double *d_A, *d_B, *d_C;
int devices;
cudaGetDeviceCount(&devices);
int A_elems = m*k;
int B_elems = k*n;
int C_elems = m*n;
int size_A = A_elems*sizeof(double);
int size_B = B_elems*sizeof(double);
int size_C = C_elems*sizeof(double);
cudaMalloc((void**)&d_A, size_A);
cudaMalloc((void**)&d_B, size_B);
cudaMalloc((void**)&d_C, size_C);
cudaMemcpy(d_A, h_A, size_A, cudaMemcpyHostToDevice);
cudaMemcpy(d_B, h_B, size_B, cudaMemcpyHostToDevice);
int blockx = 16;
int blocky = 16;
dim3 dimBlock(blockx,blocky,1);
//for column
int gridx = (m/blockx)+1;
int gridy = ((n/blocky)+1)/2 + 1;
//for row
//int gridx = ((m/blockx)+1)/2 + 1;
//int gridy = (n/blocky)+1;
dim3 dimGrid(gridx,gridy,1);
//for column
gpu3_column<<<dimGrid,dimBlock>>>(m,n,k,d_A,d_B,d_C);
//for grid
//gpu3_row<<<dimGrid,dimBlock>>>(m,n,k,d_A,d_B,d_C);
cudaDeviceSynchronize();
cudaMemcpy(h_C, d_C, size_C, cudaMemcpyDeviceToHost);
int i,j;
cudaFree(d_A);
cudaFree(d_B);
cudaFree(d_C);
}
}
|
65d23419b92ad933e638db872e0b3d821a39cea4.hip | // !!! This is a file automatically generated by hipify!!!
/*
* SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NvInfer.h"
#include "common/bertCommon.h"
#include "common/common.cuh"
#include "common/plugin.h"
#include "common/serialize.hpp"
#include <cassert>
#include <cstring>
#include <hip/hip_runtime.h>
#include <vector>
using namespace nvinfer1;
namespace bert
{
template <typename T, unsigned TPB>
__global__ void embLayerNormKernelHFace(int32_t ld, int32_t const* inputIds, int32_t const* tokenIds,
int32_t const* cuSeqlens, float const* beta, float const* gamma, T const* wordEmb, T const* posEmb, T const* tokEmb,
int32_t const wordSize, int32_t const tokSize, T* output)
{
// this code currently assumes the input shape is SxB, row-major => seqPos = s * B + b
// instead we want BxS, row-major => seqPos = b * S + s
hipcub::Sum pairSum;
// 1. lookup word and token of the block
// blockIdx.x = position in the sequence
// blockIdx.y = batch
// gridDim.x = S
// gridDim.y = B
int32_t const s = blockIdx.x;
int32_t const b = blockIdx.y;
int32_t const sumS = cuSeqlens[b];
int32_t const s_b = cuSeqlens[b + 1] - sumS;
if (s >= s_b)
{
return; // This CTA has nothing to do
}
__shared__ int32_t wordId;
__shared__ int32_t tokenId;
T const rld = T(1.f) / T(ld);
// seqPos = b + s * B
// int32_t const seqPos = blockIdx.y + blockIdx.x * gridDim.y;
// int32_t const seqPos = s * B + s;
int32_t const seqPos = sumS + s;
if (threadIdx.x == 0)
{
wordId = inputIds[seqPos];
tokenId = tokenIds[seqPos];
}
__syncthreads();
// 2. load pos/tok/word embeddings and add them toghether
// offset into embeddings is given by wordId * hidden_size
int32_t const poffset = blockIdx.x * ld;
int32_t const woffset = wordId * ld;
int32_t const toffset = tokenId * ld;
// the output offset is given by b * (S*hidden_size) + s * hidden_size
int32_t const outOffset = seqPos * ld;
kvp<T> threadData(0, 0);
if (wordId >= 0 && wordId < wordSize && tokenId >= 0 && tokenId < tokSize)
{
for (int32_t it = threadIdx.x; it < ld; it += TPB)
{
T const w(wordEmb[woffset + it]);
T const t(tokEmb[toffset + it]);
T const p(posEmb[poffset + it]);
T const val = w + t + p;
output[outOffset + it] = val;
T const rldval = rld * val;
threadData = pairSum(threadData, kvp<T>(rldval, rldval * val));
}
}
// 3. layer norm on the sum
layerNorm<T, T, float, TPB>(threadData, ld, outOffset, beta, gamma, output);
}
template <typename T>
int32_t embSkipLayerNormHFace(hipStream_t stream, int32_t ld, int32_t B, int32_t S, int32_t const* inputIds,
int32_t const* tokenIds, int32_t const* cuSeqlens, float const* beta, float const* gamma, T const* wordEmb,
T const* posEmb, T const* tokEmb, int32_t const wordSize, int32_t const tokSize, T* output)
{
constexpr int32_t tpb = 256;
dim3 const grid(S, B, 1);
dim3 const block(tpb, 1, 1);
hipLaunchKernelGGL(( embLayerNormKernelHFace<T, tpb>), dim3(grid), dim3(block), 0, stream,
ld, inputIds, tokenIds, cuSeqlens, beta, gamma, wordEmb, posEmb, tokEmb, wordSize, tokSize, output);
return hipPeekAtLastError();
}
template int32_t embSkipLayerNormHFace<float>(hipStream_t, int32_t, int32_t, int32_t, int32_t const*, int32_t const*,
int32_t const*, float const*, float const*, float const*, float const*, float const*, int32_t const, int32_t const,
float*);
template int32_t embSkipLayerNormHFace<half>(hipStream_t, int32_t, int32_t, int32_t, int32_t const*, int32_t const*,
int32_t const*, float const*, float const*, half const*, half const*, half const*, int32_t const, int32_t const,
half*);
} // namespace bert
| 65d23419b92ad933e638db872e0b3d821a39cea4.cu | /*
* SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NvInfer.h"
#include "common/bertCommon.h"
#include "common/common.cuh"
#include "common/plugin.h"
#include "common/serialize.hpp"
#include <cassert>
#include <cstring>
#include <cuda.h>
#include <vector>
using namespace nvinfer1;
namespace bert
{
template <typename T, unsigned TPB>
__global__ void embLayerNormKernelHFace(int32_t ld, int32_t const* inputIds, int32_t const* tokenIds,
int32_t const* cuSeqlens, float const* beta, float const* gamma, T const* wordEmb, T const* posEmb, T const* tokEmb,
int32_t const wordSize, int32_t const tokSize, T* output)
{
// this code currently assumes the input shape is SxB, row-major => seqPos = s * B + b
// instead we want BxS, row-major => seqPos = b * S + s
cub::Sum pairSum;
// 1. lookup word and token of the block
// blockIdx.x = position in the sequence
// blockIdx.y = batch
// gridDim.x = S
// gridDim.y = B
int32_t const s = blockIdx.x;
int32_t const b = blockIdx.y;
int32_t const sumS = cuSeqlens[b];
int32_t const s_b = cuSeqlens[b + 1] - sumS;
if (s >= s_b)
{
return; // This CTA has nothing to do
}
__shared__ int32_t wordId;
__shared__ int32_t tokenId;
T const rld = T(1.f) / T(ld);
// seqPos = b + s * B
// int32_t const seqPos = blockIdx.y + blockIdx.x * gridDim.y;
// int32_t const seqPos = s * B + s;
int32_t const seqPos = sumS + s;
if (threadIdx.x == 0)
{
wordId = inputIds[seqPos];
tokenId = tokenIds[seqPos];
}
__syncthreads();
// 2. load pos/tok/word embeddings and add them toghether
// offset into embeddings is given by wordId * hidden_size
int32_t const poffset = blockIdx.x * ld;
int32_t const woffset = wordId * ld;
int32_t const toffset = tokenId * ld;
// the output offset is given by b * (S*hidden_size) + s * hidden_size
int32_t const outOffset = seqPos * ld;
kvp<T> threadData(0, 0);
if (wordId >= 0 && wordId < wordSize && tokenId >= 0 && tokenId < tokSize)
{
for (int32_t it = threadIdx.x; it < ld; it += TPB)
{
T const w(wordEmb[woffset + it]);
T const t(tokEmb[toffset + it]);
T const p(posEmb[poffset + it]);
T const val = w + t + p;
output[outOffset + it] = val;
T const rldval = rld * val;
threadData = pairSum(threadData, kvp<T>(rldval, rldval * val));
}
}
// 3. layer norm on the sum
layerNorm<T, T, float, TPB>(threadData, ld, outOffset, beta, gamma, output);
}
template <typename T>
int32_t embSkipLayerNormHFace(cudaStream_t stream, int32_t ld, int32_t B, int32_t S, int32_t const* inputIds,
int32_t const* tokenIds, int32_t const* cuSeqlens, float const* beta, float const* gamma, T const* wordEmb,
T const* posEmb, T const* tokEmb, int32_t const wordSize, int32_t const tokSize, T* output)
{
constexpr int32_t tpb = 256;
dim3 const grid(S, B, 1);
dim3 const block(tpb, 1, 1);
embLayerNormKernelHFace<T, tpb><<<grid, block, 0, stream>>>(
ld, inputIds, tokenIds, cuSeqlens, beta, gamma, wordEmb, posEmb, tokEmb, wordSize, tokSize, output);
return cudaPeekAtLastError();
}
template int32_t embSkipLayerNormHFace<float>(cudaStream_t, int32_t, int32_t, int32_t, int32_t const*, int32_t const*,
int32_t const*, float const*, float const*, float const*, float const*, float const*, int32_t const, int32_t const,
float*);
template int32_t embSkipLayerNormHFace<half>(cudaStream_t, int32_t, int32_t, int32_t, int32_t const*, int32_t const*,
int32_t const*, float const*, float const*, half const*, half const*, half const*, int32_t const, int32_t const,
half*);
} // namespace bert
|
a6f70305cd74715b45a43a03ada766d330155615.hip | // !!! This is a file automatically generated by hipify!!!
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <hip/hip_runtime.h>
#include <hiprand/hiprand_kernel.h>
#include <hiprand/hiprand.h>
#include <rocblas.h>
#include "kernel_misc.h"
#include "prop.h"
#include "file_manager.h"
#include "memory_alloc.h"
#include "train.h"
#include "deform.h"
using namespace std;
float beta = 1.0;
float lambda = 0.000005;
float eta0 = 0.01;
int pitch_x = 32, pitch_y = 32;
int batch_size = 3000;
int NTrain = 30000;
int NTest = 10000;
int N_layer; // include input and output layer
int *N_neuron;
int N, M, N_max; // input and output layer
float **x_cpu;
float **w_cpu;
float **data_test, **data_train;
float **label_test, **label_train;
float **gpu_data_test, **gpu_data_train, **gpu_label_test, **gpu_label_train;
float **x_gpu, **w_gpu, **delta_gpu;
float *curnd;
hiprandGenerator_t curand_gen;
void learning(){
// transfer data
random_init();
cpu_to_gpu_matrix();
cpu_to_gpu_data_test();
// add noise
for(int loop=0; loop<5000; loop++){
cerr << "loop: " << loop << endl;
for(int ib=0; ib<NTrain/batch_size; ib++){
printf("loop, batch: %d, %d\n", loop, ib);
cpu_to_gpu_data_train(ib*batch_size);
// deform_image();
// for each data
for(int i=0; i<batch_size; i++){
// train_step
train_step(i, loop);
}
// calc train error
train_error();
}
// calc test error
test_error();
output_weight();
}
}
int main(){
hipblasInit();
hiprandCreateGenerator(&curand_gen, HIPRAND_RNG_PSEUDO_DEFAULT);
hiprandSetPseudoRandomGeneratorSeed(curand_gen, 0);
load_data();
gpu_alloc();
learning();
gpu_free();
return 0;
} | a6f70305cd74715b45a43a03ada766d330155615.cu |
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cuda.h>
#include <curand_kernel.h>
#include <curand.h>
#include <cublas.h>
#include "kernel_misc.h"
#include "prop.h"
#include "file_manager.h"
#include "memory_alloc.h"
#include "train.h"
#include "deform.h"
using namespace std;
float beta = 1.0;
float lambda = 0.000005;
float eta0 = 0.01;
int pitch_x = 32, pitch_y = 32;
int batch_size = 3000;
int NTrain = 30000;
int NTest = 10000;
int N_layer; // include input and output layer
int *N_neuron;
int N, M, N_max; // input and output layer
float **x_cpu;
float **w_cpu;
float **data_test, **data_train;
float **label_test, **label_train;
float **gpu_data_test, **gpu_data_train, **gpu_label_test, **gpu_label_train;
float **x_gpu, **w_gpu, **delta_gpu;
float *curnd;
curandGenerator_t curand_gen;
void learning(){
// transfer data
random_init();
cpu_to_gpu_matrix();
cpu_to_gpu_data_test();
// add noise
for(int loop=0; loop<5000; loop++){
cerr << "loop: " << loop << endl;
for(int ib=0; ib<NTrain/batch_size; ib++){
printf("loop, batch: %d, %d\n", loop, ib);
cpu_to_gpu_data_train(ib*batch_size);
// deform_image();
// for each data
for(int i=0; i<batch_size; i++){
// train_step
train_step(i, loop);
}
// calc train error
train_error();
}
// calc test error
test_error();
output_weight();
}
}
int main(){
cublasInit();
curandCreateGenerator(&curand_gen, CURAND_RNG_PSEUDO_DEFAULT);
curandSetPseudoRandomGeneratorSeed(curand_gen, 0);
load_data();
gpu_alloc();
learning();
gpu_free();
return 0;
} |
9984fbd15258d4dee017206e1ea13d3a5d78a8d4.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
-- MAGMA (version 1.4.1) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
December 2013
@generated c Tue Dec 17 13:18:45 2013
*/
#include <stdio.h>
#include "common_magma.h"
#include "magmablas.h"
#define PRECISION_c
#define A(i, j) (A + (i) + (j)*lda) // A(i, j) means at i row, j column
#define cswap_bs 64
//#if (GPUSHMEM < 200)
#define cgeru_bs 512 // 512 is max threads for 1.x cards
//#else
//#define cgeru_bs 1024
//#endif
void magma_cswap(
magma_int_t n, magmaFloatComplex *x, magma_int_t i, magma_int_t j, magma_int_t incx);
void magma_cscal_cgeru(
magma_int_t m, magma_int_t n, magmaFloatComplex *A, magma_int_t lda);
extern "C" magma_int_t
magma_cgetf2_gpu(
magma_int_t m, magma_int_t n,
magmaFloatComplex *A, magma_int_t lda,
magma_int_t *ipiv,
magma_int_t* info )
{
/* -- MAGMA (version 1.4.1) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
December 2013
CGETF2 computes an LU factorization of a general m-by-n matrix A
using partial pivoting with row interchanges.
The factorization has the form
A = P * L * U
where P is a permutation matrix, L is lower triangular with unit
diagonal elements (lower trapezoidal if m > n), and U is upper
triangular (upper trapezoidal if m < n).
This is the right-looking Level 2 BLAS version of the algorithm.
Arguments
=========
M (input) INTEGER
The number of rows of the matrix A. M >= 0.
N (input) INTEGER
The number of columns of the matrix A. N >= 0 and N <= 1024.
On CUDA architecture 1.x cards, N <= 512.
A (input/output) COMPLEX array, dimension (LDA,N)
On entry, the m by n matrix to be factored.
On exit, the factors L and U from the factorization
A = P*L*U; the unit diagonal elements of L are not stored.
LDA (input) INTEGER
The leading dimension of the array A. LDA >= max(1,M).
IPIV (output) INTEGER array, dimension (min(M,N))
The pivot indices; for 1 <= i <= min(M,N), row i of the
matrix was interchanged with row IPIV(i).
INFO (output) INTEGER
= 0: successful exit
< 0: if INFO = -k, the k-th argument had an illegal value
> 0: if INFO = k, U(k,k) is exactly zero. The factorization
has been completed, but the factor U is exactly
singular, and division by zero will occur if it is used
to solve a system of equations.
===================================================================== */
*info = 0;
if (m < 0) {
*info = -1;
} else if (n < 0 || n > cgeru_bs) {
*info = -2;
} else if (lda < max(1,m)) {
*info = -4;
}
if (*info != 0) {
magma_xerbla( __func__, -(*info) );
return *info;
}
// Quick return if possible
if (m == 0 || n == 0) {
return *info;
}
magma_int_t min_mn = min(m, n);
magma_int_t j, jp;
for( j=0; j < min_mn; j++ ) {
hipDeviceSetCacheConfig( hipFuncCachePreferShared );
// Find pivot and test for singularity.
jp = j - 1 + hipblasIcamax(m-j, A(j,j), 1);
ipiv[j] = jp + 1; // ipiv uses Fortran one-based index
// Can't check value of A since it is on GPU
//if ( A(jp, j) != 0.0) {
hipDeviceSetCacheConfig( hipFuncCachePreferL1 );
// Apply the interchange to columns 1:N.
// TODO: replace with pre-existing BLAS-standard cswap routine,
// e.g., magmablas_cswap or hipblasCswap
if (jp != j) {
magma_cswap(n, A, j, jp, lda);
//magmablas_cswap( n, A(j,0), lda, A(jp,0), lda );
//hipblasCswap( n, A(j,0), lda, A(jp,0), lda );
}
// Compute elements J+1:M of J-th column.
if (j < m) {
magma_cscal_cgeru(m-j, n-j, A(j, j), lda);
}
//}
//else if (*info == 0) {
// *info = j;
//}
}
return *info;
}
__global__
void kernel_cswap(int n, magmaFloatComplex *x, int i, int j, int incx)
{
int id = blockIdx.x * cswap_bs + threadIdx.x;
if (id < n) {
magmaFloatComplex tmp = x[i + incx*id];
x[i + incx*id] = x[j + incx*id];
x[j + incx*id] = tmp;
}
}
void magma_cswap(magma_int_t n, magmaFloatComplex *x, magma_int_t i, magma_int_t j, magma_int_t incx)
{
/*
cswap two row vectors: ith and jth
*/
dim3 threads(cswap_bs, 1, 1);
int num_blocks = (n - 1)/cswap_bs + 1;
dim3 grid(num_blocks,1);
hipLaunchKernelGGL(( kernel_cswap), dim3(grid), dim3(threads), 0, magma_stream , n, x, i, j, incx);
}
// dynamically allocated shared memory, set to size n when the kernel is launched.
// See CUDA Guide B.2.3
extern __shared__ magmaFloatComplex shared_data[];
__global__
void kernel_cscal_cgeru(int m, int n, magmaFloatComplex *A, int lda)
{
magmaFloatComplex *shared_y = shared_data;
int tid = blockIdx.x * cgeru_bs + threadIdx.x;
magmaFloatComplex reg = MAGMA_C_ZERO;
if (threadIdx.x < n) {
shared_y[threadIdx.x] = A[lda * threadIdx.x];
}
__syncthreads();
if (tid < m && tid > 0) {
reg = A[tid];
reg *= MAGMA_C_DIV(MAGMA_C_ONE, shared_y[0]);
A[tid] = reg;
#pragma unroll
for(int i=1; i < n; i++) {
A[tid + i*lda] += (MAGMA_C_NEG_ONE) * shared_y[i] * reg;
}
}
}
void magma_cscal_cgeru(magma_int_t m, magma_int_t n, magmaFloatComplex *A, magma_int_t lda)
{
/*
Specialized kernel which merged cscal and cgeru the two kernels
1) cscale the first column vector A(1:M-1,0) with 1/A(0,0);
2) Performe a cgeru Operation for trailing matrix of A(1:M-1,1:N-1) += alpha*x*y**T, where
alpha := -1.0; x := A(1:M-1,0) and y:= A(0,1:N-1);
*/
dim3 threads(cgeru_bs, 1, 1);
int num_blocks = (m - 1)/cgeru_bs + 1;
dim3 grid(num_blocks,1);
size_t shared_size = sizeof(magmaFloatComplex)*(n);
hipLaunchKernelGGL(( kernel_cscal_cgeru), dim3(grid), dim3(threads), shared_size, magma_stream, m, n, A, lda);
}
| 9984fbd15258d4dee017206e1ea13d3a5d78a8d4.cu | /*
-- MAGMA (version 1.4.1) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
December 2013
@generated c Tue Dec 17 13:18:45 2013
*/
#include <stdio.h>
#include "common_magma.h"
#include "magmablas.h"
#define PRECISION_c
#define A(i, j) (A + (i) + (j)*lda) // A(i, j) means at i row, j column
#define cswap_bs 64
//#if (GPUSHMEM < 200)
#define cgeru_bs 512 // 512 is max threads for 1.x cards
//#else
//#define cgeru_bs 1024
//#endif
void magma_cswap(
magma_int_t n, magmaFloatComplex *x, magma_int_t i, magma_int_t j, magma_int_t incx);
void magma_cscal_cgeru(
magma_int_t m, magma_int_t n, magmaFloatComplex *A, magma_int_t lda);
extern "C" magma_int_t
magma_cgetf2_gpu(
magma_int_t m, magma_int_t n,
magmaFloatComplex *A, magma_int_t lda,
magma_int_t *ipiv,
magma_int_t* info )
{
/* -- MAGMA (version 1.4.1) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
December 2013
CGETF2 computes an LU factorization of a general m-by-n matrix A
using partial pivoting with row interchanges.
The factorization has the form
A = P * L * U
where P is a permutation matrix, L is lower triangular with unit
diagonal elements (lower trapezoidal if m > n), and U is upper
triangular (upper trapezoidal if m < n).
This is the right-looking Level 2 BLAS version of the algorithm.
Arguments
=========
M (input) INTEGER
The number of rows of the matrix A. M >= 0.
N (input) INTEGER
The number of columns of the matrix A. N >= 0 and N <= 1024.
On CUDA architecture 1.x cards, N <= 512.
A (input/output) COMPLEX array, dimension (LDA,N)
On entry, the m by n matrix to be factored.
On exit, the factors L and U from the factorization
A = P*L*U; the unit diagonal elements of L are not stored.
LDA (input) INTEGER
The leading dimension of the array A. LDA >= max(1,M).
IPIV (output) INTEGER array, dimension (min(M,N))
The pivot indices; for 1 <= i <= min(M,N), row i of the
matrix was interchanged with row IPIV(i).
INFO (output) INTEGER
= 0: successful exit
< 0: if INFO = -k, the k-th argument had an illegal value
> 0: if INFO = k, U(k,k) is exactly zero. The factorization
has been completed, but the factor U is exactly
singular, and division by zero will occur if it is used
to solve a system of equations.
===================================================================== */
*info = 0;
if (m < 0) {
*info = -1;
} else if (n < 0 || n > cgeru_bs) {
*info = -2;
} else if (lda < max(1,m)) {
*info = -4;
}
if (*info != 0) {
magma_xerbla( __func__, -(*info) );
return *info;
}
// Quick return if possible
if (m == 0 || n == 0) {
return *info;
}
magma_int_t min_mn = min(m, n);
magma_int_t j, jp;
for( j=0; j < min_mn; j++ ) {
cudaDeviceSetCacheConfig( cudaFuncCachePreferShared );
// Find pivot and test for singularity.
jp = j - 1 + cublasIcamax(m-j, A(j,j), 1);
ipiv[j] = jp + 1; // ipiv uses Fortran one-based index
// Can't check value of A since it is on GPU
//if ( A(jp, j) != 0.0) {
cudaDeviceSetCacheConfig( cudaFuncCachePreferL1 );
// Apply the interchange to columns 1:N.
// TODO: replace with pre-existing BLAS-standard cswap routine,
// e.g., magmablas_cswap or cublasCswap
if (jp != j) {
magma_cswap(n, A, j, jp, lda);
//magmablas_cswap( n, A(j,0), lda, A(jp,0), lda );
//cublasCswap( n, A(j,0), lda, A(jp,0), lda );
}
// Compute elements J+1:M of J-th column.
if (j < m) {
magma_cscal_cgeru(m-j, n-j, A(j, j), lda);
}
//}
//else if (*info == 0) {
// *info = j;
//}
}
return *info;
}
__global__
void kernel_cswap(int n, magmaFloatComplex *x, int i, int j, int incx)
{
int id = blockIdx.x * cswap_bs + threadIdx.x;
if (id < n) {
magmaFloatComplex tmp = x[i + incx*id];
x[i + incx*id] = x[j + incx*id];
x[j + incx*id] = tmp;
}
}
void magma_cswap(magma_int_t n, magmaFloatComplex *x, magma_int_t i, magma_int_t j, magma_int_t incx)
{
/*
cswap two row vectors: ith and jth
*/
dim3 threads(cswap_bs, 1, 1);
int num_blocks = (n - 1)/cswap_bs + 1;
dim3 grid(num_blocks,1);
kernel_cswap<<< grid, threads, 0, magma_stream >>>(n, x, i, j, incx);
}
// dynamically allocated shared memory, set to size n when the kernel is launched.
// See CUDA Guide B.2.3
extern __shared__ magmaFloatComplex shared_data[];
__global__
void kernel_cscal_cgeru(int m, int n, magmaFloatComplex *A, int lda)
{
magmaFloatComplex *shared_y = shared_data;
int tid = blockIdx.x * cgeru_bs + threadIdx.x;
magmaFloatComplex reg = MAGMA_C_ZERO;
if (threadIdx.x < n) {
shared_y[threadIdx.x] = A[lda * threadIdx.x];
}
__syncthreads();
if (tid < m && tid > 0) {
reg = A[tid];
reg *= MAGMA_C_DIV(MAGMA_C_ONE, shared_y[0]);
A[tid] = reg;
#pragma unroll
for(int i=1; i < n; i++) {
A[tid + i*lda] += (MAGMA_C_NEG_ONE) * shared_y[i] * reg;
}
}
}
void magma_cscal_cgeru(magma_int_t m, magma_int_t n, magmaFloatComplex *A, magma_int_t lda)
{
/*
Specialized kernel which merged cscal and cgeru the two kernels
1) cscale the first column vector A(1:M-1,0) with 1/A(0,0);
2) Performe a cgeru Operation for trailing matrix of A(1:M-1,1:N-1) += alpha*x*y**T, where
alpha := -1.0; x := A(1:M-1,0) and y:= A(0,1:N-1);
*/
dim3 threads(cgeru_bs, 1, 1);
int num_blocks = (m - 1)/cgeru_bs + 1;
dim3 grid(num_blocks,1);
size_t shared_size = sizeof(magmaFloatComplex)*(n);
kernel_cscal_cgeru<<< grid, threads, shared_size, magma_stream>>>(m, n, A, lda);
}
|
f5d92d3bb6586cbe880a95a164665b6b44f265e8.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <sys/time.h>
#define stride 4
/* overload atomicAdd for double */
#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
#else
static __inline__ __device__ double atomicAdd(double *address, double val) {
unsigned long long int* address_as_ull = (unsigned long long int*)address;
unsigned long long int old = *address_as_ull, assumed;
if (val==0.0)
return __longlong_as_double(old);
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val +__longlong_as_double(assumed)));
} while (assumed != old);
return __longlong_as_double(old);
}
#endif
// global variables
int rows, columns;
__device__ int dev_rows, dev_columns, dev_sparse_count = 0;
__device__ double dev_h, dev_norm;
// device functions
__global__ void get_exp(double *x, double *y, double *w);
__global__ void get_exp_shared(double *x, double *y, double *w);
__global__ void multiply_arrays(double *x, double *w, double *y_new);
__global__ void get_sum_per_row(double *w, double *sums);
__global__ void mean_shift(double *y_new, double *sums_array, double *y, double *norms);
__global__ void compute_norms(double *norms, double *norm_per_block);
// local cpu functions
double *read_data(const char *name);
int check_results(double *y, char *name);
void write_results(char **argv, int iterations, double time);
double
now()
{
struct timeval tv;
gettimeofday(&tv, 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
int main(int argc, char **argv)
{
double *x, *y, h, epsilon, norm, *sums_array;
double *dev_x, *dev_y, *dev_w, *dev_y_new, *dev_sums_array, *dev_norms;
double *dev_blocks_norm;
int *dev_counter_per_row;
if (argc < 6){
fprintf(stderr, "it needs 5 arguments, which are: h iterations data validation_data dims\n");
exit(1);
}
// initialize arrays at the host
int iterations = atoi(argv[2]);
columns = atoi(argv[5]);
x = read_data(argv[3]);
printf("row %d\n", rows);
y = (double *) malloc(sizeof *y * rows * columns);
memcpy(y, x, sizeof(double) * rows * columns);
sums_array = (double *) malloc(sizeof *sums_array * rows);
h = atoi(argv[1]);
epsilon = 1e-4*h;
hipError_t error;
// parameters for reduction per block for the computation of norm
int blocks_size = 512;
int thread_size = blocks_size;
double *blocks_norm = (double *) malloc(sizeof *blocks_norm * (blocks_size / 2));
// initialize at the device
error = hipMalloc((void **) &dev_x, rows * columns * sizeof(double));
if (error)
printf("malloc dev_x %s\n", hipGetErrorString(error));
error = hipMalloc((void **) &dev_y, rows * columns * sizeof(double));
if (error)
printf("malloc dev_y %s\n", hipGetErrorString(error));
error = hipMalloc((void **) &dev_y_new, rows * columns * sizeof(double));
if (error)
printf("malloc dev_y_new %s\n", hipGetErrorString(error));
error = hipMalloc((void **) &dev_sums_array, rows * sizeof(double));
if (error)
printf("malloc dev_sums_array %s\n" ,hipGetErrorString(error));
error = hipMalloc((void **) &dev_w, (rows * rows) * sizeof(double));
// allocate max memory for sparse
int paranom = 2;
while (error){
error = hipMalloc((void **) &dev_w, (rows * rows) / paranom++ * sizeof(double));
if (paranom > 20){
fprintf(stderr, "%s\n", "no memory");
return 1;
}
}
error = hipMalloc((void **) &dev_counter_per_row, rows * sizeof(int));
if (error)
printf("malloc dev_counter_per_row %s\n", hipGetErrorString(error));
error = hipMalloc((void **) &dev_norms, blocks_size * thread_size * sizeof(double));
if (error)
printf("malloc dev_norms %s\n", hipGetErrorString(error));
error = hipMalloc((void **) &dev_blocks_norm, (blocks_size / 2) * sizeof(double));
if (error)
printf("malloc dev_blocks_norm %s\n", hipGetErrorString(error));
// copy initial arrays from host to device
hipMemcpy(dev_x, x, rows * columns * sizeof(double), hipMemcpyHostToDevice);
hipMemcpy(dev_y, y, rows * columns * sizeof(double), hipMemcpyHostToDevice);
hipMemcpyToSymbol(dev_rows, &rows, sizeof(int));
hipMemcpyToSymbol(dev_columns, &columns, sizeof(int));
hipMemcpyToSymbol(dev_h, &h, sizeof(double));
norm = INT_MAX;
double time_passed;
double t_start = now();
// for(int j = 0; j < iterations; j++){
int j = 0;
while(sqrt(norm) > epsilon){
norm = 0;
// fill sparse array
hipLaunchKernelGGL(( get_exp), dim3(256), dim3(64), 0, 0, dev_x, dev_y, dev_w);
hipDeviceSynchronize();
// zero new array for the sums
memset(y, 0, rows * columns * sizeof(double));
hipMemcpy(dev_y_new, y, rows * columns * sizeof(double), hipMemcpyHostToDevice);
hipLaunchKernelGGL(( multiply_arrays), dim3(256), dim3(64), 0, 0, dev_x, dev_w, dev_y_new);
hipDeviceSynchronize();
// sum sparse
memset(sums_array, 0, rows * sizeof(double));
hipMemcpy(dev_sums_array, sums_array, rows * sizeof(double), hipMemcpyHostToDevice);
hipLaunchKernelGGL(( get_sum_per_row), dim3(512), dim3(512), 0, 0, dev_w, dev_sums_array);
hipDeviceSynchronize();
// compute mean shift
hipLaunchKernelGGL(( mean_shift), dim3(blocks_size), dim3(512), 0, 0, dev_y_new, dev_sums_array, dev_y, dev_norms);
hipDeviceSynchronize();
hipLaunchKernelGGL(( compute_norms), dim3(blocks_size / 2), dim3(512), 0, 0, dev_norms, dev_blocks_norm);
hipDeviceSynchronize();
hipMemcpy(blocks_norm, dev_blocks_norm, (blocks_size / 2) * sizeof(double), hipMemcpyDeviceToHost);
for (int k = 0; k < (blocks_size/2); k++)
norm += blocks_norm[k];
printf("iteration %d error %f \n", j, sqrt(norm));
j++;
}
time_passed = now() - t_start;
printf("time passed %f\n", time_passed);
hipMemcpy(y, dev_y, rows * columns * sizeof(double), hipMemcpyDeviceToHost);
check_results(y, argv[4]);
FILE *f = fopen("res.txt", "w");
for (int i = 0; i < rows; i++){
for (int j = 0; j < columns; j++)
fprintf(f, "%f ", y[i * columns + j]);
fprintf(f, "\n");
}
fclose(f);
// clean up gpu
hipFree((void *) &dev_x);
hipFree((void *) &dev_y);
hipFree((void *) &dev_w);
hipFree((void *) &dev_sums_array);
hipFree((void *) &dev_norms);
hipFree((void *) &dev_blocks_norm);
hipFree((void *) &dev_y_new);
// clean up cpu
free(x);
free(y);
free(sums_array);
return 0;
}
__global__ void
multiply_arrays(double *x, double *w, double *y_new)
{
double tmp = 0;
int row, column;
double dist;
int global_thread_id = threadIdx.x + blockIdx.x * blockDim.x;
// get the first element of one (row,column,dist) of sparse
int w_tid = (global_thread_id) * 3;
while (w_tid < 3 * dev_sparse_count){
row = w[w_tid];
column = w[w_tid + 1];
dist = w[w_tid + 2];
// mulitply distance with every element in the row
for(int i = 0; i < dev_columns; i++){
tmp = dist * x[column * dev_columns + i];
atomicAdd(&y_new[row * dev_columns + i], tmp);
}
w_tid += blockDim.x * gridDim.x * 3;
}
}
__global__ void
get_sum_per_row(double *w, double *sums)
{
int global_thread_id = threadIdx.x + blockIdx.x * blockDim.x;
int row;
double dist;
int w_tid = (global_thread_id) * 3;
while (w_tid < dev_sparse_count * 3){
row = w[w_tid];
dist = w[w_tid + 2];
atomicAdd(&sums[row], dist);
w_tid += blockDim.x * gridDim.x * 3;
}
}
__global__ void
mean_shift(double *y_new, double *sums_array, double *y, double *norms)
{
int y_tid = threadIdx.x + blockIdx.x * blockDim.x;
int sum_tid = y_tid / dev_columns;
double m_dif = 0;
int norms_tid = y_tid;
norms[norms_tid] = 0;
dev_sparse_count = 0;
while (y_tid < (dev_rows * dev_columns)){
y_new[y_tid] /= sums_array[sum_tid];
m_dif = y_new[y_tid] - y[y_tid];
norms[norms_tid] += pow(m_dif, 2);
y[y_tid] = y_new[y_tid];
y_tid += gridDim.x * blockDim.x;
sum_tid = y_tid / dev_columns;
}
}
__global__ void
compute_norms(double *norms, double *norm_per_block)
{
int n_tid = 2 * (threadIdx.x + blockIdx.x * blockDim.x);
int i = 1;
int initial_tid = n_tid / 2;
int block_limit = gridDim.x * blockDim.x;
int block_end = 2 * (blockIdx.x * blockDim.x + blockDim.x) - 1;
if (n_tid < (2 * block_limit)){
while ( (i < (2 * blockDim.x)) && n_tid < block_end &&
(n_tid + i) <= block_end){
norms[n_tid] += norms[n_tid + i];
/* update n_tid with respect to the start of the block
double the offset of n_tid to kill half of the threads */
n_tid = n_tid + i * 2 * (initial_tid - (blockIdx.x * blockDim.x));
i *= 2;
__syncthreads();
}
// element with threadid = 0 adds the sum
if (!((initial_tid) % blockDim.x))
norm_per_block[blockIdx.x] = norms[n_tid];
}
}
__device__ double
compute_distance(double *y_i, double *x_j, double limit)
{
double dist = 0, tmp;
for (int i = 0; i < dev_columns; i++){
tmp = y_i[i] - x_j[i];
dist += tmp * tmp;
if (dist > limit)
return 0;
}
return exp( -dist / (2 * limit));
}
__global__ void
get_exp(double *x, double *y, double *w)
{
double dist;
double limit = dev_h * dev_h;
int pos;
long int global_thread_id = threadIdx.x + blockIdx.x * blockDim.x;
long int y_tid = global_thread_id / (dev_rows / stride);
long int x_tid = stride * (global_thread_id % (dev_rows / stride));
while(y_tid < dev_rows && x_tid < (dev_rows)){
for (int i = 0; (i < stride); i++){
dist = compute_distance(&y[y_tid * dev_columns], &x[x_tid * dev_columns], limit);
// insert elements to sparse
if (dist){
pos = atomicAdd(&dev_sparse_count, 1);
w[pos * 3] = y_tid;
w[pos * 3 + 1] = x_tid;
w[pos * 3 + 2] = dist;
}
x_tid++;
}
global_thread_id += blockDim.x * gridDim.x;
y_tid = global_thread_id / (dev_rows / stride);
x_tid = stride * (global_thread_id % (dev_rows/stride));
}
}
double *
read_data(const char *name)
{
FILE *f;
f = fopen(name, "rb");
fseek(f, 0L, SEEK_END);
int pos = ftell(f);
fseek(f, 0L, SEEK_SET);
int number_elements = pos / sizeof(double);
double *x = (double *) malloc(sizeof *x * number_elements);
fread(x, sizeof *x, number_elements, f);
rows = number_elements / columns;
fclose(f);
return x;
}
int
check_results(double *y, char *name)
{
double *mat_res = read_data(name);
double dist = 0;
for (int i = 0; i < rows; i++){
for (int j = 0; j < columns; j++){
dist += pow(y[i * columns + j] - mat_res[i * columns + j], 2);
// if (dist > 1)
// printf("%f %f %f\n", y[i * columns + j], mat_res[i * columns + j], dist);
}
}
printf("done dist %.10f \n", dist);
return 0;
}
| f5d92d3bb6586cbe880a95a164665b6b44f265e8.cu | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <sys/time.h>
#define stride 4
/* overload atomicAdd for double */
#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
#else
static __inline__ __device__ double atomicAdd(double *address, double val) {
unsigned long long int* address_as_ull = (unsigned long long int*)address;
unsigned long long int old = *address_as_ull, assumed;
if (val==0.0)
return __longlong_as_double(old);
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val +__longlong_as_double(assumed)));
} while (assumed != old);
return __longlong_as_double(old);
}
#endif
// global variables
int rows, columns;
__device__ int dev_rows, dev_columns, dev_sparse_count = 0;
__device__ double dev_h, dev_norm;
// device functions
__global__ void get_exp(double *x, double *y, double *w);
__global__ void get_exp_shared(double *x, double *y, double *w);
__global__ void multiply_arrays(double *x, double *w, double *y_new);
__global__ void get_sum_per_row(double *w, double *sums);
__global__ void mean_shift(double *y_new, double *sums_array, double *y, double *norms);
__global__ void compute_norms(double *norms, double *norm_per_block);
// local cpu functions
double *read_data(const char *name);
int check_results(double *y, char *name);
void write_results(char **argv, int iterations, double time);
double
now()
{
struct timeval tv;
gettimeofday(&tv, 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
int main(int argc, char **argv)
{
double *x, *y, h, epsilon, norm, *sums_array;
double *dev_x, *dev_y, *dev_w, *dev_y_new, *dev_sums_array, *dev_norms;
double *dev_blocks_norm;
int *dev_counter_per_row;
if (argc < 6){
fprintf(stderr, "it needs 5 arguments, which are: h iterations data validation_data dims\n");
exit(1);
}
// initialize arrays at the host
int iterations = atoi(argv[2]);
columns = atoi(argv[5]);
x = read_data(argv[3]);
printf("row %d\n", rows);
y = (double *) malloc(sizeof *y * rows * columns);
memcpy(y, x, sizeof(double) * rows * columns);
sums_array = (double *) malloc(sizeof *sums_array * rows);
h = atoi(argv[1]);
epsilon = 1e-4*h;
cudaError_t error;
// parameters for reduction per block for the computation of norm
int blocks_size = 512;
int thread_size = blocks_size;
double *blocks_norm = (double *) malloc(sizeof *blocks_norm * (blocks_size / 2));
// initialize at the device
error = cudaMalloc((void **) &dev_x, rows * columns * sizeof(double));
if (error)
printf("malloc dev_x %s\n", cudaGetErrorString(error));
error = cudaMalloc((void **) &dev_y, rows * columns * sizeof(double));
if (error)
printf("malloc dev_y %s\n", cudaGetErrorString(error));
error = cudaMalloc((void **) &dev_y_new, rows * columns * sizeof(double));
if (error)
printf("malloc dev_y_new %s\n", cudaGetErrorString(error));
error = cudaMalloc((void **) &dev_sums_array, rows * sizeof(double));
if (error)
printf("malloc dev_sums_array %s\n" ,cudaGetErrorString(error));
error = cudaMalloc((void **) &dev_w, (rows * rows) * sizeof(double));
// allocate max memory for sparse
int paranom = 2;
while (error){
error = cudaMalloc((void **) &dev_w, (rows * rows) / paranom++ * sizeof(double));
if (paranom > 20){
fprintf(stderr, "%s\n", "no memory");
return 1;
}
}
error = cudaMalloc((void **) &dev_counter_per_row, rows * sizeof(int));
if (error)
printf("malloc dev_counter_per_row %s\n", cudaGetErrorString(error));
error = cudaMalloc((void **) &dev_norms, blocks_size * thread_size * sizeof(double));
if (error)
printf("malloc dev_norms %s\n", cudaGetErrorString(error));
error = cudaMalloc((void **) &dev_blocks_norm, (blocks_size / 2) * sizeof(double));
if (error)
printf("malloc dev_blocks_norm %s\n", cudaGetErrorString(error));
// copy initial arrays from host to device
cudaMemcpy(dev_x, x, rows * columns * sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpy(dev_y, y, rows * columns * sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(dev_rows, &rows, sizeof(int));
cudaMemcpyToSymbol(dev_columns, &columns, sizeof(int));
cudaMemcpyToSymbol(dev_h, &h, sizeof(double));
norm = INT_MAX;
double time_passed;
double t_start = now();
// for(int j = 0; j < iterations; j++){
int j = 0;
while(sqrt(norm) > epsilon){
norm = 0;
// fill sparse array
get_exp<<<256, 64>>>(dev_x, dev_y, dev_w);
cudaDeviceSynchronize();
// zero new array for the sums
memset(y, 0, rows * columns * sizeof(double));
cudaMemcpy(dev_y_new, y, rows * columns * sizeof(double), cudaMemcpyHostToDevice);
multiply_arrays<<<256, 64>>>(dev_x, dev_w, dev_y_new);
cudaDeviceSynchronize();
// sum sparse
memset(sums_array, 0, rows * sizeof(double));
cudaMemcpy(dev_sums_array, sums_array, rows * sizeof(double), cudaMemcpyHostToDevice);
get_sum_per_row<<<512, 512>>>(dev_w, dev_sums_array);
cudaDeviceSynchronize();
// compute mean shift
mean_shift<<<blocks_size, 512>>>(dev_y_new, dev_sums_array, dev_y, dev_norms);
cudaDeviceSynchronize();
compute_norms<<<blocks_size / 2, 512>>>(dev_norms, dev_blocks_norm);
cudaDeviceSynchronize();
cudaMemcpy(blocks_norm, dev_blocks_norm, (blocks_size / 2) * sizeof(double), cudaMemcpyDeviceToHost);
for (int k = 0; k < (blocks_size/2); k++)
norm += blocks_norm[k];
printf("iteration %d error %f \n", j, sqrt(norm));
j++;
}
time_passed = now() - t_start;
printf("time passed %f\n", time_passed);
cudaMemcpy(y, dev_y, rows * columns * sizeof(double), cudaMemcpyDeviceToHost);
check_results(y, argv[4]);
FILE *f = fopen("res.txt", "w");
for (int i = 0; i < rows; i++){
for (int j = 0; j < columns; j++)
fprintf(f, "%f ", y[i * columns + j]);
fprintf(f, "\n");
}
fclose(f);
// clean up gpu
cudaFree((void *) &dev_x);
cudaFree((void *) &dev_y);
cudaFree((void *) &dev_w);
cudaFree((void *) &dev_sums_array);
cudaFree((void *) &dev_norms);
cudaFree((void *) &dev_blocks_norm);
cudaFree((void *) &dev_y_new);
// clean up cpu
free(x);
free(y);
free(sums_array);
return 0;
}
__global__ void
multiply_arrays(double *x, double *w, double *y_new)
{
double tmp = 0;
int row, column;
double dist;
int global_thread_id = threadIdx.x + blockIdx.x * blockDim.x;
// get the first element of one (row,column,dist) of sparse
int w_tid = (global_thread_id) * 3;
while (w_tid < 3 * dev_sparse_count){
row = w[w_tid];
column = w[w_tid + 1];
dist = w[w_tid + 2];
// mulitply distance with every element in the row
for(int i = 0; i < dev_columns; i++){
tmp = dist * x[column * dev_columns + i];
atomicAdd(&y_new[row * dev_columns + i], tmp);
}
w_tid += blockDim.x * gridDim.x * 3;
}
}
__global__ void
get_sum_per_row(double *w, double *sums)
{
int global_thread_id = threadIdx.x + blockIdx.x * blockDim.x;
int row;
double dist;
int w_tid = (global_thread_id) * 3;
while (w_tid < dev_sparse_count * 3){
row = w[w_tid];
dist = w[w_tid + 2];
atomicAdd(&sums[row], dist);
w_tid += blockDim.x * gridDim.x * 3;
}
}
__global__ void
mean_shift(double *y_new, double *sums_array, double *y, double *norms)
{
int y_tid = threadIdx.x + blockIdx.x * blockDim.x;
int sum_tid = y_tid / dev_columns;
double m_dif = 0;
int norms_tid = y_tid;
norms[norms_tid] = 0;
dev_sparse_count = 0;
while (y_tid < (dev_rows * dev_columns)){
y_new[y_tid] /= sums_array[sum_tid];
m_dif = y_new[y_tid] - y[y_tid];
norms[norms_tid] += pow(m_dif, 2);
y[y_tid] = y_new[y_tid];
y_tid += gridDim.x * blockDim.x;
sum_tid = y_tid / dev_columns;
}
}
__global__ void
compute_norms(double *norms, double *norm_per_block)
{
int n_tid = 2 * (threadIdx.x + blockIdx.x * blockDim.x);
int i = 1;
int initial_tid = n_tid / 2;
int block_limit = gridDim.x * blockDim.x;
int block_end = 2 * (blockIdx.x * blockDim.x + blockDim.x) - 1;
if (n_tid < (2 * block_limit)){
while ( (i < (2 * blockDim.x)) && n_tid < block_end &&
(n_tid + i) <= block_end){
norms[n_tid] += norms[n_tid + i];
/* update n_tid with respect to the start of the block
double the offset of n_tid to kill half of the threads */
n_tid = n_tid + i * 2 * (initial_tid - (blockIdx.x * blockDim.x));
i *= 2;
__syncthreads();
}
// element with threadid = 0 adds the sum
if (!((initial_tid) % blockDim.x))
norm_per_block[blockIdx.x] = norms[n_tid];
}
}
__device__ double
compute_distance(double *y_i, double *x_j, double limit)
{
double dist = 0, tmp;
for (int i = 0; i < dev_columns; i++){
tmp = y_i[i] - x_j[i];
dist += tmp * tmp;
if (dist > limit)
return 0;
}
return exp( -dist / (2 * limit));
}
__global__ void
get_exp(double *x, double *y, double *w)
{
double dist;
double limit = dev_h * dev_h;
int pos;
long int global_thread_id = threadIdx.x + blockIdx.x * blockDim.x;
long int y_tid = global_thread_id / (dev_rows / stride);
long int x_tid = stride * (global_thread_id % (dev_rows / stride));
while(y_tid < dev_rows && x_tid < (dev_rows)){
for (int i = 0; (i < stride); i++){
dist = compute_distance(&y[y_tid * dev_columns], &x[x_tid * dev_columns], limit);
// insert elements to sparse
if (dist){
pos = atomicAdd(&dev_sparse_count, 1);
w[pos * 3] = y_tid;
w[pos * 3 + 1] = x_tid;
w[pos * 3 + 2] = dist;
}
x_tid++;
}
global_thread_id += blockDim.x * gridDim.x;
y_tid = global_thread_id / (dev_rows / stride);
x_tid = stride * (global_thread_id % (dev_rows/stride));
}
}
double *
read_data(const char *name)
{
FILE *f;
f = fopen(name, "rb");
fseek(f, 0L, SEEK_END);
int pos = ftell(f);
fseek(f, 0L, SEEK_SET);
int number_elements = pos / sizeof(double);
double *x = (double *) malloc(sizeof *x * number_elements);
fread(x, sizeof *x, number_elements, f);
rows = number_elements / columns;
fclose(f);
return x;
}
int
check_results(double *y, char *name)
{
double *mat_res = read_data(name);
double dist = 0;
for (int i = 0; i < rows; i++){
for (int j = 0; j < columns; j++){
dist += pow(y[i * columns + j] - mat_res[i * columns + j], 2);
// if (dist > 1)
// printf("%f %f %f\n", y[i * columns + j], mat_res[i * columns + j], dist);
}
}
printf("done dist %.10f \n", dist);
return 0;
}
|
3cbb6b078529346ac7c917c776e9ee79818274e9.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <vector>
#include "caffe/filler.hpp"
#include "caffe/layers/inner_distance_layer.hpp"
#include "caffe/util/math_functions.hpp"
namespace caffe {
#define sign(x) (Dtype(0) < (x)) - ((x) < Dtype(0))
template <typename Dtype>
__global__ void kernel_channel_dot(const int num, const int dim,
const Dtype* data_1, const Dtype* data_2,
Dtype* channel_dot) {
CUDA_KERNEL_LOOP(index, num) {
Dtype dot = 0;
for (int d = 0; d < dim; ++d) {
dot += data_1[index * dim + d] * data_2[index * dim + d];
}
channel_dot[index] = dot;
}
}
template <typename Dtype>
__global__ void kernel_channel_scal(const int num, const int dim,
const Dtype* norm_data,
Dtype* input_output_data) {
CUDA_KERNEL_LOOP(index, num * dim) {
int n = index / dim;
input_output_data[index] *= norm_data[n];
}
}
template <typename Dtype>
__global__ void inner_distance_forward_L2(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, Dtype* top_data) {
CUDA_KERNEL_LOOP(index, M_ * N_) {
int m = index / N_;
int n = index % N_;
Dtype sum = Dtype(0);
for (int k = 0; k < K_; ++k) {
sum += (bottom_data[m * K_ + k] - weight[n * K_ + k]) * (bottom_data[m * K_ + k] - weight[n * K_ + k]);
}
top_data[index] = sum;
}
}
template <typename Dtype>
__global__ void inner_distance_forward_L1(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, Dtype* top_data) {
CUDA_KERNEL_LOOP(index, M_ * N_) {
int m = index / N_;
int n = index % N_;
Dtype sum = Dtype(0);
for (int k = 0; k < K_; ++k) {
sum += abs(bottom_data[m * K_ + k] - weight[n * K_ + k]);
}
top_data[index] = sum;
}
}
template <typename Dtype>
void InnerDistanceLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const Dtype* bottom_data = bottom[0]->gpu_data();
Dtype* top_data = top[0]->mutable_gpu_data();
const Dtype* weight = bottom.size() >= 2 ? bottom[1]->gpu_data() : this->blobs_[0]->gpu_data();
if (normalize_ && bottom.size() == 1) {
Dtype* mutable_weight = this->blobs_[0]->mutable_gpu_data();
Dtype* weight_norm_data = weight_norm_.mutable_gpu_data();
// NOLINT_NEXT_LINE(whitespace/operators)
kernel_channel_dot<Dtype> << <CAFFE_GET_BLOCKS(N_),
CAFFE_CUDA_NUM_THREADS >> > (N_, K_, weight, weight, weight_norm_data);
caffe_gpu_powx(N_, weight_norm_data, Dtype(-0.5), weight_norm_data);
// NOLINT_NEXT_LINE(whitespace/operators)
kernel_channel_scal<Dtype> << <CAFFE_GET_BLOCKS(N_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (N_, K_, weight_norm_data, mutable_weight);
}
if (distance_type_ == "L2") {
// NOLINT_NEXT_LINE(whitespace/operators)
hipLaunchKernelGGL(( inner_distance_forward_L2<Dtype>) , dim3(CAFFE_GET_BLOCKS(M_ * N_)),
dim3(CAFFE_CUDA_NUM_THREADS) , 0, 0, M_, N_, K_,
bottom_data, weight, top_data);
}
else if (distance_type_ == "L1") {
// NOLINT_NEXT_LINE(whitespace/operators)
hipLaunchKernelGGL(( inner_distance_forward_L1<Dtype>) , dim3(CAFFE_GET_BLOCKS(M_ * N_)),
dim3(CAFFE_CUDA_NUM_THREADS) , 0, 0, M_, N_, K_,
bottom_data, weight, top_data);
}
else {
NOT_IMPLEMENTED;
}
}
template <typename Dtype>
__global__ void inner_distance_backward_L2(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* bottom_diff) {
CUDA_KERNEL_LOOP(index, M_ * K_) {
int m = index / K_;
int k = index % K_;
for (int n = 0; n < N_; ++n) {
bottom_diff[index] += top_diff[m * N_ + n] * (bottom_data[m * K_ + k] - weight[n * K_ + k]) * Dtype(2);
}
}
}
template <typename Dtype>
__global__ void inner_distance_backward_L1(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* bottom_diff) {
CUDA_KERNEL_LOOP(index, M_ * K_) {
int m = index / K_;
int k = index % K_;
for (int n = 0; n < N_; ++n) {
bottom_diff[index] += top_diff[m * N_ + n] * sign(bottom_data[m * K_ + k] - weight[n * K_ + k]);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L2(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, N_ * K_) {
int n = index / K_;
int k = index % K_;
for (int m = 0; m < M_; ++m) {
weight_diff[index] += top_diff[m * N_ + n] * (weight[index] - bottom_data[m * K_ + k]) * Dtype(2);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L2_center_only(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight,
const Dtype* label_data, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, K_) {
int k = index;
for (int m = 0; m < M_; ++m) {
int n = static_cast<int>(label_data[m]);
weight_diff[n * K_ + k] += top_diff[m * N_ + n] * (weight[n * K_ + k] - bottom_data[m * K_ + k]) * Dtype(2);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L1(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, N_ * K_) {
int n = index / K_;
int k = index % K_;
for (int m = 0; m < M_; ++m) {
weight_diff[index] += top_diff[m * N_ + n] * sign(weight[index] - bottom_data[m * K_ + k]);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L1_center_only(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight,
const Dtype* label_data, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, K_) {
int k = index;
for (int m = 0; m < M_; ++m) {
int n = static_cast<int>(label_data[m]);
weight_diff[n * K_ + k] += top_diff[m * N_ + n] * sign(weight[n * K_ + k] - bottom_data[m * K_ + k]);
}
}
}
template <typename Dtype>
void InnerDistanceLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down,
const vector<Blob<Dtype>*>& bottom) {
const Dtype* top_diff = top[0]->gpu_diff();
const Dtype* bottom_data = bottom[0]->gpu_data();
const Dtype* weight = bottom.size() >= 2 ? bottom[1]->gpu_data() : this->blobs_[0]->gpu_data();
if ((bottom.size() == 1 && this->param_propagate_down_[0]) ||
(bottom.size() >= 2 && propagate_down[1])) {
Dtype* weight_diff = bottom.size() >= 2 ? bottom[1]->mutable_gpu_diff() : this->blobs_[0]->mutable_gpu_diff();
const Dtype* label_data = NULL;
if (update_center_only_) {
label_data = bottom[bottom.size() - 1]->gpu_data();
}
// Gradient with respect to weight
if (distance_type_ == "L2") {
if (update_center_only_) {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L2_center_only<Dtype> << <CAFFE_GET_BLOCKS(K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, label_data, top_diff, weight_diff);
}
else {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L2<Dtype> << <CAFFE_GET_BLOCKS(N_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, weight_diff);
}
}
else if (distance_type_ == "L1") {
if (update_center_only_) {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L1_center_only<Dtype> << <CAFFE_GET_BLOCKS(K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, label_data, top_diff, weight_diff);
}
else {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L1<Dtype> << <CAFFE_GET_BLOCKS(N_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, weight_diff);
}
}
else {
NOT_IMPLEMENTED;
}
}
if (propagate_down[0]) {
Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();
caffe_gpu_set<Dtype>(M_ * K_, 0, bottom_diff);
if (distance_type_ == "L2") {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_backward_L2<Dtype> << <CAFFE_GET_BLOCKS(M_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, bottom_diff);
}
else if (distance_type_ == "L1") {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_backward_L1<Dtype> << <CAFFE_GET_BLOCKS(M_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, bottom_diff);
}
else {
NOT_IMPLEMENTED;
}
}
}
INSTANTIATE_LAYER_GPU_FUNCS(InnerDistanceLayer);
} // namespace caffe
| 3cbb6b078529346ac7c917c776e9ee79818274e9.cu | #include <vector>
#include "caffe/filler.hpp"
#include "caffe/layers/inner_distance_layer.hpp"
#include "caffe/util/math_functions.hpp"
namespace caffe {
#define sign(x) (Dtype(0) < (x)) - ((x) < Dtype(0))
template <typename Dtype>
__global__ void kernel_channel_dot(const int num, const int dim,
const Dtype* data_1, const Dtype* data_2,
Dtype* channel_dot) {
CUDA_KERNEL_LOOP(index, num) {
Dtype dot = 0;
for (int d = 0; d < dim; ++d) {
dot += data_1[index * dim + d] * data_2[index * dim + d];
}
channel_dot[index] = dot;
}
}
template <typename Dtype>
__global__ void kernel_channel_scal(const int num, const int dim,
const Dtype* norm_data,
Dtype* input_output_data) {
CUDA_KERNEL_LOOP(index, num * dim) {
int n = index / dim;
input_output_data[index] *= norm_data[n];
}
}
template <typename Dtype>
__global__ void inner_distance_forward_L2(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, Dtype* top_data) {
CUDA_KERNEL_LOOP(index, M_ * N_) {
int m = index / N_;
int n = index % N_;
Dtype sum = Dtype(0);
for (int k = 0; k < K_; ++k) {
sum += (bottom_data[m * K_ + k] - weight[n * K_ + k]) * (bottom_data[m * K_ + k] - weight[n * K_ + k]);
}
top_data[index] = sum;
}
}
template <typename Dtype>
__global__ void inner_distance_forward_L1(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, Dtype* top_data) {
CUDA_KERNEL_LOOP(index, M_ * N_) {
int m = index / N_;
int n = index % N_;
Dtype sum = Dtype(0);
for (int k = 0; k < K_; ++k) {
sum += abs(bottom_data[m * K_ + k] - weight[n * K_ + k]);
}
top_data[index] = sum;
}
}
template <typename Dtype>
void InnerDistanceLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const Dtype* bottom_data = bottom[0]->gpu_data();
Dtype* top_data = top[0]->mutable_gpu_data();
const Dtype* weight = bottom.size() >= 2 ? bottom[1]->gpu_data() : this->blobs_[0]->gpu_data();
if (normalize_ && bottom.size() == 1) {
Dtype* mutable_weight = this->blobs_[0]->mutable_gpu_data();
Dtype* weight_norm_data = weight_norm_.mutable_gpu_data();
// NOLINT_NEXT_LINE(whitespace/operators)
kernel_channel_dot<Dtype> << <CAFFE_GET_BLOCKS(N_),
CAFFE_CUDA_NUM_THREADS >> > (N_, K_, weight, weight, weight_norm_data);
caffe_gpu_powx(N_, weight_norm_data, Dtype(-0.5), weight_norm_data);
// NOLINT_NEXT_LINE(whitespace/operators)
kernel_channel_scal<Dtype> << <CAFFE_GET_BLOCKS(N_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (N_, K_, weight_norm_data, mutable_weight);
}
if (distance_type_ == "L2") {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_forward_L2<Dtype> <<<CAFFE_GET_BLOCKS(M_ * N_),
CAFFE_CUDA_NUM_THREADS >>> (M_, N_, K_,
bottom_data, weight, top_data);
}
else if (distance_type_ == "L1") {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_forward_L1<Dtype> <<<CAFFE_GET_BLOCKS(M_ * N_),
CAFFE_CUDA_NUM_THREADS >>> (M_, N_, K_,
bottom_data, weight, top_data);
}
else {
NOT_IMPLEMENTED;
}
}
template <typename Dtype>
__global__ void inner_distance_backward_L2(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* bottom_diff) {
CUDA_KERNEL_LOOP(index, M_ * K_) {
int m = index / K_;
int k = index % K_;
for (int n = 0; n < N_; ++n) {
bottom_diff[index] += top_diff[m * N_ + n] * (bottom_data[m * K_ + k] - weight[n * K_ + k]) * Dtype(2);
}
}
}
template <typename Dtype>
__global__ void inner_distance_backward_L1(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* bottom_diff) {
CUDA_KERNEL_LOOP(index, M_ * K_) {
int m = index / K_;
int k = index % K_;
for (int n = 0; n < N_; ++n) {
bottom_diff[index] += top_diff[m * N_ + n] * sign(bottom_data[m * K_ + k] - weight[n * K_ + k]);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L2(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, N_ * K_) {
int n = index / K_;
int k = index % K_;
for (int m = 0; m < M_; ++m) {
weight_diff[index] += top_diff[m * N_ + n] * (weight[index] - bottom_data[m * K_ + k]) * Dtype(2);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L2_center_only(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight,
const Dtype* label_data, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, K_) {
int k = index;
for (int m = 0; m < M_; ++m) {
int n = static_cast<int>(label_data[m]);
weight_diff[n * K_ + k] += top_diff[m * N_ + n] * (weight[n * K_ + k] - bottom_data[m * K_ + k]) * Dtype(2);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L1(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, N_ * K_) {
int n = index / K_;
int k = index % K_;
for (int m = 0; m < M_; ++m) {
weight_diff[index] += top_diff[m * N_ + n] * sign(weight[index] - bottom_data[m * K_ + k]);
}
}
}
template <typename Dtype>
__global__ void inner_distance_weight_backward_L1_center_only(const int M_, const int N_, const int K_,
const Dtype* bottom_data, const Dtype* weight,
const Dtype* label_data, const Dtype* top_diff,
Dtype* weight_diff) {
CUDA_KERNEL_LOOP(index, K_) {
int k = index;
for (int m = 0; m < M_; ++m) {
int n = static_cast<int>(label_data[m]);
weight_diff[n * K_ + k] += top_diff[m * N_ + n] * sign(weight[n * K_ + k] - bottom_data[m * K_ + k]);
}
}
}
template <typename Dtype>
void InnerDistanceLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down,
const vector<Blob<Dtype>*>& bottom) {
const Dtype* top_diff = top[0]->gpu_diff();
const Dtype* bottom_data = bottom[0]->gpu_data();
const Dtype* weight = bottom.size() >= 2 ? bottom[1]->gpu_data() : this->blobs_[0]->gpu_data();
if ((bottom.size() == 1 && this->param_propagate_down_[0]) ||
(bottom.size() >= 2 && propagate_down[1])) {
Dtype* weight_diff = bottom.size() >= 2 ? bottom[1]->mutable_gpu_diff() : this->blobs_[0]->mutable_gpu_diff();
const Dtype* label_data = NULL;
if (update_center_only_) {
label_data = bottom[bottom.size() - 1]->gpu_data();
}
// Gradient with respect to weight
if (distance_type_ == "L2") {
if (update_center_only_) {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L2_center_only<Dtype> << <CAFFE_GET_BLOCKS(K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, label_data, top_diff, weight_diff);
}
else {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L2<Dtype> << <CAFFE_GET_BLOCKS(N_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, weight_diff);
}
}
else if (distance_type_ == "L1") {
if (update_center_only_) {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L1_center_only<Dtype> << <CAFFE_GET_BLOCKS(K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, label_data, top_diff, weight_diff);
}
else {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_weight_backward_L1<Dtype> << <CAFFE_GET_BLOCKS(N_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, weight_diff);
}
}
else {
NOT_IMPLEMENTED;
}
}
if (propagate_down[0]) {
Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();
caffe_gpu_set<Dtype>(M_ * K_, 0, bottom_diff);
if (distance_type_ == "L2") {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_backward_L2<Dtype> << <CAFFE_GET_BLOCKS(M_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, bottom_diff);
}
else if (distance_type_ == "L1") {
// NOLINT_NEXT_LINE(whitespace/operators)
inner_distance_backward_L1<Dtype> << <CAFFE_GET_BLOCKS(M_ * K_),
CAFFE_CUDA_NUM_THREADS >> > (M_, N_, K_,
bottom_data, weight, top_diff, bottom_diff);
}
else {
NOT_IMPLEMENTED;
}
}
}
INSTANTIATE_LAYER_GPU_FUNCS(InnerDistanceLayer);
} // namespace caffe
|
d267dc0a6dc6b34aea730c88e0dd64a3964bd404.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <vector>
#include "caffe/common.hpp"
#include "caffe/layer.hpp"
#include "caffe/util/im2col.hpp"
#include "caffe/layers/neighbor_dist_layer.hpp"
namespace caffe
{
template <typename Dtype>
__global__ void neighbor_dist_gpu_kernel(const int n, const Dtype* data_im,
const int height, const int width, const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int height_col, const int width_col, const int channels,const Dtype fill_data,
Dtype* data_col) {
CUDA_KERNEL_LOOP(index, n) {
int w_out = index % width_col;
int h_index = index / width_col;
int h_out = h_index % height_col;
int w_in_index = h_index / height_col;
int w_in = w_in_index % kernel_w;
int h_in_index = w_in_index / kernel_w;
int h_in = h_in_index % kernel_h;
int ch_out_idx = w_in_index;
h_in += h_out * stride_h - pad_h;
w_in += w_out* stride_w - pad_w;
//int h_in_center = h_out * stride_h - pad_h + (int)(height / 2.0);
//int w_in_center = w_out* stride_w - pad_w + (int)(width / 2.0);
int h_in_center = h_out * stride_h - pad_h + (int)(kernel_h / 2.0);
int w_in_center = w_out* stride_w - pad_w + (int)(kernel_w / 2.0);
if (h_in >= 0 && w_in >= 0 && h_in < height&&w_in < width)
{
const Dtype* data_im_ptr = data_im +
h_in*width + w_in;
const Dtype* data_im_center_ptr = data_im +
h_in_center*width + w_in_center;
int tmp_offset = height*width;
for (int ch = 0; ch < channels; ++ch)
{
data_col[index] += (data_im_ptr[0] - data_im_center_ptr[0])*(data_im_ptr[0] - data_im_center_ptr[0]);
data_im_ptr += tmp_offset;
data_im_center_ptr += tmp_offset;
}
data_col[index] = std::sqrt(data_col[index]);
}
else
{
data_col[index] = fill_data;
}
}
}
template <typename Dtype>
void NeighborDistLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top)
{
int num_kernels = kernel_h_*kernel_w_*height_out_ * width_out_;
const Dtype* bottom_data = bottom[0]->gpu_data();
Dtype* top_data = top[0]->mutable_gpu_data();
Dtype max_num = -1;//std::numeric_limits<Dtype>::max() - 1;
caffe_gpu_set(top[0]->count(), (Dtype)0, top[0]->mutable_gpu_data());
for (int n = 0; n < num_; ++n)
{
neighbor_dist_gpu_kernel<Dtype> << <CAFFE_GET_BLOCKS(num_kernels), CAFFE_CUDA_NUM_THREADS >> >(
num_kernels, bottom_data + bottom[0]->offset(n), height_, width_,
kernel_h_, kernel_w_, pad_h_,
pad_w_, stride_h_, stride_w_, height_out_,
width_out_, channels_, max_num,
top_data + top[0]->offset(n));
CUDA_POST_KERNEL_CHECK;
}
}
template <typename Dtype>
__global__ void neighbor_dist_backward_gpu_kernel(const int n, const Dtype* in_diff,
const Dtype* in_data,const Dtype* out_data,
const int height, const int width, const int channels,
const int patch_h, const int patch_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int height_col, const int width_col,
Dtype* out_diff) {
CUDA_KERNEL_LOOP(index, n) {
Dtype val = 0;
int w = index % width + pad_w;
int h = (index / width) % height + pad_h;
int c = index / (width * height);
// compute the start and end of the output
int w_col_start = (w < patch_w) ? 0 : (w - patch_w) / stride_w + 1;
int w_col_end = min(w / stride_w + 1, width_col);
int h_col_start = (h < patch_h) ? 0 : (h - patch_h) / stride_h + 1;
int h_col_end = min(h / stride_h + 1, height_col);
int offset = (h * patch_w + w) * height_col * width_col;
int coeff_h_col = (1 - stride_h * patch_w * height_col) * width_col;
int coeff_w_col = (1 - stride_w * height_col * width_col);
for (int h_col = h_col_start; h_col < h_col_end; ++h_col)
{
for (int w_col = w_col_start; w_col < w_col_end; ++w_col)
{
int w_center = w_col*stride_w - pad_w + (int)(patch_w / 2.0);
int h_center = h_col*stride_h - pad_h + (int)(patch_h / 2.0);
int idx_center = (c*height + h_center)*width + w_center;
int out_idx = offset + h_col * coeff_h_col + w_col * coeff_w_col;
if (out_data[out_idx] != 0)
{
val += in_diff[out_idx] * (in_data[index] - in_data[idx_center]) / out_data[out_idx];
}
}
}
int w_col = (w - (int)(patch_w / 2.0)) / stride_w;
int h_col = (h - (int)(patch_h / 2.0)) / stride_h;
for (int k_h = 0; k_h < patch_h; k_h++)
{
int h_in = k_h + h_col*stride_h - pad_h;
for (int k_w = 0; k_w < patch_w; k_w++)
{
int w_in = k_w + w_col*stride_w - pad_w;
int out_idx = ((k_h*patch_w + k_w)*height_col + h_col)*width_col + w_col;
if (h_in >= 0 && w_in >= 0 && h_in < height && w_in < width
&& out_data[out_idx] != 0 /*&& k_h != (int)(patch_h / 2.0) && k_w != (int)(patch_w / 2.0)*/) // why
{
int d_idx = (c*height + h_in)*width + w_in;
val -= in_diff[out_idx] / out_data[out_idx] * (in_data[d_idx] - in_data[index]);
}
}
}
out_diff[index] = val;
}
}
template <typename Dtype>
void NeighborDistLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom)
{
if (propagate_down[0])
{
int num_kernels = channels_*height_*width_;
for (int n = 0; n < bottom[0]->num(); ++n)
{
neighbor_dist_backward_gpu_kernel<Dtype> << <CAFFE_GET_BLOCKS(num_kernels), CAFFE_CUDA_NUM_THREADS >> >(
num_kernels, top[0]->gpu_diff() + top[0]->offset(n),
bottom[0]->gpu_data() + bottom[0]->offset(n),
top[0]->gpu_data() + top[0]->offset(n),
height_, width_, channels_, kernel_h_, kernel_w_,
pad_h_, pad_w_, stride_h_, stride_w_, height_out_, width_out_,
bottom[0]->mutable_gpu_diff() + bottom[0]->offset(n));
}
}
}
INSTANTIATE_LAYER_GPU_FUNCS(NeighborDistLayer);
} | d267dc0a6dc6b34aea730c88e0dd64a3964bd404.cu | #include <vector>
#include "caffe/common.hpp"
#include "caffe/layer.hpp"
#include "caffe/util/im2col.hpp"
#include "caffe/layers/neighbor_dist_layer.hpp"
namespace caffe
{
template <typename Dtype>
__global__ void neighbor_dist_gpu_kernel(const int n, const Dtype* data_im,
const int height, const int width, const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int height_col, const int width_col, const int channels,const Dtype fill_data,
Dtype* data_col) {
CUDA_KERNEL_LOOP(index, n) {
int w_out = index % width_col;
int h_index = index / width_col;
int h_out = h_index % height_col;
int w_in_index = h_index / height_col;
int w_in = w_in_index % kernel_w;
int h_in_index = w_in_index / kernel_w;
int h_in = h_in_index % kernel_h;
int ch_out_idx = w_in_index;
h_in += h_out * stride_h - pad_h;
w_in += w_out* stride_w - pad_w;
//int h_in_center = h_out * stride_h - pad_h + (int)(height / 2.0);
//int w_in_center = w_out* stride_w - pad_w + (int)(width / 2.0);
int h_in_center = h_out * stride_h - pad_h + (int)(kernel_h / 2.0);
int w_in_center = w_out* stride_w - pad_w + (int)(kernel_w / 2.0);
if (h_in >= 0 && w_in >= 0 && h_in < height&&w_in < width)
{
const Dtype* data_im_ptr = data_im +
h_in*width + w_in;
const Dtype* data_im_center_ptr = data_im +
h_in_center*width + w_in_center;
int tmp_offset = height*width;
for (int ch = 0; ch < channels; ++ch)
{
data_col[index] += (data_im_ptr[0] - data_im_center_ptr[0])*(data_im_ptr[0] - data_im_center_ptr[0]);
data_im_ptr += tmp_offset;
data_im_center_ptr += tmp_offset;
}
data_col[index] = std::sqrt(data_col[index]);
}
else
{
data_col[index] = fill_data;
}
}
}
template <typename Dtype>
void NeighborDistLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top)
{
int num_kernels = kernel_h_*kernel_w_*height_out_ * width_out_;
const Dtype* bottom_data = bottom[0]->gpu_data();
Dtype* top_data = top[0]->mutable_gpu_data();
Dtype max_num = -1;//std::numeric_limits<Dtype>::max() - 1;
caffe_gpu_set(top[0]->count(), (Dtype)0, top[0]->mutable_gpu_data());
for (int n = 0; n < num_; ++n)
{
neighbor_dist_gpu_kernel<Dtype> << <CAFFE_GET_BLOCKS(num_kernels), CAFFE_CUDA_NUM_THREADS >> >(
num_kernels, bottom_data + bottom[0]->offset(n), height_, width_,
kernel_h_, kernel_w_, pad_h_,
pad_w_, stride_h_, stride_w_, height_out_,
width_out_, channels_, max_num,
top_data + top[0]->offset(n));
CUDA_POST_KERNEL_CHECK;
}
}
template <typename Dtype>
__global__ void neighbor_dist_backward_gpu_kernel(const int n, const Dtype* in_diff,
const Dtype* in_data,const Dtype* out_data,
const int height, const int width, const int channels,
const int patch_h, const int patch_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int height_col, const int width_col,
Dtype* out_diff) {
CUDA_KERNEL_LOOP(index, n) {
Dtype val = 0;
int w = index % width + pad_w;
int h = (index / width) % height + pad_h;
int c = index / (width * height);
// compute the start and end of the output
int w_col_start = (w < patch_w) ? 0 : (w - patch_w) / stride_w + 1;
int w_col_end = min(w / stride_w + 1, width_col);
int h_col_start = (h < patch_h) ? 0 : (h - patch_h) / stride_h + 1;
int h_col_end = min(h / stride_h + 1, height_col);
int offset = (h * patch_w + w) * height_col * width_col;
int coeff_h_col = (1 - stride_h * patch_w * height_col) * width_col;
int coeff_w_col = (1 - stride_w * height_col * width_col);
for (int h_col = h_col_start; h_col < h_col_end; ++h_col)
{
for (int w_col = w_col_start; w_col < w_col_end; ++w_col)
{
int w_center = w_col*stride_w - pad_w + (int)(patch_w / 2.0);
int h_center = h_col*stride_h - pad_h + (int)(patch_h / 2.0);
int idx_center = (c*height + h_center)*width + w_center;
int out_idx = offset + h_col * coeff_h_col + w_col * coeff_w_col;
if (out_data[out_idx] != 0)
{
val += in_diff[out_idx] * (in_data[index] - in_data[idx_center]) / out_data[out_idx];
}
}
}
int w_col = (w - (int)(patch_w / 2.0)) / stride_w;
int h_col = (h - (int)(patch_h / 2.0)) / stride_h;
for (int k_h = 0; k_h < patch_h; k_h++)
{
int h_in = k_h + h_col*stride_h - pad_h;
for (int k_w = 0; k_w < patch_w; k_w++)
{
int w_in = k_w + w_col*stride_w - pad_w;
int out_idx = ((k_h*patch_w + k_w)*height_col + h_col)*width_col + w_col;
if (h_in >= 0 && w_in >= 0 && h_in < height && w_in < width
&& out_data[out_idx] != 0 /*&& k_h != (int)(patch_h / 2.0) && k_w != (int)(patch_w / 2.0)*/) // why
{
int d_idx = (c*height + h_in)*width + w_in;
val -= in_diff[out_idx] / out_data[out_idx] * (in_data[d_idx] - in_data[index]);
}
}
}
out_diff[index] = val;
}
}
template <typename Dtype>
void NeighborDistLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom)
{
if (propagate_down[0])
{
int num_kernels = channels_*height_*width_;
for (int n = 0; n < bottom[0]->num(); ++n)
{
neighbor_dist_backward_gpu_kernel<Dtype> << <CAFFE_GET_BLOCKS(num_kernels), CAFFE_CUDA_NUM_THREADS >> >(
num_kernels, top[0]->gpu_diff() + top[0]->offset(n),
bottom[0]->gpu_data() + bottom[0]->offset(n),
top[0]->gpu_data() + top[0]->offset(n),
height_, width_, channels_, kernel_h_, kernel_w_,
pad_h_, pad_w_, stride_h_, stride_w_, height_out_, width_out_,
bottom[0]->mutable_gpu_diff() + bottom[0]->offset(n));
}
}
}
INSTANTIATE_LAYER_GPU_FUNCS(NeighborDistLayer);
} |
8c10fc6322a0feb2b13478d692ba37d515abe0cb.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "color.h"
#include "image.h"
#include "platform.h"
#include "sphere.h"
#include "spheres.h"
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
#define SPHERE_COUNT 1000
#define SPHERE_MIN_RADIUS 20.0f
#define SPHERE_MAX_RADIUS 100.0f
#define SPHERE_MIN_Z 500.0f
#define SPHERE_MAX_Z 10000000.0f
int main(int argc, char *argv[])
{
image_t out_image;
image_init(&out_image, 1024, 1024);
#ifdef __NVCC__
/* TODO: Allocate memory for the image on the GPU device. */
// save pointer to CPU mem
dev_image_channel_t* out_image_data = out_image.data;
hipMalloc(&out_image.data, out_image.data_size);
//hipMemcpy(d_out_image.data, out_image_data);
#endif
sphere_t *spheres =
spheres_create_random(
SPHERE_COUNT,
SPHERE_MIN_RADIUS, SPHERE_MAX_RADIUS,
0.0f, (float) out_image.width,
0.0f, (float) out_image.height,
SPHERE_MIN_Z, SPHERE_MAX_Z
);
#ifdef __NVCC__
/* TODO: Allocate memory (`hipMalloc`) for spheres on the GPU device. */
dev_size_t spheres_size = sizeof(*spheres) * SPHERE_COUNT;
sphere_t* d_spheres;
hipMalloc(&d_spheres, spheres_size);
/* TODO: Copy sphere data from the CPU world to the GPU memory (`hipMemcpy`). */
hipMemcpy(d_spheres, spheres, spheres_size, hipMemcpyHostToDevice);
#endif
#ifndef __NVCC__
fputs("CPU path is used.\n", stderr);
spheres_raytrace(spheres, SPHERE_COUNT, out_image);
#else
fputs("GPU path is used.\n", stderr);
/* TODO: Decide on how many threads and blocks do you need, considering
that we may not have more than 1024 threads per every block. */
dim3 threads_per_block(32, 32);
dim3 blocks(out_image.width / threads_per_block.x, out_image.height / threads_per_block.y);
/* TODO: Start the kernel with the pointers to the sphere data and the image
on the GPU. The kernel will run on multiple cores and execution
units in parallel for every pixel. */
hipLaunchKernelGGL(( spheres_raytrace), dim3(blocks), dim3(threads_per_block), 0, 0, d_spheres, SPHERE_COUNT, out_image);
/* TODO: For debugging purposes, you may check for the last error with the
`hipGetLastError` call and the `hipGetErrorString` call to print
the error message. */
/* TODO: Copy the image data from the GPU back to the CPU (`hipMemcpy`). */
hipMemcpy(out_image_data, out_image.data, out_image.data_size, hipMemcpyDeviceToHost);
hipFree(&out_image.data);
out_image.data = out_image_data;
/* TODO: Synchronize execution with the CPU (`hipDeviceSynchronize`). */
hipDeviceSynchronize();
#endif
image_print_as_ppm(&out_image);
end:
#ifdef __NVCC__
/* TODO: Free the GPU memory (`hipFree`). */
hipFree(&d_spheres);
#endif
spheres_free(spheres);
image_free_data(&out_image);
return 0;
}
| 8c10fc6322a0feb2b13478d692ba37d515abe0cb.cu | #include "color.h"
#include "image.h"
#include "platform.h"
#include "sphere.h"
#include "spheres.h"
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
#define SPHERE_COUNT 1000
#define SPHERE_MIN_RADIUS 20.0f
#define SPHERE_MAX_RADIUS 100.0f
#define SPHERE_MIN_Z 500.0f
#define SPHERE_MAX_Z 10000000.0f
int main(int argc, char *argv[])
{
image_t out_image;
image_init(&out_image, 1024, 1024);
#ifdef __NVCC__
/* TODO: Allocate memory for the image on the GPU device. */
// save pointer to CPU mem
dev_image_channel_t* out_image_data = out_image.data;
cudaMalloc(&out_image.data, out_image.data_size);
//cudaMemcpy(d_out_image.data, out_image_data);
#endif
sphere_t *spheres =
spheres_create_random(
SPHERE_COUNT,
SPHERE_MIN_RADIUS, SPHERE_MAX_RADIUS,
0.0f, (float) out_image.width,
0.0f, (float) out_image.height,
SPHERE_MIN_Z, SPHERE_MAX_Z
);
#ifdef __NVCC__
/* TODO: Allocate memory (`cudaMalloc`) for spheres on the GPU device. */
dev_size_t spheres_size = sizeof(*spheres) * SPHERE_COUNT;
sphere_t* d_spheres;
cudaMalloc(&d_spheres, spheres_size);
/* TODO: Copy sphere data from the CPU world to the GPU memory (`cudaMemcpy`). */
cudaMemcpy(d_spheres, spheres, spheres_size, cudaMemcpyHostToDevice);
#endif
#ifndef __NVCC__
fputs("CPU path is used.\n", stderr);
spheres_raytrace(spheres, SPHERE_COUNT, out_image);
#else
fputs("GPU path is used.\n", stderr);
/* TODO: Decide on how many threads and blocks do you need, considering
that we may not have more than 1024 threads per every block. */
dim3 threads_per_block(32, 32);
dim3 blocks(out_image.width / threads_per_block.x, out_image.height / threads_per_block.y);
/* TODO: Start the kernel with the pointers to the sphere data and the image
on the GPU. The kernel will run on multiple cores and execution
units in parallel for every pixel. */
spheres_raytrace<<<blocks, threads_per_block>>>(d_spheres, SPHERE_COUNT, out_image);
/* TODO: For debugging purposes, you may check for the last error with the
`cudaGetLastError` call and the `cudaGetErrorString` call to print
the error message. */
/* TODO: Copy the image data from the GPU back to the CPU (`cudaMemcpy`). */
cudaMemcpy(out_image_data, out_image.data, out_image.data_size, cudaMemcpyDeviceToHost);
cudaFree(&out_image.data);
out_image.data = out_image_data;
/* TODO: Synchronize execution with the CPU (`cudaDeviceSynchronize`). */
cudaDeviceSynchronize();
#endif
image_print_as_ppm(&out_image);
end:
#ifdef __NVCC__
/* TODO: Free the GPU memory (`cudaFree`). */
cudaFree(&d_spheres);
#endif
spheres_free(spheres);
image_free_data(&out_image);
return 0;
}
|
e60acaf412fa35f5439f92962407c37cf22eefd4.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
#define BLOCK_SIZE 32 // submatrix size
#define N 256 // matrix size is N*N
typedef struct {
int n;
int* elements;
} Matrix;
__device__ float GetElement(const Matrix A, int row, int col) {
return A.elements[row * N + col];
}
__device__ void SetElement(Matrix A, int row, int col, int value) {
A.elements[row * N + col] = value;
}
__device__ Matrix GetSubMatrix(Matrix A, int row, int col, int n) {
Matrix ASub;
ASub.n = BLOCK_SIZE;
ASub.elements = &A.elements[n * BLOCK_SIZE * row + BLOCK_SIZE * col];
return ASub;
}
__global__ void matMulKernel(int* a, int* b, int* c, int n) {
int blockRow = blockIdx.y;
int blockCol = blockIdx.x;
Matrix cc;
cc.elements = c;
Matrix aa;
aa.elements = a;
Matrix bb;
bb.elements = b;
Matrix Csub = GetSubMatrix(cc, blockRow, blockCol,n);
float Cvalue = 0;
int row = threadIdx.y;
int col = threadIdx.x;
for (int m = 0; m < (N / BLOCK_SIZE); ++m) {
Matrix Asub = GetSubMatrix(aa, blockRow, m,n);
Matrix Bsub = GetSubMatrix(bb, m, blockCol,n);
__shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
__shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];
As[row][col] = GetElement(Asub, row, col);
Bs[row][col] = GetElement(Bsub, row, col);
__syncthreads();
for (int e = 0; e < BLOCK_SIZE; ++e)
Cvalue += As[row][e] * Bs[e][col];
__syncthreads();
}
SetElement(Csub, row, col, Cvalue);
}
int** matMulCPU(int** a, int** b, int** c, int n) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
c[i][j] = 0;
for (int k = 0; k < n; k++)
c[i][j] += a[i][k] * b[k][j];
}
return c;
}
bool checkResult(int** a, int* b, int n) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (a[i][j] != b[N * i + j])
return false;
return true;
}
int main(int argc, char* argv[])
{
srand(time(NULL));
int numBytes = N * N * sizeof(int);
int** a_c;
int** b_c;
int** c_c;
a_c = new int* [N];
for (int i = 0; i < N; i++)
a_c[i] = new int[N];
b_c = new int* [N];
for (int i = 0; i < N; i++)
b_c[i] = new int[N];
c_c = new int* [N];
for (int i = 0; i < N; i++)
c_c[i] = new int[N];
int* a = new int[N * N];
int* b = new int[N * N];
int* c = new int[N * N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
{
int k = N * i + j;
a[k] = (rand()) % 100;
b[k] = (rand()) % 100;
a_c[i][j] = a[k];
b_c[i][j] = b[k];
c_c[i][j] = 0;
}
clock_t time;
time = clock();
c_c=matMulCPU(a_c, b_c, c_c, N);
time = clock() - time;
int* adev = NULL;
int* bdev = NULL;
int* cdev = NULL;
hipMalloc((void**)&adev, numBytes);
hipMalloc((void**)&bdev, numBytes);
hipMalloc((void**)&cdev, numBytes);
dim3 threads(BLOCK_SIZE, BLOCK_SIZE);
dim3 blocks(N / threads.x, N / threads.y);
hipEvent_t start, stop;
float gpuTime = 0.0f;
hipEventCreate(&start);
hipEventCreate(&stop);
hipEventRecord(start, 0);
hipMemcpy(adev, a, numBytes, hipMemcpyHostToDevice);
hipMemcpy(bdev, b, numBytes, hipMemcpyHostToDevice);
matMulKernel << <blocks, threads >> > (adev, bdev, cdev, N);
hipMemcpy(c, cdev, numBytes, hipMemcpyDeviceToHost);
hipEventRecord(stop, 0);
hipEventSynchronize(stop);
hipEventElapsedTime(&gpuTime, start, stop);
if (checkResult(c_c, c, N)) {
printf("Time spent executing by the GPU: %.2f millseconds\n", gpuTime);
std::cout << "Time spent executing by the CPU: " << time * 1000.0 / CLOCKS_PER_SEC << " millseconds" << std::endl;
}
hipEventDestroy(start);
hipEventDestroy(stop);
hipFree(adev);
hipFree(bdev);
hipFree(cdev);
delete a;
delete b;
delete c;
for (int i = 0; i < N; i++)
{
delete b_c[i];
delete a_c[i];
delete c_c[i];
}
delete[]a_c;
delete[]b_c;
delete[]c_c;
return 0;
} | e60acaf412fa35f5439f92962407c37cf22eefd4.cu |
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
#define BLOCK_SIZE 32 // submatrix size
#define N 256 // matrix size is N*N
typedef struct {
int n;
int* elements;
} Matrix;
__device__ float GetElement(const Matrix A, int row, int col) {
return A.elements[row * N + col];
}
__device__ void SetElement(Matrix A, int row, int col, int value) {
A.elements[row * N + col] = value;
}
__device__ Matrix GetSubMatrix(Matrix A, int row, int col, int n) {
Matrix ASub;
ASub.n = BLOCK_SIZE;
ASub.elements = &A.elements[n * BLOCK_SIZE * row + BLOCK_SIZE * col];
return ASub;
}
__global__ void matMulKernel(int* a, int* b, int* c, int n) {
int blockRow = blockIdx.y;
int blockCol = blockIdx.x;
Matrix cc;
cc.elements = c;
Matrix aa;
aa.elements = a;
Matrix bb;
bb.elements = b;
Matrix Csub = GetSubMatrix(cc, blockRow, blockCol,n);
float Cvalue = 0;
int row = threadIdx.y;
int col = threadIdx.x;
for (int m = 0; m < (N / BLOCK_SIZE); ++m) {
Matrix Asub = GetSubMatrix(aa, blockRow, m,n);
Matrix Bsub = GetSubMatrix(bb, m, blockCol,n);
__shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
__shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];
As[row][col] = GetElement(Asub, row, col);
Bs[row][col] = GetElement(Bsub, row, col);
__syncthreads();
for (int e = 0; e < BLOCK_SIZE; ++e)
Cvalue += As[row][e] * Bs[e][col];
__syncthreads();
}
SetElement(Csub, row, col, Cvalue);
}
int** matMulCPU(int** a, int** b, int** c, int n) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
c[i][j] = 0;
for (int k = 0; k < n; k++)
c[i][j] += a[i][k] * b[k][j];
}
return c;
}
bool checkResult(int** a, int* b, int n) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (a[i][j] != b[N * i + j])
return false;
return true;
}
int main(int argc, char* argv[])
{
srand(time(NULL));
int numBytes = N * N * sizeof(int);
int** a_c;
int** b_c;
int** c_c;
a_c = new int* [N];
for (int i = 0; i < N; i++)
a_c[i] = new int[N];
b_c = new int* [N];
for (int i = 0; i < N; i++)
b_c[i] = new int[N];
c_c = new int* [N];
for (int i = 0; i < N; i++)
c_c[i] = new int[N];
int* a = new int[N * N];
int* b = new int[N * N];
int* c = new int[N * N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
{
int k = N * i + j;
a[k] = (rand()) % 100;
b[k] = (rand()) % 100;
a_c[i][j] = a[k];
b_c[i][j] = b[k];
c_c[i][j] = 0;
}
clock_t time;
time = clock();
c_c=matMulCPU(a_c, b_c, c_c, N);
time = clock() - time;
int* adev = NULL;
int* bdev = NULL;
int* cdev = NULL;
cudaMalloc((void**)&adev, numBytes);
cudaMalloc((void**)&bdev, numBytes);
cudaMalloc((void**)&cdev, numBytes);
dim3 threads(BLOCK_SIZE, BLOCK_SIZE);
dim3 blocks(N / threads.x, N / threads.y);
cudaEvent_t start, stop;
float gpuTime = 0.0f;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
cudaMemcpy(adev, a, numBytes, cudaMemcpyHostToDevice);
cudaMemcpy(bdev, b, numBytes, cudaMemcpyHostToDevice);
matMulKernel << <blocks, threads >> > (adev, bdev, cdev, N);
cudaMemcpy(c, cdev, numBytes, cudaMemcpyDeviceToHost);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&gpuTime, start, stop);
if (checkResult(c_c, c, N)) {
printf("Time spent executing by the GPU: %.2f millseconds\n", gpuTime);
std::cout << "Time spent executing by the CPU: " << time * 1000.0 / CLOCKS_PER_SEC << " millseconds" << std::endl;
}
cudaEventDestroy(start);
cudaEventDestroy(stop);
cudaFree(adev);
cudaFree(bdev);
cudaFree(cdev);
delete a;
delete b;
delete c;
for (int i = 0; i < N; i++)
{
delete b_c[i];
delete a_c[i];
delete c_c[i];
}
delete[]a_c;
delete[]b_c;
delete[]c_c;
return 0;
} |
f15d95de8a79bed8f1afb8310cfd3f2faa7b455f.hip | // !!! This is a file automatically generated by hipify!!!
/*
* Copyright (c) 2018-2020, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <raft/cudart_utils.h>
#include <raft/random/rng.cuh>
#include <raft/stats/mean.cuh>
#include <raft/stats/mean_center.cuh>
#include "../linalg/matrix_vector_op.cuh"
#include "../test_utils.h"
namespace raft {
namespace stats {
template <typename T, typename IdxType>
struct MeanCenterInputs {
T tolerance, mean;
IdxType rows, cols;
bool sample, rowMajor, bcastAlongRows;
unsigned long long int seed;
};
template <typename T, typename IdxType>
::std::ostream &operator<<(::std::ostream &os,
const MeanCenterInputs<T, IdxType> &dims) {
return os;
}
template <typename T, typename IdxType>
class MeanCenterTest
: public ::testing::TestWithParam<MeanCenterInputs<T, IdxType>> {
protected:
void SetUp() override {
params = ::testing::TestWithParam<MeanCenterInputs<T, IdxType>>::GetParam();
raft::random::Rng r(params.seed);
hipStream_t stream;
CUDA_CHECK(hipStreamCreate(&stream));
auto rows = params.rows, cols = params.cols;
auto len = rows * cols;
IdxType vecLen = params.bcastAlongRows ? cols : rows;
raft::allocate(out, len);
raft::allocate(out_ref, len);
raft::allocate(data, len);
raft::allocate(meanVec, vecLen);
r.normal(data, len, params.mean, (T)1.0, stream);
raft::stats::mean(meanVec, data, cols, rows, params.sample, params.rowMajor,
stream);
meanCenter(out, data, meanVec, cols, rows, params.rowMajor,
params.bcastAlongRows, stream);
raft::linalg::naiveMatVec(out_ref, data, meanVec, cols, rows,
params.rowMajor, params.bcastAlongRows, (T)-1.0);
CUDA_CHECK(hipStreamDestroy(stream));
}
void TearDown() override {
CUDA_CHECK(hipFree(out));
CUDA_CHECK(hipFree(out_ref));
CUDA_CHECK(hipFree(data));
CUDA_CHECK(hipFree(meanVec));
}
protected:
MeanCenterInputs<T, IdxType> params;
T *data, *meanVec, *out, *out_ref;
};
const std::vector<MeanCenterInputs<float, int>> inputsf_i32 = {
{0.05f, 1.f, 1024, 32, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, false, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<float, int> MeanCenterTestF_i32;
TEST_P(MeanCenterTestF_i32, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<float>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestF_i32,
::testing::ValuesIn(inputsf_i32));
const std::vector<MeanCenterInputs<float, size_t>> inputsf_i64 = {
{0.05f, 1.f, 1024, 32, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, false, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<float, size_t> MeanCenterTestF_i64;
TEST_P(MeanCenterTestF_i64, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<float>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestF_i64,
::testing::ValuesIn(inputsf_i64));
const std::vector<MeanCenterInputs<double, int>> inputsd_i32 = {
{0.05, 1.0, 1024, 32, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, false, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<double, int> MeanCenterTestD_i32;
TEST_P(MeanCenterTestD_i32, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<double>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestD_i32,
::testing::ValuesIn(inputsd_i32));
const std::vector<MeanCenterInputs<double, size_t>> inputsd_i64 = {
{0.05, 1.0, 1024, 32, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, false, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<double, size_t> MeanCenterTestD_i64;
TEST_P(MeanCenterTestD_i64, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<double>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestD_i64,
::testing::ValuesIn(inputsd_i64));
} // end namespace stats
} // end namespace raft
| f15d95de8a79bed8f1afb8310cfd3f2faa7b455f.cu | /*
* Copyright (c) 2018-2020, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <raft/cudart_utils.h>
#include <raft/random/rng.cuh>
#include <raft/stats/mean.cuh>
#include <raft/stats/mean_center.cuh>
#include "../linalg/matrix_vector_op.cuh"
#include "../test_utils.h"
namespace raft {
namespace stats {
template <typename T, typename IdxType>
struct MeanCenterInputs {
T tolerance, mean;
IdxType rows, cols;
bool sample, rowMajor, bcastAlongRows;
unsigned long long int seed;
};
template <typename T, typename IdxType>
::std::ostream &operator<<(::std::ostream &os,
const MeanCenterInputs<T, IdxType> &dims) {
return os;
}
template <typename T, typename IdxType>
class MeanCenterTest
: public ::testing::TestWithParam<MeanCenterInputs<T, IdxType>> {
protected:
void SetUp() override {
params = ::testing::TestWithParam<MeanCenterInputs<T, IdxType>>::GetParam();
raft::random::Rng r(params.seed);
cudaStream_t stream;
CUDA_CHECK(cudaStreamCreate(&stream));
auto rows = params.rows, cols = params.cols;
auto len = rows * cols;
IdxType vecLen = params.bcastAlongRows ? cols : rows;
raft::allocate(out, len);
raft::allocate(out_ref, len);
raft::allocate(data, len);
raft::allocate(meanVec, vecLen);
r.normal(data, len, params.mean, (T)1.0, stream);
raft::stats::mean(meanVec, data, cols, rows, params.sample, params.rowMajor,
stream);
meanCenter(out, data, meanVec, cols, rows, params.rowMajor,
params.bcastAlongRows, stream);
raft::linalg::naiveMatVec(out_ref, data, meanVec, cols, rows,
params.rowMajor, params.bcastAlongRows, (T)-1.0);
CUDA_CHECK(cudaStreamDestroy(stream));
}
void TearDown() override {
CUDA_CHECK(cudaFree(out));
CUDA_CHECK(cudaFree(out_ref));
CUDA_CHECK(cudaFree(data));
CUDA_CHECK(cudaFree(meanVec));
}
protected:
MeanCenterInputs<T, IdxType> params;
T *data, *meanVec, *out, *out_ref;
};
const std::vector<MeanCenterInputs<float, int>> inputsf_i32 = {
{0.05f, 1.f, 1024, 32, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, false, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<float, int> MeanCenterTestF_i32;
TEST_P(MeanCenterTestF_i32, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<float>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestF_i32,
::testing::ValuesIn(inputsf_i32));
const std::vector<MeanCenterInputs<float, size_t>> inputsf_i64 = {
{0.05f, 1.f, 1024, 32, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, true, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, true, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, true, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, true, 1234ULL},
{0.05f, 1.f, 1024, 32, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, false, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, false, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, false, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, false, false, 1234ULL},
{0.05f, 1.f, 1024, 32, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 64, true, true, false, 1234ULL},
{0.05f, 1.f, 1024, 128, true, true, false, 1234ULL},
{0.05f, -1.f, 1024, 32, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 64, false, true, false, 1234ULL},
{0.05f, -1.f, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<float, size_t> MeanCenterTestF_i64;
TEST_P(MeanCenterTestF_i64, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<float>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestF_i64,
::testing::ValuesIn(inputsf_i64));
const std::vector<MeanCenterInputs<double, int>> inputsd_i32 = {
{0.05, 1.0, 1024, 32, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, false, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<double, int> MeanCenterTestD_i32;
TEST_P(MeanCenterTestD_i32, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<double>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestD_i32,
::testing::ValuesIn(inputsd_i32));
const std::vector<MeanCenterInputs<double, size_t>> inputsd_i64 = {
{0.05, 1.0, 1024, 32, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, true, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, true, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, true, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, true, 1234ULL},
{0.05, 1.0, 1024, 32, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, false, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, false, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, false, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, false, false, 1234ULL},
{0.05, 1.0, 1024, 32, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 64, true, true, false, 1234ULL},
{0.05, 1.0, 1024, 128, true, true, false, 1234ULL},
{0.05, -1.0, 1024, 32, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 64, false, true, false, 1234ULL},
{0.05, -1.0, 1024, 128, false, true, false, 1234ULL}};
typedef MeanCenterTest<double, size_t> MeanCenterTestD_i64;
TEST_P(MeanCenterTestD_i64, Result) {
ASSERT_TRUE(devArrMatch(out, out_ref, params.cols,
raft::CompareApprox<double>(params.tolerance)));
}
INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestD_i64,
::testing::ValuesIn(inputsd_i64));
} // end namespace stats
} // end namespace raft
|
d9ea17246a2684838b02bb7ab0d8221aae91889d.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* Copyright 2019 BlazingDB, Inc.
* Copyright 2019 Alexander Ocsa <alexander@blazingdb.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <algorithm>
#include <cassert>
#include <thrust/fill.h>
#include <tuple>
#include <bitmask/legacy/bit_mask.cuh>
#include <cudf/legacy/copying.hpp>
#include <cudf/cudf.h>
#include <cudf/legacy/groupby.hpp>
#include <cudf/legacy/bitmask.hpp>
#include <cudf/legacy/table.hpp>
#include <cudf/utilities/legacy/nvcategory_util.hpp>
#include <cudf/utilities/legacy/type_dispatcher.hpp>
#include <table/legacy/device_table.cuh>
#include <table/legacy/device_table_row_operators.cuh>
#include <utilities/legacy/column_utils.hpp>
#include <utilities/legacy/cuda_utils.hpp>
#include "groupby/common/legacy/aggregation_requests.hpp"
#include "groupby/common/legacy/type_info.hpp"
#include "groupby/common/legacy/utils.hpp"
#include "groupby_kernels.cuh"
#include "sort_helper.hpp"
#include <quantiles/legacy/group_quantiles.hpp>
#include <reductions/legacy/group_reductions.hpp>
#include <cudf/detail/utilities/integer_utils.hpp>
namespace cudf {
namespace groupby {
namespace sort {
using index_vector = rmm::device_vector<cudf::size_type>;
namespace {
/**---------------------------------------------------------------------------*
* @brief Computes the ordered aggregation requests which were skipped
* in a previous process (`compound_to_simple`). These ordered aggregations
* were skipped because they can't be compound to simple aggregation.
*
* Then combine these results with the set of output aggregation columns
* corresponding to not ordered aggregation requests.
*
* @param groupby[in] The object for computing sort-based groupby
* @param original_requests[in] The original set of potentially ordered
* aggregation requests
* @param input_ops_args[in] The list of arguments fot each of the previous ordered
* aggregation requests
* @param current_output_values[in] Set of output aggregation columns corresponding to
* not ordered aggregation requests
* @param stream[in] CUDA stream on which to execute
* @return vector of columns satisfying each of the original aggregation requests
*---------------------------------------------------------------------------**/
std::vector<gdf_column*> compute_ordered_aggregations(
detail::helper &groupby,
std::vector<AggRequestType> const& original_requests,
std::vector<operation_args*> const& input_ops_args,
cudf::table& current_output_values,
hipStream_t stream) {
std::vector<gdf_column*> output_value(original_requests.size());
std::copy(current_output_values.begin(), current_output_values.end(), output_value.begin());
for (size_t i = 0; i < original_requests.size(); ++i) {
auto const& element = original_requests[i];
if (is_ordered(element.second)) {
gdf_column * value_col = element.first;
gdf_column sorted_values;
rmm::device_vector<cudf::size_type> group_sizes;
std::tie(sorted_values, group_sizes) = groupby.sort_values(*value_col);
auto result_col = new gdf_column;
switch (element.second) {
case MEDIAN: {
*result_col = cudf::allocate_column(
GDF_FLOAT64, groupby.num_groups(), false);
cudf::detail::group_medians(sorted_values, groupby.group_offsets(),
group_sizes, result_col, stream);
break;
}
case QUANTILE: {
auto args = static_cast<quantile_args*>(input_ops_args[i]);
*result_col = cudf::allocate_column(
GDF_FLOAT64, args->quantiles.size() * groupby.num_groups(), false);
cudf::detail::group_quantiles(sorted_values, groupby.group_offsets(),
group_sizes, result_col,
args->quantiles, args->interpolation,
stream);
break;
}
case VARIANCE: {
auto args = static_cast<std_args*>(input_ops_args[i]);
*result_col = cudf::allocate_column(
GDF_FLOAT64, groupby.num_groups());
cudf::detail::group_var(sorted_values, groupby.group_labels(),
group_sizes, result_col,
args->ddof, stream);
break;
}
case STD: {
auto args = static_cast<std_args*>(input_ops_args[i]);
*result_col = cudf::allocate_column(
GDF_FLOAT64, groupby.num_groups());
cudf::detail::group_std(sorted_values, groupby.group_labels(),
group_sizes, result_col,
args->ddof, stream);
break;
}
default:
break;
}
output_value[i] = result_col;
gdf_column_free(&sorted_values);
}
}
return output_value;
}
/**---------------------------------------------------------------------------*
* @brief Prepare input parameters for invoking the `aggregate_all_rows` kernel
* which compute the simple aggregation(s) of corresponding rows in the output
* `values` table.
* @param input_keys The table of keys
* @param options The options for controlling behavior of the groupby operation.
* @param groupby The object for computing sort-based groupby
* @param simple_values_columns The list of simple values columns
* @param simple_operators The list of simple aggregation operations
* @param stream[in] CUDA stream on which to execute
* @return output value table with the aggregation(s) computed
*---------------------------------------------------------------------------**/
template <bool keys_have_nulls, bool values_have_nulls>
cudf::table compute_simple_aggregations(const cudf::table &input_keys,
const Options &options,
detail::helper &groupby,
const std::vector<gdf_column *> &simple_values_columns,
const std::vector<operators> &simple_operators,
hipStream_t &stream) {
const gdf_column& key_sorted_order = groupby.key_sort_order();
//group_labels
const index_vector& group_labels = groupby.group_labels();
const cudf::size_type num_groups = groupby.num_groups();
// Output allocation size aligned to 4 bytes. The use of `round_up_safe`
// guarantee correct execution with cuda-memcheck for cases when
// num_groups == 1 and with dtype == int_8.
cudf::size_type const output_size_estimate = cudf::util::round_up_safe((int64_t)groupby.num_groups(), (int64_t)sizeof(int32_t));
cudf::table simple_values_table{simple_values_columns};
cudf::table simple_output_values{
output_size_estimate, target_dtypes(column_dtypes(simple_values_table), simple_operators),
column_dtype_infos(simple_values_table), values_have_nulls, false, stream};
initialize_with_identity(simple_output_values, simple_operators, stream);
auto d_input_values = device_table::create(simple_values_table);
auto d_output_values = device_table::create(simple_output_values, stream);
rmm::device_vector<operators> d_ops(simple_operators);
auto row_bitmask = cudf::row_bitmask(input_keys, stream);
cudf::util::cuda::grid_config_1d grid_params{input_keys.num_rows(), 256};
//Aggregate all rows for simple requests using the key sorted order (indices) and the group labels
hipLaunchKernelGGL(( cudf::groupby::sort::aggregate_all_rows<keys_have_nulls, values_have_nulls>),
dim3(grid_params.num_blocks), dim3(grid_params.num_threads_per_block), 0, stream,
*d_input_values, *d_output_values,
static_cast<cudf::size_type const*>(key_sorted_order.data),
group_labels.data().get(), options.ignore_null_keys,
d_ops.data().get(), row_bitmask.data().get());
std::transform(simple_output_values.begin(), simple_output_values.end(), simple_output_values.begin(),
[num_groups](gdf_column *col) {
CUDF_EXPECTS(col != nullptr, "Attempt to update Null column.");
col->size = num_groups;
return col;
});
return simple_output_values;
}
template <bool keys_have_nulls, bool values_have_nulls>
std::pair<cudf::table, std::vector<gdf_column*>> compute_sort_groupby(cudf::table const& input_keys, cudf::table const& input_values,
std::vector<operators> const& input_ops,
std::vector<operation_args*> const& input_ops_args,
Options options,
hipStream_t stream) {
auto include_nulls = not options.ignore_null_keys;
auto groupby = detail::helper(input_keys, include_nulls, options.null_sort_behavior, options.input_sorted);
if (groupby.num_groups() == 0) {
cudf::table output_values(0, target_dtypes(column_dtypes(input_values), input_ops), column_dtype_infos(input_values));
return std::make_pair(
cudf::empty_like(input_keys),
std::vector<gdf_column*>{output_values.begin(), output_values.end()}
);
}
cudf::size_type num_groups = groupby.num_groups();
// An "aggregation request" is the combination of a `gdf_column*` to a column
// of values, and an aggregation operation enum indicating the aggregation
// requested to be performed on the column
std::vector<AggRequestType> original_requests(input_values.num_columns());
std::transform(input_values.begin(), input_values.end(), input_ops.begin(),
original_requests.begin(),
[](gdf_column const* col, operators op) {
return std::make_pair(const_cast<gdf_column*>(col), op);
});
// Some aggregations are "compound", meaning they need be satisfied via the
// composition of 1 or more "simple" aggregation requests. For example, MEAN
// is satisfied via the division of the SUM by the COUNT aggregation. We
// translate these compound requests into simple requests, and compute the
// groupby operation for these simple requests. Later, we translate the simple
// requests back to compound request results.
std::vector<SimpleAggRequestCounter> simple_requests =
compound_to_simple(original_requests);
std::vector<gdf_column*> simple_values_columns;
std::vector<operators> simple_operators;
for (auto const& p : simple_requests) {
const AggRequestType& agg_req_type = p.first;
simple_values_columns.push_back(
const_cast<gdf_column*>(agg_req_type.first));
simple_operators.push_back(agg_req_type.second);
}
// If there are "simple" aggregation requests, compute the aggregations
cudf::table current_output_values{};
if (simple_values_columns.size() > 0) {
// Step 1: Aggregate all rows for simple requests
cudf::table simple_output_values = compute_simple_aggregations<keys_have_nulls, values_have_nulls>(input_keys,
options,
groupby,
simple_values_columns,
simple_operators,
stream);
// Step 2: If any of the original requests were compound, compute them from the
// results of simple aggregation requests
current_output_values = compute_original_requests(original_requests, simple_requests, simple_output_values, stream);
}
// If there are "ordered" aggregation requests like MEDIAN, QUANTILE, compute these aggregations
std::vector<gdf_column*> final_output_values = compute_ordered_aggregations(groupby, original_requests, input_ops_args, current_output_values, stream);
// Update size and null count of output columns
std::transform(final_output_values.begin(), final_output_values.end(), final_output_values.begin(),
[](gdf_column *col) {
CUDF_EXPECTS(col != nullptr, "Attempt to update Null column.");
set_null_count(*col);
return col;
});
return std::make_pair(groupby.unique_keys(), final_output_values);
}
/**---------------------------------------------------------------------------*
* @brief Returns appropriate callable instantiation of `compute_sort_groupby`
* based on presence of null values in keys and values.
*
* @param keys The groupby key columns
* @param values The groupby value columns
* @return Instantiated callable of compute_sort_groupby
*---------------------------------------------------------------------------**/
auto groupby_null_specialization(table const& keys, table const& values) {
if (cudf::has_nulls(keys)) {
if (cudf::has_nulls(values)) {
return compute_sort_groupby<true, true>;
} else {
return compute_sort_groupby<true, false>;
}
} else {
if (cudf::has_nulls(values)) {
return compute_sort_groupby<false, true>;
} else {
return compute_sort_groupby<false, false>;
}
}
}
} // anonymous namespace
namespace detail {
/**---------------------------------------------------------------------------*
* @brief Verifies the requested aggregation is valid for the arguments of the
* operator.
*
* @throw cudf::logic_error if an invalid combination of argument and operator
* is requested.
*
* @param ops The aggregation operators
* @param ops The aggregation arguments
*---------------------------------------------------------------------------**/
static void verify_operators_with_arguments(std::vector<operators> const& ops, std::vector<operation_args*> const& args) {
CUDF_EXPECTS(ops.size() == args.size(),
"Size mismatch between ops and args");
for (size_t i = 0; i < ops.size(); i++) {
if(ops[i] == QUANTILE) {
quantile_args* q_args = static_cast<quantile_args*>(args[i]);
if (q_args == nullptr or q_args->quantiles.size() == 0) {
CUDF_FAIL(
"Missing quantile aggregation arguments.");
}
}
}
}
std::pair<cudf::table, std::vector<gdf_column*>> groupby(cudf::table const& keys,
cudf::table const& values,
std::vector<operation> const& ops,
Options options,
hipStream_t stream = 0) {
CUDF_EXPECTS(keys.num_rows() == values.num_rows(),
"Size mismatch between number of rows in keys and values.");
std::vector<operators> optype_list(ops.size());
std::transform(ops.begin(), ops.end(), optype_list.begin(), [](auto const& op) {
return op.op_name;
});
std::vector<operation_args*> ops_args(ops.size());
std::transform(ops.begin(), ops.end(), ops_args.begin(), [](auto const& op) {
return op.args.get();
});
verify_operators(values, optype_list);
verify_operators_with_arguments(optype_list, ops_args);
// Empty inputs
if (keys.num_rows() == 0) {
cudf::table output_values(0, target_dtypes(column_dtypes(values), optype_list), column_dtype_infos(values));
return std::make_pair(
cudf::empty_like(keys),
std::vector<gdf_column*>{output_values.begin(), output_values.end()}
);
}
auto compute_groupby = groupby_null_specialization(keys, values);
cudf::table output_keys;
std::vector<gdf_column*> output_values;
std::tie(output_keys, output_values) =
compute_groupby(keys, values, optype_list, ops_args, options, stream);
cudf::table table_output_values(output_values);
update_nvcategories(keys, output_keys, values, table_output_values);
return std::make_pair(output_keys, output_values);
}
} // namespace detail
std::pair<cudf::table, std::vector<gdf_column*>> groupby(cudf::table const &keys,
cudf::table const &values,
std::vector<operation> const &ops,
Options options) {
return detail::groupby(keys, values, ops, options);
}
} // END: namespace sort
} // END: namespace groupby
} // END: namespace cudf
| d9ea17246a2684838b02bb7ab0d8221aae91889d.cu | /*
* Copyright 2019 BlazingDB, Inc.
* Copyright 2019 Alexander Ocsa <alexander@blazingdb.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <algorithm>
#include <cassert>
#include <thrust/fill.h>
#include <tuple>
#include <bitmask/legacy/bit_mask.cuh>
#include <cudf/legacy/copying.hpp>
#include <cudf/cudf.h>
#include <cudf/legacy/groupby.hpp>
#include <cudf/legacy/bitmask.hpp>
#include <cudf/legacy/table.hpp>
#include <cudf/utilities/legacy/nvcategory_util.hpp>
#include <cudf/utilities/legacy/type_dispatcher.hpp>
#include <table/legacy/device_table.cuh>
#include <table/legacy/device_table_row_operators.cuh>
#include <utilities/legacy/column_utils.hpp>
#include <utilities/legacy/cuda_utils.hpp>
#include "groupby/common/legacy/aggregation_requests.hpp"
#include "groupby/common/legacy/type_info.hpp"
#include "groupby/common/legacy/utils.hpp"
#include "groupby_kernels.cuh"
#include "sort_helper.hpp"
#include <quantiles/legacy/group_quantiles.hpp>
#include <reductions/legacy/group_reductions.hpp>
#include <cudf/detail/utilities/integer_utils.hpp>
namespace cudf {
namespace groupby {
namespace sort {
using index_vector = rmm::device_vector<cudf::size_type>;
namespace {
/**---------------------------------------------------------------------------*
* @brief Computes the ordered aggregation requests which were skipped
* in a previous process (`compound_to_simple`). These ordered aggregations
* were skipped because they can't be compound to simple aggregation.
*
* Then combine these results with the set of output aggregation columns
* corresponding to not ordered aggregation requests.
*
* @param groupby[in] The object for computing sort-based groupby
* @param original_requests[in] The original set of potentially ordered
* aggregation requests
* @param input_ops_args[in] The list of arguments fot each of the previous ordered
* aggregation requests
* @param current_output_values[in] Set of output aggregation columns corresponding to
* not ordered aggregation requests
* @param stream[in] CUDA stream on which to execute
* @return vector of columns satisfying each of the original aggregation requests
*---------------------------------------------------------------------------**/
std::vector<gdf_column*> compute_ordered_aggregations(
detail::helper &groupby,
std::vector<AggRequestType> const& original_requests,
std::vector<operation_args*> const& input_ops_args,
cudf::table& current_output_values,
cudaStream_t stream) {
std::vector<gdf_column*> output_value(original_requests.size());
std::copy(current_output_values.begin(), current_output_values.end(), output_value.begin());
for (size_t i = 0; i < original_requests.size(); ++i) {
auto const& element = original_requests[i];
if (is_ordered(element.second)) {
gdf_column * value_col = element.first;
gdf_column sorted_values;
rmm::device_vector<cudf::size_type> group_sizes;
std::tie(sorted_values, group_sizes) = groupby.sort_values(*value_col);
auto result_col = new gdf_column;
switch (element.second) {
case MEDIAN: {
*result_col = cudf::allocate_column(
GDF_FLOAT64, groupby.num_groups(), false);
cudf::detail::group_medians(sorted_values, groupby.group_offsets(),
group_sizes, result_col, stream);
break;
}
case QUANTILE: {
auto args = static_cast<quantile_args*>(input_ops_args[i]);
*result_col = cudf::allocate_column(
GDF_FLOAT64, args->quantiles.size() * groupby.num_groups(), false);
cudf::detail::group_quantiles(sorted_values, groupby.group_offsets(),
group_sizes, result_col,
args->quantiles, args->interpolation,
stream);
break;
}
case VARIANCE: {
auto args = static_cast<std_args*>(input_ops_args[i]);
*result_col = cudf::allocate_column(
GDF_FLOAT64, groupby.num_groups());
cudf::detail::group_var(sorted_values, groupby.group_labels(),
group_sizes, result_col,
args->ddof, stream);
break;
}
case STD: {
auto args = static_cast<std_args*>(input_ops_args[i]);
*result_col = cudf::allocate_column(
GDF_FLOAT64, groupby.num_groups());
cudf::detail::group_std(sorted_values, groupby.group_labels(),
group_sizes, result_col,
args->ddof, stream);
break;
}
default:
break;
}
output_value[i] = result_col;
gdf_column_free(&sorted_values);
}
}
return output_value;
}
/**---------------------------------------------------------------------------*
* @brief Prepare input parameters for invoking the `aggregate_all_rows` kernel
* which compute the simple aggregation(s) of corresponding rows in the output
* `values` table.
* @param input_keys The table of keys
* @param options The options for controlling behavior of the groupby operation.
* @param groupby The object for computing sort-based groupby
* @param simple_values_columns The list of simple values columns
* @param simple_operators The list of simple aggregation operations
* @param stream[in] CUDA stream on which to execute
* @return output value table with the aggregation(s) computed
*---------------------------------------------------------------------------**/
template <bool keys_have_nulls, bool values_have_nulls>
cudf::table compute_simple_aggregations(const cudf::table &input_keys,
const Options &options,
detail::helper &groupby,
const std::vector<gdf_column *> &simple_values_columns,
const std::vector<operators> &simple_operators,
cudaStream_t &stream) {
const gdf_column& key_sorted_order = groupby.key_sort_order();
//group_labels
const index_vector& group_labels = groupby.group_labels();
const cudf::size_type num_groups = groupby.num_groups();
// Output allocation size aligned to 4 bytes. The use of `round_up_safe`
// guarantee correct execution with cuda-memcheck for cases when
// num_groups == 1 and with dtype == int_8.
cudf::size_type const output_size_estimate = cudf::util::round_up_safe((int64_t)groupby.num_groups(), (int64_t)sizeof(int32_t));
cudf::table simple_values_table{simple_values_columns};
cudf::table simple_output_values{
output_size_estimate, target_dtypes(column_dtypes(simple_values_table), simple_operators),
column_dtype_infos(simple_values_table), values_have_nulls, false, stream};
initialize_with_identity(simple_output_values, simple_operators, stream);
auto d_input_values = device_table::create(simple_values_table);
auto d_output_values = device_table::create(simple_output_values, stream);
rmm::device_vector<operators> d_ops(simple_operators);
auto row_bitmask = cudf::row_bitmask(input_keys, stream);
cudf::util::cuda::grid_config_1d grid_params{input_keys.num_rows(), 256};
//Aggregate all rows for simple requests using the key sorted order (indices) and the group labels
cudf::groupby::sort::aggregate_all_rows<keys_have_nulls, values_have_nulls><<<
grid_params.num_blocks, grid_params.num_threads_per_block, 0, stream>>>(
*d_input_values, *d_output_values,
static_cast<cudf::size_type const*>(key_sorted_order.data),
group_labels.data().get(), options.ignore_null_keys,
d_ops.data().get(), row_bitmask.data().get());
std::transform(simple_output_values.begin(), simple_output_values.end(), simple_output_values.begin(),
[num_groups](gdf_column *col) {
CUDF_EXPECTS(col != nullptr, "Attempt to update Null column.");
col->size = num_groups;
return col;
});
return simple_output_values;
}
template <bool keys_have_nulls, bool values_have_nulls>
std::pair<cudf::table, std::vector<gdf_column*>> compute_sort_groupby(cudf::table const& input_keys, cudf::table const& input_values,
std::vector<operators> const& input_ops,
std::vector<operation_args*> const& input_ops_args,
Options options,
cudaStream_t stream) {
auto include_nulls = not options.ignore_null_keys;
auto groupby = detail::helper(input_keys, include_nulls, options.null_sort_behavior, options.input_sorted);
if (groupby.num_groups() == 0) {
cudf::table output_values(0, target_dtypes(column_dtypes(input_values), input_ops), column_dtype_infos(input_values));
return std::make_pair(
cudf::empty_like(input_keys),
std::vector<gdf_column*>{output_values.begin(), output_values.end()}
);
}
cudf::size_type num_groups = groupby.num_groups();
// An "aggregation request" is the combination of a `gdf_column*` to a column
// of values, and an aggregation operation enum indicating the aggregation
// requested to be performed on the column
std::vector<AggRequestType> original_requests(input_values.num_columns());
std::transform(input_values.begin(), input_values.end(), input_ops.begin(),
original_requests.begin(),
[](gdf_column const* col, operators op) {
return std::make_pair(const_cast<gdf_column*>(col), op);
});
// Some aggregations are "compound", meaning they need be satisfied via the
// composition of 1 or more "simple" aggregation requests. For example, MEAN
// is satisfied via the division of the SUM by the COUNT aggregation. We
// translate these compound requests into simple requests, and compute the
// groupby operation for these simple requests. Later, we translate the simple
// requests back to compound request results.
std::vector<SimpleAggRequestCounter> simple_requests =
compound_to_simple(original_requests);
std::vector<gdf_column*> simple_values_columns;
std::vector<operators> simple_operators;
for (auto const& p : simple_requests) {
const AggRequestType& agg_req_type = p.first;
simple_values_columns.push_back(
const_cast<gdf_column*>(agg_req_type.first));
simple_operators.push_back(agg_req_type.second);
}
// If there are "simple" aggregation requests, compute the aggregations
cudf::table current_output_values{};
if (simple_values_columns.size() > 0) {
// Step 1: Aggregate all rows for simple requests
cudf::table simple_output_values = compute_simple_aggregations<keys_have_nulls, values_have_nulls>(input_keys,
options,
groupby,
simple_values_columns,
simple_operators,
stream);
// Step 2: If any of the original requests were compound, compute them from the
// results of simple aggregation requests
current_output_values = compute_original_requests(original_requests, simple_requests, simple_output_values, stream);
}
// If there are "ordered" aggregation requests like MEDIAN, QUANTILE, compute these aggregations
std::vector<gdf_column*> final_output_values = compute_ordered_aggregations(groupby, original_requests, input_ops_args, current_output_values, stream);
// Update size and null count of output columns
std::transform(final_output_values.begin(), final_output_values.end(), final_output_values.begin(),
[](gdf_column *col) {
CUDF_EXPECTS(col != nullptr, "Attempt to update Null column.");
set_null_count(*col);
return col;
});
return std::make_pair(groupby.unique_keys(), final_output_values);
}
/**---------------------------------------------------------------------------*
* @brief Returns appropriate callable instantiation of `compute_sort_groupby`
* based on presence of null values in keys and values.
*
* @param keys The groupby key columns
* @param values The groupby value columns
* @return Instantiated callable of compute_sort_groupby
*---------------------------------------------------------------------------**/
auto groupby_null_specialization(table const& keys, table const& values) {
if (cudf::has_nulls(keys)) {
if (cudf::has_nulls(values)) {
return compute_sort_groupby<true, true>;
} else {
return compute_sort_groupby<true, false>;
}
} else {
if (cudf::has_nulls(values)) {
return compute_sort_groupby<false, true>;
} else {
return compute_sort_groupby<false, false>;
}
}
}
} // anonymous namespace
namespace detail {
/**---------------------------------------------------------------------------*
* @brief Verifies the requested aggregation is valid for the arguments of the
* operator.
*
* @throw cudf::logic_error if an invalid combination of argument and operator
* is requested.
*
* @param ops The aggregation operators
* @param ops The aggregation arguments
*---------------------------------------------------------------------------**/
static void verify_operators_with_arguments(std::vector<operators> const& ops, std::vector<operation_args*> const& args) {
CUDF_EXPECTS(ops.size() == args.size(),
"Size mismatch between ops and args");
for (size_t i = 0; i < ops.size(); i++) {
if(ops[i] == QUANTILE) {
quantile_args* q_args = static_cast<quantile_args*>(args[i]);
if (q_args == nullptr or q_args->quantiles.size() == 0) {
CUDF_FAIL(
"Missing quantile aggregation arguments.");
}
}
}
}
std::pair<cudf::table, std::vector<gdf_column*>> groupby(cudf::table const& keys,
cudf::table const& values,
std::vector<operation> const& ops,
Options options,
cudaStream_t stream = 0) {
CUDF_EXPECTS(keys.num_rows() == values.num_rows(),
"Size mismatch between number of rows in keys and values.");
std::vector<operators> optype_list(ops.size());
std::transform(ops.begin(), ops.end(), optype_list.begin(), [](auto const& op) {
return op.op_name;
});
std::vector<operation_args*> ops_args(ops.size());
std::transform(ops.begin(), ops.end(), ops_args.begin(), [](auto const& op) {
return op.args.get();
});
verify_operators(values, optype_list);
verify_operators_with_arguments(optype_list, ops_args);
// Empty inputs
if (keys.num_rows() == 0) {
cudf::table output_values(0, target_dtypes(column_dtypes(values), optype_list), column_dtype_infos(values));
return std::make_pair(
cudf::empty_like(keys),
std::vector<gdf_column*>{output_values.begin(), output_values.end()}
);
}
auto compute_groupby = groupby_null_specialization(keys, values);
cudf::table output_keys;
std::vector<gdf_column*> output_values;
std::tie(output_keys, output_values) =
compute_groupby(keys, values, optype_list, ops_args, options, stream);
cudf::table table_output_values(output_values);
update_nvcategories(keys, output_keys, values, table_output_values);
return std::make_pair(output_keys, output_values);
}
} // namespace detail
std::pair<cudf::table, std::vector<gdf_column*>> groupby(cudf::table const &keys,
cudf::table const &values,
std::vector<operation> const &ops,
Options options) {
return detail::groupby(keys, values, ops, options);
}
} // END: namespace sort
} // END: namespace groupby
} // END: namespace cudf
|
471a0de21d627a7c2a2721ee0f2dafcbec2cc702.hip | // !!! This is a file automatically generated by hipify!!!
/*!
* Copyright 2018-2019 by Contributors
* \author Rory Mitchell
*/
#include <thrust/execution_policy.h>
#include <thrust/inner_product.h>
#include <xgboost/data.h>
#include <xgboost/linear_updater.h>
#include "xgboost/span.h"
#include "coordinate_common.h"
#include "../common/common.h"
#include "../common/device_helpers.cuh"
#include "../common/timer.h"
#include "./param.h"
namespace xgboost {
namespace linear {
DMLC_REGISTRY_FILE_TAG(updater_gpu_coordinate);
/**
* \class GPUCoordinateUpdater
*
* \brief Coordinate descent algorithm that updates one feature per iteration
*/
class GPUCoordinateUpdater : public LinearUpdater { // NOLINT
public:
~GPUCoordinateUpdater() { // NOLINT
if (learner_param_->gpu_id >= 0) {
dh::safe_cuda(hipSetDevice(learner_param_->gpu_id));
}
}
// set training parameter
void Configure(Args const& args) override {
tparam_.UpdateAllowUnknown(args);
coord_param_.UpdateAllowUnknown(args);
selector_.reset(FeatureSelector::Create(tparam_.feature_selector));
monitor_.Init("GPUCoordinateUpdater");
}
void LoadConfig(Json const& in) override {
auto const& config = get<Object const>(in);
FromJson(config.at("linear_train_param"), &tparam_);
FromJson(config.at("coordinate_param"), &coord_param_);
}
void SaveConfig(Json* p_out) const override {
auto& out = *p_out;
out["linear_train_param"] = ToJson(tparam_);
out["coordinate_param"] = ToJson(coord_param_);
}
void LazyInitDevice(DMatrix *p_fmat, const LearnerModelParam &model_param) {
if (learner_param_->gpu_id < 0) return;
num_row_ = static_cast<size_t>(p_fmat->Info().num_row_);
CHECK(p_fmat->SingleColBlock());
SparsePage const& batch = *(p_fmat->GetBatches<CSCPage>().begin());
if (IsEmpty()) {
return;
}
dh::safe_cuda(hipSetDevice(learner_param_->gpu_id));
// The begin and end indices for the section of each column associated with
// this device
std::vector<std::pair<bst_uint, bst_uint>> column_segments;
row_ptr_ = {0};
// iterate through columns
for (size_t fidx = 0; fidx < batch.Size(); fidx++) {
common::Span<Entry const> col = batch[fidx];
auto cmp = [](Entry e1, Entry e2) {
return e1.index < e2.index;
};
auto column_begin =
std::lower_bound(col.cbegin(), col.cend(),
xgboost::Entry(0, 0.0f), cmp);
auto column_end =
std::lower_bound(col.cbegin(), col.cend(),
xgboost::Entry(num_row_, 0.0f), cmp);
column_segments.emplace_back(
std::make_pair(column_begin - col.cbegin(), column_end - col.cbegin()));
row_ptr_.push_back(row_ptr_.back() + (column_end - column_begin));
}
data_.resize(row_ptr_.back());
gpair_.resize(num_row_ * model_param.num_output_group);
for (size_t fidx = 0; fidx < batch.Size(); fidx++) {
auto col = batch[fidx];
auto seg = column_segments[fidx];
dh::safe_cuda(hipMemcpy(
data_.data().get() + row_ptr_[fidx],
col.data() + seg.first,
sizeof(Entry) * (seg.second - seg.first), hipMemcpyHostToDevice));
}
}
void Update(HostDeviceVector<GradientPair> *in_gpair, DMatrix *p_fmat,
gbm::GBLinearModel *model, double sum_instance_weight) override {
tparam_.DenormalizePenalties(sum_instance_weight);
monitor_.Start("LazyInitDevice");
this->LazyInitDevice(p_fmat, *(model->learner_model_param));
monitor_.Stop("LazyInitDevice");
monitor_.Start("UpdateGpair");
auto &in_gpair_host = in_gpair->ConstHostVector();
// Update gpair
if (learner_param_->gpu_id >= 0) {
this->UpdateGpair(in_gpair_host);
}
monitor_.Stop("UpdateGpair");
monitor_.Start("UpdateBias");
this->UpdateBias(p_fmat, model);
monitor_.Stop("UpdateBias");
// prepare for updating the weights
selector_->Setup(*model, in_gpair->ConstHostVector(), p_fmat,
tparam_.reg_alpha_denorm, tparam_.reg_lambda_denorm,
coord_param_.top_k);
monitor_.Start("UpdateFeature");
for (auto group_idx = 0; group_idx < model->learner_model_param->num_output_group;
++group_idx) {
for (auto i = 0U; i < model->learner_model_param->num_feature; i++) {
auto fidx = selector_->NextFeature(
i, *model, group_idx, in_gpair->ConstHostVector(), p_fmat,
tparam_.reg_alpha_denorm, tparam_.reg_lambda_denorm);
if (fidx < 0) break;
this->UpdateFeature(fidx, group_idx, &in_gpair->HostVector(), model);
}
}
monitor_.Stop("UpdateFeature");
}
void UpdateBias(DMatrix *p_fmat, gbm::GBLinearModel *model) {
for (int group_idx = 0; group_idx < model->learner_model_param->num_output_group;
++group_idx) {
// Get gradient
auto grad = GradientPair(0, 0);
if (learner_param_->gpu_id >= 0) {
grad = GetBiasGradient(group_idx, model->learner_model_param->num_output_group);
}
auto dbias = static_cast<float>(
tparam_.learning_rate *
CoordinateDeltaBias(grad.GetGrad(), grad.GetHess()));
model->Bias()[group_idx] += dbias;
// Update residual
if (learner_param_->gpu_id >= 0) {
UpdateBiasResidual(dbias, group_idx, model->learner_model_param->num_output_group);
}
}
}
void UpdateFeature(int fidx, int group_idx,
std::vector<GradientPair> *in_gpair,
gbm::GBLinearModel *model) {
bst_float &w = (*model)[fidx][group_idx];
// Get gradient
auto grad = GradientPair(0, 0);
if (learner_param_->gpu_id >= 0) {
grad = GetGradient(group_idx, model->learner_model_param->num_output_group, fidx);
}
auto dw = static_cast<float>(tparam_.learning_rate *
CoordinateDelta(grad.GetGrad(), grad.GetHess(),
w, tparam_.reg_alpha_denorm,
tparam_.reg_lambda_denorm));
w += dw;
if (learner_param_->gpu_id >= 0) {
UpdateResidual(dw, group_idx, model->learner_model_param->num_output_group, fidx);
}
}
// This needs to be public because of the __device__ lambda.
GradientPair GetBiasGradient(int group_idx, int num_group) {
dh::safe_cuda(hipSetDevice(learner_param_->gpu_id));
auto counting = thrust::make_counting_iterator(0ull);
auto f = [=] __device__(size_t idx) {
return idx * num_group + group_idx;
}; // NOLINT
thrust::transform_iterator<decltype(f), decltype(counting), size_t> skip(
counting, f);
auto perm = thrust::make_permutation_iterator(gpair_.data(), skip);
return dh::SumReduction(perm, num_row_);
}
// This needs to be public because of the __device__ lambda.
void UpdateBiasResidual(float dbias, int group_idx, int num_groups) {
if (dbias == 0.0f) return;
auto d_gpair = dh::ToSpan(gpair_);
dh::LaunchN(learner_param_->gpu_id, num_row_, [=] __device__(size_t idx) {
auto &g = d_gpair[idx * num_groups + group_idx];
g += GradientPair(g.GetHess() * dbias, 0);
});
}
// This needs to be public because of the __device__ lambda.
GradientPair GetGradient(int group_idx, int num_group, int fidx) {
dh::safe_cuda(hipSetDevice(learner_param_->gpu_id));
common::Span<xgboost::Entry> d_col = dh::ToSpan(data_).subspan(row_ptr_[fidx]);
size_t col_size = row_ptr_[fidx + 1] - row_ptr_[fidx];
common::Span<GradientPair> d_gpair = dh::ToSpan(gpair_);
auto counting = thrust::make_counting_iterator(0ull);
auto f = [=] __device__(size_t idx) {
auto entry = d_col[idx];
auto g = d_gpair[entry.index * num_group + group_idx];
return GradientPair(g.GetGrad() * entry.fvalue,
g.GetHess() * entry.fvalue * entry.fvalue);
}; // NOLINT
thrust::transform_iterator<decltype(f), decltype(counting), GradientPair>
multiply_iterator(counting, f);
return dh::SumReduction(multiply_iterator, col_size);
}
// This needs to be public because of the __device__ lambda.
void UpdateResidual(float dw, int group_idx, int num_groups, int fidx) {
common::Span<GradientPair> d_gpair = dh::ToSpan(gpair_);
common::Span<Entry> d_col = dh::ToSpan(data_).subspan(row_ptr_[fidx]);
size_t col_size = row_ptr_[fidx + 1] - row_ptr_[fidx];
dh::LaunchN(learner_param_->gpu_id, col_size, [=] __device__(size_t idx) {
auto entry = d_col[idx];
auto &g = d_gpair[entry.index * num_groups + group_idx];
g += GradientPair(g.GetHess() * dw * entry.fvalue, 0);
});
}
private:
bool IsEmpty() {
return num_row_ == 0;
}
void UpdateGpair(const std::vector<GradientPair> &host_gpair) {
dh::safe_cuda(hipMemcpyAsync(
gpair_.data().get(),
host_gpair.data(),
gpair_.size() * sizeof(GradientPair), hipMemcpyHostToDevice));
}
// training parameter
LinearTrainParam tparam_;
CoordinateParam coord_param_;
std::unique_ptr<FeatureSelector> selector_;
common::Monitor monitor_;
std::vector<size_t> row_ptr_;
dh::device_vector<xgboost::Entry> data_;
dh::caching_device_vector<GradientPair> gpair_;
size_t num_row_;
};
XGBOOST_REGISTER_LINEAR_UPDATER(GPUCoordinateUpdater, "gpu_coord_descent")
.describe(
"Update linear model according to coordinate descent algorithm. GPU "
"accelerated.")
.set_body([]() { return new GPUCoordinateUpdater(); });
} // namespace linear
} // namespace xgboost
| 471a0de21d627a7c2a2721ee0f2dafcbec2cc702.cu | /*!
* Copyright 2018-2019 by Contributors
* \author Rory Mitchell
*/
#include <thrust/execution_policy.h>
#include <thrust/inner_product.h>
#include <xgboost/data.h>
#include <xgboost/linear_updater.h>
#include "xgboost/span.h"
#include "coordinate_common.h"
#include "../common/common.h"
#include "../common/device_helpers.cuh"
#include "../common/timer.h"
#include "./param.h"
namespace xgboost {
namespace linear {
DMLC_REGISTRY_FILE_TAG(updater_gpu_coordinate);
/**
* \class GPUCoordinateUpdater
*
* \brief Coordinate descent algorithm that updates one feature per iteration
*/
class GPUCoordinateUpdater : public LinearUpdater { // NOLINT
public:
~GPUCoordinateUpdater() { // NOLINT
if (learner_param_->gpu_id >= 0) {
dh::safe_cuda(cudaSetDevice(learner_param_->gpu_id));
}
}
// set training parameter
void Configure(Args const& args) override {
tparam_.UpdateAllowUnknown(args);
coord_param_.UpdateAllowUnknown(args);
selector_.reset(FeatureSelector::Create(tparam_.feature_selector));
monitor_.Init("GPUCoordinateUpdater");
}
void LoadConfig(Json const& in) override {
auto const& config = get<Object const>(in);
FromJson(config.at("linear_train_param"), &tparam_);
FromJson(config.at("coordinate_param"), &coord_param_);
}
void SaveConfig(Json* p_out) const override {
auto& out = *p_out;
out["linear_train_param"] = ToJson(tparam_);
out["coordinate_param"] = ToJson(coord_param_);
}
void LazyInitDevice(DMatrix *p_fmat, const LearnerModelParam &model_param) {
if (learner_param_->gpu_id < 0) return;
num_row_ = static_cast<size_t>(p_fmat->Info().num_row_);
CHECK(p_fmat->SingleColBlock());
SparsePage const& batch = *(p_fmat->GetBatches<CSCPage>().begin());
if (IsEmpty()) {
return;
}
dh::safe_cuda(cudaSetDevice(learner_param_->gpu_id));
// The begin and end indices for the section of each column associated with
// this device
std::vector<std::pair<bst_uint, bst_uint>> column_segments;
row_ptr_ = {0};
// iterate through columns
for (size_t fidx = 0; fidx < batch.Size(); fidx++) {
common::Span<Entry const> col = batch[fidx];
auto cmp = [](Entry e1, Entry e2) {
return e1.index < e2.index;
};
auto column_begin =
std::lower_bound(col.cbegin(), col.cend(),
xgboost::Entry(0, 0.0f), cmp);
auto column_end =
std::lower_bound(col.cbegin(), col.cend(),
xgboost::Entry(num_row_, 0.0f), cmp);
column_segments.emplace_back(
std::make_pair(column_begin - col.cbegin(), column_end - col.cbegin()));
row_ptr_.push_back(row_ptr_.back() + (column_end - column_begin));
}
data_.resize(row_ptr_.back());
gpair_.resize(num_row_ * model_param.num_output_group);
for (size_t fidx = 0; fidx < batch.Size(); fidx++) {
auto col = batch[fidx];
auto seg = column_segments[fidx];
dh::safe_cuda(cudaMemcpy(
data_.data().get() + row_ptr_[fidx],
col.data() + seg.first,
sizeof(Entry) * (seg.second - seg.first), cudaMemcpyHostToDevice));
}
}
void Update(HostDeviceVector<GradientPair> *in_gpair, DMatrix *p_fmat,
gbm::GBLinearModel *model, double sum_instance_weight) override {
tparam_.DenormalizePenalties(sum_instance_weight);
monitor_.Start("LazyInitDevice");
this->LazyInitDevice(p_fmat, *(model->learner_model_param));
monitor_.Stop("LazyInitDevice");
monitor_.Start("UpdateGpair");
auto &in_gpair_host = in_gpair->ConstHostVector();
// Update gpair
if (learner_param_->gpu_id >= 0) {
this->UpdateGpair(in_gpair_host);
}
monitor_.Stop("UpdateGpair");
monitor_.Start("UpdateBias");
this->UpdateBias(p_fmat, model);
monitor_.Stop("UpdateBias");
// prepare for updating the weights
selector_->Setup(*model, in_gpair->ConstHostVector(), p_fmat,
tparam_.reg_alpha_denorm, tparam_.reg_lambda_denorm,
coord_param_.top_k);
monitor_.Start("UpdateFeature");
for (auto group_idx = 0; group_idx < model->learner_model_param->num_output_group;
++group_idx) {
for (auto i = 0U; i < model->learner_model_param->num_feature; i++) {
auto fidx = selector_->NextFeature(
i, *model, group_idx, in_gpair->ConstHostVector(), p_fmat,
tparam_.reg_alpha_denorm, tparam_.reg_lambda_denorm);
if (fidx < 0) break;
this->UpdateFeature(fidx, group_idx, &in_gpair->HostVector(), model);
}
}
monitor_.Stop("UpdateFeature");
}
void UpdateBias(DMatrix *p_fmat, gbm::GBLinearModel *model) {
for (int group_idx = 0; group_idx < model->learner_model_param->num_output_group;
++group_idx) {
// Get gradient
auto grad = GradientPair(0, 0);
if (learner_param_->gpu_id >= 0) {
grad = GetBiasGradient(group_idx, model->learner_model_param->num_output_group);
}
auto dbias = static_cast<float>(
tparam_.learning_rate *
CoordinateDeltaBias(grad.GetGrad(), grad.GetHess()));
model->Bias()[group_idx] += dbias;
// Update residual
if (learner_param_->gpu_id >= 0) {
UpdateBiasResidual(dbias, group_idx, model->learner_model_param->num_output_group);
}
}
}
void UpdateFeature(int fidx, int group_idx,
std::vector<GradientPair> *in_gpair,
gbm::GBLinearModel *model) {
bst_float &w = (*model)[fidx][group_idx];
// Get gradient
auto grad = GradientPair(0, 0);
if (learner_param_->gpu_id >= 0) {
grad = GetGradient(group_idx, model->learner_model_param->num_output_group, fidx);
}
auto dw = static_cast<float>(tparam_.learning_rate *
CoordinateDelta(grad.GetGrad(), grad.GetHess(),
w, tparam_.reg_alpha_denorm,
tparam_.reg_lambda_denorm));
w += dw;
if (learner_param_->gpu_id >= 0) {
UpdateResidual(dw, group_idx, model->learner_model_param->num_output_group, fidx);
}
}
// This needs to be public because of the __device__ lambda.
GradientPair GetBiasGradient(int group_idx, int num_group) {
dh::safe_cuda(cudaSetDevice(learner_param_->gpu_id));
auto counting = thrust::make_counting_iterator(0ull);
auto f = [=] __device__(size_t idx) {
return idx * num_group + group_idx;
}; // NOLINT
thrust::transform_iterator<decltype(f), decltype(counting), size_t> skip(
counting, f);
auto perm = thrust::make_permutation_iterator(gpair_.data(), skip);
return dh::SumReduction(perm, num_row_);
}
// This needs to be public because of the __device__ lambda.
void UpdateBiasResidual(float dbias, int group_idx, int num_groups) {
if (dbias == 0.0f) return;
auto d_gpair = dh::ToSpan(gpair_);
dh::LaunchN(learner_param_->gpu_id, num_row_, [=] __device__(size_t idx) {
auto &g = d_gpair[idx * num_groups + group_idx];
g += GradientPair(g.GetHess() * dbias, 0);
});
}
// This needs to be public because of the __device__ lambda.
GradientPair GetGradient(int group_idx, int num_group, int fidx) {
dh::safe_cuda(cudaSetDevice(learner_param_->gpu_id));
common::Span<xgboost::Entry> d_col = dh::ToSpan(data_).subspan(row_ptr_[fidx]);
size_t col_size = row_ptr_[fidx + 1] - row_ptr_[fidx];
common::Span<GradientPair> d_gpair = dh::ToSpan(gpair_);
auto counting = thrust::make_counting_iterator(0ull);
auto f = [=] __device__(size_t idx) {
auto entry = d_col[idx];
auto g = d_gpair[entry.index * num_group + group_idx];
return GradientPair(g.GetGrad() * entry.fvalue,
g.GetHess() * entry.fvalue * entry.fvalue);
}; // NOLINT
thrust::transform_iterator<decltype(f), decltype(counting), GradientPair>
multiply_iterator(counting, f);
return dh::SumReduction(multiply_iterator, col_size);
}
// This needs to be public because of the __device__ lambda.
void UpdateResidual(float dw, int group_idx, int num_groups, int fidx) {
common::Span<GradientPair> d_gpair = dh::ToSpan(gpair_);
common::Span<Entry> d_col = dh::ToSpan(data_).subspan(row_ptr_[fidx]);
size_t col_size = row_ptr_[fidx + 1] - row_ptr_[fidx];
dh::LaunchN(learner_param_->gpu_id, col_size, [=] __device__(size_t idx) {
auto entry = d_col[idx];
auto &g = d_gpair[entry.index * num_groups + group_idx];
g += GradientPair(g.GetHess() * dw * entry.fvalue, 0);
});
}
private:
bool IsEmpty() {
return num_row_ == 0;
}
void UpdateGpair(const std::vector<GradientPair> &host_gpair) {
dh::safe_cuda(cudaMemcpyAsync(
gpair_.data().get(),
host_gpair.data(),
gpair_.size() * sizeof(GradientPair), cudaMemcpyHostToDevice));
}
// training parameter
LinearTrainParam tparam_;
CoordinateParam coord_param_;
std::unique_ptr<FeatureSelector> selector_;
common::Monitor monitor_;
std::vector<size_t> row_ptr_;
dh::device_vector<xgboost::Entry> data_;
dh::caching_device_vector<GradientPair> gpair_;
size_t num_row_;
};
XGBOOST_REGISTER_LINEAR_UPDATER(GPUCoordinateUpdater, "gpu_coord_descent")
.describe(
"Update linear model according to coordinate descent algorithm. GPU "
"accelerated.")
.set_body([]() { return new GPUCoordinateUpdater(); });
} // namespace linear
} // namespace xgboost
|
58097e627a00f479691c6c08c8b73db6b1546372.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include<math.h>
#include"Boys_gpu.h"
#define PI 3.1415926535897932
#define P25 17.4934183276248620
#define NTHREAD_32 32
#define NTHREAD_64 64
#define NTHREAD_128 128
texture<int2,1,hipReadModeElementType> tex_Q;
texture<int2,1,hipReadModeElementType> tex_Eta;
texture<int2,1,hipReadModeElementType> tex_pq;
texture<float,1,hipReadModeElementType> tex_K2_q;
texture<int2,1,hipReadModeElementType> tex_QC;
texture<int2,1,hipReadModeElementType> tex_QD;
texture<int2,1,hipReadModeElementType> tex_Pmtrx;
void TSMJ_texture_binding_pp(double * Q_d,double * QC_d,double * QD_d,\
double * alphaQ_d,double * pq_d,float * K2_q_d,double * Pmtrx_d,\
unsigned int contrc_ket_start_pr,unsigned int primit_ket_len,unsigned int contrc_Pmtrx_start_pr){
hipBindTexture(0, tex_Q, Q_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len)*3);
hipBindTexture(0, tex_Eta, alphaQ_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len));
hipBindTexture(0, tex_pq, pq_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len));
hipBindTexture(0, tex_K2_q, K2_q_d, sizeof(float)*(contrc_ket_start_pr+primit_ket_len));
hipBindTexture(0, tex_QC, QC_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len)*3);
hipBindTexture(0, tex_QD, QD_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len)*3);
hipBindTexture(0, tex_Pmtrx, Pmtrx_d, sizeof(double)*(contrc_Pmtrx_start_pr+primit_ket_len)*9);
}
void TSMJ_texture_unbind_pp(){
hipUnbindTexture(tex_Q);
hipUnbindTexture(tex_Eta);
hipUnbindTexture(tex_pq);
hipUnbindTexture(tex_K2_q);
hipUnbindTexture(tex_QC);
hipUnbindTexture(tex_QD);
hipUnbindTexture(tex_Pmtrx);
}
__global__ void TSMJ_sspp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
QD_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
QD_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
QD_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
QD_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
QD_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
QD_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_taylor(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_sspp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double QD_010[3];
QD_010[0]=QC[jj*3+0];
QD_010[1]=QC[jj*3+1];
QD_010[2]=QC[jj*3+2];
double QD_001[3];
QD_001[0]=QD[jj*3+0];
QD_001[1]=QD[jj*3+1];
QD_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_fs_1(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_sspp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
QD_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
QD_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
QD_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
QD_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
QD_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
QD_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_fs_1(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_sspp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
QD_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
QD_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
QD_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
QD_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
QD_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
QD_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_fs_1(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
}
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_pspp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_taylor(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pspp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_fs_3(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pspp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_fs_3(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pspp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_fs_3(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
}
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pppp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_taylor(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_pppp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_pppp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_pppp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
}
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_dspp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_taylor(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dspp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dspp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dspp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
}
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dppp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_taylor(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_dppp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_fs_5(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_dppp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_fs_5(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_dppp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
double QR_011000000003=0;
double QR_010001000003=0;
double QR_010000001003=0;
double QR_001010000003=0;
double QR_000011000003=0;
double QR_000010001003=0;
double QR_001000010003=0;
double QR_000001010003=0;
double QR_000000011003=0;
double QR_011000000012=0;
double QR_010001000012=0;
double QR_010000001012=0;
double QR_001010000012=0;
double QR_000011000012=0;
double QR_000010001012=0;
double QR_001000010012=0;
double QR_000001010012=0;
double QR_000000011012=0;
double QR_011000000021=0;
double QR_010001000021=0;
double QR_010000001021=0;
double QR_001010000021=0;
double QR_000011000021=0;
double QR_000010001021=0;
double QR_001000010021=0;
double QR_000001010021=0;
double QR_000000011021=0;
double QR_011000000030=0;
double QR_010001000030=0;
double QR_010000001030=0;
double QR_001010000030=0;
double QR_000011000030=0;
double QR_000010001030=0;
double QR_001000010030=0;
double QR_000001010030=0;
double QR_000000011030=0;
double QR_011000000102=0;
double QR_010001000102=0;
double QR_010000001102=0;
double QR_001010000102=0;
double QR_000011000102=0;
double QR_000010001102=0;
double QR_001000010102=0;
double QR_000001010102=0;
double QR_000000011102=0;
double QR_011000000111=0;
double QR_010001000111=0;
double QR_010000001111=0;
double QR_001010000111=0;
double QR_000011000111=0;
double QR_000010001111=0;
double QR_001000010111=0;
double QR_000001010111=0;
double QR_000000011111=0;
double QR_011000000120=0;
double QR_010001000120=0;
double QR_010000001120=0;
double QR_001010000120=0;
double QR_000011000120=0;
double QR_000010001120=0;
double QR_001000010120=0;
double QR_000001010120=0;
double QR_000000011120=0;
double QR_011000000201=0;
double QR_010001000201=0;
double QR_010000001201=0;
double QR_001010000201=0;
double QR_000011000201=0;
double QR_000010001201=0;
double QR_001000010201=0;
double QR_000001010201=0;
double QR_000000011201=0;
double QR_011000000210=0;
double QR_010001000210=0;
double QR_010000001210=0;
double QR_001010000210=0;
double QR_000011000210=0;
double QR_000010001210=0;
double QR_001000010210=0;
double QR_000001010210=0;
double QR_000000011210=0;
double QR_011000000300=0;
double QR_010001000300=0;
double QR_010000001300=0;
double QR_001010000300=0;
double QR_000011000300=0;
double QR_000010001300=0;
double QR_001000010300=0;
double QR_000001010300=0;
double QR_000000011300=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_fs_5(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
QR_011000000003+=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
QR_010001000003+=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
QR_010000001003+=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
QR_001010000003+=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
QR_000011000003+=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
QR_000010001003+=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
QR_001000010003+=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
QR_000001010003+=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
QR_000000011003+=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
QR_011000000012+=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
QR_010001000012+=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
QR_010000001012+=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001010000012+=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
QR_000011000012+=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
QR_000010001012+=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
QR_001000010012+=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000001010012+=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
QR_000000011012+=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
QR_011000000021+=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
QR_010001000021+=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
QR_010000001021+=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001010000021+=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
QR_000011000021+=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
QR_000010001021+=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
QR_001000010021+=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000001010021+=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
QR_000000011021+=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
QR_011000000030+=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
QR_010001000030+=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
QR_010000001030+=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001010000030+=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
QR_000011000030+=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
QR_000010001030+=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
QR_001000010030+=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000001010030+=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
QR_000000011030+=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
QR_011000000102+=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
QR_010001000102+=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
QR_010000001102+=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
QR_001010000102+=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
QR_000011000102+=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
QR_000010001102+=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001000010102+=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
QR_000001010102+=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000000011102+=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
QR_011000000111+=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
QR_010001000111+=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
QR_010000001111+=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001010000111+=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
QR_000011000111+=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
QR_000010001111+=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001000010111+=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000001010111+=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000000011111+=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
QR_011000000120+=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
QR_010001000120+=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
QR_010000001120+=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001010000120+=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
QR_000011000120+=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
QR_000010001120+=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001000010120+=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000001010120+=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000000011120+=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
QR_011000000201+=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
QR_010001000201+=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
QR_010000001201+=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
QR_001010000201+=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
QR_000011000201+=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
QR_000010001201+=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001000010201+=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
QR_000001010201+=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000000011201+=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
QR_011000000210+=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
QR_010001000210+=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
QR_010000001210+=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001010000210+=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
QR_000011000210+=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
QR_000010001210+=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001000010210+=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000001010210+=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000000011210+=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
QR_011000000300+=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
QR_010001000300+=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
QR_010000001300+=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
QR_001010000300+=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
QR_000011000300+=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
QR_000010001300+=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001000010300+=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
QR_000001010300+=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000000011300+=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
}
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_ddpp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_taylor(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double QR_011000000004=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
double QR_010001000004=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
double QR_010000001004=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
double QR_001010000004=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
double QR_000011000004=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
double QR_000010001004=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
double QR_001000010004=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
double QR_000001010004=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
double QR_000000011004=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
double QR_011000000013=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
double QR_010001000013=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
double QR_010000001013=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001010000013=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
double QR_000011000013=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
double QR_000010001013=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
double QR_001000010013=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000001010013=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
double QR_000000011013=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
double QR_011000000022=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
double QR_010001000022=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
double QR_010000001022=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001010000022=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
double QR_000011000022=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
double QR_000010001022=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
double QR_001000010022=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000001010022=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
double QR_000000011022=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
double QR_011000000031=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
double QR_010001000031=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
double QR_010000001031=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001010000031=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
double QR_000011000031=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
double QR_000010001031=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
double QR_001000010031=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000001010031=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
double QR_000000011031=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
double QR_011000000040=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
double QR_010001000040=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
double QR_010000001040=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001010000040=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
double QR_000011000040=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
double QR_000010001040=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
double QR_001000010040=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000001010040=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
double QR_000000011040=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
double QR_011000000103=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
double QR_010001000103=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
double QR_010000001103=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
double QR_001010000103=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
double QR_000011000103=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
double QR_000010001103=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001000010103=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
double QR_000001010103=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000000011103=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
double QR_011000000112=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
double QR_010001000112=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
double QR_010000001112=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001010000112=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
double QR_000011000112=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
double QR_000010001112=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001000010112=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000001010112=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000000011112=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
double QR_011000000121=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
double QR_010001000121=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
double QR_010000001121=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001010000121=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
double QR_000011000121=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
double QR_000010001121=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001000010121=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000001010121=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000000011121=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
double QR_011000000130=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
double QR_010001000130=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
double QR_010000001130=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001010000130=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
double QR_000011000130=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
double QR_000010001130=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001000010130=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000001010130=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000000011130=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
double QR_011000000202=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
double QR_010001000202=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
double QR_010000001202=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
double QR_001010000202=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
double QR_000011000202=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
double QR_000010001202=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001000010202=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
double QR_000001010202=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000000011202=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
double QR_011000000211=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
double QR_010001000211=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
double QR_010000001211=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001010000211=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
double QR_000011000211=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
double QR_000010001211=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001000010211=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000001010211=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000000011211=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
double QR_011000000220=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
double QR_010001000220=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
double QR_010000001220=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001010000220=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
double QR_000011000220=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
double QR_000010001220=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001000010220=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000001010220=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000000011220=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
double QR_011000000301=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
double QR_010001000301=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
double QR_010000001301=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
double QR_001010000301=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
double QR_000011000301=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
double QR_000010001301=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001000010301=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
double QR_000001010301=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000000011301=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
double QR_011000000310=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
double QR_010001000310=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
double QR_010000001310=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001010000310=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
double QR_000011000310=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
double QR_000010001310=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001000010310=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000001010310=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000000011310=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
double QR_011000000400=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
double QR_010001000400=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
double QR_010000001400=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
double QR_001010000400=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
double QR_000011000400=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
double QR_000010001400=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001000010400=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
double QR_000001010400=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000000011400=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
__global__ void TSMJ_ddpp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_fs_6(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double QR_011000000004=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
double QR_010001000004=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
double QR_010000001004=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
double QR_001010000004=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
double QR_000011000004=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
double QR_000010001004=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
double QR_001000010004=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
double QR_000001010004=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
double QR_000000011004=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
double QR_011000000013=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
double QR_010001000013=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
double QR_010000001013=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001010000013=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
double QR_000011000013=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
double QR_000010001013=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
double QR_001000010013=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000001010013=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
double QR_000000011013=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
double QR_011000000022=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
double QR_010001000022=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
double QR_010000001022=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001010000022=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
double QR_000011000022=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
double QR_000010001022=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
double QR_001000010022=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000001010022=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
double QR_000000011022=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
double QR_011000000031=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
double QR_010001000031=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
double QR_010000001031=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001010000031=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
double QR_000011000031=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
double QR_000010001031=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
double QR_001000010031=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000001010031=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
double QR_000000011031=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
double QR_011000000040=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
double QR_010001000040=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
double QR_010000001040=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001010000040=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
double QR_000011000040=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
double QR_000010001040=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
double QR_001000010040=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000001010040=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
double QR_000000011040=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
double QR_011000000103=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
double QR_010001000103=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
double QR_010000001103=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
double QR_001010000103=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
double QR_000011000103=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
double QR_000010001103=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001000010103=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
double QR_000001010103=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000000011103=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
double QR_011000000112=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
double QR_010001000112=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
double QR_010000001112=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001010000112=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
double QR_000011000112=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
double QR_000010001112=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001000010112=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000001010112=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000000011112=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
double QR_011000000121=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
double QR_010001000121=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
double QR_010000001121=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001010000121=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
double QR_000011000121=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
double QR_000010001121=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001000010121=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000001010121=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000000011121=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
double QR_011000000130=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
double QR_010001000130=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
double QR_010000001130=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001010000130=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
double QR_000011000130=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
double QR_000010001130=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001000010130=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000001010130=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000000011130=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
double QR_011000000202=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
double QR_010001000202=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
double QR_010000001202=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
double QR_001010000202=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
double QR_000011000202=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
double QR_000010001202=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001000010202=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
double QR_000001010202=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000000011202=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
double QR_011000000211=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
double QR_010001000211=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
double QR_010000001211=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001010000211=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
double QR_000011000211=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
double QR_000010001211=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001000010211=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000001010211=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000000011211=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
double QR_011000000220=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
double QR_010001000220=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
double QR_010000001220=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001010000220=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
double QR_000011000220=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
double QR_000010001220=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001000010220=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000001010220=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000000011220=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
double QR_011000000301=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
double QR_010001000301=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
double QR_010000001301=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
double QR_001010000301=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
double QR_000011000301=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
double QR_000010001301=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001000010301=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
double QR_000001010301=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000000011301=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
double QR_011000000310=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
double QR_010001000310=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
double QR_010000001310=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001010000310=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
double QR_000011000310=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
double QR_000010001310=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001000010310=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000001010310=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000000011310=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
double QR_011000000400=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
double QR_010001000400=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
double QR_010000001400=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
double QR_001010000400=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
double QR_000011000400=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
double QR_000010001400=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001000010400=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
double QR_000001010400=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000000011400=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
__global__ void TSMJ_ddpp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_fs_6(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double QR_011000000004=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
double QR_010001000004=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
double QR_010000001004=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
double QR_001010000004=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
double QR_000011000004=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
double QR_000010001004=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
double QR_001000010004=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
double QR_000001010004=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
double QR_000000011004=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
double QR_011000000013=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
double QR_010001000013=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
double QR_010000001013=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001010000013=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
double QR_000011000013=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
double QR_000010001013=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
double QR_001000010013=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000001010013=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
double QR_000000011013=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
double QR_011000000022=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
double QR_010001000022=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
double QR_010000001022=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001010000022=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
double QR_000011000022=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
double QR_000010001022=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
double QR_001000010022=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000001010022=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
double QR_000000011022=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
double QR_011000000031=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
double QR_010001000031=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
double QR_010000001031=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001010000031=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
double QR_000011000031=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
double QR_000010001031=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
double QR_001000010031=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000001010031=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
double QR_000000011031=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
double QR_011000000040=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
double QR_010001000040=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
double QR_010000001040=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001010000040=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
double QR_000011000040=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
double QR_000010001040=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
double QR_001000010040=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000001010040=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
double QR_000000011040=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
double QR_011000000103=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
double QR_010001000103=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
double QR_010000001103=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
double QR_001010000103=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
double QR_000011000103=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
double QR_000010001103=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001000010103=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
double QR_000001010103=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000000011103=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
double QR_011000000112=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
double QR_010001000112=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
double QR_010000001112=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001010000112=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
double QR_000011000112=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
double QR_000010001112=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001000010112=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000001010112=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000000011112=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
double QR_011000000121=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
double QR_010001000121=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
double QR_010000001121=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001010000121=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
double QR_000011000121=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
double QR_000010001121=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001000010121=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000001010121=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000000011121=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
double QR_011000000130=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
double QR_010001000130=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
double QR_010000001130=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001010000130=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
double QR_000011000130=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
double QR_000010001130=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001000010130=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000001010130=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000000011130=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
double QR_011000000202=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
double QR_010001000202=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
double QR_010000001202=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
double QR_001010000202=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
double QR_000011000202=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
double QR_000010001202=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001000010202=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
double QR_000001010202=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000000011202=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
double QR_011000000211=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
double QR_010001000211=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
double QR_010000001211=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001010000211=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
double QR_000011000211=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
double QR_000010001211=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001000010211=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000001010211=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000000011211=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
double QR_011000000220=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
double QR_010001000220=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
double QR_010000001220=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001010000220=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
double QR_000011000220=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
double QR_000010001220=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001000010220=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000001010220=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000000011220=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
double QR_011000000301=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
double QR_010001000301=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
double QR_010000001301=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
double QR_001010000301=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
double QR_000011000301=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
double QR_000010001301=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001000010301=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
double QR_000001010301=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000000011301=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
double QR_011000000310=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
double QR_010001000310=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
double QR_010000001310=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001010000310=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
double QR_000011000310=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
double QR_000010001310=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001000010310=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000001010310=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000000011310=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
double QR_011000000400=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
double QR_010001000400=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
double QR_010000001400=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
double QR_001010000400=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
double QR_000011000400=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
double QR_000010001400=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001000010400=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
double QR_000001010400=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000000011400=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
__global__ void TSMJ_ddpp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
double QR_011000000003=0;
double QR_010001000003=0;
double QR_010000001003=0;
double QR_001010000003=0;
double QR_000011000003=0;
double QR_000010001003=0;
double QR_001000010003=0;
double QR_000001010003=0;
double QR_000000011003=0;
double QR_011000000012=0;
double QR_010001000012=0;
double QR_010000001012=0;
double QR_001010000012=0;
double QR_000011000012=0;
double QR_000010001012=0;
double QR_001000010012=0;
double QR_000001010012=0;
double QR_000000011012=0;
double QR_011000000021=0;
double QR_010001000021=0;
double QR_010000001021=0;
double QR_001010000021=0;
double QR_000011000021=0;
double QR_000010001021=0;
double QR_001000010021=0;
double QR_000001010021=0;
double QR_000000011021=0;
double QR_011000000030=0;
double QR_010001000030=0;
double QR_010000001030=0;
double QR_001010000030=0;
double QR_000011000030=0;
double QR_000010001030=0;
double QR_001000010030=0;
double QR_000001010030=0;
double QR_000000011030=0;
double QR_011000000102=0;
double QR_010001000102=0;
double QR_010000001102=0;
double QR_001010000102=0;
double QR_000011000102=0;
double QR_000010001102=0;
double QR_001000010102=0;
double QR_000001010102=0;
double QR_000000011102=0;
double QR_011000000111=0;
double QR_010001000111=0;
double QR_010000001111=0;
double QR_001010000111=0;
double QR_000011000111=0;
double QR_000010001111=0;
double QR_001000010111=0;
double QR_000001010111=0;
double QR_000000011111=0;
double QR_011000000120=0;
double QR_010001000120=0;
double QR_010000001120=0;
double QR_001010000120=0;
double QR_000011000120=0;
double QR_000010001120=0;
double QR_001000010120=0;
double QR_000001010120=0;
double QR_000000011120=0;
double QR_011000000201=0;
double QR_010001000201=0;
double QR_010000001201=0;
double QR_001010000201=0;
double QR_000011000201=0;
double QR_000010001201=0;
double QR_001000010201=0;
double QR_000001010201=0;
double QR_000000011201=0;
double QR_011000000210=0;
double QR_010001000210=0;
double QR_010000001210=0;
double QR_001010000210=0;
double QR_000011000210=0;
double QR_000010001210=0;
double QR_001000010210=0;
double QR_000001010210=0;
double QR_000000011210=0;
double QR_011000000300=0;
double QR_010001000300=0;
double QR_010000001300=0;
double QR_001010000300=0;
double QR_000011000300=0;
double QR_000010001300=0;
double QR_001000010300=0;
double QR_000001010300=0;
double QR_000000011300=0;
double QR_011000000004=0;
double QR_010001000004=0;
double QR_010000001004=0;
double QR_001010000004=0;
double QR_000011000004=0;
double QR_000010001004=0;
double QR_001000010004=0;
double QR_000001010004=0;
double QR_000000011004=0;
double QR_011000000013=0;
double QR_010001000013=0;
double QR_010000001013=0;
double QR_001010000013=0;
double QR_000011000013=0;
double QR_000010001013=0;
double QR_001000010013=0;
double QR_000001010013=0;
double QR_000000011013=0;
double QR_011000000022=0;
double QR_010001000022=0;
double QR_010000001022=0;
double QR_001010000022=0;
double QR_000011000022=0;
double QR_000010001022=0;
double QR_001000010022=0;
double QR_000001010022=0;
double QR_000000011022=0;
double QR_011000000031=0;
double QR_010001000031=0;
double QR_010000001031=0;
double QR_001010000031=0;
double QR_000011000031=0;
double QR_000010001031=0;
double QR_001000010031=0;
double QR_000001010031=0;
double QR_000000011031=0;
double QR_011000000040=0;
double QR_010001000040=0;
double QR_010000001040=0;
double QR_001010000040=0;
double QR_000011000040=0;
double QR_000010001040=0;
double QR_001000010040=0;
double QR_000001010040=0;
double QR_000000011040=0;
double QR_011000000103=0;
double QR_010001000103=0;
double QR_010000001103=0;
double QR_001010000103=0;
double QR_000011000103=0;
double QR_000010001103=0;
double QR_001000010103=0;
double QR_000001010103=0;
double QR_000000011103=0;
double QR_011000000112=0;
double QR_010001000112=0;
double QR_010000001112=0;
double QR_001010000112=0;
double QR_000011000112=0;
double QR_000010001112=0;
double QR_001000010112=0;
double QR_000001010112=0;
double QR_000000011112=0;
double QR_011000000121=0;
double QR_010001000121=0;
double QR_010000001121=0;
double QR_001010000121=0;
double QR_000011000121=0;
double QR_000010001121=0;
double QR_001000010121=0;
double QR_000001010121=0;
double QR_000000011121=0;
double QR_011000000130=0;
double QR_010001000130=0;
double QR_010000001130=0;
double QR_001010000130=0;
double QR_000011000130=0;
double QR_000010001130=0;
double QR_001000010130=0;
double QR_000001010130=0;
double QR_000000011130=0;
double QR_011000000202=0;
double QR_010001000202=0;
double QR_010000001202=0;
double QR_001010000202=0;
double QR_000011000202=0;
double QR_000010001202=0;
double QR_001000010202=0;
double QR_000001010202=0;
double QR_000000011202=0;
double QR_011000000211=0;
double QR_010001000211=0;
double QR_010000001211=0;
double QR_001010000211=0;
double QR_000011000211=0;
double QR_000010001211=0;
double QR_001000010211=0;
double QR_000001010211=0;
double QR_000000011211=0;
double QR_011000000220=0;
double QR_010001000220=0;
double QR_010000001220=0;
double QR_001010000220=0;
double QR_000011000220=0;
double QR_000010001220=0;
double QR_001000010220=0;
double QR_000001010220=0;
double QR_000000011220=0;
double QR_011000000301=0;
double QR_010001000301=0;
double QR_010000001301=0;
double QR_001010000301=0;
double QR_000011000301=0;
double QR_000010001301=0;
double QR_001000010301=0;
double QR_000001010301=0;
double QR_000000011301=0;
double QR_011000000310=0;
double QR_010001000310=0;
double QR_010000001310=0;
double QR_001010000310=0;
double QR_000011000310=0;
double QR_000010001310=0;
double QR_001000010310=0;
double QR_000001010310=0;
double QR_000000011310=0;
double QR_011000000400=0;
double QR_010001000400=0;
double QR_010000001400=0;
double QR_001010000400=0;
double QR_000011000400=0;
double QR_000010001400=0;
double QR_001000010400=0;
double QR_000001010400=0;
double QR_000000011400=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_fs_6(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
QR_011000000003+=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
QR_010001000003+=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
QR_010000001003+=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
QR_001010000003+=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
QR_000011000003+=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
QR_000010001003+=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
QR_001000010003+=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
QR_000001010003+=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
QR_000000011003+=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
QR_011000000012+=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
QR_010001000012+=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
QR_010000001012+=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001010000012+=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
QR_000011000012+=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
QR_000010001012+=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
QR_001000010012+=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000001010012+=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
QR_000000011012+=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
QR_011000000021+=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
QR_010001000021+=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
QR_010000001021+=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001010000021+=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
QR_000011000021+=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
QR_000010001021+=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
QR_001000010021+=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000001010021+=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
QR_000000011021+=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
QR_011000000030+=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
QR_010001000030+=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
QR_010000001030+=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001010000030+=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
QR_000011000030+=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
QR_000010001030+=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
QR_001000010030+=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000001010030+=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
QR_000000011030+=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
QR_011000000102+=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
QR_010001000102+=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
QR_010000001102+=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
QR_001010000102+=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
QR_000011000102+=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
QR_000010001102+=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001000010102+=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
QR_000001010102+=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000000011102+=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
QR_011000000111+=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
QR_010001000111+=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
QR_010000001111+=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001010000111+=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
QR_000011000111+=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
QR_000010001111+=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001000010111+=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000001010111+=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000000011111+=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
QR_011000000120+=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
QR_010001000120+=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
QR_010000001120+=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001010000120+=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
QR_000011000120+=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
QR_000010001120+=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001000010120+=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000001010120+=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000000011120+=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
QR_011000000201+=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
QR_010001000201+=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
QR_010000001201+=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
QR_001010000201+=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
QR_000011000201+=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
QR_000010001201+=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001000010201+=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
QR_000001010201+=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000000011201+=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
QR_011000000210+=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
QR_010001000210+=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
QR_010000001210+=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001010000210+=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
QR_000011000210+=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
QR_000010001210+=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001000010210+=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000001010210+=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000000011210+=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
QR_011000000300+=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
QR_010001000300+=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
QR_010000001300+=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
QR_001010000300+=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
QR_000011000300+=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
QR_000010001300+=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001000010300+=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
QR_000001010300+=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000000011300+=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
QR_011000000004+=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
QR_010001000004+=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
QR_010000001004+=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
QR_001010000004+=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
QR_000011000004+=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
QR_000010001004+=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
QR_001000010004+=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
QR_000001010004+=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
QR_000000011004+=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
QR_011000000013+=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
QR_010001000013+=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
QR_010000001013+=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
QR_001010000013+=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
QR_000011000013+=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
QR_000010001013+=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
QR_001000010013+=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
QR_000001010013+=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
QR_000000011013+=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
QR_011000000022+=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
QR_010001000022+=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
QR_010000001022+=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
QR_001010000022+=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
QR_000011000022+=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
QR_000010001022+=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
QR_001000010022+=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
QR_000001010022+=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
QR_000000011022+=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
QR_011000000031+=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
QR_010001000031+=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
QR_010000001031+=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
QR_001010000031+=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
QR_000011000031+=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
QR_000010001031+=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
QR_001000010031+=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
QR_000001010031+=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
QR_000000011031+=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
QR_011000000040+=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
QR_010001000040+=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
QR_010000001040+=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
QR_001010000040+=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
QR_000011000040+=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
QR_000010001040+=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
QR_001000010040+=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
QR_000001010040+=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
QR_000000011040+=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
QR_011000000103+=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
QR_010001000103+=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
QR_010000001103+=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
QR_001010000103+=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
QR_000011000103+=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
QR_000010001103+=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
QR_001000010103+=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
QR_000001010103+=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
QR_000000011103+=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
QR_011000000112+=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
QR_010001000112+=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
QR_010000001112+=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
QR_001010000112+=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
QR_000011000112+=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
QR_000010001112+=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
QR_001000010112+=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
QR_000001010112+=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
QR_000000011112+=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
QR_011000000121+=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
QR_010001000121+=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
QR_010000001121+=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
QR_001010000121+=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
QR_000011000121+=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
QR_000010001121+=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
QR_001000010121+=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
QR_000001010121+=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
QR_000000011121+=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
QR_011000000130+=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
QR_010001000130+=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
QR_010000001130+=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
QR_001010000130+=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
QR_000011000130+=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
QR_000010001130+=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
QR_001000010130+=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
QR_000001010130+=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
QR_000000011130+=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
QR_011000000202+=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
QR_010001000202+=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
QR_010000001202+=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
QR_001010000202+=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
QR_000011000202+=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
QR_000010001202+=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
QR_001000010202+=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
QR_000001010202+=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
QR_000000011202+=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
QR_011000000211+=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
QR_010001000211+=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
QR_010000001211+=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
QR_001010000211+=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
QR_000011000211+=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
QR_000010001211+=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
QR_001000010211+=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
QR_000001010211+=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
QR_000000011211+=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
QR_011000000220+=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
QR_010001000220+=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
QR_010000001220+=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
QR_001010000220+=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
QR_000011000220+=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
QR_000010001220+=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
QR_001000010220+=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
QR_000001010220+=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
QR_000000011220+=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
QR_011000000301+=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
QR_010001000301+=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
QR_010000001301+=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
QR_001010000301+=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
QR_000011000301+=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
QR_000010001301+=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
QR_001000010301+=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
QR_000001010301+=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
QR_000000011301+=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
QR_011000000310+=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
QR_010001000310+=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
QR_010000001310+=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
QR_001010000310+=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
QR_000011000310+=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
QR_000010001310+=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
QR_001000010310+=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
QR_000001010310+=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
QR_000000011310+=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
QR_011000000400+=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
QR_010001000400+=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
QR_010000001400+=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
QR_001010000400+=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
QR_000011000400+=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
QR_000010001400+=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
QR_001000010400+=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
QR_000001010400+=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
QR_000000011400+=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
}
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
| 58097e627a00f479691c6c08c8b73db6b1546372.cu | #include<math.h>
#include"Boys_gpu.h"
#define PI 3.1415926535897932
#define P25 17.4934183276248620
#define NTHREAD_32 32
#define NTHREAD_64 64
#define NTHREAD_128 128
texture<int2,1,cudaReadModeElementType> tex_Q;
texture<int2,1,cudaReadModeElementType> tex_Eta;
texture<int2,1,cudaReadModeElementType> tex_pq;
texture<float,1,cudaReadModeElementType> tex_K2_q;
texture<int2,1,cudaReadModeElementType> tex_QC;
texture<int2,1,cudaReadModeElementType> tex_QD;
texture<int2,1,cudaReadModeElementType> tex_Pmtrx;
void TSMJ_texture_binding_pp(double * Q_d,double * QC_d,double * QD_d,\
double * alphaQ_d,double * pq_d,float * K2_q_d,double * Pmtrx_d,\
unsigned int contrc_ket_start_pr,unsigned int primit_ket_len,unsigned int contrc_Pmtrx_start_pr){
cudaBindTexture(0, tex_Q, Q_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len)*3);
cudaBindTexture(0, tex_Eta, alphaQ_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len));
cudaBindTexture(0, tex_pq, pq_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len));
cudaBindTexture(0, tex_K2_q, K2_q_d, sizeof(float)*(contrc_ket_start_pr+primit_ket_len));
cudaBindTexture(0, tex_QC, QC_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len)*3);
cudaBindTexture(0, tex_QD, QD_d, sizeof(double)*(contrc_ket_start_pr+primit_ket_len)*3);
cudaBindTexture(0, tex_Pmtrx, Pmtrx_d, sizeof(double)*(contrc_Pmtrx_start_pr+primit_ket_len)*9);
}
void TSMJ_texture_unbind_pp(){
cudaUnbindTexture(tex_Q);
cudaUnbindTexture(tex_Eta);
cudaUnbindTexture(tex_pq);
cudaUnbindTexture(tex_K2_q);
cudaUnbindTexture(tex_QC);
cudaUnbindTexture(tex_QD);
cudaUnbindTexture(tex_Pmtrx);
}
__global__ void TSMJ_sspp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
QD_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
QD_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
QD_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
QD_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
QD_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
QD_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_taylor(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_sspp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double QD_010[3];
QD_010[0]=QC[jj*3+0];
QD_010[1]=QC[jj*3+1];
QD_010[2]=QC[jj*3+2];
double QD_001[3];
QD_001[0]=QD[jj*3+0];
QD_001[1]=QD[jj*3+1];
QD_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_fs_1(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_sspp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
QD_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
QD_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
QD_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
QD_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
QD_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
QD_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_fs_1(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_sspp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*1];
for(int i=0;i<1;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
QD_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
QD_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
QD_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double QD_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
QD_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
QD_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
QD_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[3];
Ft_fs_1(2,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
R_000[1]*=aQin1;
R_000[2]*=aQin2;
double R_100[2];
double R_200[1];
double R_010[2];
double R_110[1];
double R_020[1];
double R_001[2];
double R_101[1];
double R_011[1];
double R_002[1];
for(int i=0;i<2;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<2;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<2;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=1;i<2;i++){
R_000[i]*=aQin1;
}
for(int i=0;i<1;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<1;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<1;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<1;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
double QD_011[3];
double QD_111[3];
for(int i=0;i<3;i++){
QD_011[i]=aQin1+QD_010[i]*QD_001[i];
}
for(int i=0;i<3;i++){
QD_111[i]=(QD_001[i]+QD_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=QD_011[0];
Q_111000000=QD_111[0];
Q_010001000=QD_010[0]*QD_001[1];
Q_010000001=QD_010[0]*QD_001[2];
Q_001010000=QD_001[0]*QD_010[1];
Q_000011000=QD_011[1];
Q_000111000=QD_111[1];
Q_000010001=QD_010[1]*QD_001[2];
Q_001000010=QD_001[0]*QD_010[2];
Q_000001010=QD_001[1]*QD_010[2];
Q_000000011=QD_011[2];
Q_000000111=QD_111[2];
a1Q_010000000_1=QD_010[0];
a1Q_000001000_1=QD_001[1];
a1Q_000000001_1=QD_001[2];
a1Q_001000000_1=QD_001[0];
a1Q_000010000_1=QD_010[1];
a1Q_000000010_1=QD_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+R_002[0];
}
ans_temp[ans_id*1+0]+=Pmtrx[0]*(QR_011000000000);
ans_temp[ans_id*1+0]+=Pmtrx[1]*(QR_010001000000);
ans_temp[ans_id*1+0]+=Pmtrx[2]*(QR_010000001000);
ans_temp[ans_id*1+0]+=Pmtrx[3]*(QR_001010000000);
ans_temp[ans_id*1+0]+=Pmtrx[4]*(QR_000011000000);
ans_temp[ans_id*1+0]+=Pmtrx[5]*(QR_000010001000);
ans_temp[ans_id*1+0]+=Pmtrx[6]*(QR_001000010000);
ans_temp[ans_id*1+0]+=Pmtrx[7]*(QR_000001010000);
ans_temp[ans_id*1+0]+=Pmtrx[8]*(QR_000000011000);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<1;ians++){
ans_temp[tId_x*1+ians]+=ans_temp[(tId_x+num_thread)*1+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<1;ians++){
ans[i_contrc_bra*1+ians]=ans_temp[(tId_x)*1+ians];
}
}
}
}
__global__ void TSMJ_pspp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_taylor(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pspp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_fs_3(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pspp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_fs_3(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pspp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_128*3];
for(int i=0;i<3;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[4];
Ft_fs_3(3,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[3];
double R_200[2];
double R_300[1];
double R_010[3];
double R_110[2];
double R_210[1];
double R_020[2];
double R_120[1];
double R_030[1];
double R_001[3];
double R_101[2];
double R_201[1];
double R_011[2];
double R_111[1];
double R_021[1];
double R_002[2];
double R_102[1];
double R_012[1];
double R_003[1];
for(int i=0;i<3;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<3;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<3;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<2;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<2;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<2;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<2;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<1;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<1;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<1;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<1;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<1;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<1;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<1;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<1;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<1;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<1;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
}
double P_010000000;
double P_000010000;
double P_000000010;
P_010000000=Pd_010[0];
P_000010000=Pd_010[1];
P_000000010=Pd_010[2];
ans_temp[ans_id*3+0]+=Pmtrx[0]*(P_010000000*QR_011000000000+aPin1*QR_011000000100);
ans_temp[ans_id*3+0]+=Pmtrx[1]*(P_010000000*QR_010001000000+aPin1*QR_010001000100);
ans_temp[ans_id*3+0]+=Pmtrx[2]*(P_010000000*QR_010000001000+aPin1*QR_010000001100);
ans_temp[ans_id*3+0]+=Pmtrx[3]*(P_010000000*QR_001010000000+aPin1*QR_001010000100);
ans_temp[ans_id*3+0]+=Pmtrx[4]*(P_010000000*QR_000011000000+aPin1*QR_000011000100);
ans_temp[ans_id*3+0]+=Pmtrx[5]*(P_010000000*QR_000010001000+aPin1*QR_000010001100);
ans_temp[ans_id*3+0]+=Pmtrx[6]*(P_010000000*QR_001000010000+aPin1*QR_001000010100);
ans_temp[ans_id*3+0]+=Pmtrx[7]*(P_010000000*QR_000001010000+aPin1*QR_000001010100);
ans_temp[ans_id*3+0]+=Pmtrx[8]*(P_010000000*QR_000000011000+aPin1*QR_000000011100);
ans_temp[ans_id*3+1]+=Pmtrx[0]*(P_000010000*QR_011000000000+aPin1*QR_011000000010);
ans_temp[ans_id*3+1]+=Pmtrx[1]*(P_000010000*QR_010001000000+aPin1*QR_010001000010);
ans_temp[ans_id*3+1]+=Pmtrx[2]*(P_000010000*QR_010000001000+aPin1*QR_010000001010);
ans_temp[ans_id*3+1]+=Pmtrx[3]*(P_000010000*QR_001010000000+aPin1*QR_001010000010);
ans_temp[ans_id*3+1]+=Pmtrx[4]*(P_000010000*QR_000011000000+aPin1*QR_000011000010);
ans_temp[ans_id*3+1]+=Pmtrx[5]*(P_000010000*QR_000010001000+aPin1*QR_000010001010);
ans_temp[ans_id*3+1]+=Pmtrx[6]*(P_000010000*QR_001000010000+aPin1*QR_001000010010);
ans_temp[ans_id*3+1]+=Pmtrx[7]*(P_000010000*QR_000001010000+aPin1*QR_000001010010);
ans_temp[ans_id*3+1]+=Pmtrx[8]*(P_000010000*QR_000000011000+aPin1*QR_000000011010);
ans_temp[ans_id*3+2]+=Pmtrx[0]*(P_000000010*QR_011000000000+aPin1*QR_011000000001);
ans_temp[ans_id*3+2]+=Pmtrx[1]*(P_000000010*QR_010001000000+aPin1*QR_010001000001);
ans_temp[ans_id*3+2]+=Pmtrx[2]*(P_000000010*QR_010000001000+aPin1*QR_010000001001);
ans_temp[ans_id*3+2]+=Pmtrx[3]*(P_000000010*QR_001010000000+aPin1*QR_001010000001);
ans_temp[ans_id*3+2]+=Pmtrx[4]*(P_000000010*QR_000011000000+aPin1*QR_000011000001);
ans_temp[ans_id*3+2]+=Pmtrx[5]*(P_000000010*QR_000010001000+aPin1*QR_000010001001);
ans_temp[ans_id*3+2]+=Pmtrx[6]*(P_000000010*QR_001000010000+aPin1*QR_001000010001);
ans_temp[ans_id*3+2]+=Pmtrx[7]*(P_000000010*QR_000001010000+aPin1*QR_000001010001);
ans_temp[ans_id*3+2]+=Pmtrx[8]*(P_000000010*QR_000000011000+aPin1*QR_000000011001);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<3;ians++){
ans_temp[tId_x*3+ians]+=ans_temp[(tId_x+num_thread)*3+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<3;ians++){
ans[i_contrc_bra*3+ians]=ans_temp[(tId_x)*3+ians];
}
}
}
}
__global__ void TSMJ_pppp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_taylor(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_pppp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_pppp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_pppp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*9];
for(int i=0;i<9;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
}
double Pd_011[3];
double Pd_111[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
double P_011000000;
double P_111000000;
double P_010001000;
double P_010000001;
double P_001010000;
double P_000011000;
double P_000111000;
double P_000010001;
double P_001000010;
double P_000001010;
double P_000000011;
double P_000000111;
double a1P_010000000_1;
double a1P_000001000_1;
double a1P_000000001_1;
double a1P_001000000_1;
double a1P_000010000_1;
double a1P_000000010_1;
P_011000000=Pd_011[0];
P_111000000=Pd_111[0];
P_010001000=Pd_010[0]*Pd_001[1];
P_010000001=Pd_010[0]*Pd_001[2];
P_001010000=Pd_001[0]*Pd_010[1];
P_000011000=Pd_011[1];
P_000111000=Pd_111[1];
P_000010001=Pd_010[1]*Pd_001[2];
P_001000010=Pd_001[0]*Pd_010[2];
P_000001010=Pd_001[1]*Pd_010[2];
P_000000011=Pd_011[2];
P_000000111=Pd_111[2];
a1P_010000000_1=Pd_010[0];
a1P_000001000_1=Pd_001[1];
a1P_000000001_1=Pd_001[2];
a1P_001000000_1=Pd_001[0];
a1P_000010000_1=Pd_010[1];
a1P_000000010_1=Pd_010[2];
ans_temp[ans_id*9+0]+=Pmtrx[0]*(P_011000000*QR_011000000000+P_111000000*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*9+0]+=Pmtrx[1]*(P_011000000*QR_010001000000+P_111000000*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*9+0]+=Pmtrx[2]*(P_011000000*QR_010000001000+P_111000000*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*9+0]+=Pmtrx[3]*(P_011000000*QR_001010000000+P_111000000*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*9+0]+=Pmtrx[4]*(P_011000000*QR_000011000000+P_111000000*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*9+0]+=Pmtrx[5]*(P_011000000*QR_000010001000+P_111000000*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*9+0]+=Pmtrx[6]*(P_011000000*QR_001000010000+P_111000000*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*9+0]+=Pmtrx[7]*(P_011000000*QR_000001010000+P_111000000*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*9+0]+=Pmtrx[8]*(P_011000000*QR_000000011000+P_111000000*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*9+1]+=Pmtrx[0]*(P_010001000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000001000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+1]+=Pmtrx[1]*(P_010001000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000001000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+1]+=Pmtrx[2]*(P_010001000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000001000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+1]+=Pmtrx[3]*(P_010001000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000001000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+1]+=Pmtrx[4]*(P_010001000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000001000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+1]+=Pmtrx[5]*(P_010001000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000001000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+1]+=Pmtrx[6]*(P_010001000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000001000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+1]+=Pmtrx[7]*(P_010001000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000001000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+1]+=Pmtrx[8]*(P_010001000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000001000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+2]+=Pmtrx[0]*(P_010000001*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000001_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+2]+=Pmtrx[1]*(P_010000001*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000001_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+2]+=Pmtrx[2]*(P_010000001*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000001_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+2]+=Pmtrx[3]*(P_010000001*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000001_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+2]+=Pmtrx[4]*(P_010000001*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000001_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+2]+=Pmtrx[5]*(P_010000001*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000001_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+2]+=Pmtrx[6]*(P_010000001*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000001_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+2]+=Pmtrx[7]*(P_010000001*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000001_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+2]+=Pmtrx[8]*(P_010000001*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000001_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+3]+=Pmtrx[0]*(P_001010000*QR_011000000000+a1P_001000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*9+3]+=Pmtrx[1]*(P_001010000*QR_010001000000+a1P_001000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*9+3]+=Pmtrx[2]*(P_001010000*QR_010000001000+a1P_001000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*9+3]+=Pmtrx[3]*(P_001010000*QR_001010000000+a1P_001000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*9+3]+=Pmtrx[4]*(P_001010000*QR_000011000000+a1P_001000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*9+3]+=Pmtrx[5]*(P_001010000*QR_000010001000+a1P_001000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*9+3]+=Pmtrx[6]*(P_001010000*QR_001000010000+a1P_001000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*9+3]+=Pmtrx[7]*(P_001010000*QR_000001010000+a1P_001000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*9+3]+=Pmtrx[8]*(P_001010000*QR_000000011000+a1P_001000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*9+4]+=Pmtrx[0]*(P_000011000*QR_011000000000+P_000111000*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*9+4]+=Pmtrx[1]*(P_000011000*QR_010001000000+P_000111000*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*9+4]+=Pmtrx[2]*(P_000011000*QR_010000001000+P_000111000*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*9+4]+=Pmtrx[3]*(P_000011000*QR_001010000000+P_000111000*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*9+4]+=Pmtrx[4]*(P_000011000*QR_000011000000+P_000111000*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*9+4]+=Pmtrx[5]*(P_000011000*QR_000010001000+P_000111000*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*9+4]+=Pmtrx[6]*(P_000011000*QR_001000010000+P_000111000*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*9+4]+=Pmtrx[7]*(P_000011000*QR_000001010000+P_000111000*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*9+4]+=Pmtrx[8]*(P_000011000*QR_000000011000+P_000111000*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*9+5]+=Pmtrx[0]*(P_000010001*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000001_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+5]+=Pmtrx[1]*(P_000010001*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000001_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+5]+=Pmtrx[2]*(P_000010001*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000001_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+5]+=Pmtrx[3]*(P_000010001*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000001_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+5]+=Pmtrx[4]*(P_000010001*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000001_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+5]+=Pmtrx[5]*(P_000010001*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000001_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+5]+=Pmtrx[6]*(P_000010001*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000001_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+5]+=Pmtrx[7]*(P_000010001*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000001_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+5]+=Pmtrx[8]*(P_000010001*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000001_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+6]+=Pmtrx[0]*(P_001000010*QR_011000000000+a1P_001000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*9+6]+=Pmtrx[1]*(P_001000010*QR_010001000000+a1P_001000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*9+6]+=Pmtrx[2]*(P_001000010*QR_010000001000+a1P_001000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*9+6]+=Pmtrx[3]*(P_001000010*QR_001010000000+a1P_001000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*9+6]+=Pmtrx[4]*(P_001000010*QR_000011000000+a1P_001000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*9+6]+=Pmtrx[5]*(P_001000010*QR_000010001000+a1P_001000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*9+6]+=Pmtrx[6]*(P_001000010*QR_001000010000+a1P_001000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*9+6]+=Pmtrx[7]*(P_001000010*QR_000001010000+a1P_001000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*9+6]+=Pmtrx[8]*(P_001000010*QR_000000011000+a1P_001000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*9+7]+=Pmtrx[0]*(P_000001010*QR_011000000000+a1P_000001000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*9+7]+=Pmtrx[1]*(P_000001010*QR_010001000000+a1P_000001000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*9+7]+=Pmtrx[2]*(P_000001010*QR_010000001000+a1P_000001000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*9+7]+=Pmtrx[3]*(P_000001010*QR_001010000000+a1P_000001000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*9+7]+=Pmtrx[4]*(P_000001010*QR_000011000000+a1P_000001000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*9+7]+=Pmtrx[5]*(P_000001010*QR_000010001000+a1P_000001000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*9+7]+=Pmtrx[6]*(P_000001010*QR_001000010000+a1P_000001000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*9+7]+=Pmtrx[7]*(P_000001010*QR_000001010000+a1P_000001000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*9+7]+=Pmtrx[8]*(P_000001010*QR_000000011000+a1P_000001000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*9+8]+=Pmtrx[0]*(P_000000011*QR_011000000000+P_000000111*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*9+8]+=Pmtrx[1]*(P_000000011*QR_010001000000+P_000000111*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*9+8]+=Pmtrx[2]*(P_000000011*QR_010000001000+P_000000111*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*9+8]+=Pmtrx[3]*(P_000000011*QR_001010000000+P_000000111*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*9+8]+=Pmtrx[4]*(P_000000011*QR_000011000000+P_000000111*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*9+8]+=Pmtrx[5]*(P_000000011*QR_000010001000+P_000000111*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*9+8]+=Pmtrx[6]*(P_000000011*QR_001000010000+P_000000111*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*9+8]+=Pmtrx[7]*(P_000000011*QR_000001010000+P_000000111*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*9+8]+=Pmtrx[8]*(P_000000011*QR_000000011000+P_000000111*QR_000000011001+aPin2*QR_000000011002);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<9;ians++){
ans_temp[tId_x*9+ians]+=ans_temp[(tId_x+num_thread)*9+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<9;ians++){
ans[i_contrc_bra*9+ians]=ans_temp[(tId_x)*9+ians];
}
}
}
}
__global__ void TSMJ_dspp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_taylor(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dspp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dspp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dspp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*6];
for(int i=0;i<6;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[5];
Ft_fs_4(4,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[4];
double R_200[3];
double R_300[2];
double R_400[1];
double R_010[4];
double R_110[3];
double R_210[2];
double R_310[1];
double R_020[3];
double R_120[2];
double R_220[1];
double R_030[2];
double R_130[1];
double R_040[1];
double R_001[4];
double R_101[3];
double R_201[2];
double R_301[1];
double R_011[3];
double R_111[2];
double R_211[1];
double R_021[2];
double R_121[1];
double R_031[1];
double R_002[3];
double R_102[2];
double R_202[1];
double R_012[2];
double R_112[1];
double R_022[1];
double R_003[2];
double R_103[1];
double R_013[1];
double R_004[1];
for(int i=0;i<4;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<4;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<4;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<3;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<3;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<3;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<3;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<2;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<2;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<2;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<2;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<2;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<2;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<2;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<2;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<2;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<2;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<1;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<1;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<1;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<1;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<1;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<1;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<1;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<1;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<1;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<1;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<1;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<1;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<1;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<1;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
}
double Pd_020[3];
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
double P_020000000;
double P_010010000;
double P_000020000;
double P_010000010;
double P_000010010;
double P_000000020;
double a1P_010000000_1;
double a1P_010000000_2;
double a1P_000010000_1;
double a1P_000010000_2;
double a1P_000000010_1;
double a1P_000000010_2;
P_020000000=Pd_020[0];
P_010010000=Pd_010[0]*Pd_010[1];
P_000020000=Pd_020[1];
P_010000010=Pd_010[0]*Pd_010[2];
P_000010010=Pd_010[1]*Pd_010[2];
P_000000020=Pd_020[2];
a1P_010000000_1=Pd_010[0];
a1P_010000000_2=2*a1P_010000000_1;
a1P_000010000_1=Pd_010[1];
a1P_000010000_2=2*a1P_000010000_1;
a1P_000000010_1=Pd_010[2];
a1P_000000010_2=2*a1P_000000010_1;
ans_temp[ans_id*6+0]+=Pmtrx[0]*(P_020000000*QR_011000000000+a1P_010000000_2*QR_011000000100+aPin2*QR_011000000200);
ans_temp[ans_id*6+0]+=Pmtrx[1]*(P_020000000*QR_010001000000+a1P_010000000_2*QR_010001000100+aPin2*QR_010001000200);
ans_temp[ans_id*6+0]+=Pmtrx[2]*(P_020000000*QR_010000001000+a1P_010000000_2*QR_010000001100+aPin2*QR_010000001200);
ans_temp[ans_id*6+0]+=Pmtrx[3]*(P_020000000*QR_001010000000+a1P_010000000_2*QR_001010000100+aPin2*QR_001010000200);
ans_temp[ans_id*6+0]+=Pmtrx[4]*(P_020000000*QR_000011000000+a1P_010000000_2*QR_000011000100+aPin2*QR_000011000200);
ans_temp[ans_id*6+0]+=Pmtrx[5]*(P_020000000*QR_000010001000+a1P_010000000_2*QR_000010001100+aPin2*QR_000010001200);
ans_temp[ans_id*6+0]+=Pmtrx[6]*(P_020000000*QR_001000010000+a1P_010000000_2*QR_001000010100+aPin2*QR_001000010200);
ans_temp[ans_id*6+0]+=Pmtrx[7]*(P_020000000*QR_000001010000+a1P_010000000_2*QR_000001010100+aPin2*QR_000001010200);
ans_temp[ans_id*6+0]+=Pmtrx[8]*(P_020000000*QR_000000011000+a1P_010000000_2*QR_000000011100+aPin2*QR_000000011200);
ans_temp[ans_id*6+1]+=Pmtrx[0]*(P_010010000*QR_011000000000+a1P_010000000_1*QR_011000000010+a1P_000010000_1*QR_011000000100+aPin2*QR_011000000110);
ans_temp[ans_id*6+1]+=Pmtrx[1]*(P_010010000*QR_010001000000+a1P_010000000_1*QR_010001000010+a1P_000010000_1*QR_010001000100+aPin2*QR_010001000110);
ans_temp[ans_id*6+1]+=Pmtrx[2]*(P_010010000*QR_010000001000+a1P_010000000_1*QR_010000001010+a1P_000010000_1*QR_010000001100+aPin2*QR_010000001110);
ans_temp[ans_id*6+1]+=Pmtrx[3]*(P_010010000*QR_001010000000+a1P_010000000_1*QR_001010000010+a1P_000010000_1*QR_001010000100+aPin2*QR_001010000110);
ans_temp[ans_id*6+1]+=Pmtrx[4]*(P_010010000*QR_000011000000+a1P_010000000_1*QR_000011000010+a1P_000010000_1*QR_000011000100+aPin2*QR_000011000110);
ans_temp[ans_id*6+1]+=Pmtrx[5]*(P_010010000*QR_000010001000+a1P_010000000_1*QR_000010001010+a1P_000010000_1*QR_000010001100+aPin2*QR_000010001110);
ans_temp[ans_id*6+1]+=Pmtrx[6]*(P_010010000*QR_001000010000+a1P_010000000_1*QR_001000010010+a1P_000010000_1*QR_001000010100+aPin2*QR_001000010110);
ans_temp[ans_id*6+1]+=Pmtrx[7]*(P_010010000*QR_000001010000+a1P_010000000_1*QR_000001010010+a1P_000010000_1*QR_000001010100+aPin2*QR_000001010110);
ans_temp[ans_id*6+1]+=Pmtrx[8]*(P_010010000*QR_000000011000+a1P_010000000_1*QR_000000011010+a1P_000010000_1*QR_000000011100+aPin2*QR_000000011110);
ans_temp[ans_id*6+2]+=Pmtrx[0]*(P_000020000*QR_011000000000+a1P_000010000_2*QR_011000000010+aPin2*QR_011000000020);
ans_temp[ans_id*6+2]+=Pmtrx[1]*(P_000020000*QR_010001000000+a1P_000010000_2*QR_010001000010+aPin2*QR_010001000020);
ans_temp[ans_id*6+2]+=Pmtrx[2]*(P_000020000*QR_010000001000+a1P_000010000_2*QR_010000001010+aPin2*QR_010000001020);
ans_temp[ans_id*6+2]+=Pmtrx[3]*(P_000020000*QR_001010000000+a1P_000010000_2*QR_001010000010+aPin2*QR_001010000020);
ans_temp[ans_id*6+2]+=Pmtrx[4]*(P_000020000*QR_000011000000+a1P_000010000_2*QR_000011000010+aPin2*QR_000011000020);
ans_temp[ans_id*6+2]+=Pmtrx[5]*(P_000020000*QR_000010001000+a1P_000010000_2*QR_000010001010+aPin2*QR_000010001020);
ans_temp[ans_id*6+2]+=Pmtrx[6]*(P_000020000*QR_001000010000+a1P_000010000_2*QR_001000010010+aPin2*QR_001000010020);
ans_temp[ans_id*6+2]+=Pmtrx[7]*(P_000020000*QR_000001010000+a1P_000010000_2*QR_000001010010+aPin2*QR_000001010020);
ans_temp[ans_id*6+2]+=Pmtrx[8]*(P_000020000*QR_000000011000+a1P_000010000_2*QR_000000011010+aPin2*QR_000000011020);
ans_temp[ans_id*6+3]+=Pmtrx[0]*(P_010000010*QR_011000000000+a1P_010000000_1*QR_011000000001+a1P_000000010_1*QR_011000000100+aPin2*QR_011000000101);
ans_temp[ans_id*6+3]+=Pmtrx[1]*(P_010000010*QR_010001000000+a1P_010000000_1*QR_010001000001+a1P_000000010_1*QR_010001000100+aPin2*QR_010001000101);
ans_temp[ans_id*6+3]+=Pmtrx[2]*(P_010000010*QR_010000001000+a1P_010000000_1*QR_010000001001+a1P_000000010_1*QR_010000001100+aPin2*QR_010000001101);
ans_temp[ans_id*6+3]+=Pmtrx[3]*(P_010000010*QR_001010000000+a1P_010000000_1*QR_001010000001+a1P_000000010_1*QR_001010000100+aPin2*QR_001010000101);
ans_temp[ans_id*6+3]+=Pmtrx[4]*(P_010000010*QR_000011000000+a1P_010000000_1*QR_000011000001+a1P_000000010_1*QR_000011000100+aPin2*QR_000011000101);
ans_temp[ans_id*6+3]+=Pmtrx[5]*(P_010000010*QR_000010001000+a1P_010000000_1*QR_000010001001+a1P_000000010_1*QR_000010001100+aPin2*QR_000010001101);
ans_temp[ans_id*6+3]+=Pmtrx[6]*(P_010000010*QR_001000010000+a1P_010000000_1*QR_001000010001+a1P_000000010_1*QR_001000010100+aPin2*QR_001000010101);
ans_temp[ans_id*6+3]+=Pmtrx[7]*(P_010000010*QR_000001010000+a1P_010000000_1*QR_000001010001+a1P_000000010_1*QR_000001010100+aPin2*QR_000001010101);
ans_temp[ans_id*6+3]+=Pmtrx[8]*(P_010000010*QR_000000011000+a1P_010000000_1*QR_000000011001+a1P_000000010_1*QR_000000011100+aPin2*QR_000000011101);
ans_temp[ans_id*6+4]+=Pmtrx[0]*(P_000010010*QR_011000000000+a1P_000010000_1*QR_011000000001+a1P_000000010_1*QR_011000000010+aPin2*QR_011000000011);
ans_temp[ans_id*6+4]+=Pmtrx[1]*(P_000010010*QR_010001000000+a1P_000010000_1*QR_010001000001+a1P_000000010_1*QR_010001000010+aPin2*QR_010001000011);
ans_temp[ans_id*6+4]+=Pmtrx[2]*(P_000010010*QR_010000001000+a1P_000010000_1*QR_010000001001+a1P_000000010_1*QR_010000001010+aPin2*QR_010000001011);
ans_temp[ans_id*6+4]+=Pmtrx[3]*(P_000010010*QR_001010000000+a1P_000010000_1*QR_001010000001+a1P_000000010_1*QR_001010000010+aPin2*QR_001010000011);
ans_temp[ans_id*6+4]+=Pmtrx[4]*(P_000010010*QR_000011000000+a1P_000010000_1*QR_000011000001+a1P_000000010_1*QR_000011000010+aPin2*QR_000011000011);
ans_temp[ans_id*6+4]+=Pmtrx[5]*(P_000010010*QR_000010001000+a1P_000010000_1*QR_000010001001+a1P_000000010_1*QR_000010001010+aPin2*QR_000010001011);
ans_temp[ans_id*6+4]+=Pmtrx[6]*(P_000010010*QR_001000010000+a1P_000010000_1*QR_001000010001+a1P_000000010_1*QR_001000010010+aPin2*QR_001000010011);
ans_temp[ans_id*6+4]+=Pmtrx[7]*(P_000010010*QR_000001010000+a1P_000010000_1*QR_000001010001+a1P_000000010_1*QR_000001010010+aPin2*QR_000001010011);
ans_temp[ans_id*6+4]+=Pmtrx[8]*(P_000010010*QR_000000011000+a1P_000010000_1*QR_000000011001+a1P_000000010_1*QR_000000011010+aPin2*QR_000000011011);
ans_temp[ans_id*6+5]+=Pmtrx[0]*(P_000000020*QR_011000000000+a1P_000000010_2*QR_011000000001+aPin2*QR_011000000002);
ans_temp[ans_id*6+5]+=Pmtrx[1]*(P_000000020*QR_010001000000+a1P_000000010_2*QR_010001000001+aPin2*QR_010001000002);
ans_temp[ans_id*6+5]+=Pmtrx[2]*(P_000000020*QR_010000001000+a1P_000000010_2*QR_010000001001+aPin2*QR_010000001002);
ans_temp[ans_id*6+5]+=Pmtrx[3]*(P_000000020*QR_001010000000+a1P_000000010_2*QR_001010000001+aPin2*QR_001010000002);
ans_temp[ans_id*6+5]+=Pmtrx[4]*(P_000000020*QR_000011000000+a1P_000000010_2*QR_000011000001+aPin2*QR_000011000002);
ans_temp[ans_id*6+5]+=Pmtrx[5]*(P_000000020*QR_000010001000+a1P_000000010_2*QR_000010001001+aPin2*QR_000010001002);
ans_temp[ans_id*6+5]+=Pmtrx[6]*(P_000000020*QR_001000010000+a1P_000000010_2*QR_001000010001+aPin2*QR_001000010002);
ans_temp[ans_id*6+5]+=Pmtrx[7]*(P_000000020*QR_000001010000+a1P_000000010_2*QR_000001010001+aPin2*QR_000001010002);
ans_temp[ans_id*6+5]+=Pmtrx[8]*(P_000000020*QR_000000011000+a1P_000000010_2*QR_000000011001+aPin2*QR_000000011002);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<6;ians++){
ans_temp[tId_x*6+ians]+=ans_temp[(tId_x+num_thread)*6+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<6;ians++){
ans[i_contrc_bra*6+ians]=ans_temp[(tId_x)*6+ians];
}
}
}
}
__global__ void TSMJ_dppp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_taylor(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_dppp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_fs_5(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_dppp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_fs_5(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_dppp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*18];
for(int i=0;i<18;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
double QR_011000000003=0;
double QR_010001000003=0;
double QR_010000001003=0;
double QR_001010000003=0;
double QR_000011000003=0;
double QR_000010001003=0;
double QR_001000010003=0;
double QR_000001010003=0;
double QR_000000011003=0;
double QR_011000000012=0;
double QR_010001000012=0;
double QR_010000001012=0;
double QR_001010000012=0;
double QR_000011000012=0;
double QR_000010001012=0;
double QR_001000010012=0;
double QR_000001010012=0;
double QR_000000011012=0;
double QR_011000000021=0;
double QR_010001000021=0;
double QR_010000001021=0;
double QR_001010000021=0;
double QR_000011000021=0;
double QR_000010001021=0;
double QR_001000010021=0;
double QR_000001010021=0;
double QR_000000011021=0;
double QR_011000000030=0;
double QR_010001000030=0;
double QR_010000001030=0;
double QR_001010000030=0;
double QR_000011000030=0;
double QR_000010001030=0;
double QR_001000010030=0;
double QR_000001010030=0;
double QR_000000011030=0;
double QR_011000000102=0;
double QR_010001000102=0;
double QR_010000001102=0;
double QR_001010000102=0;
double QR_000011000102=0;
double QR_000010001102=0;
double QR_001000010102=0;
double QR_000001010102=0;
double QR_000000011102=0;
double QR_011000000111=0;
double QR_010001000111=0;
double QR_010000001111=0;
double QR_001010000111=0;
double QR_000011000111=0;
double QR_000010001111=0;
double QR_001000010111=0;
double QR_000001010111=0;
double QR_000000011111=0;
double QR_011000000120=0;
double QR_010001000120=0;
double QR_010000001120=0;
double QR_001010000120=0;
double QR_000011000120=0;
double QR_000010001120=0;
double QR_001000010120=0;
double QR_000001010120=0;
double QR_000000011120=0;
double QR_011000000201=0;
double QR_010001000201=0;
double QR_010000001201=0;
double QR_001010000201=0;
double QR_000011000201=0;
double QR_000010001201=0;
double QR_001000010201=0;
double QR_000001010201=0;
double QR_000000011201=0;
double QR_011000000210=0;
double QR_010001000210=0;
double QR_010000001210=0;
double QR_001010000210=0;
double QR_000011000210=0;
double QR_000010001210=0;
double QR_001000010210=0;
double QR_000001010210=0;
double QR_000000011210=0;
double QR_011000000300=0;
double QR_010001000300=0;
double QR_010000001300=0;
double QR_001010000300=0;
double QR_000011000300=0;
double QR_000010001300=0;
double QR_001000010300=0;
double QR_000001010300=0;
double QR_000000011300=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[6];
Ft_fs_5(5,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[5];
double R_200[4];
double R_300[3];
double R_400[2];
double R_500[1];
double R_010[5];
double R_110[4];
double R_210[3];
double R_310[2];
double R_410[1];
double R_020[4];
double R_120[3];
double R_220[2];
double R_320[1];
double R_030[3];
double R_130[2];
double R_230[1];
double R_040[2];
double R_140[1];
double R_050[1];
double R_001[5];
double R_101[4];
double R_201[3];
double R_301[2];
double R_401[1];
double R_011[4];
double R_111[3];
double R_211[2];
double R_311[1];
double R_021[3];
double R_121[2];
double R_221[1];
double R_031[2];
double R_131[1];
double R_041[1];
double R_002[4];
double R_102[3];
double R_202[2];
double R_302[1];
double R_012[3];
double R_112[2];
double R_212[1];
double R_022[2];
double R_122[1];
double R_032[1];
double R_003[3];
double R_103[2];
double R_203[1];
double R_013[2];
double R_113[1];
double R_023[1];
double R_004[2];
double R_104[1];
double R_014[1];
double R_005[1];
for(int i=0;i<5;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<5;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<5;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<4;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<4;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<4;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<4;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<3;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<3;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<3;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<3;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<3;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<3;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<3;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<3;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<3;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<3;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<2;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<2;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<2;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<2;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<2;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<2;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<2;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<2;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<2;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<2;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<2;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<2;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<2;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<2;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<1;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<1;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<1;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<1;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<1;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<1;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<1;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<1;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<1;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<1;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<1;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<1;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<1;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<1;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<1;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<1;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<1;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<1;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<1;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<1;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<1;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
QR_011000000003+=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
QR_010001000003+=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
QR_010000001003+=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
QR_001010000003+=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
QR_000011000003+=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
QR_000010001003+=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
QR_001000010003+=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
QR_000001010003+=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
QR_000000011003+=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
QR_011000000012+=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
QR_010001000012+=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
QR_010000001012+=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001010000012+=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
QR_000011000012+=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
QR_000010001012+=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
QR_001000010012+=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000001010012+=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
QR_000000011012+=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
QR_011000000021+=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
QR_010001000021+=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
QR_010000001021+=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001010000021+=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
QR_000011000021+=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
QR_000010001021+=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
QR_001000010021+=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000001010021+=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
QR_000000011021+=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
QR_011000000030+=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
QR_010001000030+=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
QR_010000001030+=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001010000030+=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
QR_000011000030+=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
QR_000010001030+=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
QR_001000010030+=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000001010030+=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
QR_000000011030+=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
QR_011000000102+=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
QR_010001000102+=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
QR_010000001102+=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
QR_001010000102+=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
QR_000011000102+=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
QR_000010001102+=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001000010102+=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
QR_000001010102+=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000000011102+=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
QR_011000000111+=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
QR_010001000111+=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
QR_010000001111+=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001010000111+=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
QR_000011000111+=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
QR_000010001111+=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001000010111+=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000001010111+=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000000011111+=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
QR_011000000120+=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
QR_010001000120+=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
QR_010000001120+=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001010000120+=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
QR_000011000120+=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
QR_000010001120+=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001000010120+=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000001010120+=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000000011120+=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
QR_011000000201+=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
QR_010001000201+=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
QR_010000001201+=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
QR_001010000201+=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
QR_000011000201+=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
QR_000010001201+=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001000010201+=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
QR_000001010201+=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000000011201+=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
QR_011000000210+=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
QR_010001000210+=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
QR_010000001210+=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001010000210+=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
QR_000011000210+=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
QR_000010001210+=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001000010210+=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000001010210+=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000000011210+=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
QR_011000000300+=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
QR_010001000300+=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
QR_010000001300+=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
QR_001010000300+=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
QR_000011000300+=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
QR_000010001300+=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001000010300+=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
QR_000001010300+=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000000011300+=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
}
double Pd_011[3];
double Pd_111[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
double P_021000000;
double P_121000000;
double P_221000000;
double P_020001000;
double P_020000001;
double P_011010000;
double P_111010000;
double P_010011000;
double P_010111000;
double P_010010001;
double P_001020000;
double P_000021000;
double P_000121000;
double P_000221000;
double P_000020001;
double P_011000010;
double P_111000010;
double P_010001010;
double P_010000011;
double P_010000111;
double P_001010010;
double P_000011010;
double P_000111010;
double P_000010011;
double P_000010111;
double P_001000020;
double P_000001020;
double P_000000021;
double P_000000121;
double P_000000221;
double a1P_020000000_1;
double a1P_010001000_1;
double a1P_010001000_2;
double a2P_010000000_1;
double a2P_010000000_2;
double a2P_000001000_1;
double a1P_010000001_1;
double a1P_010000001_2;
double a2P_000000001_1;
double a1P_011000000_1;
double a1P_111000000_1;
double a2P_000010000_1;
double a2P_000010000_2;
double a1P_000011000_1;
double a1P_000111000_1;
double a1P_010010000_1;
double a1P_000010001_1;
double a1P_000010001_2;
double a1P_001010000_1;
double a1P_001010000_2;
double a2P_001000000_1;
double a1P_000020000_1;
double a2P_000000010_1;
double a2P_000000010_2;
double a1P_010000010_1;
double a1P_000001010_1;
double a1P_000001010_2;
double a1P_000000011_1;
double a1P_000000111_1;
double a1P_001000010_1;
double a1P_001000010_2;
double a1P_000010010_1;
double a1P_000000020_1;
P_021000000=Pd_021[0];
P_121000000=Pd_121[0];
P_221000000=Pd_221[0];
P_020001000=Pd_020[0]*Pd_001[1];
P_020000001=Pd_020[0]*Pd_001[2];
P_011010000=Pd_011[0]*Pd_010[1];
P_111010000=Pd_111[0]*Pd_010[1];
P_010011000=Pd_010[0]*Pd_011[1];
P_010111000=Pd_010[0]*Pd_111[1];
P_010010001=Pd_010[0]*Pd_010[1]*Pd_001[2];
P_001020000=Pd_001[0]*Pd_020[1];
P_000021000=Pd_021[1];
P_000121000=Pd_121[1];
P_000221000=Pd_221[1];
P_000020001=Pd_020[1]*Pd_001[2];
P_011000010=Pd_011[0]*Pd_010[2];
P_111000010=Pd_111[0]*Pd_010[2];
P_010001010=Pd_010[0]*Pd_001[1]*Pd_010[2];
P_010000011=Pd_010[0]*Pd_011[2];
P_010000111=Pd_010[0]*Pd_111[2];
P_001010010=Pd_001[0]*Pd_010[1]*Pd_010[2];
P_000011010=Pd_011[1]*Pd_010[2];
P_000111010=Pd_111[1]*Pd_010[2];
P_000010011=Pd_010[1]*Pd_011[2];
P_000010111=Pd_010[1]*Pd_111[2];
P_001000020=Pd_001[0]*Pd_020[2];
P_000001020=Pd_001[1]*Pd_020[2];
P_000000021=Pd_021[2];
P_000000121=Pd_121[2];
P_000000221=Pd_221[2];
a1P_020000000_1=Pd_020[0];
a1P_010001000_1=Pd_010[0]*Pd_001[1];
a1P_010001000_2=2*a1P_010001000_1;
a2P_010000000_1=Pd_010[0];
a2P_010000000_2=2*a2P_010000000_1;
a2P_000001000_1=Pd_001[1];
a1P_010000001_1=Pd_010[0]*Pd_001[2];
a1P_010000001_2=2*a1P_010000001_1;
a2P_000000001_1=Pd_001[2];
a1P_011000000_1=Pd_011[0];
a1P_111000000_1=Pd_111[0];
a2P_000010000_1=Pd_010[1];
a2P_000010000_2=2*a2P_000010000_1;
a1P_000011000_1=Pd_011[1];
a1P_000111000_1=Pd_111[1];
a1P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010001_1=Pd_010[1]*Pd_001[2];
a1P_000010001_2=2*a1P_000010001_1;
a1P_001010000_1=Pd_001[0]*Pd_010[1];
a1P_001010000_2=2*a1P_001010000_1;
a2P_001000000_1=Pd_001[0];
a1P_000020000_1=Pd_020[1];
a2P_000000010_1=Pd_010[2];
a2P_000000010_2=2*a2P_000000010_1;
a1P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000001010_1=Pd_001[1]*Pd_010[2];
a1P_000001010_2=2*a1P_000001010_1;
a1P_000000011_1=Pd_011[2];
a1P_000000111_1=Pd_111[2];
a1P_001000010_1=Pd_001[0]*Pd_010[2];
a1P_001000010_2=2*a1P_001000010_1;
a1P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_000000020_1=Pd_020[2];
ans_temp[ans_id*18+0]+=Pmtrx[0]*(P_021000000*QR_011000000000+P_121000000*QR_011000000100+P_221000000*QR_011000000200+aPin3*QR_011000000300);
ans_temp[ans_id*18+0]+=Pmtrx[1]*(P_021000000*QR_010001000000+P_121000000*QR_010001000100+P_221000000*QR_010001000200+aPin3*QR_010001000300);
ans_temp[ans_id*18+0]+=Pmtrx[2]*(P_021000000*QR_010000001000+P_121000000*QR_010000001100+P_221000000*QR_010000001200+aPin3*QR_010000001300);
ans_temp[ans_id*18+0]+=Pmtrx[3]*(P_021000000*QR_001010000000+P_121000000*QR_001010000100+P_221000000*QR_001010000200+aPin3*QR_001010000300);
ans_temp[ans_id*18+0]+=Pmtrx[4]*(P_021000000*QR_000011000000+P_121000000*QR_000011000100+P_221000000*QR_000011000200+aPin3*QR_000011000300);
ans_temp[ans_id*18+0]+=Pmtrx[5]*(P_021000000*QR_000010001000+P_121000000*QR_000010001100+P_221000000*QR_000010001200+aPin3*QR_000010001300);
ans_temp[ans_id*18+0]+=Pmtrx[6]*(P_021000000*QR_001000010000+P_121000000*QR_001000010100+P_221000000*QR_001000010200+aPin3*QR_001000010300);
ans_temp[ans_id*18+0]+=Pmtrx[7]*(P_021000000*QR_000001010000+P_121000000*QR_000001010100+P_221000000*QR_000001010200+aPin3*QR_000001010300);
ans_temp[ans_id*18+0]+=Pmtrx[8]*(P_021000000*QR_000000011000+P_121000000*QR_000000011100+P_221000000*QR_000000011200+aPin3*QR_000000011300);
ans_temp[ans_id*18+1]+=Pmtrx[0]*(P_020001000*QR_011000000000+a1P_020000000_1*QR_011000000010+a1P_010001000_2*QR_011000000100+a2P_010000000_2*QR_011000000110+a2P_000001000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+1]+=Pmtrx[1]*(P_020001000*QR_010001000000+a1P_020000000_1*QR_010001000010+a1P_010001000_2*QR_010001000100+a2P_010000000_2*QR_010001000110+a2P_000001000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+1]+=Pmtrx[2]*(P_020001000*QR_010000001000+a1P_020000000_1*QR_010000001010+a1P_010001000_2*QR_010000001100+a2P_010000000_2*QR_010000001110+a2P_000001000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+1]+=Pmtrx[3]*(P_020001000*QR_001010000000+a1P_020000000_1*QR_001010000010+a1P_010001000_2*QR_001010000100+a2P_010000000_2*QR_001010000110+a2P_000001000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+1]+=Pmtrx[4]*(P_020001000*QR_000011000000+a1P_020000000_1*QR_000011000010+a1P_010001000_2*QR_000011000100+a2P_010000000_2*QR_000011000110+a2P_000001000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+1]+=Pmtrx[5]*(P_020001000*QR_000010001000+a1P_020000000_1*QR_000010001010+a1P_010001000_2*QR_000010001100+a2P_010000000_2*QR_000010001110+a2P_000001000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+1]+=Pmtrx[6]*(P_020001000*QR_001000010000+a1P_020000000_1*QR_001000010010+a1P_010001000_2*QR_001000010100+a2P_010000000_2*QR_001000010110+a2P_000001000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+1]+=Pmtrx[7]*(P_020001000*QR_000001010000+a1P_020000000_1*QR_000001010010+a1P_010001000_2*QR_000001010100+a2P_010000000_2*QR_000001010110+a2P_000001000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+1]+=Pmtrx[8]*(P_020001000*QR_000000011000+a1P_020000000_1*QR_000000011010+a1P_010001000_2*QR_000000011100+a2P_010000000_2*QR_000000011110+a2P_000001000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+2]+=Pmtrx[0]*(P_020000001*QR_011000000000+a1P_020000000_1*QR_011000000001+a1P_010000001_2*QR_011000000100+a2P_010000000_2*QR_011000000101+a2P_000000001_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+2]+=Pmtrx[1]*(P_020000001*QR_010001000000+a1P_020000000_1*QR_010001000001+a1P_010000001_2*QR_010001000100+a2P_010000000_2*QR_010001000101+a2P_000000001_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+2]+=Pmtrx[2]*(P_020000001*QR_010000001000+a1P_020000000_1*QR_010000001001+a1P_010000001_2*QR_010000001100+a2P_010000000_2*QR_010000001101+a2P_000000001_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+2]+=Pmtrx[3]*(P_020000001*QR_001010000000+a1P_020000000_1*QR_001010000001+a1P_010000001_2*QR_001010000100+a2P_010000000_2*QR_001010000101+a2P_000000001_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+2]+=Pmtrx[4]*(P_020000001*QR_000011000000+a1P_020000000_1*QR_000011000001+a1P_010000001_2*QR_000011000100+a2P_010000000_2*QR_000011000101+a2P_000000001_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+2]+=Pmtrx[5]*(P_020000001*QR_000010001000+a1P_020000000_1*QR_000010001001+a1P_010000001_2*QR_000010001100+a2P_010000000_2*QR_000010001101+a2P_000000001_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+2]+=Pmtrx[6]*(P_020000001*QR_001000010000+a1P_020000000_1*QR_001000010001+a1P_010000001_2*QR_001000010100+a2P_010000000_2*QR_001000010101+a2P_000000001_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+2]+=Pmtrx[7]*(P_020000001*QR_000001010000+a1P_020000000_1*QR_000001010001+a1P_010000001_2*QR_000001010100+a2P_010000000_2*QR_000001010101+a2P_000000001_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+2]+=Pmtrx[8]*(P_020000001*QR_000000011000+a1P_020000000_1*QR_000000011001+a1P_010000001_2*QR_000000011100+a2P_010000000_2*QR_000000011101+a2P_000000001_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+3]+=Pmtrx[0]*(P_011010000*QR_011000000000+a1P_011000000_1*QR_011000000010+P_111010000*QR_011000000100+a1P_111000000_1*QR_011000000110+a2P_000010000_1*QR_011000000200+aPin3*QR_011000000210);
ans_temp[ans_id*18+3]+=Pmtrx[1]*(P_011010000*QR_010001000000+a1P_011000000_1*QR_010001000010+P_111010000*QR_010001000100+a1P_111000000_1*QR_010001000110+a2P_000010000_1*QR_010001000200+aPin3*QR_010001000210);
ans_temp[ans_id*18+3]+=Pmtrx[2]*(P_011010000*QR_010000001000+a1P_011000000_1*QR_010000001010+P_111010000*QR_010000001100+a1P_111000000_1*QR_010000001110+a2P_000010000_1*QR_010000001200+aPin3*QR_010000001210);
ans_temp[ans_id*18+3]+=Pmtrx[3]*(P_011010000*QR_001010000000+a1P_011000000_1*QR_001010000010+P_111010000*QR_001010000100+a1P_111000000_1*QR_001010000110+a2P_000010000_1*QR_001010000200+aPin3*QR_001010000210);
ans_temp[ans_id*18+3]+=Pmtrx[4]*(P_011010000*QR_000011000000+a1P_011000000_1*QR_000011000010+P_111010000*QR_000011000100+a1P_111000000_1*QR_000011000110+a2P_000010000_1*QR_000011000200+aPin3*QR_000011000210);
ans_temp[ans_id*18+3]+=Pmtrx[5]*(P_011010000*QR_000010001000+a1P_011000000_1*QR_000010001010+P_111010000*QR_000010001100+a1P_111000000_1*QR_000010001110+a2P_000010000_1*QR_000010001200+aPin3*QR_000010001210);
ans_temp[ans_id*18+3]+=Pmtrx[6]*(P_011010000*QR_001000010000+a1P_011000000_1*QR_001000010010+P_111010000*QR_001000010100+a1P_111000000_1*QR_001000010110+a2P_000010000_1*QR_001000010200+aPin3*QR_001000010210);
ans_temp[ans_id*18+3]+=Pmtrx[7]*(P_011010000*QR_000001010000+a1P_011000000_1*QR_000001010010+P_111010000*QR_000001010100+a1P_111000000_1*QR_000001010110+a2P_000010000_1*QR_000001010200+aPin3*QR_000001010210);
ans_temp[ans_id*18+3]+=Pmtrx[8]*(P_011010000*QR_000000011000+a1P_011000000_1*QR_000000011010+P_111010000*QR_000000011100+a1P_111000000_1*QR_000000011110+a2P_000010000_1*QR_000000011200+aPin3*QR_000000011210);
ans_temp[ans_id*18+4]+=Pmtrx[0]*(P_010011000*QR_011000000000+P_010111000*QR_011000000010+a2P_010000000_1*QR_011000000020+a1P_000011000_1*QR_011000000100+a1P_000111000_1*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+4]+=Pmtrx[1]*(P_010011000*QR_010001000000+P_010111000*QR_010001000010+a2P_010000000_1*QR_010001000020+a1P_000011000_1*QR_010001000100+a1P_000111000_1*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+4]+=Pmtrx[2]*(P_010011000*QR_010000001000+P_010111000*QR_010000001010+a2P_010000000_1*QR_010000001020+a1P_000011000_1*QR_010000001100+a1P_000111000_1*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+4]+=Pmtrx[3]*(P_010011000*QR_001010000000+P_010111000*QR_001010000010+a2P_010000000_1*QR_001010000020+a1P_000011000_1*QR_001010000100+a1P_000111000_1*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+4]+=Pmtrx[4]*(P_010011000*QR_000011000000+P_010111000*QR_000011000010+a2P_010000000_1*QR_000011000020+a1P_000011000_1*QR_000011000100+a1P_000111000_1*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+4]+=Pmtrx[5]*(P_010011000*QR_000010001000+P_010111000*QR_000010001010+a2P_010000000_1*QR_000010001020+a1P_000011000_1*QR_000010001100+a1P_000111000_1*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+4]+=Pmtrx[6]*(P_010011000*QR_001000010000+P_010111000*QR_001000010010+a2P_010000000_1*QR_001000010020+a1P_000011000_1*QR_001000010100+a1P_000111000_1*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+4]+=Pmtrx[7]*(P_010011000*QR_000001010000+P_010111000*QR_000001010010+a2P_010000000_1*QR_000001010020+a1P_000011000_1*QR_000001010100+a1P_000111000_1*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+4]+=Pmtrx[8]*(P_010011000*QR_000000011000+P_010111000*QR_000000011010+a2P_010000000_1*QR_000000011020+a1P_000011000_1*QR_000000011100+a1P_000111000_1*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+5]+=Pmtrx[0]*(P_010010001*QR_011000000000+a1P_010010000_1*QR_011000000001+a1P_010000001_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000010001_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000001_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+5]+=Pmtrx[1]*(P_010010001*QR_010001000000+a1P_010010000_1*QR_010001000001+a1P_010000001_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000010001_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000001_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+5]+=Pmtrx[2]*(P_010010001*QR_010000001000+a1P_010010000_1*QR_010000001001+a1P_010000001_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000010001_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000001_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+5]+=Pmtrx[3]*(P_010010001*QR_001010000000+a1P_010010000_1*QR_001010000001+a1P_010000001_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000010001_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000001_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+5]+=Pmtrx[4]*(P_010010001*QR_000011000000+a1P_010010000_1*QR_000011000001+a1P_010000001_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000010001_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000001_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+5]+=Pmtrx[5]*(P_010010001*QR_000010001000+a1P_010010000_1*QR_000010001001+a1P_010000001_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000010001_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000001_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+5]+=Pmtrx[6]*(P_010010001*QR_001000010000+a1P_010010000_1*QR_001000010001+a1P_010000001_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000010001_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000001_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+5]+=Pmtrx[7]*(P_010010001*QR_000001010000+a1P_010010000_1*QR_000001010001+a1P_010000001_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000010001_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000001_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+5]+=Pmtrx[8]*(P_010010001*QR_000000011000+a1P_010010000_1*QR_000000011001+a1P_010000001_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000010001_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000001_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+6]+=Pmtrx[0]*(P_001020000*QR_011000000000+a1P_001010000_2*QR_011000000010+a2P_001000000_1*QR_011000000020+a1P_000020000_1*QR_011000000100+a2P_000010000_2*QR_011000000110+aPin3*QR_011000000120);
ans_temp[ans_id*18+6]+=Pmtrx[1]*(P_001020000*QR_010001000000+a1P_001010000_2*QR_010001000010+a2P_001000000_1*QR_010001000020+a1P_000020000_1*QR_010001000100+a2P_000010000_2*QR_010001000110+aPin3*QR_010001000120);
ans_temp[ans_id*18+6]+=Pmtrx[2]*(P_001020000*QR_010000001000+a1P_001010000_2*QR_010000001010+a2P_001000000_1*QR_010000001020+a1P_000020000_1*QR_010000001100+a2P_000010000_2*QR_010000001110+aPin3*QR_010000001120);
ans_temp[ans_id*18+6]+=Pmtrx[3]*(P_001020000*QR_001010000000+a1P_001010000_2*QR_001010000010+a2P_001000000_1*QR_001010000020+a1P_000020000_1*QR_001010000100+a2P_000010000_2*QR_001010000110+aPin3*QR_001010000120);
ans_temp[ans_id*18+6]+=Pmtrx[4]*(P_001020000*QR_000011000000+a1P_001010000_2*QR_000011000010+a2P_001000000_1*QR_000011000020+a1P_000020000_1*QR_000011000100+a2P_000010000_2*QR_000011000110+aPin3*QR_000011000120);
ans_temp[ans_id*18+6]+=Pmtrx[5]*(P_001020000*QR_000010001000+a1P_001010000_2*QR_000010001010+a2P_001000000_1*QR_000010001020+a1P_000020000_1*QR_000010001100+a2P_000010000_2*QR_000010001110+aPin3*QR_000010001120);
ans_temp[ans_id*18+6]+=Pmtrx[6]*(P_001020000*QR_001000010000+a1P_001010000_2*QR_001000010010+a2P_001000000_1*QR_001000010020+a1P_000020000_1*QR_001000010100+a2P_000010000_2*QR_001000010110+aPin3*QR_001000010120);
ans_temp[ans_id*18+6]+=Pmtrx[7]*(P_001020000*QR_000001010000+a1P_001010000_2*QR_000001010010+a2P_001000000_1*QR_000001010020+a1P_000020000_1*QR_000001010100+a2P_000010000_2*QR_000001010110+aPin3*QR_000001010120);
ans_temp[ans_id*18+6]+=Pmtrx[8]*(P_001020000*QR_000000011000+a1P_001010000_2*QR_000000011010+a2P_001000000_1*QR_000000011020+a1P_000020000_1*QR_000000011100+a2P_000010000_2*QR_000000011110+aPin3*QR_000000011120);
ans_temp[ans_id*18+7]+=Pmtrx[0]*(P_000021000*QR_011000000000+P_000121000*QR_011000000010+P_000221000*QR_011000000020+aPin3*QR_011000000030);
ans_temp[ans_id*18+7]+=Pmtrx[1]*(P_000021000*QR_010001000000+P_000121000*QR_010001000010+P_000221000*QR_010001000020+aPin3*QR_010001000030);
ans_temp[ans_id*18+7]+=Pmtrx[2]*(P_000021000*QR_010000001000+P_000121000*QR_010000001010+P_000221000*QR_010000001020+aPin3*QR_010000001030);
ans_temp[ans_id*18+7]+=Pmtrx[3]*(P_000021000*QR_001010000000+P_000121000*QR_001010000010+P_000221000*QR_001010000020+aPin3*QR_001010000030);
ans_temp[ans_id*18+7]+=Pmtrx[4]*(P_000021000*QR_000011000000+P_000121000*QR_000011000010+P_000221000*QR_000011000020+aPin3*QR_000011000030);
ans_temp[ans_id*18+7]+=Pmtrx[5]*(P_000021000*QR_000010001000+P_000121000*QR_000010001010+P_000221000*QR_000010001020+aPin3*QR_000010001030);
ans_temp[ans_id*18+7]+=Pmtrx[6]*(P_000021000*QR_001000010000+P_000121000*QR_001000010010+P_000221000*QR_001000010020+aPin3*QR_001000010030);
ans_temp[ans_id*18+7]+=Pmtrx[7]*(P_000021000*QR_000001010000+P_000121000*QR_000001010010+P_000221000*QR_000001010020+aPin3*QR_000001010030);
ans_temp[ans_id*18+7]+=Pmtrx[8]*(P_000021000*QR_000000011000+P_000121000*QR_000000011010+P_000221000*QR_000000011020+aPin3*QR_000000011030);
ans_temp[ans_id*18+8]+=Pmtrx[0]*(P_000020001*QR_011000000000+a1P_000020000_1*QR_011000000001+a1P_000010001_2*QR_011000000010+a2P_000010000_2*QR_011000000011+a2P_000000001_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+8]+=Pmtrx[1]*(P_000020001*QR_010001000000+a1P_000020000_1*QR_010001000001+a1P_000010001_2*QR_010001000010+a2P_000010000_2*QR_010001000011+a2P_000000001_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+8]+=Pmtrx[2]*(P_000020001*QR_010000001000+a1P_000020000_1*QR_010000001001+a1P_000010001_2*QR_010000001010+a2P_000010000_2*QR_010000001011+a2P_000000001_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+8]+=Pmtrx[3]*(P_000020001*QR_001010000000+a1P_000020000_1*QR_001010000001+a1P_000010001_2*QR_001010000010+a2P_000010000_2*QR_001010000011+a2P_000000001_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+8]+=Pmtrx[4]*(P_000020001*QR_000011000000+a1P_000020000_1*QR_000011000001+a1P_000010001_2*QR_000011000010+a2P_000010000_2*QR_000011000011+a2P_000000001_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+8]+=Pmtrx[5]*(P_000020001*QR_000010001000+a1P_000020000_1*QR_000010001001+a1P_000010001_2*QR_000010001010+a2P_000010000_2*QR_000010001011+a2P_000000001_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+8]+=Pmtrx[6]*(P_000020001*QR_001000010000+a1P_000020000_1*QR_001000010001+a1P_000010001_2*QR_001000010010+a2P_000010000_2*QR_001000010011+a2P_000000001_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+8]+=Pmtrx[7]*(P_000020001*QR_000001010000+a1P_000020000_1*QR_000001010001+a1P_000010001_2*QR_000001010010+a2P_000010000_2*QR_000001010011+a2P_000000001_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+8]+=Pmtrx[8]*(P_000020001*QR_000000011000+a1P_000020000_1*QR_000000011001+a1P_000010001_2*QR_000000011010+a2P_000010000_2*QR_000000011011+a2P_000000001_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+9]+=Pmtrx[0]*(P_011000010*QR_011000000000+a1P_011000000_1*QR_011000000001+P_111000010*QR_011000000100+a1P_111000000_1*QR_011000000101+a2P_000000010_1*QR_011000000200+aPin3*QR_011000000201);
ans_temp[ans_id*18+9]+=Pmtrx[1]*(P_011000010*QR_010001000000+a1P_011000000_1*QR_010001000001+P_111000010*QR_010001000100+a1P_111000000_1*QR_010001000101+a2P_000000010_1*QR_010001000200+aPin3*QR_010001000201);
ans_temp[ans_id*18+9]+=Pmtrx[2]*(P_011000010*QR_010000001000+a1P_011000000_1*QR_010000001001+P_111000010*QR_010000001100+a1P_111000000_1*QR_010000001101+a2P_000000010_1*QR_010000001200+aPin3*QR_010000001201);
ans_temp[ans_id*18+9]+=Pmtrx[3]*(P_011000010*QR_001010000000+a1P_011000000_1*QR_001010000001+P_111000010*QR_001010000100+a1P_111000000_1*QR_001010000101+a2P_000000010_1*QR_001010000200+aPin3*QR_001010000201);
ans_temp[ans_id*18+9]+=Pmtrx[4]*(P_011000010*QR_000011000000+a1P_011000000_1*QR_000011000001+P_111000010*QR_000011000100+a1P_111000000_1*QR_000011000101+a2P_000000010_1*QR_000011000200+aPin3*QR_000011000201);
ans_temp[ans_id*18+9]+=Pmtrx[5]*(P_011000010*QR_000010001000+a1P_011000000_1*QR_000010001001+P_111000010*QR_000010001100+a1P_111000000_1*QR_000010001101+a2P_000000010_1*QR_000010001200+aPin3*QR_000010001201);
ans_temp[ans_id*18+9]+=Pmtrx[6]*(P_011000010*QR_001000010000+a1P_011000000_1*QR_001000010001+P_111000010*QR_001000010100+a1P_111000000_1*QR_001000010101+a2P_000000010_1*QR_001000010200+aPin3*QR_001000010201);
ans_temp[ans_id*18+9]+=Pmtrx[7]*(P_011000010*QR_000001010000+a1P_011000000_1*QR_000001010001+P_111000010*QR_000001010100+a1P_111000000_1*QR_000001010101+a2P_000000010_1*QR_000001010200+aPin3*QR_000001010201);
ans_temp[ans_id*18+9]+=Pmtrx[8]*(P_011000010*QR_000000011000+a1P_011000000_1*QR_000000011001+P_111000010*QR_000000011100+a1P_111000000_1*QR_000000011101+a2P_000000010_1*QR_000000011200+aPin3*QR_000000011201);
ans_temp[ans_id*18+10]+=Pmtrx[0]*(P_010001010*QR_011000000000+a1P_010001000_1*QR_011000000001+a1P_010000010_1*QR_011000000010+a2P_010000000_1*QR_011000000011+a1P_000001010_1*QR_011000000100+a2P_000001000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+10]+=Pmtrx[1]*(P_010001010*QR_010001000000+a1P_010001000_1*QR_010001000001+a1P_010000010_1*QR_010001000010+a2P_010000000_1*QR_010001000011+a1P_000001010_1*QR_010001000100+a2P_000001000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+10]+=Pmtrx[2]*(P_010001010*QR_010000001000+a1P_010001000_1*QR_010000001001+a1P_010000010_1*QR_010000001010+a2P_010000000_1*QR_010000001011+a1P_000001010_1*QR_010000001100+a2P_000001000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+10]+=Pmtrx[3]*(P_010001010*QR_001010000000+a1P_010001000_1*QR_001010000001+a1P_010000010_1*QR_001010000010+a2P_010000000_1*QR_001010000011+a1P_000001010_1*QR_001010000100+a2P_000001000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+10]+=Pmtrx[4]*(P_010001010*QR_000011000000+a1P_010001000_1*QR_000011000001+a1P_010000010_1*QR_000011000010+a2P_010000000_1*QR_000011000011+a1P_000001010_1*QR_000011000100+a2P_000001000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+10]+=Pmtrx[5]*(P_010001010*QR_000010001000+a1P_010001000_1*QR_000010001001+a1P_010000010_1*QR_000010001010+a2P_010000000_1*QR_000010001011+a1P_000001010_1*QR_000010001100+a2P_000001000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+10]+=Pmtrx[6]*(P_010001010*QR_001000010000+a1P_010001000_1*QR_001000010001+a1P_010000010_1*QR_001000010010+a2P_010000000_1*QR_001000010011+a1P_000001010_1*QR_001000010100+a2P_000001000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+10]+=Pmtrx[7]*(P_010001010*QR_000001010000+a1P_010001000_1*QR_000001010001+a1P_010000010_1*QR_000001010010+a2P_010000000_1*QR_000001010011+a1P_000001010_1*QR_000001010100+a2P_000001000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+10]+=Pmtrx[8]*(P_010001010*QR_000000011000+a1P_010001000_1*QR_000000011001+a1P_010000010_1*QR_000000011010+a2P_010000000_1*QR_000000011011+a1P_000001010_1*QR_000000011100+a2P_000001000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+11]+=Pmtrx[0]*(P_010000011*QR_011000000000+P_010000111*QR_011000000001+a2P_010000000_1*QR_011000000002+a1P_000000011_1*QR_011000000100+a1P_000000111_1*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+11]+=Pmtrx[1]*(P_010000011*QR_010001000000+P_010000111*QR_010001000001+a2P_010000000_1*QR_010001000002+a1P_000000011_1*QR_010001000100+a1P_000000111_1*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+11]+=Pmtrx[2]*(P_010000011*QR_010000001000+P_010000111*QR_010000001001+a2P_010000000_1*QR_010000001002+a1P_000000011_1*QR_010000001100+a1P_000000111_1*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+11]+=Pmtrx[3]*(P_010000011*QR_001010000000+P_010000111*QR_001010000001+a2P_010000000_1*QR_001010000002+a1P_000000011_1*QR_001010000100+a1P_000000111_1*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+11]+=Pmtrx[4]*(P_010000011*QR_000011000000+P_010000111*QR_000011000001+a2P_010000000_1*QR_000011000002+a1P_000000011_1*QR_000011000100+a1P_000000111_1*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+11]+=Pmtrx[5]*(P_010000011*QR_000010001000+P_010000111*QR_000010001001+a2P_010000000_1*QR_000010001002+a1P_000000011_1*QR_000010001100+a1P_000000111_1*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+11]+=Pmtrx[6]*(P_010000011*QR_001000010000+P_010000111*QR_001000010001+a2P_010000000_1*QR_001000010002+a1P_000000011_1*QR_001000010100+a1P_000000111_1*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+11]+=Pmtrx[7]*(P_010000011*QR_000001010000+P_010000111*QR_000001010001+a2P_010000000_1*QR_000001010002+a1P_000000011_1*QR_000001010100+a1P_000000111_1*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+11]+=Pmtrx[8]*(P_010000011*QR_000000011000+P_010000111*QR_000000011001+a2P_010000000_1*QR_000000011002+a1P_000000011_1*QR_000000011100+a1P_000000111_1*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+12]+=Pmtrx[0]*(P_001010010*QR_011000000000+a1P_001010000_1*QR_011000000001+a1P_001000010_1*QR_011000000010+a2P_001000000_1*QR_011000000011+a1P_000010010_1*QR_011000000100+a2P_000010000_1*QR_011000000101+a2P_000000010_1*QR_011000000110+aPin3*QR_011000000111);
ans_temp[ans_id*18+12]+=Pmtrx[1]*(P_001010010*QR_010001000000+a1P_001010000_1*QR_010001000001+a1P_001000010_1*QR_010001000010+a2P_001000000_1*QR_010001000011+a1P_000010010_1*QR_010001000100+a2P_000010000_1*QR_010001000101+a2P_000000010_1*QR_010001000110+aPin3*QR_010001000111);
ans_temp[ans_id*18+12]+=Pmtrx[2]*(P_001010010*QR_010000001000+a1P_001010000_1*QR_010000001001+a1P_001000010_1*QR_010000001010+a2P_001000000_1*QR_010000001011+a1P_000010010_1*QR_010000001100+a2P_000010000_1*QR_010000001101+a2P_000000010_1*QR_010000001110+aPin3*QR_010000001111);
ans_temp[ans_id*18+12]+=Pmtrx[3]*(P_001010010*QR_001010000000+a1P_001010000_1*QR_001010000001+a1P_001000010_1*QR_001010000010+a2P_001000000_1*QR_001010000011+a1P_000010010_1*QR_001010000100+a2P_000010000_1*QR_001010000101+a2P_000000010_1*QR_001010000110+aPin3*QR_001010000111);
ans_temp[ans_id*18+12]+=Pmtrx[4]*(P_001010010*QR_000011000000+a1P_001010000_1*QR_000011000001+a1P_001000010_1*QR_000011000010+a2P_001000000_1*QR_000011000011+a1P_000010010_1*QR_000011000100+a2P_000010000_1*QR_000011000101+a2P_000000010_1*QR_000011000110+aPin3*QR_000011000111);
ans_temp[ans_id*18+12]+=Pmtrx[5]*(P_001010010*QR_000010001000+a1P_001010000_1*QR_000010001001+a1P_001000010_1*QR_000010001010+a2P_001000000_1*QR_000010001011+a1P_000010010_1*QR_000010001100+a2P_000010000_1*QR_000010001101+a2P_000000010_1*QR_000010001110+aPin3*QR_000010001111);
ans_temp[ans_id*18+12]+=Pmtrx[6]*(P_001010010*QR_001000010000+a1P_001010000_1*QR_001000010001+a1P_001000010_1*QR_001000010010+a2P_001000000_1*QR_001000010011+a1P_000010010_1*QR_001000010100+a2P_000010000_1*QR_001000010101+a2P_000000010_1*QR_001000010110+aPin3*QR_001000010111);
ans_temp[ans_id*18+12]+=Pmtrx[7]*(P_001010010*QR_000001010000+a1P_001010000_1*QR_000001010001+a1P_001000010_1*QR_000001010010+a2P_001000000_1*QR_000001010011+a1P_000010010_1*QR_000001010100+a2P_000010000_1*QR_000001010101+a2P_000000010_1*QR_000001010110+aPin3*QR_000001010111);
ans_temp[ans_id*18+12]+=Pmtrx[8]*(P_001010010*QR_000000011000+a1P_001010000_1*QR_000000011001+a1P_001000010_1*QR_000000011010+a2P_001000000_1*QR_000000011011+a1P_000010010_1*QR_000000011100+a2P_000010000_1*QR_000000011101+a2P_000000010_1*QR_000000011110+aPin3*QR_000000011111);
ans_temp[ans_id*18+13]+=Pmtrx[0]*(P_000011010*QR_011000000000+a1P_000011000_1*QR_011000000001+P_000111010*QR_011000000010+a1P_000111000_1*QR_011000000011+a2P_000000010_1*QR_011000000020+aPin3*QR_011000000021);
ans_temp[ans_id*18+13]+=Pmtrx[1]*(P_000011010*QR_010001000000+a1P_000011000_1*QR_010001000001+P_000111010*QR_010001000010+a1P_000111000_1*QR_010001000011+a2P_000000010_1*QR_010001000020+aPin3*QR_010001000021);
ans_temp[ans_id*18+13]+=Pmtrx[2]*(P_000011010*QR_010000001000+a1P_000011000_1*QR_010000001001+P_000111010*QR_010000001010+a1P_000111000_1*QR_010000001011+a2P_000000010_1*QR_010000001020+aPin3*QR_010000001021);
ans_temp[ans_id*18+13]+=Pmtrx[3]*(P_000011010*QR_001010000000+a1P_000011000_1*QR_001010000001+P_000111010*QR_001010000010+a1P_000111000_1*QR_001010000011+a2P_000000010_1*QR_001010000020+aPin3*QR_001010000021);
ans_temp[ans_id*18+13]+=Pmtrx[4]*(P_000011010*QR_000011000000+a1P_000011000_1*QR_000011000001+P_000111010*QR_000011000010+a1P_000111000_1*QR_000011000011+a2P_000000010_1*QR_000011000020+aPin3*QR_000011000021);
ans_temp[ans_id*18+13]+=Pmtrx[5]*(P_000011010*QR_000010001000+a1P_000011000_1*QR_000010001001+P_000111010*QR_000010001010+a1P_000111000_1*QR_000010001011+a2P_000000010_1*QR_000010001020+aPin3*QR_000010001021);
ans_temp[ans_id*18+13]+=Pmtrx[6]*(P_000011010*QR_001000010000+a1P_000011000_1*QR_001000010001+P_000111010*QR_001000010010+a1P_000111000_1*QR_001000010011+a2P_000000010_1*QR_001000010020+aPin3*QR_001000010021);
ans_temp[ans_id*18+13]+=Pmtrx[7]*(P_000011010*QR_000001010000+a1P_000011000_1*QR_000001010001+P_000111010*QR_000001010010+a1P_000111000_1*QR_000001010011+a2P_000000010_1*QR_000001010020+aPin3*QR_000001010021);
ans_temp[ans_id*18+13]+=Pmtrx[8]*(P_000011010*QR_000000011000+a1P_000011000_1*QR_000000011001+P_000111010*QR_000000011010+a1P_000111000_1*QR_000000011011+a2P_000000010_1*QR_000000011020+aPin3*QR_000000011021);
ans_temp[ans_id*18+14]+=Pmtrx[0]*(P_000010011*QR_011000000000+P_000010111*QR_011000000001+a2P_000010000_1*QR_011000000002+a1P_000000011_1*QR_011000000010+a1P_000000111_1*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+14]+=Pmtrx[1]*(P_000010011*QR_010001000000+P_000010111*QR_010001000001+a2P_000010000_1*QR_010001000002+a1P_000000011_1*QR_010001000010+a1P_000000111_1*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+14]+=Pmtrx[2]*(P_000010011*QR_010000001000+P_000010111*QR_010000001001+a2P_000010000_1*QR_010000001002+a1P_000000011_1*QR_010000001010+a1P_000000111_1*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+14]+=Pmtrx[3]*(P_000010011*QR_001010000000+P_000010111*QR_001010000001+a2P_000010000_1*QR_001010000002+a1P_000000011_1*QR_001010000010+a1P_000000111_1*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+14]+=Pmtrx[4]*(P_000010011*QR_000011000000+P_000010111*QR_000011000001+a2P_000010000_1*QR_000011000002+a1P_000000011_1*QR_000011000010+a1P_000000111_1*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+14]+=Pmtrx[5]*(P_000010011*QR_000010001000+P_000010111*QR_000010001001+a2P_000010000_1*QR_000010001002+a1P_000000011_1*QR_000010001010+a1P_000000111_1*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+14]+=Pmtrx[6]*(P_000010011*QR_001000010000+P_000010111*QR_001000010001+a2P_000010000_1*QR_001000010002+a1P_000000011_1*QR_001000010010+a1P_000000111_1*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+14]+=Pmtrx[7]*(P_000010011*QR_000001010000+P_000010111*QR_000001010001+a2P_000010000_1*QR_000001010002+a1P_000000011_1*QR_000001010010+a1P_000000111_1*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+14]+=Pmtrx[8]*(P_000010011*QR_000000011000+P_000010111*QR_000000011001+a2P_000010000_1*QR_000000011002+a1P_000000011_1*QR_000000011010+a1P_000000111_1*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+15]+=Pmtrx[0]*(P_001000020*QR_011000000000+a1P_001000010_2*QR_011000000001+a2P_001000000_1*QR_011000000002+a1P_000000020_1*QR_011000000100+a2P_000000010_2*QR_011000000101+aPin3*QR_011000000102);
ans_temp[ans_id*18+15]+=Pmtrx[1]*(P_001000020*QR_010001000000+a1P_001000010_2*QR_010001000001+a2P_001000000_1*QR_010001000002+a1P_000000020_1*QR_010001000100+a2P_000000010_2*QR_010001000101+aPin3*QR_010001000102);
ans_temp[ans_id*18+15]+=Pmtrx[2]*(P_001000020*QR_010000001000+a1P_001000010_2*QR_010000001001+a2P_001000000_1*QR_010000001002+a1P_000000020_1*QR_010000001100+a2P_000000010_2*QR_010000001101+aPin3*QR_010000001102);
ans_temp[ans_id*18+15]+=Pmtrx[3]*(P_001000020*QR_001010000000+a1P_001000010_2*QR_001010000001+a2P_001000000_1*QR_001010000002+a1P_000000020_1*QR_001010000100+a2P_000000010_2*QR_001010000101+aPin3*QR_001010000102);
ans_temp[ans_id*18+15]+=Pmtrx[4]*(P_001000020*QR_000011000000+a1P_001000010_2*QR_000011000001+a2P_001000000_1*QR_000011000002+a1P_000000020_1*QR_000011000100+a2P_000000010_2*QR_000011000101+aPin3*QR_000011000102);
ans_temp[ans_id*18+15]+=Pmtrx[5]*(P_001000020*QR_000010001000+a1P_001000010_2*QR_000010001001+a2P_001000000_1*QR_000010001002+a1P_000000020_1*QR_000010001100+a2P_000000010_2*QR_000010001101+aPin3*QR_000010001102);
ans_temp[ans_id*18+15]+=Pmtrx[6]*(P_001000020*QR_001000010000+a1P_001000010_2*QR_001000010001+a2P_001000000_1*QR_001000010002+a1P_000000020_1*QR_001000010100+a2P_000000010_2*QR_001000010101+aPin3*QR_001000010102);
ans_temp[ans_id*18+15]+=Pmtrx[7]*(P_001000020*QR_000001010000+a1P_001000010_2*QR_000001010001+a2P_001000000_1*QR_000001010002+a1P_000000020_1*QR_000001010100+a2P_000000010_2*QR_000001010101+aPin3*QR_000001010102);
ans_temp[ans_id*18+15]+=Pmtrx[8]*(P_001000020*QR_000000011000+a1P_001000010_2*QR_000000011001+a2P_001000000_1*QR_000000011002+a1P_000000020_1*QR_000000011100+a2P_000000010_2*QR_000000011101+aPin3*QR_000000011102);
ans_temp[ans_id*18+16]+=Pmtrx[0]*(P_000001020*QR_011000000000+a1P_000001010_2*QR_011000000001+a2P_000001000_1*QR_011000000002+a1P_000000020_1*QR_011000000010+a2P_000000010_2*QR_011000000011+aPin3*QR_011000000012);
ans_temp[ans_id*18+16]+=Pmtrx[1]*(P_000001020*QR_010001000000+a1P_000001010_2*QR_010001000001+a2P_000001000_1*QR_010001000002+a1P_000000020_1*QR_010001000010+a2P_000000010_2*QR_010001000011+aPin3*QR_010001000012);
ans_temp[ans_id*18+16]+=Pmtrx[2]*(P_000001020*QR_010000001000+a1P_000001010_2*QR_010000001001+a2P_000001000_1*QR_010000001002+a1P_000000020_1*QR_010000001010+a2P_000000010_2*QR_010000001011+aPin3*QR_010000001012);
ans_temp[ans_id*18+16]+=Pmtrx[3]*(P_000001020*QR_001010000000+a1P_000001010_2*QR_001010000001+a2P_000001000_1*QR_001010000002+a1P_000000020_1*QR_001010000010+a2P_000000010_2*QR_001010000011+aPin3*QR_001010000012);
ans_temp[ans_id*18+16]+=Pmtrx[4]*(P_000001020*QR_000011000000+a1P_000001010_2*QR_000011000001+a2P_000001000_1*QR_000011000002+a1P_000000020_1*QR_000011000010+a2P_000000010_2*QR_000011000011+aPin3*QR_000011000012);
ans_temp[ans_id*18+16]+=Pmtrx[5]*(P_000001020*QR_000010001000+a1P_000001010_2*QR_000010001001+a2P_000001000_1*QR_000010001002+a1P_000000020_1*QR_000010001010+a2P_000000010_2*QR_000010001011+aPin3*QR_000010001012);
ans_temp[ans_id*18+16]+=Pmtrx[6]*(P_000001020*QR_001000010000+a1P_000001010_2*QR_001000010001+a2P_000001000_1*QR_001000010002+a1P_000000020_1*QR_001000010010+a2P_000000010_2*QR_001000010011+aPin3*QR_001000010012);
ans_temp[ans_id*18+16]+=Pmtrx[7]*(P_000001020*QR_000001010000+a1P_000001010_2*QR_000001010001+a2P_000001000_1*QR_000001010002+a1P_000000020_1*QR_000001010010+a2P_000000010_2*QR_000001010011+aPin3*QR_000001010012);
ans_temp[ans_id*18+16]+=Pmtrx[8]*(P_000001020*QR_000000011000+a1P_000001010_2*QR_000000011001+a2P_000001000_1*QR_000000011002+a1P_000000020_1*QR_000000011010+a2P_000000010_2*QR_000000011011+aPin3*QR_000000011012);
ans_temp[ans_id*18+17]+=Pmtrx[0]*(P_000000021*QR_011000000000+P_000000121*QR_011000000001+P_000000221*QR_011000000002+aPin3*QR_011000000003);
ans_temp[ans_id*18+17]+=Pmtrx[1]*(P_000000021*QR_010001000000+P_000000121*QR_010001000001+P_000000221*QR_010001000002+aPin3*QR_010001000003);
ans_temp[ans_id*18+17]+=Pmtrx[2]*(P_000000021*QR_010000001000+P_000000121*QR_010000001001+P_000000221*QR_010000001002+aPin3*QR_010000001003);
ans_temp[ans_id*18+17]+=Pmtrx[3]*(P_000000021*QR_001010000000+P_000000121*QR_001010000001+P_000000221*QR_001010000002+aPin3*QR_001010000003);
ans_temp[ans_id*18+17]+=Pmtrx[4]*(P_000000021*QR_000011000000+P_000000121*QR_000011000001+P_000000221*QR_000011000002+aPin3*QR_000011000003);
ans_temp[ans_id*18+17]+=Pmtrx[5]*(P_000000021*QR_000010001000+P_000000121*QR_000010001001+P_000000221*QR_000010001002+aPin3*QR_000010001003);
ans_temp[ans_id*18+17]+=Pmtrx[6]*(P_000000021*QR_001000010000+P_000000121*QR_001000010001+P_000000221*QR_001000010002+aPin3*QR_001000010003);
ans_temp[ans_id*18+17]+=Pmtrx[7]*(P_000000021*QR_000001010000+P_000000121*QR_000001010001+P_000000221*QR_000001010002+aPin3*QR_000001010003);
ans_temp[ans_id*18+17]+=Pmtrx[8]*(P_000000021*QR_000000011000+P_000000121*QR_000000011001+P_000000221*QR_000000011002+aPin3*QR_000000011003);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<18;ians++){
ans_temp[tId_x*18+ians]+=ans_temp[(tId_x+num_thread)*18+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<18;ians++){
ans[i_contrc_bra*18+ians]=ans_temp[(tId_x)*18+ians];
}
}
}
}
__global__ void TSMJ_ddpp_taylor(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_taylor(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double QR_011000000004=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
double QR_010001000004=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
double QR_010000001004=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
double QR_001010000004=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
double QR_000011000004=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
double QR_000010001004=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
double QR_001000010004=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
double QR_000001010004=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
double QR_000000011004=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
double QR_011000000013=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
double QR_010001000013=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
double QR_010000001013=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001010000013=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
double QR_000011000013=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
double QR_000010001013=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
double QR_001000010013=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000001010013=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
double QR_000000011013=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
double QR_011000000022=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
double QR_010001000022=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
double QR_010000001022=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001010000022=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
double QR_000011000022=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
double QR_000010001022=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
double QR_001000010022=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000001010022=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
double QR_000000011022=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
double QR_011000000031=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
double QR_010001000031=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
double QR_010000001031=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001010000031=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
double QR_000011000031=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
double QR_000010001031=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
double QR_001000010031=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000001010031=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
double QR_000000011031=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
double QR_011000000040=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
double QR_010001000040=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
double QR_010000001040=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001010000040=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
double QR_000011000040=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
double QR_000010001040=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
double QR_001000010040=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000001010040=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
double QR_000000011040=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
double QR_011000000103=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
double QR_010001000103=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
double QR_010000001103=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
double QR_001010000103=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
double QR_000011000103=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
double QR_000010001103=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001000010103=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
double QR_000001010103=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000000011103=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
double QR_011000000112=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
double QR_010001000112=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
double QR_010000001112=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001010000112=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
double QR_000011000112=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
double QR_000010001112=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001000010112=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000001010112=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000000011112=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
double QR_011000000121=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
double QR_010001000121=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
double QR_010000001121=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001010000121=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
double QR_000011000121=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
double QR_000010001121=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001000010121=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000001010121=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000000011121=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
double QR_011000000130=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
double QR_010001000130=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
double QR_010000001130=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001010000130=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
double QR_000011000130=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
double QR_000010001130=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001000010130=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000001010130=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000000011130=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
double QR_011000000202=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
double QR_010001000202=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
double QR_010000001202=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
double QR_001010000202=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
double QR_000011000202=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
double QR_000010001202=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001000010202=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
double QR_000001010202=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000000011202=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
double QR_011000000211=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
double QR_010001000211=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
double QR_010000001211=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001010000211=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
double QR_000011000211=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
double QR_000010001211=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001000010211=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000001010211=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000000011211=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
double QR_011000000220=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
double QR_010001000220=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
double QR_010000001220=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001010000220=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
double QR_000011000220=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
double QR_000010001220=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001000010220=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000001010220=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000000011220=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
double QR_011000000301=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
double QR_010001000301=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
double QR_010000001301=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
double QR_001010000301=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
double QR_000011000301=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
double QR_000010001301=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001000010301=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
double QR_000001010301=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000000011301=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
double QR_011000000310=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
double QR_010001000310=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
double QR_010000001310=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001010000310=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
double QR_000011000310=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
double QR_000010001310=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001000010310=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000001010310=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000000011310=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
double QR_011000000400=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
double QR_010001000400=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
double QR_010000001400=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
double QR_001010000400=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
double QR_000011000400=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
double QR_000010001400=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001000010400=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
double QR_000001010400=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000000011400=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
__global__ void TSMJ_ddpp_NTX(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * Q,\
double * QC,\
double * QD,\
double * Eta_in,\
double * pq_in,\
float * K2_q_in,\
double * Pmtrx_in,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=K2_q_in[jj];
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
double QX=Q[jj*3+0];
double QY=Q[jj*3+1];
double QZ=Q[jj*3+2];
double Qd_010[3];
Qd_010[0]=QC[jj*3+0];
Qd_010[1]=QC[jj*3+1];
Qd_010[2]=QC[jj*3+2];
double Qd_001[3];
Qd_001[0]=QD[jj*3+0];
Qd_001[1]=QD[jj*3+1];
Qd_001[2]=QD[jj*3+2];
double Eta=Eta_in[jj];
double pq=pq_in[jj];
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
Pmtrx[p_i]=Pmtrx_in[p_jj+p_i];
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_fs_6(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double QR_011000000004=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
double QR_010001000004=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
double QR_010000001004=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
double QR_001010000004=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
double QR_000011000004=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
double QR_000010001004=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
double QR_001000010004=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
double QR_000001010004=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
double QR_000000011004=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
double QR_011000000013=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
double QR_010001000013=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
double QR_010000001013=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001010000013=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
double QR_000011000013=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
double QR_000010001013=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
double QR_001000010013=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000001010013=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
double QR_000000011013=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
double QR_011000000022=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
double QR_010001000022=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
double QR_010000001022=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001010000022=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
double QR_000011000022=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
double QR_000010001022=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
double QR_001000010022=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000001010022=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
double QR_000000011022=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
double QR_011000000031=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
double QR_010001000031=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
double QR_010000001031=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001010000031=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
double QR_000011000031=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
double QR_000010001031=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
double QR_001000010031=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000001010031=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
double QR_000000011031=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
double QR_011000000040=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
double QR_010001000040=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
double QR_010000001040=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001010000040=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
double QR_000011000040=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
double QR_000010001040=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
double QR_001000010040=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000001010040=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
double QR_000000011040=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
double QR_011000000103=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
double QR_010001000103=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
double QR_010000001103=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
double QR_001010000103=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
double QR_000011000103=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
double QR_000010001103=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001000010103=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
double QR_000001010103=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000000011103=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
double QR_011000000112=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
double QR_010001000112=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
double QR_010000001112=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001010000112=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
double QR_000011000112=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
double QR_000010001112=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001000010112=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000001010112=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000000011112=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
double QR_011000000121=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
double QR_010001000121=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
double QR_010000001121=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001010000121=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
double QR_000011000121=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
double QR_000010001121=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001000010121=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000001010121=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000000011121=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
double QR_011000000130=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
double QR_010001000130=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
double QR_010000001130=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001010000130=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
double QR_000011000130=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
double QR_000010001130=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001000010130=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000001010130=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000000011130=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
double QR_011000000202=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
double QR_010001000202=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
double QR_010000001202=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
double QR_001010000202=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
double QR_000011000202=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
double QR_000010001202=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001000010202=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
double QR_000001010202=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000000011202=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
double QR_011000000211=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
double QR_010001000211=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
double QR_010000001211=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001010000211=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
double QR_000011000211=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
double QR_000010001211=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001000010211=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000001010211=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000000011211=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
double QR_011000000220=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
double QR_010001000220=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
double QR_010000001220=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001010000220=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
double QR_000011000220=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
double QR_000010001220=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001000010220=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000001010220=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000000011220=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
double QR_011000000301=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
double QR_010001000301=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
double QR_010000001301=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
double QR_001010000301=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
double QR_000011000301=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
double QR_000010001301=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001000010301=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
double QR_000001010301=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000000011301=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
double QR_011000000310=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
double QR_010001000310=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
double QR_010000001310=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001010000310=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
double QR_000011000310=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
double QR_000010001310=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001000010310=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000001010310=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000000011310=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
double QR_011000000400=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
double QR_010001000400=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
double QR_010000001400=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
double QR_001010000400=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
double QR_000011000400=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
double QR_000010001400=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001000010400=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
double QR_000001010400=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000000011400=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
__global__ void TSMJ_ddpp_fs(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_fs_6(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
double QR_011000000000=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
double QR_010001000000=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
double QR_010000001000=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
double QR_001010000000=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
double QR_000011000000=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
double QR_000010001000=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
double QR_001000010000=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
double QR_000001010000=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
double QR_000000011000=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
double QR_011000000001=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
double QR_010001000001=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
double QR_010000001001=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
double QR_001010000001=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
double QR_000011000001=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
double QR_000010001001=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
double QR_001000010001=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
double QR_000001010001=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
double QR_000000011001=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
double QR_011000000010=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
double QR_010001000010=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
double QR_010000001010=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001010000010=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
double QR_000011000010=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
double QR_000010001010=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
double QR_001000010010=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000001010010=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
double QR_000000011010=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
double QR_011000000100=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
double QR_010001000100=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
double QR_010000001100=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
double QR_001010000100=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
double QR_000011000100=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
double QR_000010001100=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
double QR_001000010100=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
double QR_000001010100=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
double QR_000000011100=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
double QR_011000000002=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
double QR_010001000002=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
double QR_010000001002=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
double QR_001010000002=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
double QR_000011000002=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
double QR_000010001002=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
double QR_001000010002=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
double QR_000001010002=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
double QR_000000011002=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
double QR_011000000011=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
double QR_010001000011=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
double QR_010000001011=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001010000011=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
double QR_000011000011=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
double QR_000010001011=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
double QR_001000010011=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000001010011=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
double QR_000000011011=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
double QR_011000000020=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
double QR_010001000020=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
double QR_010000001020=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001010000020=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
double QR_000011000020=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
double QR_000010001020=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
double QR_001000010020=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000001010020=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
double QR_000000011020=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
double QR_011000000101=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
double QR_010001000101=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
double QR_010000001101=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
double QR_001010000101=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
double QR_000011000101=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
double QR_000010001101=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
double QR_001000010101=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
double QR_000001010101=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
double QR_000000011101=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
double QR_011000000110=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
double QR_010001000110=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
double QR_010000001110=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001010000110=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
double QR_000011000110=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
double QR_000010001110=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
double QR_001000010110=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000001010110=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
double QR_000000011110=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
double QR_011000000200=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
double QR_010001000200=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
double QR_010000001200=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
double QR_001010000200=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
double QR_000011000200=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
double QR_000010001200=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
double QR_001000010200=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
double QR_000001010200=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
double QR_000000011200=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
double QR_011000000003=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
double QR_010001000003=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
double QR_010000001003=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
double QR_001010000003=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
double QR_000011000003=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
double QR_000010001003=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
double QR_001000010003=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
double QR_000001010003=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
double QR_000000011003=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
double QR_011000000012=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
double QR_010001000012=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
double QR_010000001012=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001010000012=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
double QR_000011000012=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
double QR_000010001012=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
double QR_001000010012=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000001010012=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
double QR_000000011012=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
double QR_011000000021=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
double QR_010001000021=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
double QR_010000001021=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001010000021=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
double QR_000011000021=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
double QR_000010001021=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
double QR_001000010021=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000001010021=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
double QR_000000011021=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
double QR_011000000030=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
double QR_010001000030=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
double QR_010000001030=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001010000030=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
double QR_000011000030=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
double QR_000010001030=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
double QR_001000010030=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000001010030=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
double QR_000000011030=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
double QR_011000000102=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
double QR_010001000102=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
double QR_010000001102=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
double QR_001010000102=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
double QR_000011000102=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
double QR_000010001102=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
double QR_001000010102=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
double QR_000001010102=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
double QR_000000011102=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
double QR_011000000111=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
double QR_010001000111=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
double QR_010000001111=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001010000111=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
double QR_000011000111=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
double QR_000010001111=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
double QR_001000010111=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000001010111=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
double QR_000000011111=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
double QR_011000000120=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
double QR_010001000120=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
double QR_010000001120=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001010000120=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
double QR_000011000120=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
double QR_000010001120=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
double QR_001000010120=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000001010120=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
double QR_000000011120=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
double QR_011000000201=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
double QR_010001000201=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
double QR_010000001201=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
double QR_001010000201=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
double QR_000011000201=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
double QR_000010001201=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
double QR_001000010201=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
double QR_000001010201=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
double QR_000000011201=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
double QR_011000000210=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
double QR_010001000210=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
double QR_010000001210=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001010000210=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
double QR_000011000210=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
double QR_000010001210=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
double QR_001000010210=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000001010210=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
double QR_000000011210=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
double QR_011000000300=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
double QR_010001000300=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
double QR_010000001300=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
double QR_001010000300=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
double QR_000011000300=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
double QR_000010001300=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
double QR_001000010300=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
double QR_000001010300=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
double QR_000000011300=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
double QR_011000000004=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
double QR_010001000004=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
double QR_010000001004=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
double QR_001010000004=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
double QR_000011000004=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
double QR_000010001004=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
double QR_001000010004=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
double QR_000001010004=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
double QR_000000011004=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
double QR_011000000013=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
double QR_010001000013=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
double QR_010000001013=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001010000013=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
double QR_000011000013=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
double QR_000010001013=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
double QR_001000010013=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000001010013=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
double QR_000000011013=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
double QR_011000000022=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
double QR_010001000022=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
double QR_010000001022=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001010000022=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
double QR_000011000022=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
double QR_000010001022=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
double QR_001000010022=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000001010022=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
double QR_000000011022=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
double QR_011000000031=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
double QR_010001000031=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
double QR_010000001031=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001010000031=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
double QR_000011000031=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
double QR_000010001031=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
double QR_001000010031=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000001010031=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
double QR_000000011031=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
double QR_011000000040=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
double QR_010001000040=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
double QR_010000001040=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001010000040=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
double QR_000011000040=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
double QR_000010001040=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
double QR_001000010040=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000001010040=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
double QR_000000011040=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
double QR_011000000103=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
double QR_010001000103=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
double QR_010000001103=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
double QR_001010000103=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
double QR_000011000103=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
double QR_000010001103=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
double QR_001000010103=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
double QR_000001010103=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
double QR_000000011103=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
double QR_011000000112=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
double QR_010001000112=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
double QR_010000001112=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001010000112=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
double QR_000011000112=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
double QR_000010001112=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
double QR_001000010112=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000001010112=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
double QR_000000011112=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
double QR_011000000121=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
double QR_010001000121=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
double QR_010000001121=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001010000121=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
double QR_000011000121=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
double QR_000010001121=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
double QR_001000010121=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000001010121=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
double QR_000000011121=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
double QR_011000000130=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
double QR_010001000130=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
double QR_010000001130=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001010000130=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
double QR_000011000130=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
double QR_000010001130=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
double QR_001000010130=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000001010130=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
double QR_000000011130=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
double QR_011000000202=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
double QR_010001000202=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
double QR_010000001202=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
double QR_001010000202=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
double QR_000011000202=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
double QR_000010001202=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
double QR_001000010202=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
double QR_000001010202=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
double QR_000000011202=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
double QR_011000000211=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
double QR_010001000211=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
double QR_010000001211=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001010000211=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
double QR_000011000211=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
double QR_000010001211=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
double QR_001000010211=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000001010211=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
double QR_000000011211=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
double QR_011000000220=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
double QR_010001000220=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
double QR_010000001220=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001010000220=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
double QR_000011000220=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
double QR_000010001220=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
double QR_001000010220=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000001010220=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
double QR_000000011220=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
double QR_011000000301=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
double QR_010001000301=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
double QR_010000001301=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
double QR_001010000301=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
double QR_000011000301=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
double QR_000010001301=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
double QR_001000010301=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
double QR_000001010301=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
double QR_000000011301=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
double QR_011000000310=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
double QR_010001000310=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
double QR_010000001310=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001010000310=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
double QR_000011000310=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
double QR_000010001310=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
double QR_001000010310=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000001010310=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
double QR_000000011310=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
double QR_011000000400=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
double QR_010001000400=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
double QR_010000001400=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
double QR_001010000400=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
double QR_000011000400=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
double QR_000010001400=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
double QR_001000010400=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
double QR_000001010400=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
double QR_000000011400=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
__global__ void TSMJ_ddpp_JME(unsigned int contrc_bra_num,unsigned int primit_ket_len,\
unsigned int contrc_bra_start_pr,\
unsigned int contrc_ket_start_pr,\
unsigned int contrc_Pmtrx_start_pr,\
unsigned int * contrc_bra_id,\
double * P,\
double * PA,\
double * PB,\
double * Zta_in,\
double * pp_in,\
float * K2_p,\
double * ans){
unsigned int tId_x = threadIdx.x;
unsigned int bId_x = blockIdx.x;
unsigned int tdis = blockDim.x;
unsigned int bdis = gridDim.x;
unsigned int ans_id=tId_x;
double Pmtrx[9]={0.0};
__shared__ double ans_temp[NTHREAD_32*36];
for(int i=0;i<36;i++){
ans_temp[i*tdis+tId_x]=0.0;
}
for(unsigned int i_contrc_bra=bId_x;i_contrc_bra<contrc_bra_num;i_contrc_bra+=bdis){
unsigned int primit_bra_start = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra ];
unsigned int primit_bra_end = contrc_bra_start_pr+contrc_bra_id[i_contrc_bra+1];
for(unsigned int ii=primit_bra_start;ii<primit_bra_end;ii++){
double PX=P[ii*3+0];
double PY=P[ii*3+1];
double PZ=P[ii*3+2];
double Pd_010[3];
Pd_010[0]=PA[ii*3+0];
Pd_010[1]=PA[ii*3+1];
Pd_010[2]=PA[ii*3+2];
double Pd_001[3];
Pd_001[0]=PB[ii*3+0];
Pd_001[1]=PB[ii*3+1];
Pd_001[2]=PB[ii*3+2];
double Zta=Zta_in[ii];
double pp=pp_in[ii];
double aPin1=1/(2*Zta);
double aPin2=aPin1*aPin1;
double aPin3=aPin1*aPin2;
double aPin4=aPin1*aPin3;
double QR_011000000000=0;
double QR_010001000000=0;
double QR_010000001000=0;
double QR_001010000000=0;
double QR_000011000000=0;
double QR_000010001000=0;
double QR_001000010000=0;
double QR_000001010000=0;
double QR_000000011000=0;
double QR_011000000001=0;
double QR_010001000001=0;
double QR_010000001001=0;
double QR_001010000001=0;
double QR_000011000001=0;
double QR_000010001001=0;
double QR_001000010001=0;
double QR_000001010001=0;
double QR_000000011001=0;
double QR_011000000010=0;
double QR_010001000010=0;
double QR_010000001010=0;
double QR_001010000010=0;
double QR_000011000010=0;
double QR_000010001010=0;
double QR_001000010010=0;
double QR_000001010010=0;
double QR_000000011010=0;
double QR_011000000100=0;
double QR_010001000100=0;
double QR_010000001100=0;
double QR_001010000100=0;
double QR_000011000100=0;
double QR_000010001100=0;
double QR_001000010100=0;
double QR_000001010100=0;
double QR_000000011100=0;
double QR_011000000002=0;
double QR_010001000002=0;
double QR_010000001002=0;
double QR_001010000002=0;
double QR_000011000002=0;
double QR_000010001002=0;
double QR_001000010002=0;
double QR_000001010002=0;
double QR_000000011002=0;
double QR_011000000011=0;
double QR_010001000011=0;
double QR_010000001011=0;
double QR_001010000011=0;
double QR_000011000011=0;
double QR_000010001011=0;
double QR_001000010011=0;
double QR_000001010011=0;
double QR_000000011011=0;
double QR_011000000020=0;
double QR_010001000020=0;
double QR_010000001020=0;
double QR_001010000020=0;
double QR_000011000020=0;
double QR_000010001020=0;
double QR_001000010020=0;
double QR_000001010020=0;
double QR_000000011020=0;
double QR_011000000101=0;
double QR_010001000101=0;
double QR_010000001101=0;
double QR_001010000101=0;
double QR_000011000101=0;
double QR_000010001101=0;
double QR_001000010101=0;
double QR_000001010101=0;
double QR_000000011101=0;
double QR_011000000110=0;
double QR_010001000110=0;
double QR_010000001110=0;
double QR_001010000110=0;
double QR_000011000110=0;
double QR_000010001110=0;
double QR_001000010110=0;
double QR_000001010110=0;
double QR_000000011110=0;
double QR_011000000200=0;
double QR_010001000200=0;
double QR_010000001200=0;
double QR_001010000200=0;
double QR_000011000200=0;
double QR_000010001200=0;
double QR_001000010200=0;
double QR_000001010200=0;
double QR_000000011200=0;
double QR_011000000003=0;
double QR_010001000003=0;
double QR_010000001003=0;
double QR_001010000003=0;
double QR_000011000003=0;
double QR_000010001003=0;
double QR_001000010003=0;
double QR_000001010003=0;
double QR_000000011003=0;
double QR_011000000012=0;
double QR_010001000012=0;
double QR_010000001012=0;
double QR_001010000012=0;
double QR_000011000012=0;
double QR_000010001012=0;
double QR_001000010012=0;
double QR_000001010012=0;
double QR_000000011012=0;
double QR_011000000021=0;
double QR_010001000021=0;
double QR_010000001021=0;
double QR_001010000021=0;
double QR_000011000021=0;
double QR_000010001021=0;
double QR_001000010021=0;
double QR_000001010021=0;
double QR_000000011021=0;
double QR_011000000030=0;
double QR_010001000030=0;
double QR_010000001030=0;
double QR_001010000030=0;
double QR_000011000030=0;
double QR_000010001030=0;
double QR_001000010030=0;
double QR_000001010030=0;
double QR_000000011030=0;
double QR_011000000102=0;
double QR_010001000102=0;
double QR_010000001102=0;
double QR_001010000102=0;
double QR_000011000102=0;
double QR_000010001102=0;
double QR_001000010102=0;
double QR_000001010102=0;
double QR_000000011102=0;
double QR_011000000111=0;
double QR_010001000111=0;
double QR_010000001111=0;
double QR_001010000111=0;
double QR_000011000111=0;
double QR_000010001111=0;
double QR_001000010111=0;
double QR_000001010111=0;
double QR_000000011111=0;
double QR_011000000120=0;
double QR_010001000120=0;
double QR_010000001120=0;
double QR_001010000120=0;
double QR_000011000120=0;
double QR_000010001120=0;
double QR_001000010120=0;
double QR_000001010120=0;
double QR_000000011120=0;
double QR_011000000201=0;
double QR_010001000201=0;
double QR_010000001201=0;
double QR_001010000201=0;
double QR_000011000201=0;
double QR_000010001201=0;
double QR_001000010201=0;
double QR_000001010201=0;
double QR_000000011201=0;
double QR_011000000210=0;
double QR_010001000210=0;
double QR_010000001210=0;
double QR_001010000210=0;
double QR_000011000210=0;
double QR_000010001210=0;
double QR_001000010210=0;
double QR_000001010210=0;
double QR_000000011210=0;
double QR_011000000300=0;
double QR_010001000300=0;
double QR_010000001300=0;
double QR_001010000300=0;
double QR_000011000300=0;
double QR_000010001300=0;
double QR_001000010300=0;
double QR_000001010300=0;
double QR_000000011300=0;
double QR_011000000004=0;
double QR_010001000004=0;
double QR_010000001004=0;
double QR_001010000004=0;
double QR_000011000004=0;
double QR_000010001004=0;
double QR_001000010004=0;
double QR_000001010004=0;
double QR_000000011004=0;
double QR_011000000013=0;
double QR_010001000013=0;
double QR_010000001013=0;
double QR_001010000013=0;
double QR_000011000013=0;
double QR_000010001013=0;
double QR_001000010013=0;
double QR_000001010013=0;
double QR_000000011013=0;
double QR_011000000022=0;
double QR_010001000022=0;
double QR_010000001022=0;
double QR_001010000022=0;
double QR_000011000022=0;
double QR_000010001022=0;
double QR_001000010022=0;
double QR_000001010022=0;
double QR_000000011022=0;
double QR_011000000031=0;
double QR_010001000031=0;
double QR_010000001031=0;
double QR_001010000031=0;
double QR_000011000031=0;
double QR_000010001031=0;
double QR_001000010031=0;
double QR_000001010031=0;
double QR_000000011031=0;
double QR_011000000040=0;
double QR_010001000040=0;
double QR_010000001040=0;
double QR_001010000040=0;
double QR_000011000040=0;
double QR_000010001040=0;
double QR_001000010040=0;
double QR_000001010040=0;
double QR_000000011040=0;
double QR_011000000103=0;
double QR_010001000103=0;
double QR_010000001103=0;
double QR_001010000103=0;
double QR_000011000103=0;
double QR_000010001103=0;
double QR_001000010103=0;
double QR_000001010103=0;
double QR_000000011103=0;
double QR_011000000112=0;
double QR_010001000112=0;
double QR_010000001112=0;
double QR_001010000112=0;
double QR_000011000112=0;
double QR_000010001112=0;
double QR_001000010112=0;
double QR_000001010112=0;
double QR_000000011112=0;
double QR_011000000121=0;
double QR_010001000121=0;
double QR_010000001121=0;
double QR_001010000121=0;
double QR_000011000121=0;
double QR_000010001121=0;
double QR_001000010121=0;
double QR_000001010121=0;
double QR_000000011121=0;
double QR_011000000130=0;
double QR_010001000130=0;
double QR_010000001130=0;
double QR_001010000130=0;
double QR_000011000130=0;
double QR_000010001130=0;
double QR_001000010130=0;
double QR_000001010130=0;
double QR_000000011130=0;
double QR_011000000202=0;
double QR_010001000202=0;
double QR_010000001202=0;
double QR_001010000202=0;
double QR_000011000202=0;
double QR_000010001202=0;
double QR_001000010202=0;
double QR_000001010202=0;
double QR_000000011202=0;
double QR_011000000211=0;
double QR_010001000211=0;
double QR_010000001211=0;
double QR_001010000211=0;
double QR_000011000211=0;
double QR_000010001211=0;
double QR_001000010211=0;
double QR_000001010211=0;
double QR_000000011211=0;
double QR_011000000220=0;
double QR_010001000220=0;
double QR_010000001220=0;
double QR_001010000220=0;
double QR_000011000220=0;
double QR_000010001220=0;
double QR_001000010220=0;
double QR_000001010220=0;
double QR_000000011220=0;
double QR_011000000301=0;
double QR_010001000301=0;
double QR_010000001301=0;
double QR_001010000301=0;
double QR_000011000301=0;
double QR_000010001301=0;
double QR_001000010301=0;
double QR_000001010301=0;
double QR_000000011301=0;
double QR_011000000310=0;
double QR_010001000310=0;
double QR_010000001310=0;
double QR_001010000310=0;
double QR_000011000310=0;
double QR_000010001310=0;
double QR_001000010310=0;
double QR_000001010310=0;
double QR_000000011310=0;
double QR_011000000400=0;
double QR_010001000400=0;
double QR_010000001400=0;
double QR_001010000400=0;
double QR_000011000400=0;
double QR_000010001400=0;
double QR_001000010400=0;
double QR_000001010400=0;
double QR_000000011400=0;
for(unsigned int j=tId_x;j<primit_ket_len;j+=tdis){
unsigned int jj=contrc_ket_start_pr+j;
float K2_q=tex1Dfetch(tex_K2_q,jj);
if(fabsf(K2_p[ii]*K2_q)<1.0E-14){
break;
}
int2 temp_int2;
temp_int2=tex1Dfetch(tex_Eta,jj);
double Eta=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_pq,jj);
double pq=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+0);
double QX=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+1);
double QY=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_Q,jj*3+2);
double QZ=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_010[3];
temp_int2=tex1Dfetch(tex_QC,jj*3+0);
Qd_010[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+1);
Qd_010[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QC,jj*3+2);
Qd_010[2]=__hiloint2double(temp_int2.y,temp_int2.x);
double Qd_001[3];
temp_int2=tex1Dfetch(tex_QD,jj*3+0);
Qd_001[0]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+1);
Qd_001[1]=__hiloint2double(temp_int2.y,temp_int2.x);
temp_int2=tex1Dfetch(tex_QD,jj*3+2);
Qd_001[2]=__hiloint2double(temp_int2.y,temp_int2.x);
unsigned int p_jj=contrc_Pmtrx_start_pr+j*9;
double P_max=0.0;
for(int p_i=0;p_i<9;p_i++){
int2 Pmtrx_2=tex1Dfetch(tex_Pmtrx,p_jj+p_i);
Pmtrx[p_i]=__hiloint2double(Pmtrx_2.y,Pmtrx_2.x);
if(P_max<Pmtrx[p_i]) P_max=Pmtrx[p_i];
}
double alphaT=rsqrt(Eta+Zta);
double lmd=2*P25*pp*pq*alphaT;
alphaT=Eta*Zta*alphaT*alphaT;
double TX=PX-QX;
double TY=PY-QY;
double TZ=PZ-QZ;
double T=alphaT*(TX*TX+TY*TY+TZ*TZ);
double R_000[7];
Ft_fs_6(6,T,R_000);
R_000[0]*=lmd;
R_000[1]*=-2*alphaT*lmd;
R_000[2]*=4*alphaT*alphaT*lmd;
R_000[3]*=-8*alphaT*alphaT*alphaT*lmd;
R_000[4]*=16*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[5]*=-32*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
R_000[6]*=64*alphaT*alphaT*alphaT*alphaT*alphaT*alphaT*lmd;
double aQin1=1/(2*Eta);
double aQin2=aQin1*aQin1;
double R_100[6];
double R_200[5];
double R_300[4];
double R_400[3];
double R_500[2];
double R_600[1];
double R_010[6];
double R_110[5];
double R_210[4];
double R_310[3];
double R_410[2];
double R_510[1];
double R_020[5];
double R_120[4];
double R_220[3];
double R_320[2];
double R_420[1];
double R_030[4];
double R_130[3];
double R_230[2];
double R_330[1];
double R_040[3];
double R_140[2];
double R_240[1];
double R_050[2];
double R_150[1];
double R_060[1];
double R_001[6];
double R_101[5];
double R_201[4];
double R_301[3];
double R_401[2];
double R_501[1];
double R_011[5];
double R_111[4];
double R_211[3];
double R_311[2];
double R_411[1];
double R_021[4];
double R_121[3];
double R_221[2];
double R_321[1];
double R_031[3];
double R_131[2];
double R_231[1];
double R_041[2];
double R_141[1];
double R_051[1];
double R_002[5];
double R_102[4];
double R_202[3];
double R_302[2];
double R_402[1];
double R_012[4];
double R_112[3];
double R_212[2];
double R_312[1];
double R_022[3];
double R_122[2];
double R_222[1];
double R_032[2];
double R_132[1];
double R_042[1];
double R_003[4];
double R_103[3];
double R_203[2];
double R_303[1];
double R_013[3];
double R_113[2];
double R_213[1];
double R_023[2];
double R_123[1];
double R_033[1];
double R_004[3];
double R_104[2];
double R_204[1];
double R_014[2];
double R_114[1];
double R_024[1];
double R_005[2];
double R_105[1];
double R_015[1];
double R_006[1];
for(int i=0;i<6;i++){
R_100[i]=TX*R_000[i+1];
}
for(int i=0;i<6;i++){
R_010[i]=TY*R_000[i+1];
}
for(int i=0;i<6;i++){
R_001[i]=TZ*R_000[i+1];
}
for(int i=0;i<5;i++){
R_200[i]=TX*R_100[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_110[i]=TX*R_010[i+1];
}
for(int i=0;i<5;i++){
R_020[i]=TY*R_010[i+1]+R_000[i+1];
}
for(int i=0;i<5;i++){
R_101[i]=TX*R_001[i+1];
}
for(int i=0;i<5;i++){
R_011[i]=TY*R_001[i+1];
}
for(int i=0;i<5;i++){
R_002[i]=TZ*R_001[i+1]+R_000[i+1];
}
for(int i=0;i<4;i++){
R_300[i]=TX*R_200[i+1]+2*R_100[i+1];
}
for(int i=0;i<4;i++){
R_210[i]=TY*R_200[i+1];
}
for(int i=0;i<4;i++){
R_120[i]=TX*R_020[i+1];
}
for(int i=0;i<4;i++){
R_030[i]=TY*R_020[i+1]+2*R_010[i+1];
}
for(int i=0;i<4;i++){
R_201[i]=TZ*R_200[i+1];
}
for(int i=0;i<4;i++){
R_111[i]=TX*R_011[i+1];
}
for(int i=0;i<4;i++){
R_021[i]=TZ*R_020[i+1];
}
for(int i=0;i<4;i++){
R_102[i]=TX*R_002[i+1];
}
for(int i=0;i<4;i++){
R_012[i]=TY*R_002[i+1];
}
for(int i=0;i<4;i++){
R_003[i]=TZ*R_002[i+1]+2*R_001[i+1];
}
for(int i=0;i<3;i++){
R_400[i]=TX*R_300[i+1]+3*R_200[i+1];
}
for(int i=0;i<3;i++){
R_310[i]=TY*R_300[i+1];
}
for(int i=0;i<3;i++){
R_220[i]=TX*R_120[i+1]+R_020[i+1];
}
for(int i=0;i<3;i++){
R_130[i]=TX*R_030[i+1];
}
for(int i=0;i<3;i++){
R_040[i]=TY*R_030[i+1]+3*R_020[i+1];
}
for(int i=0;i<3;i++){
R_301[i]=TZ*R_300[i+1];
}
for(int i=0;i<3;i++){
R_211[i]=TY*R_201[i+1];
}
for(int i=0;i<3;i++){
R_121[i]=TX*R_021[i+1];
}
for(int i=0;i<3;i++){
R_031[i]=TZ*R_030[i+1];
}
for(int i=0;i<3;i++){
R_202[i]=TX*R_102[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_112[i]=TX*R_012[i+1];
}
for(int i=0;i<3;i++){
R_022[i]=TY*R_012[i+1]+R_002[i+1];
}
for(int i=0;i<3;i++){
R_103[i]=TX*R_003[i+1];
}
for(int i=0;i<3;i++){
R_013[i]=TY*R_003[i+1];
}
for(int i=0;i<3;i++){
R_004[i]=TZ*R_003[i+1]+3*R_002[i+1];
}
for(int i=0;i<2;i++){
R_500[i]=TX*R_400[i+1]+4*R_300[i+1];
}
for(int i=0;i<2;i++){
R_410[i]=TY*R_400[i+1];
}
for(int i=0;i<2;i++){
R_320[i]=TX*R_220[i+1]+2*R_120[i+1];
}
for(int i=0;i<2;i++){
R_230[i]=TY*R_220[i+1]+2*R_210[i+1];
}
for(int i=0;i<2;i++){
R_140[i]=TX*R_040[i+1];
}
for(int i=0;i<2;i++){
R_050[i]=TY*R_040[i+1]+4*R_030[i+1];
}
for(int i=0;i<2;i++){
R_401[i]=TZ*R_400[i+1];
}
for(int i=0;i<2;i++){
R_311[i]=TY*R_301[i+1];
}
for(int i=0;i<2;i++){
R_221[i]=TZ*R_220[i+1];
}
for(int i=0;i<2;i++){
R_131[i]=TX*R_031[i+1];
}
for(int i=0;i<2;i++){
R_041[i]=TZ*R_040[i+1];
}
for(int i=0;i<2;i++){
R_302[i]=TX*R_202[i+1]+2*R_102[i+1];
}
for(int i=0;i<2;i++){
R_212[i]=TY*R_202[i+1];
}
for(int i=0;i<2;i++){
R_122[i]=TX*R_022[i+1];
}
for(int i=0;i<2;i++){
R_032[i]=TY*R_022[i+1]+2*R_012[i+1];
}
for(int i=0;i<2;i++){
R_203[i]=TZ*R_202[i+1]+2*R_201[i+1];
}
for(int i=0;i<2;i++){
R_113[i]=TX*R_013[i+1];
}
for(int i=0;i<2;i++){
R_023[i]=TZ*R_022[i+1]+2*R_021[i+1];
}
for(int i=0;i<2;i++){
R_104[i]=TX*R_004[i+1];
}
for(int i=0;i<2;i++){
R_014[i]=TY*R_004[i+1];
}
for(int i=0;i<2;i++){
R_005[i]=TZ*R_004[i+1]+4*R_003[i+1];
}
for(int i=0;i<1;i++){
R_600[i]=TX*R_500[i+1]+5*R_400[i+1];
}
for(int i=0;i<1;i++){
R_510[i]=TY*R_500[i+1];
}
for(int i=0;i<1;i++){
R_420[i]=TX*R_320[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_330[i]=TX*R_230[i+1]+2*R_130[i+1];
}
for(int i=0;i<1;i++){
R_240[i]=TY*R_230[i+1]+3*R_220[i+1];
}
for(int i=0;i<1;i++){
R_150[i]=TX*R_050[i+1];
}
for(int i=0;i<1;i++){
R_060[i]=TY*R_050[i+1]+5*R_040[i+1];
}
for(int i=0;i<1;i++){
R_501[i]=TZ*R_500[i+1];
}
for(int i=0;i<1;i++){
R_411[i]=TY*R_401[i+1];
}
for(int i=0;i<1;i++){
R_321[i]=TZ*R_320[i+1];
}
for(int i=0;i<1;i++){
R_231[i]=TZ*R_230[i+1];
}
for(int i=0;i<1;i++){
R_141[i]=TX*R_041[i+1];
}
for(int i=0;i<1;i++){
R_051[i]=TZ*R_050[i+1];
}
for(int i=0;i<1;i++){
R_402[i]=TX*R_302[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_312[i]=TY*R_302[i+1];
}
for(int i=0;i<1;i++){
R_222[i]=TX*R_122[i+1]+R_022[i+1];
}
for(int i=0;i<1;i++){
R_132[i]=TX*R_032[i+1];
}
for(int i=0;i<1;i++){
R_042[i]=TY*R_032[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_303[i]=TX*R_203[i+1]+2*R_103[i+1];
}
for(int i=0;i<1;i++){
R_213[i]=TY*R_203[i+1];
}
for(int i=0;i<1;i++){
R_123[i]=TX*R_023[i+1];
}
for(int i=0;i<1;i++){
R_033[i]=TY*R_023[i+1]+2*R_013[i+1];
}
for(int i=0;i<1;i++){
R_204[i]=TZ*R_203[i+1]+3*R_202[i+1];
}
for(int i=0;i<1;i++){
R_114[i]=TX*R_014[i+1];
}
for(int i=0;i<1;i++){
R_024[i]=TZ*R_023[i+1]+3*R_022[i+1];
}
for(int i=0;i<1;i++){
R_105[i]=TX*R_005[i+1];
}
for(int i=0;i<1;i++){
R_015[i]=TY*R_005[i+1];
}
for(int i=0;i<1;i++){
R_006[i]=TZ*R_005[i+1]+5*R_004[i+1];
}
double Qd_011[3];
double Qd_111[3];
for(int i=0;i<3;i++){
Qd_011[i]=aQin1+Qd_010[i]*Qd_001[i];
}
for(int i=0;i<3;i++){
Qd_111[i]=aQin1*(Qd_001[i]+Qd_010[i]);
}
double Q_011000000;
double Q_111000000;
double Q_010001000;
double Q_010000001;
double Q_001010000;
double Q_000011000;
double Q_000111000;
double Q_000010001;
double Q_001000010;
double Q_000001010;
double Q_000000011;
double Q_000000111;
double a1Q_010000000_1;
double a1Q_000001000_1;
double a1Q_000000001_1;
double a1Q_001000000_1;
double a1Q_000010000_1;
double a1Q_000000010_1;
Q_011000000=Qd_011[0];
Q_111000000=Qd_111[0];
Q_010001000=Qd_010[0]*Qd_001[1];
Q_010000001=Qd_010[0]*Qd_001[2];
Q_001010000=Qd_001[0]*Qd_010[1];
Q_000011000=Qd_011[1];
Q_000111000=Qd_111[1];
Q_000010001=Qd_010[1]*Qd_001[2];
Q_001000010=Qd_001[0]*Qd_010[2];
Q_000001010=Qd_001[1]*Qd_010[2];
Q_000000011=Qd_011[2];
Q_000000111=Qd_111[2];
a1Q_010000000_1=Qd_010[0];
a1Q_000001000_1=Qd_001[1];
a1Q_000000001_1=Qd_001[2];
a1Q_001000000_1=Qd_001[0];
a1Q_000010000_1=Qd_010[1];
a1Q_000000010_1=Qd_010[2];
QR_011000000000+=Q_011000000*R_000[0]-Q_111000000*R_100[0]+aQin2*R_200[0];
QR_010001000000+=Q_010001000*R_000[0]-a1Q_010000000_1*R_010[0]-a1Q_000001000_1*R_100[0]+aQin2*R_110[0];
QR_010000001000+=Q_010000001*R_000[0]-a1Q_010000000_1*R_001[0]-a1Q_000000001_1*R_100[0]+aQin2*R_101[0];
QR_001010000000+=Q_001010000*R_000[0]-a1Q_001000000_1*R_010[0]-a1Q_000010000_1*R_100[0]+aQin2*R_110[0];
QR_000011000000+=Q_000011000*R_000[0]-Q_000111000*R_010[0]+aQin2*R_020[0];
QR_000010001000+=Q_000010001*R_000[0]-a1Q_000010000_1*R_001[0]-a1Q_000000001_1*R_010[0]+aQin2*R_011[0];
QR_001000010000+=Q_001000010*R_000[0]-a1Q_001000000_1*R_001[0]-a1Q_000000010_1*R_100[0]+aQin2*R_101[0];
QR_000001010000+=Q_000001010*R_000[0]-a1Q_000001000_1*R_001[0]-a1Q_000000010_1*R_010[0]+aQin2*R_011[0];
QR_000000011000+=Q_000000011*R_000[0]-Q_000000111*R_001[0]+aQin2*R_002[0];
QR_011000000001+=Q_011000000*R_001[0]-Q_111000000*R_101[0]+aQin2*R_201[0];
QR_010001000001+=Q_010001000*R_001[0]-a1Q_010000000_1*R_011[0]-a1Q_000001000_1*R_101[0]+aQin2*R_111[0];
QR_010000001001+=Q_010000001*R_001[0]-a1Q_010000000_1*R_002[0]-a1Q_000000001_1*R_101[0]+aQin2*R_102[0];
QR_001010000001+=Q_001010000*R_001[0]-a1Q_001000000_1*R_011[0]-a1Q_000010000_1*R_101[0]+aQin2*R_111[0];
QR_000011000001+=Q_000011000*R_001[0]-Q_000111000*R_011[0]+aQin2*R_021[0];
QR_000010001001+=Q_000010001*R_001[0]-a1Q_000010000_1*R_002[0]-a1Q_000000001_1*R_011[0]+aQin2*R_012[0];
QR_001000010001+=Q_001000010*R_001[0]-a1Q_001000000_1*R_002[0]-a1Q_000000010_1*R_101[0]+aQin2*R_102[0];
QR_000001010001+=Q_000001010*R_001[0]-a1Q_000001000_1*R_002[0]-a1Q_000000010_1*R_011[0]+aQin2*R_012[0];
QR_000000011001+=Q_000000011*R_001[0]-Q_000000111*R_002[0]+aQin2*R_003[0];
QR_011000000010+=Q_011000000*R_010[0]-Q_111000000*R_110[0]+aQin2*R_210[0];
QR_010001000010+=Q_010001000*R_010[0]-a1Q_010000000_1*R_020[0]-a1Q_000001000_1*R_110[0]+aQin2*R_120[0];
QR_010000001010+=Q_010000001*R_010[0]-a1Q_010000000_1*R_011[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001010000010+=Q_001010000*R_010[0]-a1Q_001000000_1*R_020[0]-a1Q_000010000_1*R_110[0]+aQin2*R_120[0];
QR_000011000010+=Q_000011000*R_010[0]-Q_000111000*R_020[0]+aQin2*R_030[0];
QR_000010001010+=Q_000010001*R_010[0]-a1Q_000010000_1*R_011[0]-a1Q_000000001_1*R_020[0]+aQin2*R_021[0];
QR_001000010010+=Q_001000010*R_010[0]-a1Q_001000000_1*R_011[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000001010010+=Q_000001010*R_010[0]-a1Q_000001000_1*R_011[0]-a1Q_000000010_1*R_020[0]+aQin2*R_021[0];
QR_000000011010+=Q_000000011*R_010[0]-Q_000000111*R_011[0]+aQin2*R_012[0];
QR_011000000100+=Q_011000000*R_100[0]-Q_111000000*R_200[0]+aQin2*R_300[0];
QR_010001000100+=Q_010001000*R_100[0]-a1Q_010000000_1*R_110[0]-a1Q_000001000_1*R_200[0]+aQin2*R_210[0];
QR_010000001100+=Q_010000001*R_100[0]-a1Q_010000000_1*R_101[0]-a1Q_000000001_1*R_200[0]+aQin2*R_201[0];
QR_001010000100+=Q_001010000*R_100[0]-a1Q_001000000_1*R_110[0]-a1Q_000010000_1*R_200[0]+aQin2*R_210[0];
QR_000011000100+=Q_000011000*R_100[0]-Q_000111000*R_110[0]+aQin2*R_120[0];
QR_000010001100+=Q_000010001*R_100[0]-a1Q_000010000_1*R_101[0]-a1Q_000000001_1*R_110[0]+aQin2*R_111[0];
QR_001000010100+=Q_001000010*R_100[0]-a1Q_001000000_1*R_101[0]-a1Q_000000010_1*R_200[0]+aQin2*R_201[0];
QR_000001010100+=Q_000001010*R_100[0]-a1Q_000001000_1*R_101[0]-a1Q_000000010_1*R_110[0]+aQin2*R_111[0];
QR_000000011100+=Q_000000011*R_100[0]-Q_000000111*R_101[0]+aQin2*R_102[0];
QR_011000000002+=Q_011000000*R_002[0]-Q_111000000*R_102[0]+aQin2*R_202[0];
QR_010001000002+=Q_010001000*R_002[0]-a1Q_010000000_1*R_012[0]-a1Q_000001000_1*R_102[0]+aQin2*R_112[0];
QR_010000001002+=Q_010000001*R_002[0]-a1Q_010000000_1*R_003[0]-a1Q_000000001_1*R_102[0]+aQin2*R_103[0];
QR_001010000002+=Q_001010000*R_002[0]-a1Q_001000000_1*R_012[0]-a1Q_000010000_1*R_102[0]+aQin2*R_112[0];
QR_000011000002+=Q_000011000*R_002[0]-Q_000111000*R_012[0]+aQin2*R_022[0];
QR_000010001002+=Q_000010001*R_002[0]-a1Q_000010000_1*R_003[0]-a1Q_000000001_1*R_012[0]+aQin2*R_013[0];
QR_001000010002+=Q_001000010*R_002[0]-a1Q_001000000_1*R_003[0]-a1Q_000000010_1*R_102[0]+aQin2*R_103[0];
QR_000001010002+=Q_000001010*R_002[0]-a1Q_000001000_1*R_003[0]-a1Q_000000010_1*R_012[0]+aQin2*R_013[0];
QR_000000011002+=Q_000000011*R_002[0]-Q_000000111*R_003[0]+aQin2*R_004[0];
QR_011000000011+=Q_011000000*R_011[0]-Q_111000000*R_111[0]+aQin2*R_211[0];
QR_010001000011+=Q_010001000*R_011[0]-a1Q_010000000_1*R_021[0]-a1Q_000001000_1*R_111[0]+aQin2*R_121[0];
QR_010000001011+=Q_010000001*R_011[0]-a1Q_010000000_1*R_012[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001010000011+=Q_001010000*R_011[0]-a1Q_001000000_1*R_021[0]-a1Q_000010000_1*R_111[0]+aQin2*R_121[0];
QR_000011000011+=Q_000011000*R_011[0]-Q_000111000*R_021[0]+aQin2*R_031[0];
QR_000010001011+=Q_000010001*R_011[0]-a1Q_000010000_1*R_012[0]-a1Q_000000001_1*R_021[0]+aQin2*R_022[0];
QR_001000010011+=Q_001000010*R_011[0]-a1Q_001000000_1*R_012[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000001010011+=Q_000001010*R_011[0]-a1Q_000001000_1*R_012[0]-a1Q_000000010_1*R_021[0]+aQin2*R_022[0];
QR_000000011011+=Q_000000011*R_011[0]-Q_000000111*R_012[0]+aQin2*R_013[0];
QR_011000000020+=Q_011000000*R_020[0]-Q_111000000*R_120[0]+aQin2*R_220[0];
QR_010001000020+=Q_010001000*R_020[0]-a1Q_010000000_1*R_030[0]-a1Q_000001000_1*R_120[0]+aQin2*R_130[0];
QR_010000001020+=Q_010000001*R_020[0]-a1Q_010000000_1*R_021[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001010000020+=Q_001010000*R_020[0]-a1Q_001000000_1*R_030[0]-a1Q_000010000_1*R_120[0]+aQin2*R_130[0];
QR_000011000020+=Q_000011000*R_020[0]-Q_000111000*R_030[0]+aQin2*R_040[0];
QR_000010001020+=Q_000010001*R_020[0]-a1Q_000010000_1*R_021[0]-a1Q_000000001_1*R_030[0]+aQin2*R_031[0];
QR_001000010020+=Q_001000010*R_020[0]-a1Q_001000000_1*R_021[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000001010020+=Q_000001010*R_020[0]-a1Q_000001000_1*R_021[0]-a1Q_000000010_1*R_030[0]+aQin2*R_031[0];
QR_000000011020+=Q_000000011*R_020[0]-Q_000000111*R_021[0]+aQin2*R_022[0];
QR_011000000101+=Q_011000000*R_101[0]-Q_111000000*R_201[0]+aQin2*R_301[0];
QR_010001000101+=Q_010001000*R_101[0]-a1Q_010000000_1*R_111[0]-a1Q_000001000_1*R_201[0]+aQin2*R_211[0];
QR_010000001101+=Q_010000001*R_101[0]-a1Q_010000000_1*R_102[0]-a1Q_000000001_1*R_201[0]+aQin2*R_202[0];
QR_001010000101+=Q_001010000*R_101[0]-a1Q_001000000_1*R_111[0]-a1Q_000010000_1*R_201[0]+aQin2*R_211[0];
QR_000011000101+=Q_000011000*R_101[0]-Q_000111000*R_111[0]+aQin2*R_121[0];
QR_000010001101+=Q_000010001*R_101[0]-a1Q_000010000_1*R_102[0]-a1Q_000000001_1*R_111[0]+aQin2*R_112[0];
QR_001000010101+=Q_001000010*R_101[0]-a1Q_001000000_1*R_102[0]-a1Q_000000010_1*R_201[0]+aQin2*R_202[0];
QR_000001010101+=Q_000001010*R_101[0]-a1Q_000001000_1*R_102[0]-a1Q_000000010_1*R_111[0]+aQin2*R_112[0];
QR_000000011101+=Q_000000011*R_101[0]-Q_000000111*R_102[0]+aQin2*R_103[0];
QR_011000000110+=Q_011000000*R_110[0]-Q_111000000*R_210[0]+aQin2*R_310[0];
QR_010001000110+=Q_010001000*R_110[0]-a1Q_010000000_1*R_120[0]-a1Q_000001000_1*R_210[0]+aQin2*R_220[0];
QR_010000001110+=Q_010000001*R_110[0]-a1Q_010000000_1*R_111[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001010000110+=Q_001010000*R_110[0]-a1Q_001000000_1*R_120[0]-a1Q_000010000_1*R_210[0]+aQin2*R_220[0];
QR_000011000110+=Q_000011000*R_110[0]-Q_000111000*R_120[0]+aQin2*R_130[0];
QR_000010001110+=Q_000010001*R_110[0]-a1Q_000010000_1*R_111[0]-a1Q_000000001_1*R_120[0]+aQin2*R_121[0];
QR_001000010110+=Q_001000010*R_110[0]-a1Q_001000000_1*R_111[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000001010110+=Q_000001010*R_110[0]-a1Q_000001000_1*R_111[0]-a1Q_000000010_1*R_120[0]+aQin2*R_121[0];
QR_000000011110+=Q_000000011*R_110[0]-Q_000000111*R_111[0]+aQin2*R_112[0];
QR_011000000200+=Q_011000000*R_200[0]-Q_111000000*R_300[0]+aQin2*R_400[0];
QR_010001000200+=Q_010001000*R_200[0]-a1Q_010000000_1*R_210[0]-a1Q_000001000_1*R_300[0]+aQin2*R_310[0];
QR_010000001200+=Q_010000001*R_200[0]-a1Q_010000000_1*R_201[0]-a1Q_000000001_1*R_300[0]+aQin2*R_301[0];
QR_001010000200+=Q_001010000*R_200[0]-a1Q_001000000_1*R_210[0]-a1Q_000010000_1*R_300[0]+aQin2*R_310[0];
QR_000011000200+=Q_000011000*R_200[0]-Q_000111000*R_210[0]+aQin2*R_220[0];
QR_000010001200+=Q_000010001*R_200[0]-a1Q_000010000_1*R_201[0]-a1Q_000000001_1*R_210[0]+aQin2*R_211[0];
QR_001000010200+=Q_001000010*R_200[0]-a1Q_001000000_1*R_201[0]-a1Q_000000010_1*R_300[0]+aQin2*R_301[0];
QR_000001010200+=Q_000001010*R_200[0]-a1Q_000001000_1*R_201[0]-a1Q_000000010_1*R_210[0]+aQin2*R_211[0];
QR_000000011200+=Q_000000011*R_200[0]-Q_000000111*R_201[0]+aQin2*R_202[0];
QR_011000000003+=Q_011000000*R_003[0]-Q_111000000*R_103[0]+aQin2*R_203[0];
QR_010001000003+=Q_010001000*R_003[0]-a1Q_010000000_1*R_013[0]-a1Q_000001000_1*R_103[0]+aQin2*R_113[0];
QR_010000001003+=Q_010000001*R_003[0]-a1Q_010000000_1*R_004[0]-a1Q_000000001_1*R_103[0]+aQin2*R_104[0];
QR_001010000003+=Q_001010000*R_003[0]-a1Q_001000000_1*R_013[0]-a1Q_000010000_1*R_103[0]+aQin2*R_113[0];
QR_000011000003+=Q_000011000*R_003[0]-Q_000111000*R_013[0]+aQin2*R_023[0];
QR_000010001003+=Q_000010001*R_003[0]-a1Q_000010000_1*R_004[0]-a1Q_000000001_1*R_013[0]+aQin2*R_014[0];
QR_001000010003+=Q_001000010*R_003[0]-a1Q_001000000_1*R_004[0]-a1Q_000000010_1*R_103[0]+aQin2*R_104[0];
QR_000001010003+=Q_000001010*R_003[0]-a1Q_000001000_1*R_004[0]-a1Q_000000010_1*R_013[0]+aQin2*R_014[0];
QR_000000011003+=Q_000000011*R_003[0]-Q_000000111*R_004[0]+aQin2*R_005[0];
QR_011000000012+=Q_011000000*R_012[0]-Q_111000000*R_112[0]+aQin2*R_212[0];
QR_010001000012+=Q_010001000*R_012[0]-a1Q_010000000_1*R_022[0]-a1Q_000001000_1*R_112[0]+aQin2*R_122[0];
QR_010000001012+=Q_010000001*R_012[0]-a1Q_010000000_1*R_013[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001010000012+=Q_001010000*R_012[0]-a1Q_001000000_1*R_022[0]-a1Q_000010000_1*R_112[0]+aQin2*R_122[0];
QR_000011000012+=Q_000011000*R_012[0]-Q_000111000*R_022[0]+aQin2*R_032[0];
QR_000010001012+=Q_000010001*R_012[0]-a1Q_000010000_1*R_013[0]-a1Q_000000001_1*R_022[0]+aQin2*R_023[0];
QR_001000010012+=Q_001000010*R_012[0]-a1Q_001000000_1*R_013[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000001010012+=Q_000001010*R_012[0]-a1Q_000001000_1*R_013[0]-a1Q_000000010_1*R_022[0]+aQin2*R_023[0];
QR_000000011012+=Q_000000011*R_012[0]-Q_000000111*R_013[0]+aQin2*R_014[0];
QR_011000000021+=Q_011000000*R_021[0]-Q_111000000*R_121[0]+aQin2*R_221[0];
QR_010001000021+=Q_010001000*R_021[0]-a1Q_010000000_1*R_031[0]-a1Q_000001000_1*R_121[0]+aQin2*R_131[0];
QR_010000001021+=Q_010000001*R_021[0]-a1Q_010000000_1*R_022[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001010000021+=Q_001010000*R_021[0]-a1Q_001000000_1*R_031[0]-a1Q_000010000_1*R_121[0]+aQin2*R_131[0];
QR_000011000021+=Q_000011000*R_021[0]-Q_000111000*R_031[0]+aQin2*R_041[0];
QR_000010001021+=Q_000010001*R_021[0]-a1Q_000010000_1*R_022[0]-a1Q_000000001_1*R_031[0]+aQin2*R_032[0];
QR_001000010021+=Q_001000010*R_021[0]-a1Q_001000000_1*R_022[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000001010021+=Q_000001010*R_021[0]-a1Q_000001000_1*R_022[0]-a1Q_000000010_1*R_031[0]+aQin2*R_032[0];
QR_000000011021+=Q_000000011*R_021[0]-Q_000000111*R_022[0]+aQin2*R_023[0];
QR_011000000030+=Q_011000000*R_030[0]-Q_111000000*R_130[0]+aQin2*R_230[0];
QR_010001000030+=Q_010001000*R_030[0]-a1Q_010000000_1*R_040[0]-a1Q_000001000_1*R_130[0]+aQin2*R_140[0];
QR_010000001030+=Q_010000001*R_030[0]-a1Q_010000000_1*R_031[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001010000030+=Q_001010000*R_030[0]-a1Q_001000000_1*R_040[0]-a1Q_000010000_1*R_130[0]+aQin2*R_140[0];
QR_000011000030+=Q_000011000*R_030[0]-Q_000111000*R_040[0]+aQin2*R_050[0];
QR_000010001030+=Q_000010001*R_030[0]-a1Q_000010000_1*R_031[0]-a1Q_000000001_1*R_040[0]+aQin2*R_041[0];
QR_001000010030+=Q_001000010*R_030[0]-a1Q_001000000_1*R_031[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000001010030+=Q_000001010*R_030[0]-a1Q_000001000_1*R_031[0]-a1Q_000000010_1*R_040[0]+aQin2*R_041[0];
QR_000000011030+=Q_000000011*R_030[0]-Q_000000111*R_031[0]+aQin2*R_032[0];
QR_011000000102+=Q_011000000*R_102[0]-Q_111000000*R_202[0]+aQin2*R_302[0];
QR_010001000102+=Q_010001000*R_102[0]-a1Q_010000000_1*R_112[0]-a1Q_000001000_1*R_202[0]+aQin2*R_212[0];
QR_010000001102+=Q_010000001*R_102[0]-a1Q_010000000_1*R_103[0]-a1Q_000000001_1*R_202[0]+aQin2*R_203[0];
QR_001010000102+=Q_001010000*R_102[0]-a1Q_001000000_1*R_112[0]-a1Q_000010000_1*R_202[0]+aQin2*R_212[0];
QR_000011000102+=Q_000011000*R_102[0]-Q_000111000*R_112[0]+aQin2*R_122[0];
QR_000010001102+=Q_000010001*R_102[0]-a1Q_000010000_1*R_103[0]-a1Q_000000001_1*R_112[0]+aQin2*R_113[0];
QR_001000010102+=Q_001000010*R_102[0]-a1Q_001000000_1*R_103[0]-a1Q_000000010_1*R_202[0]+aQin2*R_203[0];
QR_000001010102+=Q_000001010*R_102[0]-a1Q_000001000_1*R_103[0]-a1Q_000000010_1*R_112[0]+aQin2*R_113[0];
QR_000000011102+=Q_000000011*R_102[0]-Q_000000111*R_103[0]+aQin2*R_104[0];
QR_011000000111+=Q_011000000*R_111[0]-Q_111000000*R_211[0]+aQin2*R_311[0];
QR_010001000111+=Q_010001000*R_111[0]-a1Q_010000000_1*R_121[0]-a1Q_000001000_1*R_211[0]+aQin2*R_221[0];
QR_010000001111+=Q_010000001*R_111[0]-a1Q_010000000_1*R_112[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001010000111+=Q_001010000*R_111[0]-a1Q_001000000_1*R_121[0]-a1Q_000010000_1*R_211[0]+aQin2*R_221[0];
QR_000011000111+=Q_000011000*R_111[0]-Q_000111000*R_121[0]+aQin2*R_131[0];
QR_000010001111+=Q_000010001*R_111[0]-a1Q_000010000_1*R_112[0]-a1Q_000000001_1*R_121[0]+aQin2*R_122[0];
QR_001000010111+=Q_001000010*R_111[0]-a1Q_001000000_1*R_112[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000001010111+=Q_000001010*R_111[0]-a1Q_000001000_1*R_112[0]-a1Q_000000010_1*R_121[0]+aQin2*R_122[0];
QR_000000011111+=Q_000000011*R_111[0]-Q_000000111*R_112[0]+aQin2*R_113[0];
QR_011000000120+=Q_011000000*R_120[0]-Q_111000000*R_220[0]+aQin2*R_320[0];
QR_010001000120+=Q_010001000*R_120[0]-a1Q_010000000_1*R_130[0]-a1Q_000001000_1*R_220[0]+aQin2*R_230[0];
QR_010000001120+=Q_010000001*R_120[0]-a1Q_010000000_1*R_121[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001010000120+=Q_001010000*R_120[0]-a1Q_001000000_1*R_130[0]-a1Q_000010000_1*R_220[0]+aQin2*R_230[0];
QR_000011000120+=Q_000011000*R_120[0]-Q_000111000*R_130[0]+aQin2*R_140[0];
QR_000010001120+=Q_000010001*R_120[0]-a1Q_000010000_1*R_121[0]-a1Q_000000001_1*R_130[0]+aQin2*R_131[0];
QR_001000010120+=Q_001000010*R_120[0]-a1Q_001000000_1*R_121[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000001010120+=Q_000001010*R_120[0]-a1Q_000001000_1*R_121[0]-a1Q_000000010_1*R_130[0]+aQin2*R_131[0];
QR_000000011120+=Q_000000011*R_120[0]-Q_000000111*R_121[0]+aQin2*R_122[0];
QR_011000000201+=Q_011000000*R_201[0]-Q_111000000*R_301[0]+aQin2*R_401[0];
QR_010001000201+=Q_010001000*R_201[0]-a1Q_010000000_1*R_211[0]-a1Q_000001000_1*R_301[0]+aQin2*R_311[0];
QR_010000001201+=Q_010000001*R_201[0]-a1Q_010000000_1*R_202[0]-a1Q_000000001_1*R_301[0]+aQin2*R_302[0];
QR_001010000201+=Q_001010000*R_201[0]-a1Q_001000000_1*R_211[0]-a1Q_000010000_1*R_301[0]+aQin2*R_311[0];
QR_000011000201+=Q_000011000*R_201[0]-Q_000111000*R_211[0]+aQin2*R_221[0];
QR_000010001201+=Q_000010001*R_201[0]-a1Q_000010000_1*R_202[0]-a1Q_000000001_1*R_211[0]+aQin2*R_212[0];
QR_001000010201+=Q_001000010*R_201[0]-a1Q_001000000_1*R_202[0]-a1Q_000000010_1*R_301[0]+aQin2*R_302[0];
QR_000001010201+=Q_000001010*R_201[0]-a1Q_000001000_1*R_202[0]-a1Q_000000010_1*R_211[0]+aQin2*R_212[0];
QR_000000011201+=Q_000000011*R_201[0]-Q_000000111*R_202[0]+aQin2*R_203[0];
QR_011000000210+=Q_011000000*R_210[0]-Q_111000000*R_310[0]+aQin2*R_410[0];
QR_010001000210+=Q_010001000*R_210[0]-a1Q_010000000_1*R_220[0]-a1Q_000001000_1*R_310[0]+aQin2*R_320[0];
QR_010000001210+=Q_010000001*R_210[0]-a1Q_010000000_1*R_211[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001010000210+=Q_001010000*R_210[0]-a1Q_001000000_1*R_220[0]-a1Q_000010000_1*R_310[0]+aQin2*R_320[0];
QR_000011000210+=Q_000011000*R_210[0]-Q_000111000*R_220[0]+aQin2*R_230[0];
QR_000010001210+=Q_000010001*R_210[0]-a1Q_000010000_1*R_211[0]-a1Q_000000001_1*R_220[0]+aQin2*R_221[0];
QR_001000010210+=Q_001000010*R_210[0]-a1Q_001000000_1*R_211[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000001010210+=Q_000001010*R_210[0]-a1Q_000001000_1*R_211[0]-a1Q_000000010_1*R_220[0]+aQin2*R_221[0];
QR_000000011210+=Q_000000011*R_210[0]-Q_000000111*R_211[0]+aQin2*R_212[0];
QR_011000000300+=Q_011000000*R_300[0]-Q_111000000*R_400[0]+aQin2*R_500[0];
QR_010001000300+=Q_010001000*R_300[0]-a1Q_010000000_1*R_310[0]-a1Q_000001000_1*R_400[0]+aQin2*R_410[0];
QR_010000001300+=Q_010000001*R_300[0]-a1Q_010000000_1*R_301[0]-a1Q_000000001_1*R_400[0]+aQin2*R_401[0];
QR_001010000300+=Q_001010000*R_300[0]-a1Q_001000000_1*R_310[0]-a1Q_000010000_1*R_400[0]+aQin2*R_410[0];
QR_000011000300+=Q_000011000*R_300[0]-Q_000111000*R_310[0]+aQin2*R_320[0];
QR_000010001300+=Q_000010001*R_300[0]-a1Q_000010000_1*R_301[0]-a1Q_000000001_1*R_310[0]+aQin2*R_311[0];
QR_001000010300+=Q_001000010*R_300[0]-a1Q_001000000_1*R_301[0]-a1Q_000000010_1*R_400[0]+aQin2*R_401[0];
QR_000001010300+=Q_000001010*R_300[0]-a1Q_000001000_1*R_301[0]-a1Q_000000010_1*R_310[0]+aQin2*R_311[0];
QR_000000011300+=Q_000000011*R_300[0]-Q_000000111*R_301[0]+aQin2*R_302[0];
QR_011000000004+=Q_011000000*R_004[0]-Q_111000000*R_104[0]+aQin2*R_204[0];
QR_010001000004+=Q_010001000*R_004[0]-a1Q_010000000_1*R_014[0]-a1Q_000001000_1*R_104[0]+aQin2*R_114[0];
QR_010000001004+=Q_010000001*R_004[0]-a1Q_010000000_1*R_005[0]-a1Q_000000001_1*R_104[0]+aQin2*R_105[0];
QR_001010000004+=Q_001010000*R_004[0]-a1Q_001000000_1*R_014[0]-a1Q_000010000_1*R_104[0]+aQin2*R_114[0];
QR_000011000004+=Q_000011000*R_004[0]-Q_000111000*R_014[0]+aQin2*R_024[0];
QR_000010001004+=Q_000010001*R_004[0]-a1Q_000010000_1*R_005[0]-a1Q_000000001_1*R_014[0]+aQin2*R_015[0];
QR_001000010004+=Q_001000010*R_004[0]-a1Q_001000000_1*R_005[0]-a1Q_000000010_1*R_104[0]+aQin2*R_105[0];
QR_000001010004+=Q_000001010*R_004[0]-a1Q_000001000_1*R_005[0]-a1Q_000000010_1*R_014[0]+aQin2*R_015[0];
QR_000000011004+=Q_000000011*R_004[0]-Q_000000111*R_005[0]+aQin2*R_006[0];
QR_011000000013+=Q_011000000*R_013[0]-Q_111000000*R_113[0]+aQin2*R_213[0];
QR_010001000013+=Q_010001000*R_013[0]-a1Q_010000000_1*R_023[0]-a1Q_000001000_1*R_113[0]+aQin2*R_123[0];
QR_010000001013+=Q_010000001*R_013[0]-a1Q_010000000_1*R_014[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
QR_001010000013+=Q_001010000*R_013[0]-a1Q_001000000_1*R_023[0]-a1Q_000010000_1*R_113[0]+aQin2*R_123[0];
QR_000011000013+=Q_000011000*R_013[0]-Q_000111000*R_023[0]+aQin2*R_033[0];
QR_000010001013+=Q_000010001*R_013[0]-a1Q_000010000_1*R_014[0]-a1Q_000000001_1*R_023[0]+aQin2*R_024[0];
QR_001000010013+=Q_001000010*R_013[0]-a1Q_001000000_1*R_014[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
QR_000001010013+=Q_000001010*R_013[0]-a1Q_000001000_1*R_014[0]-a1Q_000000010_1*R_023[0]+aQin2*R_024[0];
QR_000000011013+=Q_000000011*R_013[0]-Q_000000111*R_014[0]+aQin2*R_015[0];
QR_011000000022+=Q_011000000*R_022[0]-Q_111000000*R_122[0]+aQin2*R_222[0];
QR_010001000022+=Q_010001000*R_022[0]-a1Q_010000000_1*R_032[0]-a1Q_000001000_1*R_122[0]+aQin2*R_132[0];
QR_010000001022+=Q_010000001*R_022[0]-a1Q_010000000_1*R_023[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
QR_001010000022+=Q_001010000*R_022[0]-a1Q_001000000_1*R_032[0]-a1Q_000010000_1*R_122[0]+aQin2*R_132[0];
QR_000011000022+=Q_000011000*R_022[0]-Q_000111000*R_032[0]+aQin2*R_042[0];
QR_000010001022+=Q_000010001*R_022[0]-a1Q_000010000_1*R_023[0]-a1Q_000000001_1*R_032[0]+aQin2*R_033[0];
QR_001000010022+=Q_001000010*R_022[0]-a1Q_001000000_1*R_023[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
QR_000001010022+=Q_000001010*R_022[0]-a1Q_000001000_1*R_023[0]-a1Q_000000010_1*R_032[0]+aQin2*R_033[0];
QR_000000011022+=Q_000000011*R_022[0]-Q_000000111*R_023[0]+aQin2*R_024[0];
QR_011000000031+=Q_011000000*R_031[0]-Q_111000000*R_131[0]+aQin2*R_231[0];
QR_010001000031+=Q_010001000*R_031[0]-a1Q_010000000_1*R_041[0]-a1Q_000001000_1*R_131[0]+aQin2*R_141[0];
QR_010000001031+=Q_010000001*R_031[0]-a1Q_010000000_1*R_032[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
QR_001010000031+=Q_001010000*R_031[0]-a1Q_001000000_1*R_041[0]-a1Q_000010000_1*R_131[0]+aQin2*R_141[0];
QR_000011000031+=Q_000011000*R_031[0]-Q_000111000*R_041[0]+aQin2*R_051[0];
QR_000010001031+=Q_000010001*R_031[0]-a1Q_000010000_1*R_032[0]-a1Q_000000001_1*R_041[0]+aQin2*R_042[0];
QR_001000010031+=Q_001000010*R_031[0]-a1Q_001000000_1*R_032[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
QR_000001010031+=Q_000001010*R_031[0]-a1Q_000001000_1*R_032[0]-a1Q_000000010_1*R_041[0]+aQin2*R_042[0];
QR_000000011031+=Q_000000011*R_031[0]-Q_000000111*R_032[0]+aQin2*R_033[0];
QR_011000000040+=Q_011000000*R_040[0]-Q_111000000*R_140[0]+aQin2*R_240[0];
QR_010001000040+=Q_010001000*R_040[0]-a1Q_010000000_1*R_050[0]-a1Q_000001000_1*R_140[0]+aQin2*R_150[0];
QR_010000001040+=Q_010000001*R_040[0]-a1Q_010000000_1*R_041[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
QR_001010000040+=Q_001010000*R_040[0]-a1Q_001000000_1*R_050[0]-a1Q_000010000_1*R_140[0]+aQin2*R_150[0];
QR_000011000040+=Q_000011000*R_040[0]-Q_000111000*R_050[0]+aQin2*R_060[0];
QR_000010001040+=Q_000010001*R_040[0]-a1Q_000010000_1*R_041[0]-a1Q_000000001_1*R_050[0]+aQin2*R_051[0];
QR_001000010040+=Q_001000010*R_040[0]-a1Q_001000000_1*R_041[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
QR_000001010040+=Q_000001010*R_040[0]-a1Q_000001000_1*R_041[0]-a1Q_000000010_1*R_050[0]+aQin2*R_051[0];
QR_000000011040+=Q_000000011*R_040[0]-Q_000000111*R_041[0]+aQin2*R_042[0];
QR_011000000103+=Q_011000000*R_103[0]-Q_111000000*R_203[0]+aQin2*R_303[0];
QR_010001000103+=Q_010001000*R_103[0]-a1Q_010000000_1*R_113[0]-a1Q_000001000_1*R_203[0]+aQin2*R_213[0];
QR_010000001103+=Q_010000001*R_103[0]-a1Q_010000000_1*R_104[0]-a1Q_000000001_1*R_203[0]+aQin2*R_204[0];
QR_001010000103+=Q_001010000*R_103[0]-a1Q_001000000_1*R_113[0]-a1Q_000010000_1*R_203[0]+aQin2*R_213[0];
QR_000011000103+=Q_000011000*R_103[0]-Q_000111000*R_113[0]+aQin2*R_123[0];
QR_000010001103+=Q_000010001*R_103[0]-a1Q_000010000_1*R_104[0]-a1Q_000000001_1*R_113[0]+aQin2*R_114[0];
QR_001000010103+=Q_001000010*R_103[0]-a1Q_001000000_1*R_104[0]-a1Q_000000010_1*R_203[0]+aQin2*R_204[0];
QR_000001010103+=Q_000001010*R_103[0]-a1Q_000001000_1*R_104[0]-a1Q_000000010_1*R_113[0]+aQin2*R_114[0];
QR_000000011103+=Q_000000011*R_103[0]-Q_000000111*R_104[0]+aQin2*R_105[0];
QR_011000000112+=Q_011000000*R_112[0]-Q_111000000*R_212[0]+aQin2*R_312[0];
QR_010001000112+=Q_010001000*R_112[0]-a1Q_010000000_1*R_122[0]-a1Q_000001000_1*R_212[0]+aQin2*R_222[0];
QR_010000001112+=Q_010000001*R_112[0]-a1Q_010000000_1*R_113[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
QR_001010000112+=Q_001010000*R_112[0]-a1Q_001000000_1*R_122[0]-a1Q_000010000_1*R_212[0]+aQin2*R_222[0];
QR_000011000112+=Q_000011000*R_112[0]-Q_000111000*R_122[0]+aQin2*R_132[0];
QR_000010001112+=Q_000010001*R_112[0]-a1Q_000010000_1*R_113[0]-a1Q_000000001_1*R_122[0]+aQin2*R_123[0];
QR_001000010112+=Q_001000010*R_112[0]-a1Q_001000000_1*R_113[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
QR_000001010112+=Q_000001010*R_112[0]-a1Q_000001000_1*R_113[0]-a1Q_000000010_1*R_122[0]+aQin2*R_123[0];
QR_000000011112+=Q_000000011*R_112[0]-Q_000000111*R_113[0]+aQin2*R_114[0];
QR_011000000121+=Q_011000000*R_121[0]-Q_111000000*R_221[0]+aQin2*R_321[0];
QR_010001000121+=Q_010001000*R_121[0]-a1Q_010000000_1*R_131[0]-a1Q_000001000_1*R_221[0]+aQin2*R_231[0];
QR_010000001121+=Q_010000001*R_121[0]-a1Q_010000000_1*R_122[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
QR_001010000121+=Q_001010000*R_121[0]-a1Q_001000000_1*R_131[0]-a1Q_000010000_1*R_221[0]+aQin2*R_231[0];
QR_000011000121+=Q_000011000*R_121[0]-Q_000111000*R_131[0]+aQin2*R_141[0];
QR_000010001121+=Q_000010001*R_121[0]-a1Q_000010000_1*R_122[0]-a1Q_000000001_1*R_131[0]+aQin2*R_132[0];
QR_001000010121+=Q_001000010*R_121[0]-a1Q_001000000_1*R_122[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
QR_000001010121+=Q_000001010*R_121[0]-a1Q_000001000_1*R_122[0]-a1Q_000000010_1*R_131[0]+aQin2*R_132[0];
QR_000000011121+=Q_000000011*R_121[0]-Q_000000111*R_122[0]+aQin2*R_123[0];
QR_011000000130+=Q_011000000*R_130[0]-Q_111000000*R_230[0]+aQin2*R_330[0];
QR_010001000130+=Q_010001000*R_130[0]-a1Q_010000000_1*R_140[0]-a1Q_000001000_1*R_230[0]+aQin2*R_240[0];
QR_010000001130+=Q_010000001*R_130[0]-a1Q_010000000_1*R_131[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
QR_001010000130+=Q_001010000*R_130[0]-a1Q_001000000_1*R_140[0]-a1Q_000010000_1*R_230[0]+aQin2*R_240[0];
QR_000011000130+=Q_000011000*R_130[0]-Q_000111000*R_140[0]+aQin2*R_150[0];
QR_000010001130+=Q_000010001*R_130[0]-a1Q_000010000_1*R_131[0]-a1Q_000000001_1*R_140[0]+aQin2*R_141[0];
QR_001000010130+=Q_001000010*R_130[0]-a1Q_001000000_1*R_131[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
QR_000001010130+=Q_000001010*R_130[0]-a1Q_000001000_1*R_131[0]-a1Q_000000010_1*R_140[0]+aQin2*R_141[0];
QR_000000011130+=Q_000000011*R_130[0]-Q_000000111*R_131[0]+aQin2*R_132[0];
QR_011000000202+=Q_011000000*R_202[0]-Q_111000000*R_302[0]+aQin2*R_402[0];
QR_010001000202+=Q_010001000*R_202[0]-a1Q_010000000_1*R_212[0]-a1Q_000001000_1*R_302[0]+aQin2*R_312[0];
QR_010000001202+=Q_010000001*R_202[0]-a1Q_010000000_1*R_203[0]-a1Q_000000001_1*R_302[0]+aQin2*R_303[0];
QR_001010000202+=Q_001010000*R_202[0]-a1Q_001000000_1*R_212[0]-a1Q_000010000_1*R_302[0]+aQin2*R_312[0];
QR_000011000202+=Q_000011000*R_202[0]-Q_000111000*R_212[0]+aQin2*R_222[0];
QR_000010001202+=Q_000010001*R_202[0]-a1Q_000010000_1*R_203[0]-a1Q_000000001_1*R_212[0]+aQin2*R_213[0];
QR_001000010202+=Q_001000010*R_202[0]-a1Q_001000000_1*R_203[0]-a1Q_000000010_1*R_302[0]+aQin2*R_303[0];
QR_000001010202+=Q_000001010*R_202[0]-a1Q_000001000_1*R_203[0]-a1Q_000000010_1*R_212[0]+aQin2*R_213[0];
QR_000000011202+=Q_000000011*R_202[0]-Q_000000111*R_203[0]+aQin2*R_204[0];
QR_011000000211+=Q_011000000*R_211[0]-Q_111000000*R_311[0]+aQin2*R_411[0];
QR_010001000211+=Q_010001000*R_211[0]-a1Q_010000000_1*R_221[0]-a1Q_000001000_1*R_311[0]+aQin2*R_321[0];
QR_010000001211+=Q_010000001*R_211[0]-a1Q_010000000_1*R_212[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
QR_001010000211+=Q_001010000*R_211[0]-a1Q_001000000_1*R_221[0]-a1Q_000010000_1*R_311[0]+aQin2*R_321[0];
QR_000011000211+=Q_000011000*R_211[0]-Q_000111000*R_221[0]+aQin2*R_231[0];
QR_000010001211+=Q_000010001*R_211[0]-a1Q_000010000_1*R_212[0]-a1Q_000000001_1*R_221[0]+aQin2*R_222[0];
QR_001000010211+=Q_001000010*R_211[0]-a1Q_001000000_1*R_212[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
QR_000001010211+=Q_000001010*R_211[0]-a1Q_000001000_1*R_212[0]-a1Q_000000010_1*R_221[0]+aQin2*R_222[0];
QR_000000011211+=Q_000000011*R_211[0]-Q_000000111*R_212[0]+aQin2*R_213[0];
QR_011000000220+=Q_011000000*R_220[0]-Q_111000000*R_320[0]+aQin2*R_420[0];
QR_010001000220+=Q_010001000*R_220[0]-a1Q_010000000_1*R_230[0]-a1Q_000001000_1*R_320[0]+aQin2*R_330[0];
QR_010000001220+=Q_010000001*R_220[0]-a1Q_010000000_1*R_221[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
QR_001010000220+=Q_001010000*R_220[0]-a1Q_001000000_1*R_230[0]-a1Q_000010000_1*R_320[0]+aQin2*R_330[0];
QR_000011000220+=Q_000011000*R_220[0]-Q_000111000*R_230[0]+aQin2*R_240[0];
QR_000010001220+=Q_000010001*R_220[0]-a1Q_000010000_1*R_221[0]-a1Q_000000001_1*R_230[0]+aQin2*R_231[0];
QR_001000010220+=Q_001000010*R_220[0]-a1Q_001000000_1*R_221[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
QR_000001010220+=Q_000001010*R_220[0]-a1Q_000001000_1*R_221[0]-a1Q_000000010_1*R_230[0]+aQin2*R_231[0];
QR_000000011220+=Q_000000011*R_220[0]-Q_000000111*R_221[0]+aQin2*R_222[0];
QR_011000000301+=Q_011000000*R_301[0]-Q_111000000*R_401[0]+aQin2*R_501[0];
QR_010001000301+=Q_010001000*R_301[0]-a1Q_010000000_1*R_311[0]-a1Q_000001000_1*R_401[0]+aQin2*R_411[0];
QR_010000001301+=Q_010000001*R_301[0]-a1Q_010000000_1*R_302[0]-a1Q_000000001_1*R_401[0]+aQin2*R_402[0];
QR_001010000301+=Q_001010000*R_301[0]-a1Q_001000000_1*R_311[0]-a1Q_000010000_1*R_401[0]+aQin2*R_411[0];
QR_000011000301+=Q_000011000*R_301[0]-Q_000111000*R_311[0]+aQin2*R_321[0];
QR_000010001301+=Q_000010001*R_301[0]-a1Q_000010000_1*R_302[0]-a1Q_000000001_1*R_311[0]+aQin2*R_312[0];
QR_001000010301+=Q_001000010*R_301[0]-a1Q_001000000_1*R_302[0]-a1Q_000000010_1*R_401[0]+aQin2*R_402[0];
QR_000001010301+=Q_000001010*R_301[0]-a1Q_000001000_1*R_302[0]-a1Q_000000010_1*R_311[0]+aQin2*R_312[0];
QR_000000011301+=Q_000000011*R_301[0]-Q_000000111*R_302[0]+aQin2*R_303[0];
QR_011000000310+=Q_011000000*R_310[0]-Q_111000000*R_410[0]+aQin2*R_510[0];
QR_010001000310+=Q_010001000*R_310[0]-a1Q_010000000_1*R_320[0]-a1Q_000001000_1*R_410[0]+aQin2*R_420[0];
QR_010000001310+=Q_010000001*R_310[0]-a1Q_010000000_1*R_311[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
QR_001010000310+=Q_001010000*R_310[0]-a1Q_001000000_1*R_320[0]-a1Q_000010000_1*R_410[0]+aQin2*R_420[0];
QR_000011000310+=Q_000011000*R_310[0]-Q_000111000*R_320[0]+aQin2*R_330[0];
QR_000010001310+=Q_000010001*R_310[0]-a1Q_000010000_1*R_311[0]-a1Q_000000001_1*R_320[0]+aQin2*R_321[0];
QR_001000010310+=Q_001000010*R_310[0]-a1Q_001000000_1*R_311[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
QR_000001010310+=Q_000001010*R_310[0]-a1Q_000001000_1*R_311[0]-a1Q_000000010_1*R_320[0]+aQin2*R_321[0];
QR_000000011310+=Q_000000011*R_310[0]-Q_000000111*R_311[0]+aQin2*R_312[0];
QR_011000000400+=Q_011000000*R_400[0]-Q_111000000*R_500[0]+aQin2*R_600[0];
QR_010001000400+=Q_010001000*R_400[0]-a1Q_010000000_1*R_410[0]-a1Q_000001000_1*R_500[0]+aQin2*R_510[0];
QR_010000001400+=Q_010000001*R_400[0]-a1Q_010000000_1*R_401[0]-a1Q_000000001_1*R_500[0]+aQin2*R_501[0];
QR_001010000400+=Q_001010000*R_400[0]-a1Q_001000000_1*R_410[0]-a1Q_000010000_1*R_500[0]+aQin2*R_510[0];
QR_000011000400+=Q_000011000*R_400[0]-Q_000111000*R_410[0]+aQin2*R_420[0];
QR_000010001400+=Q_000010001*R_400[0]-a1Q_000010000_1*R_401[0]-a1Q_000000001_1*R_410[0]+aQin2*R_411[0];
QR_001000010400+=Q_001000010*R_400[0]-a1Q_001000000_1*R_401[0]-a1Q_000000010_1*R_500[0]+aQin2*R_501[0];
QR_000001010400+=Q_000001010*R_400[0]-a1Q_000001000_1*R_401[0]-a1Q_000000010_1*R_410[0]+aQin2*R_411[0];
QR_000000011400+=Q_000000011*R_400[0]-Q_000000111*R_401[0]+aQin2*R_402[0];
}
double Pd_002[3];
double Pd_102[3];
double Pd_011[3];
double Pd_111[3];
double Pd_012[3];
double Pd_112[3];
double Pd_212[3];
double Pd_020[3];
double Pd_120[3];
double Pd_021[3];
double Pd_121[3];
double Pd_221[3];
double Pd_022[3];
double Pd_122[3];
double Pd_222[3];
for(int i=0;i<3;i++){
Pd_002[i]=aPin1+Pd_001[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_102[i]=aPin1*(2.000000*Pd_001[i]);
}
for(int i=0;i<3;i++){
Pd_011[i]=aPin1+Pd_010[i]*Pd_001[i];
}
for(int i=0;i<3;i++){
Pd_111[i]=aPin1*(Pd_001[i]+Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_012[i]=Pd_111[i]+Pd_001[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_112[i]=aPin1*(Pd_002[i]+2.000000*Pd_011[i]);
}
for(int i=0;i<3;i++){
Pd_212[i]=aPin1*(0.500000*Pd_102[i]+Pd_111[i]);
}
for(int i=0;i<3;i++){
Pd_020[i]=aPin1+Pd_010[i]*Pd_010[i];
}
for(int i=0;i<3;i++){
Pd_120[i]=aPin1*(2.000000*Pd_010[i]);
}
for(int i=0;i<3;i++){
Pd_021[i]=Pd_111[i]+Pd_010[i]*Pd_011[i];
}
for(int i=0;i<3;i++){
Pd_121[i]=aPin1*(2.000000*Pd_011[i]+Pd_020[i]);
}
for(int i=0;i<3;i++){
Pd_221[i]=aPin1*(Pd_111[i]+0.500000*Pd_120[i]);
}
for(int i=0;i<3;i++){
Pd_022[i]=Pd_112[i]+Pd_010[i]*Pd_012[i];
}
for(int i=0;i<3;i++){
Pd_122[i]=aPin1*2.000000*(Pd_012[i]+Pd_021[i]);
}
for(int i=0;i<3;i++){
Pd_222[i]=aPin1*(Pd_112[i]+Pd_121[i]);
}
double P_022000000;
double P_122000000;
double P_222000000;
double P_021001000;
double P_121001000;
double P_221001000;
double P_020002000;
double P_021000001;
double P_121000001;
double P_221000001;
double P_020001001;
double P_020000002;
double P_012010000;
double P_112010000;
double P_212010000;
double P_011011000;
double P_011111000;
double P_111011000;
double P_111111000;
double P_010012000;
double P_010112000;
double P_010212000;
double P_011010001;
double P_111010001;
double P_010011001;
double P_010111001;
double P_010010002;
double P_002020000;
double P_001021000;
double P_001121000;
double P_001221000;
double P_000022000;
double P_000122000;
double P_000222000;
double P_001020001;
double P_000021001;
double P_000121001;
double P_000221001;
double P_000020002;
double P_012000010;
double P_112000010;
double P_212000010;
double P_011001010;
double P_111001010;
double P_010002010;
double P_011000011;
double P_011000111;
double P_111000011;
double P_111000111;
double P_010001011;
double P_010001111;
double P_010000012;
double P_010000112;
double P_010000212;
double P_002010010;
double P_001011010;
double P_001111010;
double P_000012010;
double P_000112010;
double P_000212010;
double P_001010011;
double P_001010111;
double P_000011011;
double P_000011111;
double P_000111011;
double P_000111111;
double P_000010012;
double P_000010112;
double P_000010212;
double P_002000020;
double P_001001020;
double P_000002020;
double P_001000021;
double P_001000121;
double P_001000221;
double P_000001021;
double P_000001121;
double P_000001221;
double P_000000022;
double P_000000122;
double P_000000222;
double a2P_111000000_1;
double a2P_111000000_2;
double a1P_021000000_1;
double a1P_121000000_1;
double a1P_221000000_1;
double a3P_000001000_1;
double a3P_000001000_2;
double a1P_020001000_1;
double a1P_020001000_2;
double a2P_020000000_1;
double a1P_010002000_1;
double a1P_010002000_2;
double a2P_010001000_1;
double a2P_010001000_4;
double a2P_010001000_2;
double a3P_010000000_1;
double a3P_010000000_2;
double a2P_000002000_1;
double a3P_000000001_1;
double a3P_000000001_2;
double a1P_020000001_1;
double a1P_020000001_2;
double a1P_010001001_1;
double a1P_010001001_2;
double a2P_010000001_1;
double a2P_010000001_2;
double a2P_010000001_4;
double a2P_000001001_1;
double a1P_010000002_1;
double a1P_010000002_2;
double a2P_000000002_1;
double a1P_012000000_1;
double a1P_112000000_1;
double a1P_212000000_1;
double a3P_000010000_1;
double a3P_000010000_2;
double a2P_011000000_1;
double a2P_000011000_1;
double a2P_000111000_1;
double a2P_000111000_2;
double a1P_000012000_1;
double a1P_000112000_1;
double a1P_000212000_1;
double a1P_011010000_1;
double a1P_011000001_1;
double a1P_111010000_1;
double a1P_111000001_1;
double a2P_000010001_1;
double a2P_000010001_2;
double a2P_000010001_4;
double a1P_010011000_1;
double a1P_010111000_1;
double a1P_000011001_1;
double a1P_000111001_1;
double a1P_010010001_1;
double a1P_010010001_2;
double a2P_010010000_1;
double a1P_000010002_1;
double a1P_000010002_2;
double a1P_002010000_1;
double a1P_002010000_2;
double a2P_002000000_1;
double a1P_001020000_1;
double a1P_001020000_2;
double a2P_001010000_1;
double a2P_001010000_4;
double a2P_001010000_2;
double a3P_001000000_1;
double a3P_001000000_2;
double a2P_000020000_1;
double a1P_000021000_1;
double a1P_000121000_1;
double a1P_000221000_1;
double a1P_001010001_1;
double a1P_001010001_2;
double a2P_001000001_1;
double a1P_000020001_1;
double a1P_000020001_2;
double a3P_000000010_1;
double a3P_000000010_2;
double a1P_011001000_1;
double a1P_011000010_1;
double a1P_111001000_1;
double a1P_111000010_1;
double a2P_000001010_1;
double a2P_000001010_2;
double a2P_000001010_4;
double a1P_010001010_1;
double a1P_010001010_2;
double a2P_010000010_1;
double a1P_000002010_1;
double a1P_000002010_2;
double a2P_000000011_1;
double a2P_000000111_1;
double a2P_000000111_2;
double a1P_010000011_1;
double a1P_010000111_1;
double a1P_000001011_1;
double a1P_000001111_1;
double a1P_000000012_1;
double a1P_000000112_1;
double a1P_000000212_1;
double a1P_002000010_1;
double a1P_002000010_2;
double a1P_001010010_1;
double a1P_001010010_2;
double a2P_001000010_1;
double a2P_001000010_2;
double a2P_001000010_4;
double a2P_000010010_1;
double a1P_001011000_1;
double a1P_001111000_1;
double a1P_000011010_1;
double a1P_000111010_1;
double a1P_001000011_1;
double a1P_001000111_1;
double a1P_000010011_1;
double a1P_000010111_1;
double a1P_001000020_1;
double a1P_001000020_2;
double a2P_000000020_1;
double a1P_001001010_1;
double a1P_001001010_2;
double a2P_001001000_1;
double a1P_000001020_1;
double a1P_000001020_2;
double a1P_000000021_1;
double a1P_000000121_1;
double a1P_000000221_1;
P_022000000=Pd_022[0];
P_122000000=Pd_122[0];
P_222000000=Pd_222[0];
P_021001000=Pd_021[0]*Pd_001[1];
P_121001000=Pd_121[0]*Pd_001[1];
P_221001000=Pd_221[0]*Pd_001[1];
P_020002000=Pd_020[0]*Pd_002[1];
P_021000001=Pd_021[0]*Pd_001[2];
P_121000001=Pd_121[0]*Pd_001[2];
P_221000001=Pd_221[0]*Pd_001[2];
P_020001001=Pd_020[0]*Pd_001[1]*Pd_001[2];
P_020000002=Pd_020[0]*Pd_002[2];
P_012010000=Pd_012[0]*Pd_010[1];
P_112010000=Pd_112[0]*Pd_010[1];
P_212010000=Pd_212[0]*Pd_010[1];
P_011011000=Pd_011[0]*Pd_011[1];
P_011111000=Pd_011[0]*Pd_111[1];
P_111011000=Pd_111[0]*Pd_011[1];
P_111111000=Pd_111[0]*Pd_111[1];
P_010012000=Pd_010[0]*Pd_012[1];
P_010112000=Pd_010[0]*Pd_112[1];
P_010212000=Pd_010[0]*Pd_212[1];
P_011010001=Pd_011[0]*Pd_010[1]*Pd_001[2];
P_111010001=Pd_111[0]*Pd_010[1]*Pd_001[2];
P_010011001=Pd_010[0]*Pd_011[1]*Pd_001[2];
P_010111001=Pd_010[0]*Pd_111[1]*Pd_001[2];
P_010010002=Pd_010[0]*Pd_010[1]*Pd_002[2];
P_002020000=Pd_002[0]*Pd_020[1];
P_001021000=Pd_001[0]*Pd_021[1];
P_001121000=Pd_001[0]*Pd_121[1];
P_001221000=Pd_001[0]*Pd_221[1];
P_000022000=Pd_022[1];
P_000122000=Pd_122[1];
P_000222000=Pd_222[1];
P_001020001=Pd_001[0]*Pd_020[1]*Pd_001[2];
P_000021001=Pd_021[1]*Pd_001[2];
P_000121001=Pd_121[1]*Pd_001[2];
P_000221001=Pd_221[1]*Pd_001[2];
P_000020002=Pd_020[1]*Pd_002[2];
P_012000010=Pd_012[0]*Pd_010[2];
P_112000010=Pd_112[0]*Pd_010[2];
P_212000010=Pd_212[0]*Pd_010[2];
P_011001010=Pd_011[0]*Pd_001[1]*Pd_010[2];
P_111001010=Pd_111[0]*Pd_001[1]*Pd_010[2];
P_010002010=Pd_010[0]*Pd_002[1]*Pd_010[2];
P_011000011=Pd_011[0]*Pd_011[2];
P_011000111=Pd_011[0]*Pd_111[2];
P_111000011=Pd_111[0]*Pd_011[2];
P_111000111=Pd_111[0]*Pd_111[2];
P_010001011=Pd_010[0]*Pd_001[1]*Pd_011[2];
P_010001111=Pd_010[0]*Pd_001[1]*Pd_111[2];
P_010000012=Pd_010[0]*Pd_012[2];
P_010000112=Pd_010[0]*Pd_112[2];
P_010000212=Pd_010[0]*Pd_212[2];
P_002010010=Pd_002[0]*Pd_010[1]*Pd_010[2];
P_001011010=Pd_001[0]*Pd_011[1]*Pd_010[2];
P_001111010=Pd_001[0]*Pd_111[1]*Pd_010[2];
P_000012010=Pd_012[1]*Pd_010[2];
P_000112010=Pd_112[1]*Pd_010[2];
P_000212010=Pd_212[1]*Pd_010[2];
P_001010011=Pd_001[0]*Pd_010[1]*Pd_011[2];
P_001010111=Pd_001[0]*Pd_010[1]*Pd_111[2];
P_000011011=Pd_011[1]*Pd_011[2];
P_000011111=Pd_011[1]*Pd_111[2];
P_000111011=Pd_111[1]*Pd_011[2];
P_000111111=Pd_111[1]*Pd_111[2];
P_000010012=Pd_010[1]*Pd_012[2];
P_000010112=Pd_010[1]*Pd_112[2];
P_000010212=Pd_010[1]*Pd_212[2];
P_002000020=Pd_002[0]*Pd_020[2];
P_001001020=Pd_001[0]*Pd_001[1]*Pd_020[2];
P_000002020=Pd_002[1]*Pd_020[2];
P_001000021=Pd_001[0]*Pd_021[2];
P_001000121=Pd_001[0]*Pd_121[2];
P_001000221=Pd_001[0]*Pd_221[2];
P_000001021=Pd_001[1]*Pd_021[2];
P_000001121=Pd_001[1]*Pd_121[2];
P_000001221=Pd_001[1]*Pd_221[2];
P_000000022=Pd_022[2];
P_000000122=Pd_122[2];
P_000000222=Pd_222[2];
a2P_111000000_1=Pd_111[0];
a2P_111000000_2=2*a2P_111000000_1;
a1P_021000000_1=Pd_021[0];
a1P_121000000_1=Pd_121[0];
a1P_221000000_1=Pd_221[0];
a3P_000001000_1=Pd_001[1];
a3P_000001000_2=2*a3P_000001000_1;
a1P_020001000_1=Pd_020[0]*Pd_001[1];
a1P_020001000_2=2*a1P_020001000_1;
a2P_020000000_1=Pd_020[0];
a1P_010002000_1=Pd_010[0]*Pd_002[1];
a1P_010002000_2=2*a1P_010002000_1;
a2P_010001000_1=Pd_010[0]*Pd_001[1];
a2P_010001000_4=4*a2P_010001000_1;
a2P_010001000_2=2*a2P_010001000_1;
a3P_010000000_1=Pd_010[0];
a3P_010000000_2=2*a3P_010000000_1;
a2P_000002000_1=Pd_002[1];
a3P_000000001_1=Pd_001[2];
a3P_000000001_2=2*a3P_000000001_1;
a1P_020000001_1=Pd_020[0]*Pd_001[2];
a1P_020000001_2=2*a1P_020000001_1;
a1P_010001001_1=Pd_010[0]*Pd_001[1]*Pd_001[2];
a1P_010001001_2=2*a1P_010001001_1;
a2P_010000001_1=Pd_010[0]*Pd_001[2];
a2P_010000001_2=2*a2P_010000001_1;
a2P_010000001_4=4*a2P_010000001_1;
a2P_000001001_1=Pd_001[1]*Pd_001[2];
a1P_010000002_1=Pd_010[0]*Pd_002[2];
a1P_010000002_2=2*a1P_010000002_1;
a2P_000000002_1=Pd_002[2];
a1P_012000000_1=Pd_012[0];
a1P_112000000_1=Pd_112[0];
a1P_212000000_1=Pd_212[0];
a3P_000010000_1=Pd_010[1];
a3P_000010000_2=2*a3P_000010000_1;
a2P_011000000_1=Pd_011[0];
a2P_000011000_1=Pd_011[1];
a2P_000111000_1=Pd_111[1];
a2P_000111000_2=2*a2P_000111000_1;
a1P_000012000_1=Pd_012[1];
a1P_000112000_1=Pd_112[1];
a1P_000212000_1=Pd_212[1];
a1P_011010000_1=Pd_011[0]*Pd_010[1];
a1P_011000001_1=Pd_011[0]*Pd_001[2];
a1P_111010000_1=Pd_111[0]*Pd_010[1];
a1P_111000001_1=Pd_111[0]*Pd_001[2];
a2P_000010001_1=Pd_010[1]*Pd_001[2];
a2P_000010001_2=2*a2P_000010001_1;
a2P_000010001_4=4*a2P_000010001_1;
a1P_010011000_1=Pd_010[0]*Pd_011[1];
a1P_010111000_1=Pd_010[0]*Pd_111[1];
a1P_000011001_1=Pd_011[1]*Pd_001[2];
a1P_000111001_1=Pd_111[1]*Pd_001[2];
a1P_010010001_1=Pd_010[0]*Pd_010[1]*Pd_001[2];
a1P_010010001_2=2*a1P_010010001_1;
a2P_010010000_1=Pd_010[0]*Pd_010[1];
a1P_000010002_1=Pd_010[1]*Pd_002[2];
a1P_000010002_2=2*a1P_000010002_1;
a1P_002010000_1=Pd_002[0]*Pd_010[1];
a1P_002010000_2=2*a1P_002010000_1;
a2P_002000000_1=Pd_002[0];
a1P_001020000_1=Pd_001[0]*Pd_020[1];
a1P_001020000_2=2*a1P_001020000_1;
a2P_001010000_1=Pd_001[0]*Pd_010[1];
a2P_001010000_4=4*a2P_001010000_1;
a2P_001010000_2=2*a2P_001010000_1;
a3P_001000000_1=Pd_001[0];
a3P_001000000_2=2*a3P_001000000_1;
a2P_000020000_1=Pd_020[1];
a1P_000021000_1=Pd_021[1];
a1P_000121000_1=Pd_121[1];
a1P_000221000_1=Pd_221[1];
a1P_001010001_1=Pd_001[0]*Pd_010[1]*Pd_001[2];
a1P_001010001_2=2*a1P_001010001_1;
a2P_001000001_1=Pd_001[0]*Pd_001[2];
a1P_000020001_1=Pd_020[1]*Pd_001[2];
a1P_000020001_2=2*a1P_000020001_1;
a3P_000000010_1=Pd_010[2];
a3P_000000010_2=2*a3P_000000010_1;
a1P_011001000_1=Pd_011[0]*Pd_001[1];
a1P_011000010_1=Pd_011[0]*Pd_010[2];
a1P_111001000_1=Pd_111[0]*Pd_001[1];
a1P_111000010_1=Pd_111[0]*Pd_010[2];
a2P_000001010_1=Pd_001[1]*Pd_010[2];
a2P_000001010_2=2*a2P_000001010_1;
a2P_000001010_4=4*a2P_000001010_1;
a1P_010001010_1=Pd_010[0]*Pd_001[1]*Pd_010[2];
a1P_010001010_2=2*a1P_010001010_1;
a2P_010000010_1=Pd_010[0]*Pd_010[2];
a1P_000002010_1=Pd_002[1]*Pd_010[2];
a1P_000002010_2=2*a1P_000002010_1;
a2P_000000011_1=Pd_011[2];
a2P_000000111_1=Pd_111[2];
a2P_000000111_2=2*a2P_000000111_1;
a1P_010000011_1=Pd_010[0]*Pd_011[2];
a1P_010000111_1=Pd_010[0]*Pd_111[2];
a1P_000001011_1=Pd_001[1]*Pd_011[2];
a1P_000001111_1=Pd_001[1]*Pd_111[2];
a1P_000000012_1=Pd_012[2];
a1P_000000112_1=Pd_112[2];
a1P_000000212_1=Pd_212[2];
a1P_002000010_1=Pd_002[0]*Pd_010[2];
a1P_002000010_2=2*a1P_002000010_1;
a1P_001010010_1=Pd_001[0]*Pd_010[1]*Pd_010[2];
a1P_001010010_2=2*a1P_001010010_1;
a2P_001000010_1=Pd_001[0]*Pd_010[2];
a2P_001000010_2=2*a2P_001000010_1;
a2P_001000010_4=4*a2P_001000010_1;
a2P_000010010_1=Pd_010[1]*Pd_010[2];
a1P_001011000_1=Pd_001[0]*Pd_011[1];
a1P_001111000_1=Pd_001[0]*Pd_111[1];
a1P_000011010_1=Pd_011[1]*Pd_010[2];
a1P_000111010_1=Pd_111[1]*Pd_010[2];
a1P_001000011_1=Pd_001[0]*Pd_011[2];
a1P_001000111_1=Pd_001[0]*Pd_111[2];
a1P_000010011_1=Pd_010[1]*Pd_011[2];
a1P_000010111_1=Pd_010[1]*Pd_111[2];
a1P_001000020_1=Pd_001[0]*Pd_020[2];
a1P_001000020_2=2*a1P_001000020_1;
a2P_000000020_1=Pd_020[2];
a1P_001001010_1=Pd_001[0]*Pd_001[1]*Pd_010[2];
a1P_001001010_2=2*a1P_001001010_1;
a2P_001001000_1=Pd_001[0]*Pd_001[1];
a1P_000001020_1=Pd_001[1]*Pd_020[2];
a1P_000001020_2=2*a1P_000001020_1;
a1P_000000021_1=Pd_021[2];
a1P_000000121_1=Pd_121[2];
a1P_000000221_1=Pd_221[2];
ans_temp[ans_id*36+0]+=Pmtrx[0]*(P_022000000*QR_011000000000+P_122000000*QR_011000000100+P_222000000*QR_011000000200+a2P_111000000_2*QR_011000000300+aPin4*QR_011000000400);
ans_temp[ans_id*36+0]+=Pmtrx[1]*(P_022000000*QR_010001000000+P_122000000*QR_010001000100+P_222000000*QR_010001000200+a2P_111000000_2*QR_010001000300+aPin4*QR_010001000400);
ans_temp[ans_id*36+0]+=Pmtrx[2]*(P_022000000*QR_010000001000+P_122000000*QR_010000001100+P_222000000*QR_010000001200+a2P_111000000_2*QR_010000001300+aPin4*QR_010000001400);
ans_temp[ans_id*36+0]+=Pmtrx[3]*(P_022000000*QR_001010000000+P_122000000*QR_001010000100+P_222000000*QR_001010000200+a2P_111000000_2*QR_001010000300+aPin4*QR_001010000400);
ans_temp[ans_id*36+0]+=Pmtrx[4]*(P_022000000*QR_000011000000+P_122000000*QR_000011000100+P_222000000*QR_000011000200+a2P_111000000_2*QR_000011000300+aPin4*QR_000011000400);
ans_temp[ans_id*36+0]+=Pmtrx[5]*(P_022000000*QR_000010001000+P_122000000*QR_000010001100+P_222000000*QR_000010001200+a2P_111000000_2*QR_000010001300+aPin4*QR_000010001400);
ans_temp[ans_id*36+0]+=Pmtrx[6]*(P_022000000*QR_001000010000+P_122000000*QR_001000010100+P_222000000*QR_001000010200+a2P_111000000_2*QR_001000010300+aPin4*QR_001000010400);
ans_temp[ans_id*36+0]+=Pmtrx[7]*(P_022000000*QR_000001010000+P_122000000*QR_000001010100+P_222000000*QR_000001010200+a2P_111000000_2*QR_000001010300+aPin4*QR_000001010400);
ans_temp[ans_id*36+0]+=Pmtrx[8]*(P_022000000*QR_000000011000+P_122000000*QR_000000011100+P_222000000*QR_000000011200+a2P_111000000_2*QR_000000011300+aPin4*QR_000000011400);
ans_temp[ans_id*36+1]+=Pmtrx[0]*(P_021001000*QR_011000000000+a1P_021000000_1*QR_011000000010+P_121001000*QR_011000000100+a1P_121000000_1*QR_011000000110+P_221001000*QR_011000000200+a1P_221000000_1*QR_011000000210+a3P_000001000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+1]+=Pmtrx[1]*(P_021001000*QR_010001000000+a1P_021000000_1*QR_010001000010+P_121001000*QR_010001000100+a1P_121000000_1*QR_010001000110+P_221001000*QR_010001000200+a1P_221000000_1*QR_010001000210+a3P_000001000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+1]+=Pmtrx[2]*(P_021001000*QR_010000001000+a1P_021000000_1*QR_010000001010+P_121001000*QR_010000001100+a1P_121000000_1*QR_010000001110+P_221001000*QR_010000001200+a1P_221000000_1*QR_010000001210+a3P_000001000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+1]+=Pmtrx[3]*(P_021001000*QR_001010000000+a1P_021000000_1*QR_001010000010+P_121001000*QR_001010000100+a1P_121000000_1*QR_001010000110+P_221001000*QR_001010000200+a1P_221000000_1*QR_001010000210+a3P_000001000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+1]+=Pmtrx[4]*(P_021001000*QR_000011000000+a1P_021000000_1*QR_000011000010+P_121001000*QR_000011000100+a1P_121000000_1*QR_000011000110+P_221001000*QR_000011000200+a1P_221000000_1*QR_000011000210+a3P_000001000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+1]+=Pmtrx[5]*(P_021001000*QR_000010001000+a1P_021000000_1*QR_000010001010+P_121001000*QR_000010001100+a1P_121000000_1*QR_000010001110+P_221001000*QR_000010001200+a1P_221000000_1*QR_000010001210+a3P_000001000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+1]+=Pmtrx[6]*(P_021001000*QR_001000010000+a1P_021000000_1*QR_001000010010+P_121001000*QR_001000010100+a1P_121000000_1*QR_001000010110+P_221001000*QR_001000010200+a1P_221000000_1*QR_001000010210+a3P_000001000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+1]+=Pmtrx[7]*(P_021001000*QR_000001010000+a1P_021000000_1*QR_000001010010+P_121001000*QR_000001010100+a1P_121000000_1*QR_000001010110+P_221001000*QR_000001010200+a1P_221000000_1*QR_000001010210+a3P_000001000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+1]+=Pmtrx[8]*(P_021001000*QR_000000011000+a1P_021000000_1*QR_000000011010+P_121001000*QR_000000011100+a1P_121000000_1*QR_000000011110+P_221001000*QR_000000011200+a1P_221000000_1*QR_000000011210+a3P_000001000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+2]+=Pmtrx[0]*(P_020002000*QR_011000000000+a1P_020001000_2*QR_011000000010+a2P_020000000_1*QR_011000000020+a1P_010002000_2*QR_011000000100+a2P_010001000_4*QR_011000000110+a3P_010000000_2*QR_011000000120+a2P_000002000_1*QR_011000000200+a3P_000001000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+2]+=Pmtrx[1]*(P_020002000*QR_010001000000+a1P_020001000_2*QR_010001000010+a2P_020000000_1*QR_010001000020+a1P_010002000_2*QR_010001000100+a2P_010001000_4*QR_010001000110+a3P_010000000_2*QR_010001000120+a2P_000002000_1*QR_010001000200+a3P_000001000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+2]+=Pmtrx[2]*(P_020002000*QR_010000001000+a1P_020001000_2*QR_010000001010+a2P_020000000_1*QR_010000001020+a1P_010002000_2*QR_010000001100+a2P_010001000_4*QR_010000001110+a3P_010000000_2*QR_010000001120+a2P_000002000_1*QR_010000001200+a3P_000001000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+2]+=Pmtrx[3]*(P_020002000*QR_001010000000+a1P_020001000_2*QR_001010000010+a2P_020000000_1*QR_001010000020+a1P_010002000_2*QR_001010000100+a2P_010001000_4*QR_001010000110+a3P_010000000_2*QR_001010000120+a2P_000002000_1*QR_001010000200+a3P_000001000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+2]+=Pmtrx[4]*(P_020002000*QR_000011000000+a1P_020001000_2*QR_000011000010+a2P_020000000_1*QR_000011000020+a1P_010002000_2*QR_000011000100+a2P_010001000_4*QR_000011000110+a3P_010000000_2*QR_000011000120+a2P_000002000_1*QR_000011000200+a3P_000001000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+2]+=Pmtrx[5]*(P_020002000*QR_000010001000+a1P_020001000_2*QR_000010001010+a2P_020000000_1*QR_000010001020+a1P_010002000_2*QR_000010001100+a2P_010001000_4*QR_000010001110+a3P_010000000_2*QR_000010001120+a2P_000002000_1*QR_000010001200+a3P_000001000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+2]+=Pmtrx[6]*(P_020002000*QR_001000010000+a1P_020001000_2*QR_001000010010+a2P_020000000_1*QR_001000010020+a1P_010002000_2*QR_001000010100+a2P_010001000_4*QR_001000010110+a3P_010000000_2*QR_001000010120+a2P_000002000_1*QR_001000010200+a3P_000001000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+2]+=Pmtrx[7]*(P_020002000*QR_000001010000+a1P_020001000_2*QR_000001010010+a2P_020000000_1*QR_000001010020+a1P_010002000_2*QR_000001010100+a2P_010001000_4*QR_000001010110+a3P_010000000_2*QR_000001010120+a2P_000002000_1*QR_000001010200+a3P_000001000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+2]+=Pmtrx[8]*(P_020002000*QR_000000011000+a1P_020001000_2*QR_000000011010+a2P_020000000_1*QR_000000011020+a1P_010002000_2*QR_000000011100+a2P_010001000_4*QR_000000011110+a3P_010000000_2*QR_000000011120+a2P_000002000_1*QR_000000011200+a3P_000001000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+3]+=Pmtrx[0]*(P_021000001*QR_011000000000+a1P_021000000_1*QR_011000000001+P_121000001*QR_011000000100+a1P_121000000_1*QR_011000000101+P_221000001*QR_011000000200+a1P_221000000_1*QR_011000000201+a3P_000000001_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+3]+=Pmtrx[1]*(P_021000001*QR_010001000000+a1P_021000000_1*QR_010001000001+P_121000001*QR_010001000100+a1P_121000000_1*QR_010001000101+P_221000001*QR_010001000200+a1P_221000000_1*QR_010001000201+a3P_000000001_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+3]+=Pmtrx[2]*(P_021000001*QR_010000001000+a1P_021000000_1*QR_010000001001+P_121000001*QR_010000001100+a1P_121000000_1*QR_010000001101+P_221000001*QR_010000001200+a1P_221000000_1*QR_010000001201+a3P_000000001_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+3]+=Pmtrx[3]*(P_021000001*QR_001010000000+a1P_021000000_1*QR_001010000001+P_121000001*QR_001010000100+a1P_121000000_1*QR_001010000101+P_221000001*QR_001010000200+a1P_221000000_1*QR_001010000201+a3P_000000001_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+3]+=Pmtrx[4]*(P_021000001*QR_000011000000+a1P_021000000_1*QR_000011000001+P_121000001*QR_000011000100+a1P_121000000_1*QR_000011000101+P_221000001*QR_000011000200+a1P_221000000_1*QR_000011000201+a3P_000000001_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+3]+=Pmtrx[5]*(P_021000001*QR_000010001000+a1P_021000000_1*QR_000010001001+P_121000001*QR_000010001100+a1P_121000000_1*QR_000010001101+P_221000001*QR_000010001200+a1P_221000000_1*QR_000010001201+a3P_000000001_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+3]+=Pmtrx[6]*(P_021000001*QR_001000010000+a1P_021000000_1*QR_001000010001+P_121000001*QR_001000010100+a1P_121000000_1*QR_001000010101+P_221000001*QR_001000010200+a1P_221000000_1*QR_001000010201+a3P_000000001_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+3]+=Pmtrx[7]*(P_021000001*QR_000001010000+a1P_021000000_1*QR_000001010001+P_121000001*QR_000001010100+a1P_121000000_1*QR_000001010101+P_221000001*QR_000001010200+a1P_221000000_1*QR_000001010201+a3P_000000001_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+3]+=Pmtrx[8]*(P_021000001*QR_000000011000+a1P_021000000_1*QR_000000011001+P_121000001*QR_000000011100+a1P_121000000_1*QR_000000011101+P_221000001*QR_000000011200+a1P_221000000_1*QR_000000011201+a3P_000000001_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+4]+=Pmtrx[0]*(P_020001001*QR_011000000000+a1P_020001000_1*QR_011000000001+a1P_020000001_1*QR_011000000010+a2P_020000000_1*QR_011000000011+a1P_010001001_2*QR_011000000100+a2P_010001000_2*QR_011000000101+a2P_010000001_2*QR_011000000110+a3P_010000000_2*QR_011000000111+a2P_000001001_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+4]+=Pmtrx[1]*(P_020001001*QR_010001000000+a1P_020001000_1*QR_010001000001+a1P_020000001_1*QR_010001000010+a2P_020000000_1*QR_010001000011+a1P_010001001_2*QR_010001000100+a2P_010001000_2*QR_010001000101+a2P_010000001_2*QR_010001000110+a3P_010000000_2*QR_010001000111+a2P_000001001_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+4]+=Pmtrx[2]*(P_020001001*QR_010000001000+a1P_020001000_1*QR_010000001001+a1P_020000001_1*QR_010000001010+a2P_020000000_1*QR_010000001011+a1P_010001001_2*QR_010000001100+a2P_010001000_2*QR_010000001101+a2P_010000001_2*QR_010000001110+a3P_010000000_2*QR_010000001111+a2P_000001001_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+4]+=Pmtrx[3]*(P_020001001*QR_001010000000+a1P_020001000_1*QR_001010000001+a1P_020000001_1*QR_001010000010+a2P_020000000_1*QR_001010000011+a1P_010001001_2*QR_001010000100+a2P_010001000_2*QR_001010000101+a2P_010000001_2*QR_001010000110+a3P_010000000_2*QR_001010000111+a2P_000001001_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+4]+=Pmtrx[4]*(P_020001001*QR_000011000000+a1P_020001000_1*QR_000011000001+a1P_020000001_1*QR_000011000010+a2P_020000000_1*QR_000011000011+a1P_010001001_2*QR_000011000100+a2P_010001000_2*QR_000011000101+a2P_010000001_2*QR_000011000110+a3P_010000000_2*QR_000011000111+a2P_000001001_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+4]+=Pmtrx[5]*(P_020001001*QR_000010001000+a1P_020001000_1*QR_000010001001+a1P_020000001_1*QR_000010001010+a2P_020000000_1*QR_000010001011+a1P_010001001_2*QR_000010001100+a2P_010001000_2*QR_000010001101+a2P_010000001_2*QR_000010001110+a3P_010000000_2*QR_000010001111+a2P_000001001_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+4]+=Pmtrx[6]*(P_020001001*QR_001000010000+a1P_020001000_1*QR_001000010001+a1P_020000001_1*QR_001000010010+a2P_020000000_1*QR_001000010011+a1P_010001001_2*QR_001000010100+a2P_010001000_2*QR_001000010101+a2P_010000001_2*QR_001000010110+a3P_010000000_2*QR_001000010111+a2P_000001001_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+4]+=Pmtrx[7]*(P_020001001*QR_000001010000+a1P_020001000_1*QR_000001010001+a1P_020000001_1*QR_000001010010+a2P_020000000_1*QR_000001010011+a1P_010001001_2*QR_000001010100+a2P_010001000_2*QR_000001010101+a2P_010000001_2*QR_000001010110+a3P_010000000_2*QR_000001010111+a2P_000001001_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+4]+=Pmtrx[8]*(P_020001001*QR_000000011000+a1P_020001000_1*QR_000000011001+a1P_020000001_1*QR_000000011010+a2P_020000000_1*QR_000000011011+a1P_010001001_2*QR_000000011100+a2P_010001000_2*QR_000000011101+a2P_010000001_2*QR_000000011110+a3P_010000000_2*QR_000000011111+a2P_000001001_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+5]+=Pmtrx[0]*(P_020000002*QR_011000000000+a1P_020000001_2*QR_011000000001+a2P_020000000_1*QR_011000000002+a1P_010000002_2*QR_011000000100+a2P_010000001_4*QR_011000000101+a3P_010000000_2*QR_011000000102+a2P_000000002_1*QR_011000000200+a3P_000000001_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+5]+=Pmtrx[1]*(P_020000002*QR_010001000000+a1P_020000001_2*QR_010001000001+a2P_020000000_1*QR_010001000002+a1P_010000002_2*QR_010001000100+a2P_010000001_4*QR_010001000101+a3P_010000000_2*QR_010001000102+a2P_000000002_1*QR_010001000200+a3P_000000001_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+5]+=Pmtrx[2]*(P_020000002*QR_010000001000+a1P_020000001_2*QR_010000001001+a2P_020000000_1*QR_010000001002+a1P_010000002_2*QR_010000001100+a2P_010000001_4*QR_010000001101+a3P_010000000_2*QR_010000001102+a2P_000000002_1*QR_010000001200+a3P_000000001_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+5]+=Pmtrx[3]*(P_020000002*QR_001010000000+a1P_020000001_2*QR_001010000001+a2P_020000000_1*QR_001010000002+a1P_010000002_2*QR_001010000100+a2P_010000001_4*QR_001010000101+a3P_010000000_2*QR_001010000102+a2P_000000002_1*QR_001010000200+a3P_000000001_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+5]+=Pmtrx[4]*(P_020000002*QR_000011000000+a1P_020000001_2*QR_000011000001+a2P_020000000_1*QR_000011000002+a1P_010000002_2*QR_000011000100+a2P_010000001_4*QR_000011000101+a3P_010000000_2*QR_000011000102+a2P_000000002_1*QR_000011000200+a3P_000000001_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+5]+=Pmtrx[5]*(P_020000002*QR_000010001000+a1P_020000001_2*QR_000010001001+a2P_020000000_1*QR_000010001002+a1P_010000002_2*QR_000010001100+a2P_010000001_4*QR_000010001101+a3P_010000000_2*QR_000010001102+a2P_000000002_1*QR_000010001200+a3P_000000001_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+5]+=Pmtrx[6]*(P_020000002*QR_001000010000+a1P_020000001_2*QR_001000010001+a2P_020000000_1*QR_001000010002+a1P_010000002_2*QR_001000010100+a2P_010000001_4*QR_001000010101+a3P_010000000_2*QR_001000010102+a2P_000000002_1*QR_001000010200+a3P_000000001_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+5]+=Pmtrx[7]*(P_020000002*QR_000001010000+a1P_020000001_2*QR_000001010001+a2P_020000000_1*QR_000001010002+a1P_010000002_2*QR_000001010100+a2P_010000001_4*QR_000001010101+a3P_010000000_2*QR_000001010102+a2P_000000002_1*QR_000001010200+a3P_000000001_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+5]+=Pmtrx[8]*(P_020000002*QR_000000011000+a1P_020000001_2*QR_000000011001+a2P_020000000_1*QR_000000011002+a1P_010000002_2*QR_000000011100+a2P_010000001_4*QR_000000011101+a3P_010000000_2*QR_000000011102+a2P_000000002_1*QR_000000011200+a3P_000000001_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+6]+=Pmtrx[0]*(P_012010000*QR_011000000000+a1P_012000000_1*QR_011000000010+P_112010000*QR_011000000100+a1P_112000000_1*QR_011000000110+P_212010000*QR_011000000200+a1P_212000000_1*QR_011000000210+a3P_000010000_1*QR_011000000300+aPin4*QR_011000000310);
ans_temp[ans_id*36+6]+=Pmtrx[1]*(P_012010000*QR_010001000000+a1P_012000000_1*QR_010001000010+P_112010000*QR_010001000100+a1P_112000000_1*QR_010001000110+P_212010000*QR_010001000200+a1P_212000000_1*QR_010001000210+a3P_000010000_1*QR_010001000300+aPin4*QR_010001000310);
ans_temp[ans_id*36+6]+=Pmtrx[2]*(P_012010000*QR_010000001000+a1P_012000000_1*QR_010000001010+P_112010000*QR_010000001100+a1P_112000000_1*QR_010000001110+P_212010000*QR_010000001200+a1P_212000000_1*QR_010000001210+a3P_000010000_1*QR_010000001300+aPin4*QR_010000001310);
ans_temp[ans_id*36+6]+=Pmtrx[3]*(P_012010000*QR_001010000000+a1P_012000000_1*QR_001010000010+P_112010000*QR_001010000100+a1P_112000000_1*QR_001010000110+P_212010000*QR_001010000200+a1P_212000000_1*QR_001010000210+a3P_000010000_1*QR_001010000300+aPin4*QR_001010000310);
ans_temp[ans_id*36+6]+=Pmtrx[4]*(P_012010000*QR_000011000000+a1P_012000000_1*QR_000011000010+P_112010000*QR_000011000100+a1P_112000000_1*QR_000011000110+P_212010000*QR_000011000200+a1P_212000000_1*QR_000011000210+a3P_000010000_1*QR_000011000300+aPin4*QR_000011000310);
ans_temp[ans_id*36+6]+=Pmtrx[5]*(P_012010000*QR_000010001000+a1P_012000000_1*QR_000010001010+P_112010000*QR_000010001100+a1P_112000000_1*QR_000010001110+P_212010000*QR_000010001200+a1P_212000000_1*QR_000010001210+a3P_000010000_1*QR_000010001300+aPin4*QR_000010001310);
ans_temp[ans_id*36+6]+=Pmtrx[6]*(P_012010000*QR_001000010000+a1P_012000000_1*QR_001000010010+P_112010000*QR_001000010100+a1P_112000000_1*QR_001000010110+P_212010000*QR_001000010200+a1P_212000000_1*QR_001000010210+a3P_000010000_1*QR_001000010300+aPin4*QR_001000010310);
ans_temp[ans_id*36+6]+=Pmtrx[7]*(P_012010000*QR_000001010000+a1P_012000000_1*QR_000001010010+P_112010000*QR_000001010100+a1P_112000000_1*QR_000001010110+P_212010000*QR_000001010200+a1P_212000000_1*QR_000001010210+a3P_000010000_1*QR_000001010300+aPin4*QR_000001010310);
ans_temp[ans_id*36+6]+=Pmtrx[8]*(P_012010000*QR_000000011000+a1P_012000000_1*QR_000000011010+P_112010000*QR_000000011100+a1P_112000000_1*QR_000000011110+P_212010000*QR_000000011200+a1P_212000000_1*QR_000000011210+a3P_000010000_1*QR_000000011300+aPin4*QR_000000011310);
ans_temp[ans_id*36+7]+=Pmtrx[0]*(P_011011000*QR_011000000000+P_011111000*QR_011000000010+a2P_011000000_1*QR_011000000020+P_111011000*QR_011000000100+P_111111000*QR_011000000110+a2P_111000000_1*QR_011000000120+a2P_000011000_1*QR_011000000200+a2P_000111000_1*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+7]+=Pmtrx[1]*(P_011011000*QR_010001000000+P_011111000*QR_010001000010+a2P_011000000_1*QR_010001000020+P_111011000*QR_010001000100+P_111111000*QR_010001000110+a2P_111000000_1*QR_010001000120+a2P_000011000_1*QR_010001000200+a2P_000111000_1*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+7]+=Pmtrx[2]*(P_011011000*QR_010000001000+P_011111000*QR_010000001010+a2P_011000000_1*QR_010000001020+P_111011000*QR_010000001100+P_111111000*QR_010000001110+a2P_111000000_1*QR_010000001120+a2P_000011000_1*QR_010000001200+a2P_000111000_1*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+7]+=Pmtrx[3]*(P_011011000*QR_001010000000+P_011111000*QR_001010000010+a2P_011000000_1*QR_001010000020+P_111011000*QR_001010000100+P_111111000*QR_001010000110+a2P_111000000_1*QR_001010000120+a2P_000011000_1*QR_001010000200+a2P_000111000_1*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+7]+=Pmtrx[4]*(P_011011000*QR_000011000000+P_011111000*QR_000011000010+a2P_011000000_1*QR_000011000020+P_111011000*QR_000011000100+P_111111000*QR_000011000110+a2P_111000000_1*QR_000011000120+a2P_000011000_1*QR_000011000200+a2P_000111000_1*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+7]+=Pmtrx[5]*(P_011011000*QR_000010001000+P_011111000*QR_000010001010+a2P_011000000_1*QR_000010001020+P_111011000*QR_000010001100+P_111111000*QR_000010001110+a2P_111000000_1*QR_000010001120+a2P_000011000_1*QR_000010001200+a2P_000111000_1*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+7]+=Pmtrx[6]*(P_011011000*QR_001000010000+P_011111000*QR_001000010010+a2P_011000000_1*QR_001000010020+P_111011000*QR_001000010100+P_111111000*QR_001000010110+a2P_111000000_1*QR_001000010120+a2P_000011000_1*QR_001000010200+a2P_000111000_1*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+7]+=Pmtrx[7]*(P_011011000*QR_000001010000+P_011111000*QR_000001010010+a2P_011000000_1*QR_000001010020+P_111011000*QR_000001010100+P_111111000*QR_000001010110+a2P_111000000_1*QR_000001010120+a2P_000011000_1*QR_000001010200+a2P_000111000_1*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+7]+=Pmtrx[8]*(P_011011000*QR_000000011000+P_011111000*QR_000000011010+a2P_011000000_1*QR_000000011020+P_111011000*QR_000000011100+P_111111000*QR_000000011110+a2P_111000000_1*QR_000000011120+a2P_000011000_1*QR_000000011200+a2P_000111000_1*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+8]+=Pmtrx[0]*(P_010012000*QR_011000000000+P_010112000*QR_011000000010+P_010212000*QR_011000000020+a3P_010000000_1*QR_011000000030+a1P_000012000_1*QR_011000000100+a1P_000112000_1*QR_011000000110+a1P_000212000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+8]+=Pmtrx[1]*(P_010012000*QR_010001000000+P_010112000*QR_010001000010+P_010212000*QR_010001000020+a3P_010000000_1*QR_010001000030+a1P_000012000_1*QR_010001000100+a1P_000112000_1*QR_010001000110+a1P_000212000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+8]+=Pmtrx[2]*(P_010012000*QR_010000001000+P_010112000*QR_010000001010+P_010212000*QR_010000001020+a3P_010000000_1*QR_010000001030+a1P_000012000_1*QR_010000001100+a1P_000112000_1*QR_010000001110+a1P_000212000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+8]+=Pmtrx[3]*(P_010012000*QR_001010000000+P_010112000*QR_001010000010+P_010212000*QR_001010000020+a3P_010000000_1*QR_001010000030+a1P_000012000_1*QR_001010000100+a1P_000112000_1*QR_001010000110+a1P_000212000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+8]+=Pmtrx[4]*(P_010012000*QR_000011000000+P_010112000*QR_000011000010+P_010212000*QR_000011000020+a3P_010000000_1*QR_000011000030+a1P_000012000_1*QR_000011000100+a1P_000112000_1*QR_000011000110+a1P_000212000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+8]+=Pmtrx[5]*(P_010012000*QR_000010001000+P_010112000*QR_000010001010+P_010212000*QR_000010001020+a3P_010000000_1*QR_000010001030+a1P_000012000_1*QR_000010001100+a1P_000112000_1*QR_000010001110+a1P_000212000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+8]+=Pmtrx[6]*(P_010012000*QR_001000010000+P_010112000*QR_001000010010+P_010212000*QR_001000010020+a3P_010000000_1*QR_001000010030+a1P_000012000_1*QR_001000010100+a1P_000112000_1*QR_001000010110+a1P_000212000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+8]+=Pmtrx[7]*(P_010012000*QR_000001010000+P_010112000*QR_000001010010+P_010212000*QR_000001010020+a3P_010000000_1*QR_000001010030+a1P_000012000_1*QR_000001010100+a1P_000112000_1*QR_000001010110+a1P_000212000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+8]+=Pmtrx[8]*(P_010012000*QR_000000011000+P_010112000*QR_000000011010+P_010212000*QR_000000011020+a3P_010000000_1*QR_000000011030+a1P_000012000_1*QR_000000011100+a1P_000112000_1*QR_000000011110+a1P_000212000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+9]+=Pmtrx[0]*(P_011010001*QR_011000000000+a1P_011010000_1*QR_011000000001+a1P_011000001_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111010001*QR_011000000100+a1P_111010000_1*QR_011000000101+a1P_111000001_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000010001_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000001_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+9]+=Pmtrx[1]*(P_011010001*QR_010001000000+a1P_011010000_1*QR_010001000001+a1P_011000001_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111010001*QR_010001000100+a1P_111010000_1*QR_010001000101+a1P_111000001_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000010001_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000001_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+9]+=Pmtrx[2]*(P_011010001*QR_010000001000+a1P_011010000_1*QR_010000001001+a1P_011000001_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111010001*QR_010000001100+a1P_111010000_1*QR_010000001101+a1P_111000001_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000010001_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000001_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+9]+=Pmtrx[3]*(P_011010001*QR_001010000000+a1P_011010000_1*QR_001010000001+a1P_011000001_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111010001*QR_001010000100+a1P_111010000_1*QR_001010000101+a1P_111000001_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000010001_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000001_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+9]+=Pmtrx[4]*(P_011010001*QR_000011000000+a1P_011010000_1*QR_000011000001+a1P_011000001_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111010001*QR_000011000100+a1P_111010000_1*QR_000011000101+a1P_111000001_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000010001_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000001_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+9]+=Pmtrx[5]*(P_011010001*QR_000010001000+a1P_011010000_1*QR_000010001001+a1P_011000001_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111010001*QR_000010001100+a1P_111010000_1*QR_000010001101+a1P_111000001_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000010001_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000001_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+9]+=Pmtrx[6]*(P_011010001*QR_001000010000+a1P_011010000_1*QR_001000010001+a1P_011000001_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111010001*QR_001000010100+a1P_111010000_1*QR_001000010101+a1P_111000001_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000010001_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000001_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+9]+=Pmtrx[7]*(P_011010001*QR_000001010000+a1P_011010000_1*QR_000001010001+a1P_011000001_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111010001*QR_000001010100+a1P_111010000_1*QR_000001010101+a1P_111000001_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000010001_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000001_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+9]+=Pmtrx[8]*(P_011010001*QR_000000011000+a1P_011010000_1*QR_000000011001+a1P_011000001_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111010001*QR_000000011100+a1P_111010000_1*QR_000000011101+a1P_111000001_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000010001_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000001_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+10]+=Pmtrx[0]*(P_010011001*QR_011000000000+a1P_010011000_1*QR_011000000001+P_010111001*QR_011000000010+a1P_010111000_1*QR_011000000011+a2P_010000001_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000011001_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111001_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+10]+=Pmtrx[1]*(P_010011001*QR_010001000000+a1P_010011000_1*QR_010001000001+P_010111001*QR_010001000010+a1P_010111000_1*QR_010001000011+a2P_010000001_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000011001_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111001_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+10]+=Pmtrx[2]*(P_010011001*QR_010000001000+a1P_010011000_1*QR_010000001001+P_010111001*QR_010000001010+a1P_010111000_1*QR_010000001011+a2P_010000001_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000011001_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111001_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+10]+=Pmtrx[3]*(P_010011001*QR_001010000000+a1P_010011000_1*QR_001010000001+P_010111001*QR_001010000010+a1P_010111000_1*QR_001010000011+a2P_010000001_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000011001_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111001_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+10]+=Pmtrx[4]*(P_010011001*QR_000011000000+a1P_010011000_1*QR_000011000001+P_010111001*QR_000011000010+a1P_010111000_1*QR_000011000011+a2P_010000001_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000011001_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111001_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+10]+=Pmtrx[5]*(P_010011001*QR_000010001000+a1P_010011000_1*QR_000010001001+P_010111001*QR_000010001010+a1P_010111000_1*QR_000010001011+a2P_010000001_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000011001_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111001_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+10]+=Pmtrx[6]*(P_010011001*QR_001000010000+a1P_010011000_1*QR_001000010001+P_010111001*QR_001000010010+a1P_010111000_1*QR_001000010011+a2P_010000001_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000011001_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111001_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+10]+=Pmtrx[7]*(P_010011001*QR_000001010000+a1P_010011000_1*QR_000001010001+P_010111001*QR_000001010010+a1P_010111000_1*QR_000001010011+a2P_010000001_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000011001_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111001_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+10]+=Pmtrx[8]*(P_010011001*QR_000000011000+a1P_010011000_1*QR_000000011001+P_010111001*QR_000000011010+a1P_010111000_1*QR_000000011011+a2P_010000001_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000011001_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111001_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+11]+=Pmtrx[0]*(P_010010002*QR_011000000000+a1P_010010001_2*QR_011000000001+a2P_010010000_1*QR_011000000002+a1P_010000002_1*QR_011000000010+a2P_010000001_2*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000010002_1*QR_011000000100+a2P_000010001_2*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000002_1*QR_011000000110+a3P_000000001_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+11]+=Pmtrx[1]*(P_010010002*QR_010001000000+a1P_010010001_2*QR_010001000001+a2P_010010000_1*QR_010001000002+a1P_010000002_1*QR_010001000010+a2P_010000001_2*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000010002_1*QR_010001000100+a2P_000010001_2*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000002_1*QR_010001000110+a3P_000000001_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+11]+=Pmtrx[2]*(P_010010002*QR_010000001000+a1P_010010001_2*QR_010000001001+a2P_010010000_1*QR_010000001002+a1P_010000002_1*QR_010000001010+a2P_010000001_2*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000010002_1*QR_010000001100+a2P_000010001_2*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000002_1*QR_010000001110+a3P_000000001_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+11]+=Pmtrx[3]*(P_010010002*QR_001010000000+a1P_010010001_2*QR_001010000001+a2P_010010000_1*QR_001010000002+a1P_010000002_1*QR_001010000010+a2P_010000001_2*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000010002_1*QR_001010000100+a2P_000010001_2*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000002_1*QR_001010000110+a3P_000000001_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+11]+=Pmtrx[4]*(P_010010002*QR_000011000000+a1P_010010001_2*QR_000011000001+a2P_010010000_1*QR_000011000002+a1P_010000002_1*QR_000011000010+a2P_010000001_2*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000010002_1*QR_000011000100+a2P_000010001_2*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000002_1*QR_000011000110+a3P_000000001_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+11]+=Pmtrx[5]*(P_010010002*QR_000010001000+a1P_010010001_2*QR_000010001001+a2P_010010000_1*QR_000010001002+a1P_010000002_1*QR_000010001010+a2P_010000001_2*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000010002_1*QR_000010001100+a2P_000010001_2*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000002_1*QR_000010001110+a3P_000000001_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+11]+=Pmtrx[6]*(P_010010002*QR_001000010000+a1P_010010001_2*QR_001000010001+a2P_010010000_1*QR_001000010002+a1P_010000002_1*QR_001000010010+a2P_010000001_2*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000010002_1*QR_001000010100+a2P_000010001_2*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000002_1*QR_001000010110+a3P_000000001_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+11]+=Pmtrx[7]*(P_010010002*QR_000001010000+a1P_010010001_2*QR_000001010001+a2P_010010000_1*QR_000001010002+a1P_010000002_1*QR_000001010010+a2P_010000001_2*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000010002_1*QR_000001010100+a2P_000010001_2*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000002_1*QR_000001010110+a3P_000000001_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+11]+=Pmtrx[8]*(P_010010002*QR_000000011000+a1P_010010001_2*QR_000000011001+a2P_010010000_1*QR_000000011002+a1P_010000002_1*QR_000000011010+a2P_010000001_2*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000010002_1*QR_000000011100+a2P_000010001_2*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000002_1*QR_000000011110+a3P_000000001_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+12]+=Pmtrx[0]*(P_002020000*QR_011000000000+a1P_002010000_2*QR_011000000010+a2P_002000000_1*QR_011000000020+a1P_001020000_2*QR_011000000100+a2P_001010000_4*QR_011000000110+a3P_001000000_2*QR_011000000120+a2P_000020000_1*QR_011000000200+a3P_000010000_2*QR_011000000210+aPin4*QR_011000000220);
ans_temp[ans_id*36+12]+=Pmtrx[1]*(P_002020000*QR_010001000000+a1P_002010000_2*QR_010001000010+a2P_002000000_1*QR_010001000020+a1P_001020000_2*QR_010001000100+a2P_001010000_4*QR_010001000110+a3P_001000000_2*QR_010001000120+a2P_000020000_1*QR_010001000200+a3P_000010000_2*QR_010001000210+aPin4*QR_010001000220);
ans_temp[ans_id*36+12]+=Pmtrx[2]*(P_002020000*QR_010000001000+a1P_002010000_2*QR_010000001010+a2P_002000000_1*QR_010000001020+a1P_001020000_2*QR_010000001100+a2P_001010000_4*QR_010000001110+a3P_001000000_2*QR_010000001120+a2P_000020000_1*QR_010000001200+a3P_000010000_2*QR_010000001210+aPin4*QR_010000001220);
ans_temp[ans_id*36+12]+=Pmtrx[3]*(P_002020000*QR_001010000000+a1P_002010000_2*QR_001010000010+a2P_002000000_1*QR_001010000020+a1P_001020000_2*QR_001010000100+a2P_001010000_4*QR_001010000110+a3P_001000000_2*QR_001010000120+a2P_000020000_1*QR_001010000200+a3P_000010000_2*QR_001010000210+aPin4*QR_001010000220);
ans_temp[ans_id*36+12]+=Pmtrx[4]*(P_002020000*QR_000011000000+a1P_002010000_2*QR_000011000010+a2P_002000000_1*QR_000011000020+a1P_001020000_2*QR_000011000100+a2P_001010000_4*QR_000011000110+a3P_001000000_2*QR_000011000120+a2P_000020000_1*QR_000011000200+a3P_000010000_2*QR_000011000210+aPin4*QR_000011000220);
ans_temp[ans_id*36+12]+=Pmtrx[5]*(P_002020000*QR_000010001000+a1P_002010000_2*QR_000010001010+a2P_002000000_1*QR_000010001020+a1P_001020000_2*QR_000010001100+a2P_001010000_4*QR_000010001110+a3P_001000000_2*QR_000010001120+a2P_000020000_1*QR_000010001200+a3P_000010000_2*QR_000010001210+aPin4*QR_000010001220);
ans_temp[ans_id*36+12]+=Pmtrx[6]*(P_002020000*QR_001000010000+a1P_002010000_2*QR_001000010010+a2P_002000000_1*QR_001000010020+a1P_001020000_2*QR_001000010100+a2P_001010000_4*QR_001000010110+a3P_001000000_2*QR_001000010120+a2P_000020000_1*QR_001000010200+a3P_000010000_2*QR_001000010210+aPin4*QR_001000010220);
ans_temp[ans_id*36+12]+=Pmtrx[7]*(P_002020000*QR_000001010000+a1P_002010000_2*QR_000001010010+a2P_002000000_1*QR_000001010020+a1P_001020000_2*QR_000001010100+a2P_001010000_4*QR_000001010110+a3P_001000000_2*QR_000001010120+a2P_000020000_1*QR_000001010200+a3P_000010000_2*QR_000001010210+aPin4*QR_000001010220);
ans_temp[ans_id*36+12]+=Pmtrx[8]*(P_002020000*QR_000000011000+a1P_002010000_2*QR_000000011010+a2P_002000000_1*QR_000000011020+a1P_001020000_2*QR_000000011100+a2P_001010000_4*QR_000000011110+a3P_001000000_2*QR_000000011120+a2P_000020000_1*QR_000000011200+a3P_000010000_2*QR_000000011210+aPin4*QR_000000011220);
ans_temp[ans_id*36+13]+=Pmtrx[0]*(P_001021000*QR_011000000000+P_001121000*QR_011000000010+P_001221000*QR_011000000020+a3P_001000000_1*QR_011000000030+a1P_000021000_1*QR_011000000100+a1P_000121000_1*QR_011000000110+a1P_000221000_1*QR_011000000120+aPin4*QR_011000000130);
ans_temp[ans_id*36+13]+=Pmtrx[1]*(P_001021000*QR_010001000000+P_001121000*QR_010001000010+P_001221000*QR_010001000020+a3P_001000000_1*QR_010001000030+a1P_000021000_1*QR_010001000100+a1P_000121000_1*QR_010001000110+a1P_000221000_1*QR_010001000120+aPin4*QR_010001000130);
ans_temp[ans_id*36+13]+=Pmtrx[2]*(P_001021000*QR_010000001000+P_001121000*QR_010000001010+P_001221000*QR_010000001020+a3P_001000000_1*QR_010000001030+a1P_000021000_1*QR_010000001100+a1P_000121000_1*QR_010000001110+a1P_000221000_1*QR_010000001120+aPin4*QR_010000001130);
ans_temp[ans_id*36+13]+=Pmtrx[3]*(P_001021000*QR_001010000000+P_001121000*QR_001010000010+P_001221000*QR_001010000020+a3P_001000000_1*QR_001010000030+a1P_000021000_1*QR_001010000100+a1P_000121000_1*QR_001010000110+a1P_000221000_1*QR_001010000120+aPin4*QR_001010000130);
ans_temp[ans_id*36+13]+=Pmtrx[4]*(P_001021000*QR_000011000000+P_001121000*QR_000011000010+P_001221000*QR_000011000020+a3P_001000000_1*QR_000011000030+a1P_000021000_1*QR_000011000100+a1P_000121000_1*QR_000011000110+a1P_000221000_1*QR_000011000120+aPin4*QR_000011000130);
ans_temp[ans_id*36+13]+=Pmtrx[5]*(P_001021000*QR_000010001000+P_001121000*QR_000010001010+P_001221000*QR_000010001020+a3P_001000000_1*QR_000010001030+a1P_000021000_1*QR_000010001100+a1P_000121000_1*QR_000010001110+a1P_000221000_1*QR_000010001120+aPin4*QR_000010001130);
ans_temp[ans_id*36+13]+=Pmtrx[6]*(P_001021000*QR_001000010000+P_001121000*QR_001000010010+P_001221000*QR_001000010020+a3P_001000000_1*QR_001000010030+a1P_000021000_1*QR_001000010100+a1P_000121000_1*QR_001000010110+a1P_000221000_1*QR_001000010120+aPin4*QR_001000010130);
ans_temp[ans_id*36+13]+=Pmtrx[7]*(P_001021000*QR_000001010000+P_001121000*QR_000001010010+P_001221000*QR_000001010020+a3P_001000000_1*QR_000001010030+a1P_000021000_1*QR_000001010100+a1P_000121000_1*QR_000001010110+a1P_000221000_1*QR_000001010120+aPin4*QR_000001010130);
ans_temp[ans_id*36+13]+=Pmtrx[8]*(P_001021000*QR_000000011000+P_001121000*QR_000000011010+P_001221000*QR_000000011020+a3P_001000000_1*QR_000000011030+a1P_000021000_1*QR_000000011100+a1P_000121000_1*QR_000000011110+a1P_000221000_1*QR_000000011120+aPin4*QR_000000011130);
ans_temp[ans_id*36+14]+=Pmtrx[0]*(P_000022000*QR_011000000000+P_000122000*QR_011000000010+P_000222000*QR_011000000020+a2P_000111000_2*QR_011000000030+aPin4*QR_011000000040);
ans_temp[ans_id*36+14]+=Pmtrx[1]*(P_000022000*QR_010001000000+P_000122000*QR_010001000010+P_000222000*QR_010001000020+a2P_000111000_2*QR_010001000030+aPin4*QR_010001000040);
ans_temp[ans_id*36+14]+=Pmtrx[2]*(P_000022000*QR_010000001000+P_000122000*QR_010000001010+P_000222000*QR_010000001020+a2P_000111000_2*QR_010000001030+aPin4*QR_010000001040);
ans_temp[ans_id*36+14]+=Pmtrx[3]*(P_000022000*QR_001010000000+P_000122000*QR_001010000010+P_000222000*QR_001010000020+a2P_000111000_2*QR_001010000030+aPin4*QR_001010000040);
ans_temp[ans_id*36+14]+=Pmtrx[4]*(P_000022000*QR_000011000000+P_000122000*QR_000011000010+P_000222000*QR_000011000020+a2P_000111000_2*QR_000011000030+aPin4*QR_000011000040);
ans_temp[ans_id*36+14]+=Pmtrx[5]*(P_000022000*QR_000010001000+P_000122000*QR_000010001010+P_000222000*QR_000010001020+a2P_000111000_2*QR_000010001030+aPin4*QR_000010001040);
ans_temp[ans_id*36+14]+=Pmtrx[6]*(P_000022000*QR_001000010000+P_000122000*QR_001000010010+P_000222000*QR_001000010020+a2P_000111000_2*QR_001000010030+aPin4*QR_001000010040);
ans_temp[ans_id*36+14]+=Pmtrx[7]*(P_000022000*QR_000001010000+P_000122000*QR_000001010010+P_000222000*QR_000001010020+a2P_000111000_2*QR_000001010030+aPin4*QR_000001010040);
ans_temp[ans_id*36+14]+=Pmtrx[8]*(P_000022000*QR_000000011000+P_000122000*QR_000000011010+P_000222000*QR_000000011020+a2P_000111000_2*QR_000000011030+aPin4*QR_000000011040);
ans_temp[ans_id*36+15]+=Pmtrx[0]*(P_001020001*QR_011000000000+a1P_001020000_1*QR_011000000001+a1P_001010001_2*QR_011000000010+a2P_001010000_2*QR_011000000011+a2P_001000001_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000020001_1*QR_011000000100+a2P_000020000_1*QR_011000000101+a2P_000010001_2*QR_011000000110+a3P_000010000_2*QR_011000000111+a3P_000000001_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+15]+=Pmtrx[1]*(P_001020001*QR_010001000000+a1P_001020000_1*QR_010001000001+a1P_001010001_2*QR_010001000010+a2P_001010000_2*QR_010001000011+a2P_001000001_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000020001_1*QR_010001000100+a2P_000020000_1*QR_010001000101+a2P_000010001_2*QR_010001000110+a3P_000010000_2*QR_010001000111+a3P_000000001_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+15]+=Pmtrx[2]*(P_001020001*QR_010000001000+a1P_001020000_1*QR_010000001001+a1P_001010001_2*QR_010000001010+a2P_001010000_2*QR_010000001011+a2P_001000001_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000020001_1*QR_010000001100+a2P_000020000_1*QR_010000001101+a2P_000010001_2*QR_010000001110+a3P_000010000_2*QR_010000001111+a3P_000000001_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+15]+=Pmtrx[3]*(P_001020001*QR_001010000000+a1P_001020000_1*QR_001010000001+a1P_001010001_2*QR_001010000010+a2P_001010000_2*QR_001010000011+a2P_001000001_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000020001_1*QR_001010000100+a2P_000020000_1*QR_001010000101+a2P_000010001_2*QR_001010000110+a3P_000010000_2*QR_001010000111+a3P_000000001_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+15]+=Pmtrx[4]*(P_001020001*QR_000011000000+a1P_001020000_1*QR_000011000001+a1P_001010001_2*QR_000011000010+a2P_001010000_2*QR_000011000011+a2P_001000001_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000020001_1*QR_000011000100+a2P_000020000_1*QR_000011000101+a2P_000010001_2*QR_000011000110+a3P_000010000_2*QR_000011000111+a3P_000000001_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+15]+=Pmtrx[5]*(P_001020001*QR_000010001000+a1P_001020000_1*QR_000010001001+a1P_001010001_2*QR_000010001010+a2P_001010000_2*QR_000010001011+a2P_001000001_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000020001_1*QR_000010001100+a2P_000020000_1*QR_000010001101+a2P_000010001_2*QR_000010001110+a3P_000010000_2*QR_000010001111+a3P_000000001_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+15]+=Pmtrx[6]*(P_001020001*QR_001000010000+a1P_001020000_1*QR_001000010001+a1P_001010001_2*QR_001000010010+a2P_001010000_2*QR_001000010011+a2P_001000001_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000020001_1*QR_001000010100+a2P_000020000_1*QR_001000010101+a2P_000010001_2*QR_001000010110+a3P_000010000_2*QR_001000010111+a3P_000000001_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+15]+=Pmtrx[7]*(P_001020001*QR_000001010000+a1P_001020000_1*QR_000001010001+a1P_001010001_2*QR_000001010010+a2P_001010000_2*QR_000001010011+a2P_001000001_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000020001_1*QR_000001010100+a2P_000020000_1*QR_000001010101+a2P_000010001_2*QR_000001010110+a3P_000010000_2*QR_000001010111+a3P_000000001_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+15]+=Pmtrx[8]*(P_001020001*QR_000000011000+a1P_001020000_1*QR_000000011001+a1P_001010001_2*QR_000000011010+a2P_001010000_2*QR_000000011011+a2P_001000001_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000020001_1*QR_000000011100+a2P_000020000_1*QR_000000011101+a2P_000010001_2*QR_000000011110+a3P_000010000_2*QR_000000011111+a3P_000000001_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+16]+=Pmtrx[0]*(P_000021001*QR_011000000000+a1P_000021000_1*QR_011000000001+P_000121001*QR_011000000010+a1P_000121000_1*QR_011000000011+P_000221001*QR_011000000020+a1P_000221000_1*QR_011000000021+a3P_000000001_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+16]+=Pmtrx[1]*(P_000021001*QR_010001000000+a1P_000021000_1*QR_010001000001+P_000121001*QR_010001000010+a1P_000121000_1*QR_010001000011+P_000221001*QR_010001000020+a1P_000221000_1*QR_010001000021+a3P_000000001_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+16]+=Pmtrx[2]*(P_000021001*QR_010000001000+a1P_000021000_1*QR_010000001001+P_000121001*QR_010000001010+a1P_000121000_1*QR_010000001011+P_000221001*QR_010000001020+a1P_000221000_1*QR_010000001021+a3P_000000001_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+16]+=Pmtrx[3]*(P_000021001*QR_001010000000+a1P_000021000_1*QR_001010000001+P_000121001*QR_001010000010+a1P_000121000_1*QR_001010000011+P_000221001*QR_001010000020+a1P_000221000_1*QR_001010000021+a3P_000000001_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+16]+=Pmtrx[4]*(P_000021001*QR_000011000000+a1P_000021000_1*QR_000011000001+P_000121001*QR_000011000010+a1P_000121000_1*QR_000011000011+P_000221001*QR_000011000020+a1P_000221000_1*QR_000011000021+a3P_000000001_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+16]+=Pmtrx[5]*(P_000021001*QR_000010001000+a1P_000021000_1*QR_000010001001+P_000121001*QR_000010001010+a1P_000121000_1*QR_000010001011+P_000221001*QR_000010001020+a1P_000221000_1*QR_000010001021+a3P_000000001_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+16]+=Pmtrx[6]*(P_000021001*QR_001000010000+a1P_000021000_1*QR_001000010001+P_000121001*QR_001000010010+a1P_000121000_1*QR_001000010011+P_000221001*QR_001000010020+a1P_000221000_1*QR_001000010021+a3P_000000001_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+16]+=Pmtrx[7]*(P_000021001*QR_000001010000+a1P_000021000_1*QR_000001010001+P_000121001*QR_000001010010+a1P_000121000_1*QR_000001010011+P_000221001*QR_000001010020+a1P_000221000_1*QR_000001010021+a3P_000000001_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+16]+=Pmtrx[8]*(P_000021001*QR_000000011000+a1P_000021000_1*QR_000000011001+P_000121001*QR_000000011010+a1P_000121000_1*QR_000000011011+P_000221001*QR_000000011020+a1P_000221000_1*QR_000000011021+a3P_000000001_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+17]+=Pmtrx[0]*(P_000020002*QR_011000000000+a1P_000020001_2*QR_011000000001+a2P_000020000_1*QR_011000000002+a1P_000010002_2*QR_011000000010+a2P_000010001_4*QR_011000000011+a3P_000010000_2*QR_011000000012+a2P_000000002_1*QR_011000000020+a3P_000000001_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+17]+=Pmtrx[1]*(P_000020002*QR_010001000000+a1P_000020001_2*QR_010001000001+a2P_000020000_1*QR_010001000002+a1P_000010002_2*QR_010001000010+a2P_000010001_4*QR_010001000011+a3P_000010000_2*QR_010001000012+a2P_000000002_1*QR_010001000020+a3P_000000001_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+17]+=Pmtrx[2]*(P_000020002*QR_010000001000+a1P_000020001_2*QR_010000001001+a2P_000020000_1*QR_010000001002+a1P_000010002_2*QR_010000001010+a2P_000010001_4*QR_010000001011+a3P_000010000_2*QR_010000001012+a2P_000000002_1*QR_010000001020+a3P_000000001_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+17]+=Pmtrx[3]*(P_000020002*QR_001010000000+a1P_000020001_2*QR_001010000001+a2P_000020000_1*QR_001010000002+a1P_000010002_2*QR_001010000010+a2P_000010001_4*QR_001010000011+a3P_000010000_2*QR_001010000012+a2P_000000002_1*QR_001010000020+a3P_000000001_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+17]+=Pmtrx[4]*(P_000020002*QR_000011000000+a1P_000020001_2*QR_000011000001+a2P_000020000_1*QR_000011000002+a1P_000010002_2*QR_000011000010+a2P_000010001_4*QR_000011000011+a3P_000010000_2*QR_000011000012+a2P_000000002_1*QR_000011000020+a3P_000000001_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+17]+=Pmtrx[5]*(P_000020002*QR_000010001000+a1P_000020001_2*QR_000010001001+a2P_000020000_1*QR_000010001002+a1P_000010002_2*QR_000010001010+a2P_000010001_4*QR_000010001011+a3P_000010000_2*QR_000010001012+a2P_000000002_1*QR_000010001020+a3P_000000001_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+17]+=Pmtrx[6]*(P_000020002*QR_001000010000+a1P_000020001_2*QR_001000010001+a2P_000020000_1*QR_001000010002+a1P_000010002_2*QR_001000010010+a2P_000010001_4*QR_001000010011+a3P_000010000_2*QR_001000010012+a2P_000000002_1*QR_001000010020+a3P_000000001_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+17]+=Pmtrx[7]*(P_000020002*QR_000001010000+a1P_000020001_2*QR_000001010001+a2P_000020000_1*QR_000001010002+a1P_000010002_2*QR_000001010010+a2P_000010001_4*QR_000001010011+a3P_000010000_2*QR_000001010012+a2P_000000002_1*QR_000001010020+a3P_000000001_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+17]+=Pmtrx[8]*(P_000020002*QR_000000011000+a1P_000020001_2*QR_000000011001+a2P_000020000_1*QR_000000011002+a1P_000010002_2*QR_000000011010+a2P_000010001_4*QR_000000011011+a3P_000010000_2*QR_000000011012+a2P_000000002_1*QR_000000011020+a3P_000000001_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+18]+=Pmtrx[0]*(P_012000010*QR_011000000000+a1P_012000000_1*QR_011000000001+P_112000010*QR_011000000100+a1P_112000000_1*QR_011000000101+P_212000010*QR_011000000200+a1P_212000000_1*QR_011000000201+a3P_000000010_1*QR_011000000300+aPin4*QR_011000000301);
ans_temp[ans_id*36+18]+=Pmtrx[1]*(P_012000010*QR_010001000000+a1P_012000000_1*QR_010001000001+P_112000010*QR_010001000100+a1P_112000000_1*QR_010001000101+P_212000010*QR_010001000200+a1P_212000000_1*QR_010001000201+a3P_000000010_1*QR_010001000300+aPin4*QR_010001000301);
ans_temp[ans_id*36+18]+=Pmtrx[2]*(P_012000010*QR_010000001000+a1P_012000000_1*QR_010000001001+P_112000010*QR_010000001100+a1P_112000000_1*QR_010000001101+P_212000010*QR_010000001200+a1P_212000000_1*QR_010000001201+a3P_000000010_1*QR_010000001300+aPin4*QR_010000001301);
ans_temp[ans_id*36+18]+=Pmtrx[3]*(P_012000010*QR_001010000000+a1P_012000000_1*QR_001010000001+P_112000010*QR_001010000100+a1P_112000000_1*QR_001010000101+P_212000010*QR_001010000200+a1P_212000000_1*QR_001010000201+a3P_000000010_1*QR_001010000300+aPin4*QR_001010000301);
ans_temp[ans_id*36+18]+=Pmtrx[4]*(P_012000010*QR_000011000000+a1P_012000000_1*QR_000011000001+P_112000010*QR_000011000100+a1P_112000000_1*QR_000011000101+P_212000010*QR_000011000200+a1P_212000000_1*QR_000011000201+a3P_000000010_1*QR_000011000300+aPin4*QR_000011000301);
ans_temp[ans_id*36+18]+=Pmtrx[5]*(P_012000010*QR_000010001000+a1P_012000000_1*QR_000010001001+P_112000010*QR_000010001100+a1P_112000000_1*QR_000010001101+P_212000010*QR_000010001200+a1P_212000000_1*QR_000010001201+a3P_000000010_1*QR_000010001300+aPin4*QR_000010001301);
ans_temp[ans_id*36+18]+=Pmtrx[6]*(P_012000010*QR_001000010000+a1P_012000000_1*QR_001000010001+P_112000010*QR_001000010100+a1P_112000000_1*QR_001000010101+P_212000010*QR_001000010200+a1P_212000000_1*QR_001000010201+a3P_000000010_1*QR_001000010300+aPin4*QR_001000010301);
ans_temp[ans_id*36+18]+=Pmtrx[7]*(P_012000010*QR_000001010000+a1P_012000000_1*QR_000001010001+P_112000010*QR_000001010100+a1P_112000000_1*QR_000001010101+P_212000010*QR_000001010200+a1P_212000000_1*QR_000001010201+a3P_000000010_1*QR_000001010300+aPin4*QR_000001010301);
ans_temp[ans_id*36+18]+=Pmtrx[8]*(P_012000010*QR_000000011000+a1P_012000000_1*QR_000000011001+P_112000010*QR_000000011100+a1P_112000000_1*QR_000000011101+P_212000010*QR_000000011200+a1P_212000000_1*QR_000000011201+a3P_000000010_1*QR_000000011300+aPin4*QR_000000011301);
ans_temp[ans_id*36+19]+=Pmtrx[0]*(P_011001010*QR_011000000000+a1P_011001000_1*QR_011000000001+a1P_011000010_1*QR_011000000010+a2P_011000000_1*QR_011000000011+P_111001010*QR_011000000100+a1P_111001000_1*QR_011000000101+a1P_111000010_1*QR_011000000110+a2P_111000000_1*QR_011000000111+a2P_000001010_1*QR_011000000200+a3P_000001000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+19]+=Pmtrx[1]*(P_011001010*QR_010001000000+a1P_011001000_1*QR_010001000001+a1P_011000010_1*QR_010001000010+a2P_011000000_1*QR_010001000011+P_111001010*QR_010001000100+a1P_111001000_1*QR_010001000101+a1P_111000010_1*QR_010001000110+a2P_111000000_1*QR_010001000111+a2P_000001010_1*QR_010001000200+a3P_000001000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+19]+=Pmtrx[2]*(P_011001010*QR_010000001000+a1P_011001000_1*QR_010000001001+a1P_011000010_1*QR_010000001010+a2P_011000000_1*QR_010000001011+P_111001010*QR_010000001100+a1P_111001000_1*QR_010000001101+a1P_111000010_1*QR_010000001110+a2P_111000000_1*QR_010000001111+a2P_000001010_1*QR_010000001200+a3P_000001000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+19]+=Pmtrx[3]*(P_011001010*QR_001010000000+a1P_011001000_1*QR_001010000001+a1P_011000010_1*QR_001010000010+a2P_011000000_1*QR_001010000011+P_111001010*QR_001010000100+a1P_111001000_1*QR_001010000101+a1P_111000010_1*QR_001010000110+a2P_111000000_1*QR_001010000111+a2P_000001010_1*QR_001010000200+a3P_000001000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+19]+=Pmtrx[4]*(P_011001010*QR_000011000000+a1P_011001000_1*QR_000011000001+a1P_011000010_1*QR_000011000010+a2P_011000000_1*QR_000011000011+P_111001010*QR_000011000100+a1P_111001000_1*QR_000011000101+a1P_111000010_1*QR_000011000110+a2P_111000000_1*QR_000011000111+a2P_000001010_1*QR_000011000200+a3P_000001000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+19]+=Pmtrx[5]*(P_011001010*QR_000010001000+a1P_011001000_1*QR_000010001001+a1P_011000010_1*QR_000010001010+a2P_011000000_1*QR_000010001011+P_111001010*QR_000010001100+a1P_111001000_1*QR_000010001101+a1P_111000010_1*QR_000010001110+a2P_111000000_1*QR_000010001111+a2P_000001010_1*QR_000010001200+a3P_000001000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+19]+=Pmtrx[6]*(P_011001010*QR_001000010000+a1P_011001000_1*QR_001000010001+a1P_011000010_1*QR_001000010010+a2P_011000000_1*QR_001000010011+P_111001010*QR_001000010100+a1P_111001000_1*QR_001000010101+a1P_111000010_1*QR_001000010110+a2P_111000000_1*QR_001000010111+a2P_000001010_1*QR_001000010200+a3P_000001000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+19]+=Pmtrx[7]*(P_011001010*QR_000001010000+a1P_011001000_1*QR_000001010001+a1P_011000010_1*QR_000001010010+a2P_011000000_1*QR_000001010011+P_111001010*QR_000001010100+a1P_111001000_1*QR_000001010101+a1P_111000010_1*QR_000001010110+a2P_111000000_1*QR_000001010111+a2P_000001010_1*QR_000001010200+a3P_000001000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+19]+=Pmtrx[8]*(P_011001010*QR_000000011000+a1P_011001000_1*QR_000000011001+a1P_011000010_1*QR_000000011010+a2P_011000000_1*QR_000000011011+P_111001010*QR_000000011100+a1P_111001000_1*QR_000000011101+a1P_111000010_1*QR_000000011110+a2P_111000000_1*QR_000000011111+a2P_000001010_1*QR_000000011200+a3P_000001000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+20]+=Pmtrx[0]*(P_010002010*QR_011000000000+a1P_010002000_1*QR_011000000001+a1P_010001010_2*QR_011000000010+a2P_010001000_2*QR_011000000011+a2P_010000010_1*QR_011000000020+a3P_010000000_1*QR_011000000021+a1P_000002010_1*QR_011000000100+a2P_000002000_1*QR_011000000101+a2P_000001010_2*QR_011000000110+a3P_000001000_2*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+20]+=Pmtrx[1]*(P_010002010*QR_010001000000+a1P_010002000_1*QR_010001000001+a1P_010001010_2*QR_010001000010+a2P_010001000_2*QR_010001000011+a2P_010000010_1*QR_010001000020+a3P_010000000_1*QR_010001000021+a1P_000002010_1*QR_010001000100+a2P_000002000_1*QR_010001000101+a2P_000001010_2*QR_010001000110+a3P_000001000_2*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+20]+=Pmtrx[2]*(P_010002010*QR_010000001000+a1P_010002000_1*QR_010000001001+a1P_010001010_2*QR_010000001010+a2P_010001000_2*QR_010000001011+a2P_010000010_1*QR_010000001020+a3P_010000000_1*QR_010000001021+a1P_000002010_1*QR_010000001100+a2P_000002000_1*QR_010000001101+a2P_000001010_2*QR_010000001110+a3P_000001000_2*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+20]+=Pmtrx[3]*(P_010002010*QR_001010000000+a1P_010002000_1*QR_001010000001+a1P_010001010_2*QR_001010000010+a2P_010001000_2*QR_001010000011+a2P_010000010_1*QR_001010000020+a3P_010000000_1*QR_001010000021+a1P_000002010_1*QR_001010000100+a2P_000002000_1*QR_001010000101+a2P_000001010_2*QR_001010000110+a3P_000001000_2*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+20]+=Pmtrx[4]*(P_010002010*QR_000011000000+a1P_010002000_1*QR_000011000001+a1P_010001010_2*QR_000011000010+a2P_010001000_2*QR_000011000011+a2P_010000010_1*QR_000011000020+a3P_010000000_1*QR_000011000021+a1P_000002010_1*QR_000011000100+a2P_000002000_1*QR_000011000101+a2P_000001010_2*QR_000011000110+a3P_000001000_2*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+20]+=Pmtrx[5]*(P_010002010*QR_000010001000+a1P_010002000_1*QR_000010001001+a1P_010001010_2*QR_000010001010+a2P_010001000_2*QR_000010001011+a2P_010000010_1*QR_000010001020+a3P_010000000_1*QR_000010001021+a1P_000002010_1*QR_000010001100+a2P_000002000_1*QR_000010001101+a2P_000001010_2*QR_000010001110+a3P_000001000_2*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+20]+=Pmtrx[6]*(P_010002010*QR_001000010000+a1P_010002000_1*QR_001000010001+a1P_010001010_2*QR_001000010010+a2P_010001000_2*QR_001000010011+a2P_010000010_1*QR_001000010020+a3P_010000000_1*QR_001000010021+a1P_000002010_1*QR_001000010100+a2P_000002000_1*QR_001000010101+a2P_000001010_2*QR_001000010110+a3P_000001000_2*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+20]+=Pmtrx[7]*(P_010002010*QR_000001010000+a1P_010002000_1*QR_000001010001+a1P_010001010_2*QR_000001010010+a2P_010001000_2*QR_000001010011+a2P_010000010_1*QR_000001010020+a3P_010000000_1*QR_000001010021+a1P_000002010_1*QR_000001010100+a2P_000002000_1*QR_000001010101+a2P_000001010_2*QR_000001010110+a3P_000001000_2*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+20]+=Pmtrx[8]*(P_010002010*QR_000000011000+a1P_010002000_1*QR_000000011001+a1P_010001010_2*QR_000000011010+a2P_010001000_2*QR_000000011011+a2P_010000010_1*QR_000000011020+a3P_010000000_1*QR_000000011021+a1P_000002010_1*QR_000000011100+a2P_000002000_1*QR_000000011101+a2P_000001010_2*QR_000000011110+a3P_000001000_2*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+21]+=Pmtrx[0]*(P_011000011*QR_011000000000+P_011000111*QR_011000000001+a2P_011000000_1*QR_011000000002+P_111000011*QR_011000000100+P_111000111*QR_011000000101+a2P_111000000_1*QR_011000000102+a2P_000000011_1*QR_011000000200+a2P_000000111_1*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+21]+=Pmtrx[1]*(P_011000011*QR_010001000000+P_011000111*QR_010001000001+a2P_011000000_1*QR_010001000002+P_111000011*QR_010001000100+P_111000111*QR_010001000101+a2P_111000000_1*QR_010001000102+a2P_000000011_1*QR_010001000200+a2P_000000111_1*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+21]+=Pmtrx[2]*(P_011000011*QR_010000001000+P_011000111*QR_010000001001+a2P_011000000_1*QR_010000001002+P_111000011*QR_010000001100+P_111000111*QR_010000001101+a2P_111000000_1*QR_010000001102+a2P_000000011_1*QR_010000001200+a2P_000000111_1*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+21]+=Pmtrx[3]*(P_011000011*QR_001010000000+P_011000111*QR_001010000001+a2P_011000000_1*QR_001010000002+P_111000011*QR_001010000100+P_111000111*QR_001010000101+a2P_111000000_1*QR_001010000102+a2P_000000011_1*QR_001010000200+a2P_000000111_1*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+21]+=Pmtrx[4]*(P_011000011*QR_000011000000+P_011000111*QR_000011000001+a2P_011000000_1*QR_000011000002+P_111000011*QR_000011000100+P_111000111*QR_000011000101+a2P_111000000_1*QR_000011000102+a2P_000000011_1*QR_000011000200+a2P_000000111_1*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+21]+=Pmtrx[5]*(P_011000011*QR_000010001000+P_011000111*QR_000010001001+a2P_011000000_1*QR_000010001002+P_111000011*QR_000010001100+P_111000111*QR_000010001101+a2P_111000000_1*QR_000010001102+a2P_000000011_1*QR_000010001200+a2P_000000111_1*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+21]+=Pmtrx[6]*(P_011000011*QR_001000010000+P_011000111*QR_001000010001+a2P_011000000_1*QR_001000010002+P_111000011*QR_001000010100+P_111000111*QR_001000010101+a2P_111000000_1*QR_001000010102+a2P_000000011_1*QR_001000010200+a2P_000000111_1*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+21]+=Pmtrx[7]*(P_011000011*QR_000001010000+P_011000111*QR_000001010001+a2P_011000000_1*QR_000001010002+P_111000011*QR_000001010100+P_111000111*QR_000001010101+a2P_111000000_1*QR_000001010102+a2P_000000011_1*QR_000001010200+a2P_000000111_1*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+21]+=Pmtrx[8]*(P_011000011*QR_000000011000+P_011000111*QR_000000011001+a2P_011000000_1*QR_000000011002+P_111000011*QR_000000011100+P_111000111*QR_000000011101+a2P_111000000_1*QR_000000011102+a2P_000000011_1*QR_000000011200+a2P_000000111_1*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+22]+=Pmtrx[0]*(P_010001011*QR_011000000000+P_010001111*QR_011000000001+a2P_010001000_1*QR_011000000002+a1P_010000011_1*QR_011000000010+a1P_010000111_1*QR_011000000011+a3P_010000000_1*QR_011000000012+a1P_000001011_1*QR_011000000100+a1P_000001111_1*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+22]+=Pmtrx[1]*(P_010001011*QR_010001000000+P_010001111*QR_010001000001+a2P_010001000_1*QR_010001000002+a1P_010000011_1*QR_010001000010+a1P_010000111_1*QR_010001000011+a3P_010000000_1*QR_010001000012+a1P_000001011_1*QR_010001000100+a1P_000001111_1*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+22]+=Pmtrx[2]*(P_010001011*QR_010000001000+P_010001111*QR_010000001001+a2P_010001000_1*QR_010000001002+a1P_010000011_1*QR_010000001010+a1P_010000111_1*QR_010000001011+a3P_010000000_1*QR_010000001012+a1P_000001011_1*QR_010000001100+a1P_000001111_1*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+22]+=Pmtrx[3]*(P_010001011*QR_001010000000+P_010001111*QR_001010000001+a2P_010001000_1*QR_001010000002+a1P_010000011_1*QR_001010000010+a1P_010000111_1*QR_001010000011+a3P_010000000_1*QR_001010000012+a1P_000001011_1*QR_001010000100+a1P_000001111_1*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+22]+=Pmtrx[4]*(P_010001011*QR_000011000000+P_010001111*QR_000011000001+a2P_010001000_1*QR_000011000002+a1P_010000011_1*QR_000011000010+a1P_010000111_1*QR_000011000011+a3P_010000000_1*QR_000011000012+a1P_000001011_1*QR_000011000100+a1P_000001111_1*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+22]+=Pmtrx[5]*(P_010001011*QR_000010001000+P_010001111*QR_000010001001+a2P_010001000_1*QR_000010001002+a1P_010000011_1*QR_000010001010+a1P_010000111_1*QR_000010001011+a3P_010000000_1*QR_000010001012+a1P_000001011_1*QR_000010001100+a1P_000001111_1*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+22]+=Pmtrx[6]*(P_010001011*QR_001000010000+P_010001111*QR_001000010001+a2P_010001000_1*QR_001000010002+a1P_010000011_1*QR_001000010010+a1P_010000111_1*QR_001000010011+a3P_010000000_1*QR_001000010012+a1P_000001011_1*QR_001000010100+a1P_000001111_1*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+22]+=Pmtrx[7]*(P_010001011*QR_000001010000+P_010001111*QR_000001010001+a2P_010001000_1*QR_000001010002+a1P_010000011_1*QR_000001010010+a1P_010000111_1*QR_000001010011+a3P_010000000_1*QR_000001010012+a1P_000001011_1*QR_000001010100+a1P_000001111_1*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+22]+=Pmtrx[8]*(P_010001011*QR_000000011000+P_010001111*QR_000000011001+a2P_010001000_1*QR_000000011002+a1P_010000011_1*QR_000000011010+a1P_010000111_1*QR_000000011011+a3P_010000000_1*QR_000000011012+a1P_000001011_1*QR_000000011100+a1P_000001111_1*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+23]+=Pmtrx[0]*(P_010000012*QR_011000000000+P_010000112*QR_011000000001+P_010000212*QR_011000000002+a3P_010000000_1*QR_011000000003+a1P_000000012_1*QR_011000000100+a1P_000000112_1*QR_011000000101+a1P_000000212_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+23]+=Pmtrx[1]*(P_010000012*QR_010001000000+P_010000112*QR_010001000001+P_010000212*QR_010001000002+a3P_010000000_1*QR_010001000003+a1P_000000012_1*QR_010001000100+a1P_000000112_1*QR_010001000101+a1P_000000212_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+23]+=Pmtrx[2]*(P_010000012*QR_010000001000+P_010000112*QR_010000001001+P_010000212*QR_010000001002+a3P_010000000_1*QR_010000001003+a1P_000000012_1*QR_010000001100+a1P_000000112_1*QR_010000001101+a1P_000000212_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+23]+=Pmtrx[3]*(P_010000012*QR_001010000000+P_010000112*QR_001010000001+P_010000212*QR_001010000002+a3P_010000000_1*QR_001010000003+a1P_000000012_1*QR_001010000100+a1P_000000112_1*QR_001010000101+a1P_000000212_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+23]+=Pmtrx[4]*(P_010000012*QR_000011000000+P_010000112*QR_000011000001+P_010000212*QR_000011000002+a3P_010000000_1*QR_000011000003+a1P_000000012_1*QR_000011000100+a1P_000000112_1*QR_000011000101+a1P_000000212_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+23]+=Pmtrx[5]*(P_010000012*QR_000010001000+P_010000112*QR_000010001001+P_010000212*QR_000010001002+a3P_010000000_1*QR_000010001003+a1P_000000012_1*QR_000010001100+a1P_000000112_1*QR_000010001101+a1P_000000212_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+23]+=Pmtrx[6]*(P_010000012*QR_001000010000+P_010000112*QR_001000010001+P_010000212*QR_001000010002+a3P_010000000_1*QR_001000010003+a1P_000000012_1*QR_001000010100+a1P_000000112_1*QR_001000010101+a1P_000000212_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+23]+=Pmtrx[7]*(P_010000012*QR_000001010000+P_010000112*QR_000001010001+P_010000212*QR_000001010002+a3P_010000000_1*QR_000001010003+a1P_000000012_1*QR_000001010100+a1P_000000112_1*QR_000001010101+a1P_000000212_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+23]+=Pmtrx[8]*(P_010000012*QR_000000011000+P_010000112*QR_000000011001+P_010000212*QR_000000011002+a3P_010000000_1*QR_000000011003+a1P_000000012_1*QR_000000011100+a1P_000000112_1*QR_000000011101+a1P_000000212_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+24]+=Pmtrx[0]*(P_002010010*QR_011000000000+a1P_002010000_1*QR_011000000001+a1P_002000010_1*QR_011000000010+a2P_002000000_1*QR_011000000011+a1P_001010010_2*QR_011000000100+a2P_001010000_2*QR_011000000101+a2P_001000010_2*QR_011000000110+a3P_001000000_2*QR_011000000111+a2P_000010010_1*QR_011000000200+a3P_000010000_1*QR_011000000201+a3P_000000010_1*QR_011000000210+aPin4*QR_011000000211);
ans_temp[ans_id*36+24]+=Pmtrx[1]*(P_002010010*QR_010001000000+a1P_002010000_1*QR_010001000001+a1P_002000010_1*QR_010001000010+a2P_002000000_1*QR_010001000011+a1P_001010010_2*QR_010001000100+a2P_001010000_2*QR_010001000101+a2P_001000010_2*QR_010001000110+a3P_001000000_2*QR_010001000111+a2P_000010010_1*QR_010001000200+a3P_000010000_1*QR_010001000201+a3P_000000010_1*QR_010001000210+aPin4*QR_010001000211);
ans_temp[ans_id*36+24]+=Pmtrx[2]*(P_002010010*QR_010000001000+a1P_002010000_1*QR_010000001001+a1P_002000010_1*QR_010000001010+a2P_002000000_1*QR_010000001011+a1P_001010010_2*QR_010000001100+a2P_001010000_2*QR_010000001101+a2P_001000010_2*QR_010000001110+a3P_001000000_2*QR_010000001111+a2P_000010010_1*QR_010000001200+a3P_000010000_1*QR_010000001201+a3P_000000010_1*QR_010000001210+aPin4*QR_010000001211);
ans_temp[ans_id*36+24]+=Pmtrx[3]*(P_002010010*QR_001010000000+a1P_002010000_1*QR_001010000001+a1P_002000010_1*QR_001010000010+a2P_002000000_1*QR_001010000011+a1P_001010010_2*QR_001010000100+a2P_001010000_2*QR_001010000101+a2P_001000010_2*QR_001010000110+a3P_001000000_2*QR_001010000111+a2P_000010010_1*QR_001010000200+a3P_000010000_1*QR_001010000201+a3P_000000010_1*QR_001010000210+aPin4*QR_001010000211);
ans_temp[ans_id*36+24]+=Pmtrx[4]*(P_002010010*QR_000011000000+a1P_002010000_1*QR_000011000001+a1P_002000010_1*QR_000011000010+a2P_002000000_1*QR_000011000011+a1P_001010010_2*QR_000011000100+a2P_001010000_2*QR_000011000101+a2P_001000010_2*QR_000011000110+a3P_001000000_2*QR_000011000111+a2P_000010010_1*QR_000011000200+a3P_000010000_1*QR_000011000201+a3P_000000010_1*QR_000011000210+aPin4*QR_000011000211);
ans_temp[ans_id*36+24]+=Pmtrx[5]*(P_002010010*QR_000010001000+a1P_002010000_1*QR_000010001001+a1P_002000010_1*QR_000010001010+a2P_002000000_1*QR_000010001011+a1P_001010010_2*QR_000010001100+a2P_001010000_2*QR_000010001101+a2P_001000010_2*QR_000010001110+a3P_001000000_2*QR_000010001111+a2P_000010010_1*QR_000010001200+a3P_000010000_1*QR_000010001201+a3P_000000010_1*QR_000010001210+aPin4*QR_000010001211);
ans_temp[ans_id*36+24]+=Pmtrx[6]*(P_002010010*QR_001000010000+a1P_002010000_1*QR_001000010001+a1P_002000010_1*QR_001000010010+a2P_002000000_1*QR_001000010011+a1P_001010010_2*QR_001000010100+a2P_001010000_2*QR_001000010101+a2P_001000010_2*QR_001000010110+a3P_001000000_2*QR_001000010111+a2P_000010010_1*QR_001000010200+a3P_000010000_1*QR_001000010201+a3P_000000010_1*QR_001000010210+aPin4*QR_001000010211);
ans_temp[ans_id*36+24]+=Pmtrx[7]*(P_002010010*QR_000001010000+a1P_002010000_1*QR_000001010001+a1P_002000010_1*QR_000001010010+a2P_002000000_1*QR_000001010011+a1P_001010010_2*QR_000001010100+a2P_001010000_2*QR_000001010101+a2P_001000010_2*QR_000001010110+a3P_001000000_2*QR_000001010111+a2P_000010010_1*QR_000001010200+a3P_000010000_1*QR_000001010201+a3P_000000010_1*QR_000001010210+aPin4*QR_000001010211);
ans_temp[ans_id*36+24]+=Pmtrx[8]*(P_002010010*QR_000000011000+a1P_002010000_1*QR_000000011001+a1P_002000010_1*QR_000000011010+a2P_002000000_1*QR_000000011011+a1P_001010010_2*QR_000000011100+a2P_001010000_2*QR_000000011101+a2P_001000010_2*QR_000000011110+a3P_001000000_2*QR_000000011111+a2P_000010010_1*QR_000000011200+a3P_000010000_1*QR_000000011201+a3P_000000010_1*QR_000000011210+aPin4*QR_000000011211);
ans_temp[ans_id*36+25]+=Pmtrx[0]*(P_001011010*QR_011000000000+a1P_001011000_1*QR_011000000001+P_001111010*QR_011000000010+a1P_001111000_1*QR_011000000011+a2P_001000010_1*QR_011000000020+a3P_001000000_1*QR_011000000021+a1P_000011010_1*QR_011000000100+a2P_000011000_1*QR_011000000101+a1P_000111010_1*QR_011000000110+a2P_000111000_1*QR_011000000111+a3P_000000010_1*QR_011000000120+aPin4*QR_011000000121);
ans_temp[ans_id*36+25]+=Pmtrx[1]*(P_001011010*QR_010001000000+a1P_001011000_1*QR_010001000001+P_001111010*QR_010001000010+a1P_001111000_1*QR_010001000011+a2P_001000010_1*QR_010001000020+a3P_001000000_1*QR_010001000021+a1P_000011010_1*QR_010001000100+a2P_000011000_1*QR_010001000101+a1P_000111010_1*QR_010001000110+a2P_000111000_1*QR_010001000111+a3P_000000010_1*QR_010001000120+aPin4*QR_010001000121);
ans_temp[ans_id*36+25]+=Pmtrx[2]*(P_001011010*QR_010000001000+a1P_001011000_1*QR_010000001001+P_001111010*QR_010000001010+a1P_001111000_1*QR_010000001011+a2P_001000010_1*QR_010000001020+a3P_001000000_1*QR_010000001021+a1P_000011010_1*QR_010000001100+a2P_000011000_1*QR_010000001101+a1P_000111010_1*QR_010000001110+a2P_000111000_1*QR_010000001111+a3P_000000010_1*QR_010000001120+aPin4*QR_010000001121);
ans_temp[ans_id*36+25]+=Pmtrx[3]*(P_001011010*QR_001010000000+a1P_001011000_1*QR_001010000001+P_001111010*QR_001010000010+a1P_001111000_1*QR_001010000011+a2P_001000010_1*QR_001010000020+a3P_001000000_1*QR_001010000021+a1P_000011010_1*QR_001010000100+a2P_000011000_1*QR_001010000101+a1P_000111010_1*QR_001010000110+a2P_000111000_1*QR_001010000111+a3P_000000010_1*QR_001010000120+aPin4*QR_001010000121);
ans_temp[ans_id*36+25]+=Pmtrx[4]*(P_001011010*QR_000011000000+a1P_001011000_1*QR_000011000001+P_001111010*QR_000011000010+a1P_001111000_1*QR_000011000011+a2P_001000010_1*QR_000011000020+a3P_001000000_1*QR_000011000021+a1P_000011010_1*QR_000011000100+a2P_000011000_1*QR_000011000101+a1P_000111010_1*QR_000011000110+a2P_000111000_1*QR_000011000111+a3P_000000010_1*QR_000011000120+aPin4*QR_000011000121);
ans_temp[ans_id*36+25]+=Pmtrx[5]*(P_001011010*QR_000010001000+a1P_001011000_1*QR_000010001001+P_001111010*QR_000010001010+a1P_001111000_1*QR_000010001011+a2P_001000010_1*QR_000010001020+a3P_001000000_1*QR_000010001021+a1P_000011010_1*QR_000010001100+a2P_000011000_1*QR_000010001101+a1P_000111010_1*QR_000010001110+a2P_000111000_1*QR_000010001111+a3P_000000010_1*QR_000010001120+aPin4*QR_000010001121);
ans_temp[ans_id*36+25]+=Pmtrx[6]*(P_001011010*QR_001000010000+a1P_001011000_1*QR_001000010001+P_001111010*QR_001000010010+a1P_001111000_1*QR_001000010011+a2P_001000010_1*QR_001000010020+a3P_001000000_1*QR_001000010021+a1P_000011010_1*QR_001000010100+a2P_000011000_1*QR_001000010101+a1P_000111010_1*QR_001000010110+a2P_000111000_1*QR_001000010111+a3P_000000010_1*QR_001000010120+aPin4*QR_001000010121);
ans_temp[ans_id*36+25]+=Pmtrx[7]*(P_001011010*QR_000001010000+a1P_001011000_1*QR_000001010001+P_001111010*QR_000001010010+a1P_001111000_1*QR_000001010011+a2P_001000010_1*QR_000001010020+a3P_001000000_1*QR_000001010021+a1P_000011010_1*QR_000001010100+a2P_000011000_1*QR_000001010101+a1P_000111010_1*QR_000001010110+a2P_000111000_1*QR_000001010111+a3P_000000010_1*QR_000001010120+aPin4*QR_000001010121);
ans_temp[ans_id*36+25]+=Pmtrx[8]*(P_001011010*QR_000000011000+a1P_001011000_1*QR_000000011001+P_001111010*QR_000000011010+a1P_001111000_1*QR_000000011011+a2P_001000010_1*QR_000000011020+a3P_001000000_1*QR_000000011021+a1P_000011010_1*QR_000000011100+a2P_000011000_1*QR_000000011101+a1P_000111010_1*QR_000000011110+a2P_000111000_1*QR_000000011111+a3P_000000010_1*QR_000000011120+aPin4*QR_000000011121);
ans_temp[ans_id*36+26]+=Pmtrx[0]*(P_000012010*QR_011000000000+a1P_000012000_1*QR_011000000001+P_000112010*QR_011000000010+a1P_000112000_1*QR_011000000011+P_000212010*QR_011000000020+a1P_000212000_1*QR_011000000021+a3P_000000010_1*QR_011000000030+aPin4*QR_011000000031);
ans_temp[ans_id*36+26]+=Pmtrx[1]*(P_000012010*QR_010001000000+a1P_000012000_1*QR_010001000001+P_000112010*QR_010001000010+a1P_000112000_1*QR_010001000011+P_000212010*QR_010001000020+a1P_000212000_1*QR_010001000021+a3P_000000010_1*QR_010001000030+aPin4*QR_010001000031);
ans_temp[ans_id*36+26]+=Pmtrx[2]*(P_000012010*QR_010000001000+a1P_000012000_1*QR_010000001001+P_000112010*QR_010000001010+a1P_000112000_1*QR_010000001011+P_000212010*QR_010000001020+a1P_000212000_1*QR_010000001021+a3P_000000010_1*QR_010000001030+aPin4*QR_010000001031);
ans_temp[ans_id*36+26]+=Pmtrx[3]*(P_000012010*QR_001010000000+a1P_000012000_1*QR_001010000001+P_000112010*QR_001010000010+a1P_000112000_1*QR_001010000011+P_000212010*QR_001010000020+a1P_000212000_1*QR_001010000021+a3P_000000010_1*QR_001010000030+aPin4*QR_001010000031);
ans_temp[ans_id*36+26]+=Pmtrx[4]*(P_000012010*QR_000011000000+a1P_000012000_1*QR_000011000001+P_000112010*QR_000011000010+a1P_000112000_1*QR_000011000011+P_000212010*QR_000011000020+a1P_000212000_1*QR_000011000021+a3P_000000010_1*QR_000011000030+aPin4*QR_000011000031);
ans_temp[ans_id*36+26]+=Pmtrx[5]*(P_000012010*QR_000010001000+a1P_000012000_1*QR_000010001001+P_000112010*QR_000010001010+a1P_000112000_1*QR_000010001011+P_000212010*QR_000010001020+a1P_000212000_1*QR_000010001021+a3P_000000010_1*QR_000010001030+aPin4*QR_000010001031);
ans_temp[ans_id*36+26]+=Pmtrx[6]*(P_000012010*QR_001000010000+a1P_000012000_1*QR_001000010001+P_000112010*QR_001000010010+a1P_000112000_1*QR_001000010011+P_000212010*QR_001000010020+a1P_000212000_1*QR_001000010021+a3P_000000010_1*QR_001000010030+aPin4*QR_001000010031);
ans_temp[ans_id*36+26]+=Pmtrx[7]*(P_000012010*QR_000001010000+a1P_000012000_1*QR_000001010001+P_000112010*QR_000001010010+a1P_000112000_1*QR_000001010011+P_000212010*QR_000001010020+a1P_000212000_1*QR_000001010021+a3P_000000010_1*QR_000001010030+aPin4*QR_000001010031);
ans_temp[ans_id*36+26]+=Pmtrx[8]*(P_000012010*QR_000000011000+a1P_000012000_1*QR_000000011001+P_000112010*QR_000000011010+a1P_000112000_1*QR_000000011011+P_000212010*QR_000000011020+a1P_000212000_1*QR_000000011021+a3P_000000010_1*QR_000000011030+aPin4*QR_000000011031);
ans_temp[ans_id*36+27]+=Pmtrx[0]*(P_001010011*QR_011000000000+P_001010111*QR_011000000001+a2P_001010000_1*QR_011000000002+a1P_001000011_1*QR_011000000010+a1P_001000111_1*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000010011_1*QR_011000000100+a1P_000010111_1*QR_011000000101+a3P_000010000_1*QR_011000000102+a2P_000000011_1*QR_011000000110+a2P_000000111_1*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+27]+=Pmtrx[1]*(P_001010011*QR_010001000000+P_001010111*QR_010001000001+a2P_001010000_1*QR_010001000002+a1P_001000011_1*QR_010001000010+a1P_001000111_1*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000010011_1*QR_010001000100+a1P_000010111_1*QR_010001000101+a3P_000010000_1*QR_010001000102+a2P_000000011_1*QR_010001000110+a2P_000000111_1*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+27]+=Pmtrx[2]*(P_001010011*QR_010000001000+P_001010111*QR_010000001001+a2P_001010000_1*QR_010000001002+a1P_001000011_1*QR_010000001010+a1P_001000111_1*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000010011_1*QR_010000001100+a1P_000010111_1*QR_010000001101+a3P_000010000_1*QR_010000001102+a2P_000000011_1*QR_010000001110+a2P_000000111_1*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+27]+=Pmtrx[3]*(P_001010011*QR_001010000000+P_001010111*QR_001010000001+a2P_001010000_1*QR_001010000002+a1P_001000011_1*QR_001010000010+a1P_001000111_1*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000010011_1*QR_001010000100+a1P_000010111_1*QR_001010000101+a3P_000010000_1*QR_001010000102+a2P_000000011_1*QR_001010000110+a2P_000000111_1*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+27]+=Pmtrx[4]*(P_001010011*QR_000011000000+P_001010111*QR_000011000001+a2P_001010000_1*QR_000011000002+a1P_001000011_1*QR_000011000010+a1P_001000111_1*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000010011_1*QR_000011000100+a1P_000010111_1*QR_000011000101+a3P_000010000_1*QR_000011000102+a2P_000000011_1*QR_000011000110+a2P_000000111_1*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+27]+=Pmtrx[5]*(P_001010011*QR_000010001000+P_001010111*QR_000010001001+a2P_001010000_1*QR_000010001002+a1P_001000011_1*QR_000010001010+a1P_001000111_1*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000010011_1*QR_000010001100+a1P_000010111_1*QR_000010001101+a3P_000010000_1*QR_000010001102+a2P_000000011_1*QR_000010001110+a2P_000000111_1*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+27]+=Pmtrx[6]*(P_001010011*QR_001000010000+P_001010111*QR_001000010001+a2P_001010000_1*QR_001000010002+a1P_001000011_1*QR_001000010010+a1P_001000111_1*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000010011_1*QR_001000010100+a1P_000010111_1*QR_001000010101+a3P_000010000_1*QR_001000010102+a2P_000000011_1*QR_001000010110+a2P_000000111_1*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+27]+=Pmtrx[7]*(P_001010011*QR_000001010000+P_001010111*QR_000001010001+a2P_001010000_1*QR_000001010002+a1P_001000011_1*QR_000001010010+a1P_001000111_1*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000010011_1*QR_000001010100+a1P_000010111_1*QR_000001010101+a3P_000010000_1*QR_000001010102+a2P_000000011_1*QR_000001010110+a2P_000000111_1*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+27]+=Pmtrx[8]*(P_001010011*QR_000000011000+P_001010111*QR_000000011001+a2P_001010000_1*QR_000000011002+a1P_001000011_1*QR_000000011010+a1P_001000111_1*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000010011_1*QR_000000011100+a1P_000010111_1*QR_000000011101+a3P_000010000_1*QR_000000011102+a2P_000000011_1*QR_000000011110+a2P_000000111_1*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+28]+=Pmtrx[0]*(P_000011011*QR_011000000000+P_000011111*QR_011000000001+a2P_000011000_1*QR_011000000002+P_000111011*QR_011000000010+P_000111111*QR_011000000011+a2P_000111000_1*QR_011000000012+a2P_000000011_1*QR_011000000020+a2P_000000111_1*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+28]+=Pmtrx[1]*(P_000011011*QR_010001000000+P_000011111*QR_010001000001+a2P_000011000_1*QR_010001000002+P_000111011*QR_010001000010+P_000111111*QR_010001000011+a2P_000111000_1*QR_010001000012+a2P_000000011_1*QR_010001000020+a2P_000000111_1*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+28]+=Pmtrx[2]*(P_000011011*QR_010000001000+P_000011111*QR_010000001001+a2P_000011000_1*QR_010000001002+P_000111011*QR_010000001010+P_000111111*QR_010000001011+a2P_000111000_1*QR_010000001012+a2P_000000011_1*QR_010000001020+a2P_000000111_1*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+28]+=Pmtrx[3]*(P_000011011*QR_001010000000+P_000011111*QR_001010000001+a2P_000011000_1*QR_001010000002+P_000111011*QR_001010000010+P_000111111*QR_001010000011+a2P_000111000_1*QR_001010000012+a2P_000000011_1*QR_001010000020+a2P_000000111_1*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+28]+=Pmtrx[4]*(P_000011011*QR_000011000000+P_000011111*QR_000011000001+a2P_000011000_1*QR_000011000002+P_000111011*QR_000011000010+P_000111111*QR_000011000011+a2P_000111000_1*QR_000011000012+a2P_000000011_1*QR_000011000020+a2P_000000111_1*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+28]+=Pmtrx[5]*(P_000011011*QR_000010001000+P_000011111*QR_000010001001+a2P_000011000_1*QR_000010001002+P_000111011*QR_000010001010+P_000111111*QR_000010001011+a2P_000111000_1*QR_000010001012+a2P_000000011_1*QR_000010001020+a2P_000000111_1*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+28]+=Pmtrx[6]*(P_000011011*QR_001000010000+P_000011111*QR_001000010001+a2P_000011000_1*QR_001000010002+P_000111011*QR_001000010010+P_000111111*QR_001000010011+a2P_000111000_1*QR_001000010012+a2P_000000011_1*QR_001000010020+a2P_000000111_1*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+28]+=Pmtrx[7]*(P_000011011*QR_000001010000+P_000011111*QR_000001010001+a2P_000011000_1*QR_000001010002+P_000111011*QR_000001010010+P_000111111*QR_000001010011+a2P_000111000_1*QR_000001010012+a2P_000000011_1*QR_000001010020+a2P_000000111_1*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+28]+=Pmtrx[8]*(P_000011011*QR_000000011000+P_000011111*QR_000000011001+a2P_000011000_1*QR_000000011002+P_000111011*QR_000000011010+P_000111111*QR_000000011011+a2P_000111000_1*QR_000000011012+a2P_000000011_1*QR_000000011020+a2P_000000111_1*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+29]+=Pmtrx[0]*(P_000010012*QR_011000000000+P_000010112*QR_011000000001+P_000010212*QR_011000000002+a3P_000010000_1*QR_011000000003+a1P_000000012_1*QR_011000000010+a1P_000000112_1*QR_011000000011+a1P_000000212_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+29]+=Pmtrx[1]*(P_000010012*QR_010001000000+P_000010112*QR_010001000001+P_000010212*QR_010001000002+a3P_000010000_1*QR_010001000003+a1P_000000012_1*QR_010001000010+a1P_000000112_1*QR_010001000011+a1P_000000212_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+29]+=Pmtrx[2]*(P_000010012*QR_010000001000+P_000010112*QR_010000001001+P_000010212*QR_010000001002+a3P_000010000_1*QR_010000001003+a1P_000000012_1*QR_010000001010+a1P_000000112_1*QR_010000001011+a1P_000000212_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+29]+=Pmtrx[3]*(P_000010012*QR_001010000000+P_000010112*QR_001010000001+P_000010212*QR_001010000002+a3P_000010000_1*QR_001010000003+a1P_000000012_1*QR_001010000010+a1P_000000112_1*QR_001010000011+a1P_000000212_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+29]+=Pmtrx[4]*(P_000010012*QR_000011000000+P_000010112*QR_000011000001+P_000010212*QR_000011000002+a3P_000010000_1*QR_000011000003+a1P_000000012_1*QR_000011000010+a1P_000000112_1*QR_000011000011+a1P_000000212_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+29]+=Pmtrx[5]*(P_000010012*QR_000010001000+P_000010112*QR_000010001001+P_000010212*QR_000010001002+a3P_000010000_1*QR_000010001003+a1P_000000012_1*QR_000010001010+a1P_000000112_1*QR_000010001011+a1P_000000212_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+29]+=Pmtrx[6]*(P_000010012*QR_001000010000+P_000010112*QR_001000010001+P_000010212*QR_001000010002+a3P_000010000_1*QR_001000010003+a1P_000000012_1*QR_001000010010+a1P_000000112_1*QR_001000010011+a1P_000000212_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+29]+=Pmtrx[7]*(P_000010012*QR_000001010000+P_000010112*QR_000001010001+P_000010212*QR_000001010002+a3P_000010000_1*QR_000001010003+a1P_000000012_1*QR_000001010010+a1P_000000112_1*QR_000001010011+a1P_000000212_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+29]+=Pmtrx[8]*(P_000010012*QR_000000011000+P_000010112*QR_000000011001+P_000010212*QR_000000011002+a3P_000010000_1*QR_000000011003+a1P_000000012_1*QR_000000011010+a1P_000000112_1*QR_000000011011+a1P_000000212_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+30]+=Pmtrx[0]*(P_002000020*QR_011000000000+a1P_002000010_2*QR_011000000001+a2P_002000000_1*QR_011000000002+a1P_001000020_2*QR_011000000100+a2P_001000010_4*QR_011000000101+a3P_001000000_2*QR_011000000102+a2P_000000020_1*QR_011000000200+a3P_000000010_2*QR_011000000201+aPin4*QR_011000000202);
ans_temp[ans_id*36+30]+=Pmtrx[1]*(P_002000020*QR_010001000000+a1P_002000010_2*QR_010001000001+a2P_002000000_1*QR_010001000002+a1P_001000020_2*QR_010001000100+a2P_001000010_4*QR_010001000101+a3P_001000000_2*QR_010001000102+a2P_000000020_1*QR_010001000200+a3P_000000010_2*QR_010001000201+aPin4*QR_010001000202);
ans_temp[ans_id*36+30]+=Pmtrx[2]*(P_002000020*QR_010000001000+a1P_002000010_2*QR_010000001001+a2P_002000000_1*QR_010000001002+a1P_001000020_2*QR_010000001100+a2P_001000010_4*QR_010000001101+a3P_001000000_2*QR_010000001102+a2P_000000020_1*QR_010000001200+a3P_000000010_2*QR_010000001201+aPin4*QR_010000001202);
ans_temp[ans_id*36+30]+=Pmtrx[3]*(P_002000020*QR_001010000000+a1P_002000010_2*QR_001010000001+a2P_002000000_1*QR_001010000002+a1P_001000020_2*QR_001010000100+a2P_001000010_4*QR_001010000101+a3P_001000000_2*QR_001010000102+a2P_000000020_1*QR_001010000200+a3P_000000010_2*QR_001010000201+aPin4*QR_001010000202);
ans_temp[ans_id*36+30]+=Pmtrx[4]*(P_002000020*QR_000011000000+a1P_002000010_2*QR_000011000001+a2P_002000000_1*QR_000011000002+a1P_001000020_2*QR_000011000100+a2P_001000010_4*QR_000011000101+a3P_001000000_2*QR_000011000102+a2P_000000020_1*QR_000011000200+a3P_000000010_2*QR_000011000201+aPin4*QR_000011000202);
ans_temp[ans_id*36+30]+=Pmtrx[5]*(P_002000020*QR_000010001000+a1P_002000010_2*QR_000010001001+a2P_002000000_1*QR_000010001002+a1P_001000020_2*QR_000010001100+a2P_001000010_4*QR_000010001101+a3P_001000000_2*QR_000010001102+a2P_000000020_1*QR_000010001200+a3P_000000010_2*QR_000010001201+aPin4*QR_000010001202);
ans_temp[ans_id*36+30]+=Pmtrx[6]*(P_002000020*QR_001000010000+a1P_002000010_2*QR_001000010001+a2P_002000000_1*QR_001000010002+a1P_001000020_2*QR_001000010100+a2P_001000010_4*QR_001000010101+a3P_001000000_2*QR_001000010102+a2P_000000020_1*QR_001000010200+a3P_000000010_2*QR_001000010201+aPin4*QR_001000010202);
ans_temp[ans_id*36+30]+=Pmtrx[7]*(P_002000020*QR_000001010000+a1P_002000010_2*QR_000001010001+a2P_002000000_1*QR_000001010002+a1P_001000020_2*QR_000001010100+a2P_001000010_4*QR_000001010101+a3P_001000000_2*QR_000001010102+a2P_000000020_1*QR_000001010200+a3P_000000010_2*QR_000001010201+aPin4*QR_000001010202);
ans_temp[ans_id*36+30]+=Pmtrx[8]*(P_002000020*QR_000000011000+a1P_002000010_2*QR_000000011001+a2P_002000000_1*QR_000000011002+a1P_001000020_2*QR_000000011100+a2P_001000010_4*QR_000000011101+a3P_001000000_2*QR_000000011102+a2P_000000020_1*QR_000000011200+a3P_000000010_2*QR_000000011201+aPin4*QR_000000011202);
ans_temp[ans_id*36+31]+=Pmtrx[0]*(P_001001020*QR_011000000000+a1P_001001010_2*QR_011000000001+a2P_001001000_1*QR_011000000002+a1P_001000020_1*QR_011000000010+a2P_001000010_2*QR_011000000011+a3P_001000000_1*QR_011000000012+a1P_000001020_1*QR_011000000100+a2P_000001010_2*QR_011000000101+a3P_000001000_1*QR_011000000102+a2P_000000020_1*QR_011000000110+a3P_000000010_2*QR_011000000111+aPin4*QR_011000000112);
ans_temp[ans_id*36+31]+=Pmtrx[1]*(P_001001020*QR_010001000000+a1P_001001010_2*QR_010001000001+a2P_001001000_1*QR_010001000002+a1P_001000020_1*QR_010001000010+a2P_001000010_2*QR_010001000011+a3P_001000000_1*QR_010001000012+a1P_000001020_1*QR_010001000100+a2P_000001010_2*QR_010001000101+a3P_000001000_1*QR_010001000102+a2P_000000020_1*QR_010001000110+a3P_000000010_2*QR_010001000111+aPin4*QR_010001000112);
ans_temp[ans_id*36+31]+=Pmtrx[2]*(P_001001020*QR_010000001000+a1P_001001010_2*QR_010000001001+a2P_001001000_1*QR_010000001002+a1P_001000020_1*QR_010000001010+a2P_001000010_2*QR_010000001011+a3P_001000000_1*QR_010000001012+a1P_000001020_1*QR_010000001100+a2P_000001010_2*QR_010000001101+a3P_000001000_1*QR_010000001102+a2P_000000020_1*QR_010000001110+a3P_000000010_2*QR_010000001111+aPin4*QR_010000001112);
ans_temp[ans_id*36+31]+=Pmtrx[3]*(P_001001020*QR_001010000000+a1P_001001010_2*QR_001010000001+a2P_001001000_1*QR_001010000002+a1P_001000020_1*QR_001010000010+a2P_001000010_2*QR_001010000011+a3P_001000000_1*QR_001010000012+a1P_000001020_1*QR_001010000100+a2P_000001010_2*QR_001010000101+a3P_000001000_1*QR_001010000102+a2P_000000020_1*QR_001010000110+a3P_000000010_2*QR_001010000111+aPin4*QR_001010000112);
ans_temp[ans_id*36+31]+=Pmtrx[4]*(P_001001020*QR_000011000000+a1P_001001010_2*QR_000011000001+a2P_001001000_1*QR_000011000002+a1P_001000020_1*QR_000011000010+a2P_001000010_2*QR_000011000011+a3P_001000000_1*QR_000011000012+a1P_000001020_1*QR_000011000100+a2P_000001010_2*QR_000011000101+a3P_000001000_1*QR_000011000102+a2P_000000020_1*QR_000011000110+a3P_000000010_2*QR_000011000111+aPin4*QR_000011000112);
ans_temp[ans_id*36+31]+=Pmtrx[5]*(P_001001020*QR_000010001000+a1P_001001010_2*QR_000010001001+a2P_001001000_1*QR_000010001002+a1P_001000020_1*QR_000010001010+a2P_001000010_2*QR_000010001011+a3P_001000000_1*QR_000010001012+a1P_000001020_1*QR_000010001100+a2P_000001010_2*QR_000010001101+a3P_000001000_1*QR_000010001102+a2P_000000020_1*QR_000010001110+a3P_000000010_2*QR_000010001111+aPin4*QR_000010001112);
ans_temp[ans_id*36+31]+=Pmtrx[6]*(P_001001020*QR_001000010000+a1P_001001010_2*QR_001000010001+a2P_001001000_1*QR_001000010002+a1P_001000020_1*QR_001000010010+a2P_001000010_2*QR_001000010011+a3P_001000000_1*QR_001000010012+a1P_000001020_1*QR_001000010100+a2P_000001010_2*QR_001000010101+a3P_000001000_1*QR_001000010102+a2P_000000020_1*QR_001000010110+a3P_000000010_2*QR_001000010111+aPin4*QR_001000010112);
ans_temp[ans_id*36+31]+=Pmtrx[7]*(P_001001020*QR_000001010000+a1P_001001010_2*QR_000001010001+a2P_001001000_1*QR_000001010002+a1P_001000020_1*QR_000001010010+a2P_001000010_2*QR_000001010011+a3P_001000000_1*QR_000001010012+a1P_000001020_1*QR_000001010100+a2P_000001010_2*QR_000001010101+a3P_000001000_1*QR_000001010102+a2P_000000020_1*QR_000001010110+a3P_000000010_2*QR_000001010111+aPin4*QR_000001010112);
ans_temp[ans_id*36+31]+=Pmtrx[8]*(P_001001020*QR_000000011000+a1P_001001010_2*QR_000000011001+a2P_001001000_1*QR_000000011002+a1P_001000020_1*QR_000000011010+a2P_001000010_2*QR_000000011011+a3P_001000000_1*QR_000000011012+a1P_000001020_1*QR_000000011100+a2P_000001010_2*QR_000000011101+a3P_000001000_1*QR_000000011102+a2P_000000020_1*QR_000000011110+a3P_000000010_2*QR_000000011111+aPin4*QR_000000011112);
ans_temp[ans_id*36+32]+=Pmtrx[0]*(P_000002020*QR_011000000000+a1P_000002010_2*QR_011000000001+a2P_000002000_1*QR_011000000002+a1P_000001020_2*QR_011000000010+a2P_000001010_4*QR_011000000011+a3P_000001000_2*QR_011000000012+a2P_000000020_1*QR_011000000020+a3P_000000010_2*QR_011000000021+aPin4*QR_011000000022);
ans_temp[ans_id*36+32]+=Pmtrx[1]*(P_000002020*QR_010001000000+a1P_000002010_2*QR_010001000001+a2P_000002000_1*QR_010001000002+a1P_000001020_2*QR_010001000010+a2P_000001010_4*QR_010001000011+a3P_000001000_2*QR_010001000012+a2P_000000020_1*QR_010001000020+a3P_000000010_2*QR_010001000021+aPin4*QR_010001000022);
ans_temp[ans_id*36+32]+=Pmtrx[2]*(P_000002020*QR_010000001000+a1P_000002010_2*QR_010000001001+a2P_000002000_1*QR_010000001002+a1P_000001020_2*QR_010000001010+a2P_000001010_4*QR_010000001011+a3P_000001000_2*QR_010000001012+a2P_000000020_1*QR_010000001020+a3P_000000010_2*QR_010000001021+aPin4*QR_010000001022);
ans_temp[ans_id*36+32]+=Pmtrx[3]*(P_000002020*QR_001010000000+a1P_000002010_2*QR_001010000001+a2P_000002000_1*QR_001010000002+a1P_000001020_2*QR_001010000010+a2P_000001010_4*QR_001010000011+a3P_000001000_2*QR_001010000012+a2P_000000020_1*QR_001010000020+a3P_000000010_2*QR_001010000021+aPin4*QR_001010000022);
ans_temp[ans_id*36+32]+=Pmtrx[4]*(P_000002020*QR_000011000000+a1P_000002010_2*QR_000011000001+a2P_000002000_1*QR_000011000002+a1P_000001020_2*QR_000011000010+a2P_000001010_4*QR_000011000011+a3P_000001000_2*QR_000011000012+a2P_000000020_1*QR_000011000020+a3P_000000010_2*QR_000011000021+aPin4*QR_000011000022);
ans_temp[ans_id*36+32]+=Pmtrx[5]*(P_000002020*QR_000010001000+a1P_000002010_2*QR_000010001001+a2P_000002000_1*QR_000010001002+a1P_000001020_2*QR_000010001010+a2P_000001010_4*QR_000010001011+a3P_000001000_2*QR_000010001012+a2P_000000020_1*QR_000010001020+a3P_000000010_2*QR_000010001021+aPin4*QR_000010001022);
ans_temp[ans_id*36+32]+=Pmtrx[6]*(P_000002020*QR_001000010000+a1P_000002010_2*QR_001000010001+a2P_000002000_1*QR_001000010002+a1P_000001020_2*QR_001000010010+a2P_000001010_4*QR_001000010011+a3P_000001000_2*QR_001000010012+a2P_000000020_1*QR_001000010020+a3P_000000010_2*QR_001000010021+aPin4*QR_001000010022);
ans_temp[ans_id*36+32]+=Pmtrx[7]*(P_000002020*QR_000001010000+a1P_000002010_2*QR_000001010001+a2P_000002000_1*QR_000001010002+a1P_000001020_2*QR_000001010010+a2P_000001010_4*QR_000001010011+a3P_000001000_2*QR_000001010012+a2P_000000020_1*QR_000001010020+a3P_000000010_2*QR_000001010021+aPin4*QR_000001010022);
ans_temp[ans_id*36+32]+=Pmtrx[8]*(P_000002020*QR_000000011000+a1P_000002010_2*QR_000000011001+a2P_000002000_1*QR_000000011002+a1P_000001020_2*QR_000000011010+a2P_000001010_4*QR_000000011011+a3P_000001000_2*QR_000000011012+a2P_000000020_1*QR_000000011020+a3P_000000010_2*QR_000000011021+aPin4*QR_000000011022);
ans_temp[ans_id*36+33]+=Pmtrx[0]*(P_001000021*QR_011000000000+P_001000121*QR_011000000001+P_001000221*QR_011000000002+a3P_001000000_1*QR_011000000003+a1P_000000021_1*QR_011000000100+a1P_000000121_1*QR_011000000101+a1P_000000221_1*QR_011000000102+aPin4*QR_011000000103);
ans_temp[ans_id*36+33]+=Pmtrx[1]*(P_001000021*QR_010001000000+P_001000121*QR_010001000001+P_001000221*QR_010001000002+a3P_001000000_1*QR_010001000003+a1P_000000021_1*QR_010001000100+a1P_000000121_1*QR_010001000101+a1P_000000221_1*QR_010001000102+aPin4*QR_010001000103);
ans_temp[ans_id*36+33]+=Pmtrx[2]*(P_001000021*QR_010000001000+P_001000121*QR_010000001001+P_001000221*QR_010000001002+a3P_001000000_1*QR_010000001003+a1P_000000021_1*QR_010000001100+a1P_000000121_1*QR_010000001101+a1P_000000221_1*QR_010000001102+aPin4*QR_010000001103);
ans_temp[ans_id*36+33]+=Pmtrx[3]*(P_001000021*QR_001010000000+P_001000121*QR_001010000001+P_001000221*QR_001010000002+a3P_001000000_1*QR_001010000003+a1P_000000021_1*QR_001010000100+a1P_000000121_1*QR_001010000101+a1P_000000221_1*QR_001010000102+aPin4*QR_001010000103);
ans_temp[ans_id*36+33]+=Pmtrx[4]*(P_001000021*QR_000011000000+P_001000121*QR_000011000001+P_001000221*QR_000011000002+a3P_001000000_1*QR_000011000003+a1P_000000021_1*QR_000011000100+a1P_000000121_1*QR_000011000101+a1P_000000221_1*QR_000011000102+aPin4*QR_000011000103);
ans_temp[ans_id*36+33]+=Pmtrx[5]*(P_001000021*QR_000010001000+P_001000121*QR_000010001001+P_001000221*QR_000010001002+a3P_001000000_1*QR_000010001003+a1P_000000021_1*QR_000010001100+a1P_000000121_1*QR_000010001101+a1P_000000221_1*QR_000010001102+aPin4*QR_000010001103);
ans_temp[ans_id*36+33]+=Pmtrx[6]*(P_001000021*QR_001000010000+P_001000121*QR_001000010001+P_001000221*QR_001000010002+a3P_001000000_1*QR_001000010003+a1P_000000021_1*QR_001000010100+a1P_000000121_1*QR_001000010101+a1P_000000221_1*QR_001000010102+aPin4*QR_001000010103);
ans_temp[ans_id*36+33]+=Pmtrx[7]*(P_001000021*QR_000001010000+P_001000121*QR_000001010001+P_001000221*QR_000001010002+a3P_001000000_1*QR_000001010003+a1P_000000021_1*QR_000001010100+a1P_000000121_1*QR_000001010101+a1P_000000221_1*QR_000001010102+aPin4*QR_000001010103);
ans_temp[ans_id*36+33]+=Pmtrx[8]*(P_001000021*QR_000000011000+P_001000121*QR_000000011001+P_001000221*QR_000000011002+a3P_001000000_1*QR_000000011003+a1P_000000021_1*QR_000000011100+a1P_000000121_1*QR_000000011101+a1P_000000221_1*QR_000000011102+aPin4*QR_000000011103);
ans_temp[ans_id*36+34]+=Pmtrx[0]*(P_000001021*QR_011000000000+P_000001121*QR_011000000001+P_000001221*QR_011000000002+a3P_000001000_1*QR_011000000003+a1P_000000021_1*QR_011000000010+a1P_000000121_1*QR_011000000011+a1P_000000221_1*QR_011000000012+aPin4*QR_011000000013);
ans_temp[ans_id*36+34]+=Pmtrx[1]*(P_000001021*QR_010001000000+P_000001121*QR_010001000001+P_000001221*QR_010001000002+a3P_000001000_1*QR_010001000003+a1P_000000021_1*QR_010001000010+a1P_000000121_1*QR_010001000011+a1P_000000221_1*QR_010001000012+aPin4*QR_010001000013);
ans_temp[ans_id*36+34]+=Pmtrx[2]*(P_000001021*QR_010000001000+P_000001121*QR_010000001001+P_000001221*QR_010000001002+a3P_000001000_1*QR_010000001003+a1P_000000021_1*QR_010000001010+a1P_000000121_1*QR_010000001011+a1P_000000221_1*QR_010000001012+aPin4*QR_010000001013);
ans_temp[ans_id*36+34]+=Pmtrx[3]*(P_000001021*QR_001010000000+P_000001121*QR_001010000001+P_000001221*QR_001010000002+a3P_000001000_1*QR_001010000003+a1P_000000021_1*QR_001010000010+a1P_000000121_1*QR_001010000011+a1P_000000221_1*QR_001010000012+aPin4*QR_001010000013);
ans_temp[ans_id*36+34]+=Pmtrx[4]*(P_000001021*QR_000011000000+P_000001121*QR_000011000001+P_000001221*QR_000011000002+a3P_000001000_1*QR_000011000003+a1P_000000021_1*QR_000011000010+a1P_000000121_1*QR_000011000011+a1P_000000221_1*QR_000011000012+aPin4*QR_000011000013);
ans_temp[ans_id*36+34]+=Pmtrx[5]*(P_000001021*QR_000010001000+P_000001121*QR_000010001001+P_000001221*QR_000010001002+a3P_000001000_1*QR_000010001003+a1P_000000021_1*QR_000010001010+a1P_000000121_1*QR_000010001011+a1P_000000221_1*QR_000010001012+aPin4*QR_000010001013);
ans_temp[ans_id*36+34]+=Pmtrx[6]*(P_000001021*QR_001000010000+P_000001121*QR_001000010001+P_000001221*QR_001000010002+a3P_000001000_1*QR_001000010003+a1P_000000021_1*QR_001000010010+a1P_000000121_1*QR_001000010011+a1P_000000221_1*QR_001000010012+aPin4*QR_001000010013);
ans_temp[ans_id*36+34]+=Pmtrx[7]*(P_000001021*QR_000001010000+P_000001121*QR_000001010001+P_000001221*QR_000001010002+a3P_000001000_1*QR_000001010003+a1P_000000021_1*QR_000001010010+a1P_000000121_1*QR_000001010011+a1P_000000221_1*QR_000001010012+aPin4*QR_000001010013);
ans_temp[ans_id*36+34]+=Pmtrx[8]*(P_000001021*QR_000000011000+P_000001121*QR_000000011001+P_000001221*QR_000000011002+a3P_000001000_1*QR_000000011003+a1P_000000021_1*QR_000000011010+a1P_000000121_1*QR_000000011011+a1P_000000221_1*QR_000000011012+aPin4*QR_000000011013);
ans_temp[ans_id*36+35]+=Pmtrx[0]*(P_000000022*QR_011000000000+P_000000122*QR_011000000001+P_000000222*QR_011000000002+a2P_000000111_2*QR_011000000003+aPin4*QR_011000000004);
ans_temp[ans_id*36+35]+=Pmtrx[1]*(P_000000022*QR_010001000000+P_000000122*QR_010001000001+P_000000222*QR_010001000002+a2P_000000111_2*QR_010001000003+aPin4*QR_010001000004);
ans_temp[ans_id*36+35]+=Pmtrx[2]*(P_000000022*QR_010000001000+P_000000122*QR_010000001001+P_000000222*QR_010000001002+a2P_000000111_2*QR_010000001003+aPin4*QR_010000001004);
ans_temp[ans_id*36+35]+=Pmtrx[3]*(P_000000022*QR_001010000000+P_000000122*QR_001010000001+P_000000222*QR_001010000002+a2P_000000111_2*QR_001010000003+aPin4*QR_001010000004);
ans_temp[ans_id*36+35]+=Pmtrx[4]*(P_000000022*QR_000011000000+P_000000122*QR_000011000001+P_000000222*QR_000011000002+a2P_000000111_2*QR_000011000003+aPin4*QR_000011000004);
ans_temp[ans_id*36+35]+=Pmtrx[5]*(P_000000022*QR_000010001000+P_000000122*QR_000010001001+P_000000222*QR_000010001002+a2P_000000111_2*QR_000010001003+aPin4*QR_000010001004);
ans_temp[ans_id*36+35]+=Pmtrx[6]*(P_000000022*QR_001000010000+P_000000122*QR_001000010001+P_000000222*QR_001000010002+a2P_000000111_2*QR_001000010003+aPin4*QR_001000010004);
ans_temp[ans_id*36+35]+=Pmtrx[7]*(P_000000022*QR_000001010000+P_000000122*QR_000001010001+P_000000222*QR_000001010002+a2P_000000111_2*QR_000001010003+aPin4*QR_000001010004);
ans_temp[ans_id*36+35]+=Pmtrx[8]*(P_000000022*QR_000000011000+P_000000122*QR_000000011001+P_000000222*QR_000000011002+a2P_000000111_2*QR_000000011003+aPin4*QR_000000011004);
}
__syncthreads();
int num_thread=tdis/2;
while (num_thread!=0){
__syncthreads();
if(tId_x<num_thread){
for(int ians=0;ians<36;ians++){
ans_temp[tId_x*36+ians]+=ans_temp[(tId_x+num_thread)*36+ians];
}
}
num_thread/=2;
}
if(tId_x==0){
for(int ians=0;ians<36;ians++){
ans[i_contrc_bra*36+ians]=ans_temp[(tId_x)*36+ians];
}
}
}
}
|
31db47daaa0627dddd594c9a52e76cd574c55bcb.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "../inc/Renderer.h"
#include <cstdint>
#include <vector_functions.h>
#include <hip/hip_vector_types.h>
#include "../inc/BFSJob.h"
#include "../inc/extended_helper_math.h"
#include "../inc/float4x4.h"
#include "../inc/Light.h"
__device__
unsigned long int d_getChildCountFromMask( unsigned long int mask )
{
return ( 1ul & mask ) +
(( 2ul & mask ) >> 1 ) +
(( 4ul & mask ) >> 2 ) +
(( 8ul & mask ) >> 3 ) +
(( 16ul & mask ) >> 4 ) +
(( 32ul & mask ) >> 5 ) +
(( 64ul & mask ) >> 6 ) +
(( 128ul & mask ) >> 7 );
}
/**
* The main kernel responsible for rendering. Equivalent to the rasterizer plus vertex shader.
* The kernel is invoked with as many threads as the job queue contains elements.
* Every thread processes one job and either draws the voxel that blongs ot it or
* decides that the voxel needs further subdivision and adds new jobs to the queue
* (one for every child of the voxel).
*
* In the first case, the voxel isn't actually drawn but rather its depth and
* visual data is stored in the depth map and voxel buffer at the coordinates that
* correspond to the voxel's center. This is done because it is cheaper to scan multiple
* neighboring pixels from the depth map for a voxel than it is to write a voxel's depth into
* multiple pixels of the depth map (which requires multiple atomicMin calls).
*
* Drawing a voxel consists of projecting it into screen space and determining visibility
* through a depth buffer. The actual coloring happens at a later stage.
*
* @param innerNodeCount The number of inner nodes of the octree that is traversed.
* @param innerNodes The inner nodes of the octree.
* @param leaves The leaf nodes of the octree.
* @param dimension The dimension of the octree (cube).
* @param world The world transformation of the model the octree represents.
* @param view The view transformation of the virtual camera.
* @param projection The projection transformation of the virtual camera.
* @param animation A set of matrices encoding the bone transformations for every frame.
* @param boneCount The number of bones of the model.
* @param depthBuffer The depth buffer.
* @param voxelBuffer The voxel buffer (think input to the pixel/fragment shader).
*/
static __global__ void traverse
(
unsigned long int innerNodeCount,
BFSInnerNode const * innerNodes,
VisualData const * leaves,
float dimension,
float4x4 world, float3 camPos, float4x4 view, float4x4 projection,
float4x4 const * animation, unsigned char boneCount,
unsigned int * depthBuffer, VoxelData * voxelBuffer,
int frameWidth, int frameHeight,
int animationFrameIndex,
int octreeLevel,
int const * startIndex, int const * endIndex,
int * travQueuePtr,
BFSJob * jobQueue
)
{
unsigned long int index = blockDim.x * blockIdx.x + threadIdx.x + ( * startIndex );
short int x, y, z, w = 2;
unsigned int depth;
__shared__ unsigned int sharedTravQueuePtr;
if (threadIdx.x == 0)
sharedTravQueuePtr = 0;
__syncthreads();
if( index < ( * endIndex ) )
{
BFSJob job = jobQueue[ index ];
BFSInnerNode node;
node.childPtr = 0;
node.mask = 0;
if( job.index < innerNodeCount )
{
node = innerNodes[ job.index ];
}
else
{
node.vd = leaves[ job.index - innerNodeCount ];
}
float gridCellDim = dimension / ( (float) ( 1 << octreeLevel ) );
float gridCellHalfDim = gridCellDim * 0.5f;
float minCoord = -0.5f * dimension;
float3 center = { fmaf(job.x, gridCellDim, minCoord + gridCellHalfDim),
fmaf(job.y, gridCellDim, minCoord + gridCellHalfDim),
fmaf(job.z, gridCellDim, minCoord + gridCellHalfDim) };
float3 skinnedCenter = make_float3( 0 );
unsigned char involvedBones = 0;
if (node.vd.boneWeights.x > 0.f)
{
skinnedCenter = (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex0 ]
) * node.vd.boneWeights.x;
++involvedBones;
}
if (node.vd.boneWeights.y > 0.f)
{
skinnedCenter += (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex1 ]
) * node.vd.boneWeights.y;
++involvedBones;
}
if (node.vd.boneWeights.z > 0.f)
{
skinnedCenter += (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex2 ]
) * node.vd.boneWeights.z;
++involvedBones;
}
if (node.vd.boneWeights.w > 0.f)
{
skinnedCenter += (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex3 ]
) * node.vd.boneWeights.w;
++involvedBones;
}
center = skinnedCenter;
float3 originalCenter = center;
// resizing of voxel to counter stretching.
gridCellHalfDim *= fminf(2.f, involvedBones);
center = center * world;
float3 eyeVec = normalize( camPos - center );
center = center * view;
float3 dimVec = make_float3( gridCellHalfDim, gridCellHalfDim, center.z );
center = center * projection;
dimVec = dimVec * projection;
//viewing frustum + clockwise culling
node.vd.normal = node.vd.normal * world;
// TODO: Add check whether adding the current node's children
// to the job queue would exceed the queue's size limit
if ( -1.f <= center.x + dimVec.x && center.x - dimVec.x <= 1.f &&
-1.f <= center.y + dimVec.x && center.y - dimVec.x <= 1.f &&
0.f <= center.z + dimVec.x && center.z - dimVec.x <= 1.f &&
( octreeLevel <= 8 || dot( node.vd.normal, eyeVec ) >= -0.4f ))
{
center.x = (center.x + 1.f) * frameWidth * 0.5f;
center.y = frameHeight - (center.y + 1.f) * frameHeight * 0.5f;
dimVec.x *= frameWidth;
dimVec.y *= frameHeight;
x = center.x;
y = center.y;
x = max(x, 0);
x = min(x, frameWidth - 1);
y = max(y, 0);
y = min(y, frameHeight - 1);
depth = center.z * INT_MAX;
index = x + y * frameWidth;
if ((dimVec.x > 1.f) && (z = d_getChildCountFromMask(node.mask)) != 0)
{
index = atomicAdd(&sharedTravQueuePtr, z);
w = 0;
}
else
{
atomicMin(depthBuffer + index, depth);
w = 1;
}
}
__syncthreads();
if( threadIdx.x == 0 )
{
sharedTravQueuePtr = atomicAdd( travQueuePtr, sharedTravQueuePtr );
}
__syncthreads();
if (w == 0)
{
index += sharedTravQueuePtr;
#pragma unroll 8
for (w = 0; w < 8; ++w)
{
if ((node.mask & (1u << w)) != 0)
{
x = 2 * job.x + (w & 1u);
y = 2 * job.y + ((w & 2u) >> 1);
z = 2 * job.z + ((w & 4u) >> 2);
jobQueue[ index++ ] = make_BFSJob( node.childPtr++, x, y, z );
}
}
}
else if (w == 1 && depth == depthBuffer[index])
{
VoxelData vd = { node.vd.normal,
node.vd.tangent * world,
make_float4( center.x, center.y, dimVec.x, dimVec.y ),
node.vd.texCoord,
eyeVec,
originalCenter };
voxelBuffer[index] = vd;
}
}
}
/**
* Draws an image of a rendered voxel model to the screen. For every pixel p visible
* on the screen it scans a certain number of neighboring pixels in the depth map for a voxel and
* selects the nearest voxel that covers p.
*
* This function could be easily implemented in the form of a shader by
* storing the voxel data in a set of textures (one for every voxel property like
* normals, texCoords, etc.) and send them to the GPU, which could combine this data with
* triangle meshes (since one can output depth information in pixel/fragment shaders).
*
* @param depthBuffer The depth buffer.
* @param colorBuffer The color buffer.
* @param voxelBuffer The voxel buffer.
* @param shadowMap The shadow map.
* @param light The light direction.
* @param lightWorldViewProjection light transform * model world transform * camera view transform * camera projection transform
* @param diffusPower The diffuse intensity of the light source.
*/
static __global__ void draw
(
uchar4 * colorBuffer,
VoxelData * voxelBuffer,
float * shadowMap,
int frameWidth, int frameHeight,
float3 light,
float4x4 lightWorldViewProjection,
float diffusePower,
hipTextureObject_t depthBuffer,
hipTextureObject_t diffuse,
hipTextureObject_t illum,
hipTextureObject_t normal,
hipTextureObject_t spec
)
{
unsigned index = blockIdx.x * blockDim.x + threadIdx.x, index2;
unsigned minDepth = INT_MAX;
unsigned depth;
int startIndex, curIndex, x, y;
VoxelData vd, minVd;
if( index < frameWidth * frameHeight )
{
y = index / frameWidth;
x = index - y * frameWidth;
startIndex = index - frameWidth - 1;
curIndex = 0;
#pragma unroll 9
for (int i = 0; i < 9; ++i)
{
index2 = min(max(startIndex + curIndex, 0), frameWidth * frameHeight);
if( ( depth = tex1Dfetch< unsigned >( depthBuffer, index2 ) ) < minDepth )
{
vd = voxelBuffer[ index2 ];
if (fabsf(vd.pos.x - .5f - x) <= vd.pos.z)
if (fabsf(vd.pos.y - .5f - y) <= vd.pos.w)
{
minDepth = depth;
minVd = vd;
}
}
if (++curIndex == 3)
{
curIndex = 0;
startIndex += frameWidth;
}
}
if (minDepth < INT_MAX)
{
float4 color = make_float4(0.f, 0.f, 0.f, 0.f);
//shadow mapping
minVd.center = minVd.center * lightWorldViewProjection;
minVd.center.x = (minVd.center.x + 1.f) * frameWidth * 0.5f;
minVd.center.y = frameHeight - (minVd.center.y + 1.f) * frameHeight * 0.5f;
x = minVd.center.x;
y = minVd.center.y;
x = max(x, 0);
x = min(x, frameWidth - 1);
y = max(y, 0);
y = min(y, frameHeight - 1);
index2 = x + y * frameWidth;
float4 tempf;
if (minVd.center.z <= shadowMap[index2] + 0.01f) //not in shadow
{
//normal mapping
tempf = tex2D< float4 >( normal, minVd.texCoord.x, minVd.texCoord.y );
float3 tempv = cross( minVd.normal, minVd.tangent );
minVd.normal = normalize(
minVd.normal * tempf.z +
minVd.tangent * tempf.x +
tempv * tempf.y
);
tempf = tex2D< float4 >( illum, minVd.texCoord.x, minVd.texCoord.y );
float intensity = fmaxf( 0.f, dot( minVd.normal, light ) );
if (intensity > 0.f || diffusePower < 1.f)
{
color = tex2D< float4 >( diffuse, minVd.texCoord.x, minVd.texCoord.y );
color.x *= intensity * diffusePower + tempf.x + 1.0f - diffusePower;
color.y *= intensity * diffusePower + tempf.y + 1.0f - diffusePower;
color.z *= intensity * diffusePower + tempf.z + 1.0f - diffusePower;
}
tempv = normalize( lerp( minVd.eyeVec, light, 0.5f ) );
intensity = powf( fmaxf( 0.f, dot( tempv, minVd.normal ) ), 32.f );
if (intensity > 0.f)
{
tempf = tex2D< float4 >( spec, minVd.texCoord.x, minVd.texCoord.y );
color.x += diffusePower * intensity * tempf.x;
color.y += diffusePower * intensity * tempf.y;
color.z += diffusePower * intensity * tempf.z;
}
}
else
{
color = tex2D< float4 >( diffuse, minVd.texCoord.x, minVd.texCoord.y );
tempf = tex2D< float4 >( illum, minVd.texCoord.x, minVd.texCoord.y );
color.x *= tempf.x + 1.0f - diffusePower;
color.y *= tempf.y + 1.0f - diffusePower;
color.z *= tempf.z + 1.0f - diffusePower;
}
color.x = fminf(1.f, color.x);
color.y = fminf(1.f, color.y);
color.z = fminf(1.f, color.z);
colorBuffer[index] = make_uchar4(color.x * 255.f, color.y * 255.f, color.z * 255.f, 0);
}
}
}
/**
* @see draw
* Like draw but outputs a shadow map.
*
* @param depthBuffer The depth buffer.
* @param shadowMap The shadow map to output the data to.
* @param voxelBuffer The voxel buffer.
*/
static __global__ void drawShadowMap
(
hipTextureObject_t depthBuffer,
float * shadowMap,
VoxelData * voxelBuffer,
int frameWidth, int frameHeight
)
{
unsigned int index = blockIdx.x * blockDim.x + threadIdx.x, index2, minDepth = INT_MAX, depth;
int startIndex, curIndex, x, y;
VoxelData vd;
if (index < frameWidth * frameHeight)
{
y = index / frameWidth;
x = index - y * frameWidth;
startIndex = index - frameWidth - 1;
curIndex = 0;
#pragma unroll 9
for (int i = 0; i < 9; ++i)
{
index2 = min(max(startIndex + curIndex, 0), frameWidth * frameHeight);
if( ( depth = tex1Dfetch< unsigned >( depthBuffer, index2 ) ) < minDepth )
{
vd = voxelBuffer[index2];
if (fabsf(vd.pos.x - .5f - x) <= vd.pos.z)
if (fabsf(vd.pos.y - .5f - y) <= vd.pos.w)
minDepth = depth;
}
if (++curIndex == 3)
{
curIndex = 0;
startIndex += frameWidth;
}
}
if (minDepth < INT_MAX)
{
float color = ((float)minDepth) / ((float)INT_MAX);
shadowMap[index] = color;
}
}
}
Renderer::Renderer( int frameWidthInPixels, int frameHeightInPixels, bool shadowMapping ) :
m_frameWidth( frameWidthInPixels ),
m_frameHeight( frameHeightInPixels ),
m_shadowMapping( shadowMapping )
{
// TODO: Dynamically resize queue if it gets too small instead of
// using a big conservative value
m_dJobQueue.resize( 10000000 );
m_dDepthBuffer.resize( resolution() );
m_dVoxelBuffer.resize( resolution() );
m_dShadowMap.resize( resolution() );
hipResourceDesc depthBufferResDesc;
std::memset( & depthBufferResDesc, 0, sizeof( depthBufferResDesc ) );
depthBufferResDesc.resType = hipResourceTypeLinear;
depthBufferResDesc.res.linear.desc = hipCreateChannelDesc< unsigned >();
depthBufferResDesc.res.linear.devPtr = thrust::raw_pointer_cast( m_dDepthBuffer.data() );
depthBufferResDesc.res.linear.sizeInBytes = m_dDepthBuffer.size() * 4;
hipTextureDesc depthBufferTexDesc;
std::memset( & depthBufferTexDesc, 0, sizeof( depthBufferTexDesc ) );
depthBufferTexDesc.addressMode[ 0 ] = hipAddressModeClamp;
depthBufferTexDesc.filterMode = hipFilterModePoint;
depthBufferTexDesc.normalizedCoords = false;
depthBufferTexDesc.readMode = hipReadModeElementType;
hipCreateTextureObject( & m_tDepthBuffer, & depthBufferResDesc, & depthBufferTexDesc, nullptr );
}
Renderer::~Renderer()
{
hipDestroyTextureObject( m_tDepthBuffer );
}
void Renderer::render
(
Object3D const & obj,
Camera const & cam,
Light const & light,
int animationFrameIndex,
uchar4 * outColorBuffer
)
{
if( m_shadowMapping )
{
fillJobQueue( thrust::raw_pointer_cast( obj.data()->jobs().data() ), obj.data()->jobs().size() );
clearDepthBuffer();
clearShadowMap();
rasterize
(
obj,
light.camera(),
light,
animationFrameIndex,
true,
outColorBuffer
);
}
fillJobQueue( thrust::raw_pointer_cast( obj.data()->jobs().data() ), obj.data()->jobs().size() );
clearColorBuffer( outColorBuffer );
clearDepthBuffer();
if( ! m_shadowMapping )
{
clearShadowMap();
}
rasterize
(
obj,
cam,
light,
animationFrameIndex,
false,
outColorBuffer
);
}
void Renderer::rasterize
(
Object3D const & obj,
Camera const & cam,
Light const & light,
int animationFrameIndex,
bool shadowPass,
uchar4 * outColorBuffer
)
{
int hStartIndex = 0;
int hEndIndex = obj.data()->jobs().size();
// TODO: Extract into DeviceQueue class
thrust::device_vector< int > dStartIndex( 1 );
thrust::device_vector< int > dEndIndex( 1 );
thrust::device_vector< int > dTravQueuePtr( 1 );
dTravQueuePtr[ 0 ] = hEndIndex;
int octreeLevel = obj.data()->level();
do
{
dStartIndex[ 0 ] = hStartIndex;
dEndIndex[ 0 ] = hEndIndex;
hipLaunchKernelGGL(( traverse), dim3(nBlocks( hEndIndex - hStartIndex, nTHREADS_TRAV_KERNEL )), dim3(nTHREADS_TRAV_KERNEL) , 0, 0,
obj.data()->innerNodes().size(),
thrust::raw_pointer_cast( obj.data()->innerNodes().data() ),
thrust::raw_pointer_cast( obj.data()->leaves().data() ),
obj.data()->dim(),
obj.transform(), cam.position(), cam.viewMatrix(), cam.projectionMatrix(),
thrust::raw_pointer_cast( obj.data()->animation().data() ),
obj.data()->boneCount(),
thrust::raw_pointer_cast( m_dDepthBuffer.data() ), thrust::raw_pointer_cast( m_dVoxelBuffer.data() ),
m_frameWidth, m_frameHeight,
animationFrameIndex,
octreeLevel,
thrust::raw_pointer_cast( dStartIndex.data() ), thrust::raw_pointer_cast( dEndIndex.data() ),
thrust::raw_pointer_cast( dTravQueuePtr.data() ),
thrust::raw_pointer_cast( m_dJobQueue.data() )
);
hStartIndex = hEndIndex;
hEndIndex = dTravQueuePtr[ 0 ];
octreeLevel++;
}
while( hEndIndex - hStartIndex > 0 );
if( shadowPass )
{
hipLaunchKernelGGL(( drawShadowMap), dim3(nBlocks( resolution(), nTHREADS_DRAW_SHADOW_KERNEL )), dim3(nTHREADS_DRAW_SHADOW_KERNEL) , 0, 0,
m_tDepthBuffer,
thrust::raw_pointer_cast( m_dShadowMap.data() ),
thrust::raw_pointer_cast( m_dVoxelBuffer.data() ),
m_frameWidth, m_frameHeight
);
}
else
{
hipLaunchKernelGGL(( draw), dim3(nBlocks( resolution(), nTHREADS_DRAW_KERNEL )), dim3(nTHREADS_DRAW_KERNEL) , 0, 0,
outColorBuffer,
thrust::raw_pointer_cast( m_dVoxelBuffer.data() ),
thrust::raw_pointer_cast( m_dShadowMap.data() ),
m_frameWidth, m_frameHeight,
light.direction(),
light.camera().viewProjectionMatrix(),
light.diffusePower(),
m_tDepthBuffer,
obj.data()->diffuse().textureObject(),
obj.data()->illum().textureObject(),
obj.data()->normal().textureObject(),
obj.data()->spec().textureObject()
);
}
}
void Renderer::clearColorBuffer( uchar4 * dpOutColorBuffer )
{
uchar4 const colorBufferClearValue = make_uchar4( 51, 51, 51, 255 );
thrust::device_ptr< uchar4 > wrappedPtr( dpOutColorBuffer );
thrust::fill
(
wrappedPtr,
wrappedPtr + resolution(),
colorBufferClearValue
);
}
void Renderer::clearDepthBuffer()
{
unsigned int const depthBufferClearValue = std::numeric_limits< unsigned int >::max();
m_dDepthBuffer.assign( m_dDepthBuffer.size(), depthBufferClearValue );
}
void Renderer::clearShadowMap()
{
float const shadowMapClearValue = 1;
m_dShadowMap.assign( m_dShadowMap.size(), shadowMapClearValue );
}
void Renderer::fillJobQueue( BFSJob const * dpJobs, int jobCount )
{
hipMemcpy
(
thrust::raw_pointer_cast( m_dJobQueue.data() ),
dpJobs,
jobCount * sizeof( BFSJob ),
hipMemcpyDeviceToDevice
);
}
int Renderer::resolution() const
{
return m_frameWidth * m_frameHeight;
}
// static
int Renderer::nBlocks( int nElements, int nThreadsPerBlock )
{
int result = nElements / nThreadsPerBlock;
return result + ( result * nThreadsPerBlock < nElements );
} | 31db47daaa0627dddd594c9a52e76cd574c55bcb.cu | #include "../inc/Renderer.h"
#include <cstdint>
#include <vector_functions.h>
#include <vector_types.h>
#include "../inc/BFSJob.h"
#include "../inc/extended_helper_math.h"
#include "../inc/float4x4.h"
#include "../inc/Light.h"
__device__
unsigned long int d_getChildCountFromMask( unsigned long int mask )
{
return ( 1ul & mask ) +
(( 2ul & mask ) >> 1 ) +
(( 4ul & mask ) >> 2 ) +
(( 8ul & mask ) >> 3 ) +
(( 16ul & mask ) >> 4 ) +
(( 32ul & mask ) >> 5 ) +
(( 64ul & mask ) >> 6 ) +
(( 128ul & mask ) >> 7 );
}
/**
* The main kernel responsible for rendering. Equivalent to the rasterizer plus vertex shader.
* The kernel is invoked with as many threads as the job queue contains elements.
* Every thread processes one job and either draws the voxel that blongs ot it or
* decides that the voxel needs further subdivision and adds new jobs to the queue
* (one for every child of the voxel).
*
* In the first case, the voxel isn't actually drawn but rather its depth and
* visual data is stored in the depth map and voxel buffer at the coordinates that
* correspond to the voxel's center. This is done because it is cheaper to scan multiple
* neighboring pixels from the depth map for a voxel than it is to write a voxel's depth into
* multiple pixels of the depth map (which requires multiple atomicMin calls).
*
* Drawing a voxel consists of projecting it into screen space and determining visibility
* through a depth buffer. The actual coloring happens at a later stage.
*
* @param innerNodeCount The number of inner nodes of the octree that is traversed.
* @param innerNodes The inner nodes of the octree.
* @param leaves The leaf nodes of the octree.
* @param dimension The dimension of the octree (cube).
* @param world The world transformation of the model the octree represents.
* @param view The view transformation of the virtual camera.
* @param projection The projection transformation of the virtual camera.
* @param animation A set of matrices encoding the bone transformations for every frame.
* @param boneCount The number of bones of the model.
* @param depthBuffer The depth buffer.
* @param voxelBuffer The voxel buffer (think input to the pixel/fragment shader).
*/
static __global__ void traverse
(
unsigned long int innerNodeCount,
BFSInnerNode const * innerNodes,
VisualData const * leaves,
float dimension,
float4x4 world, float3 camPos, float4x4 view, float4x4 projection,
float4x4 const * animation, unsigned char boneCount,
unsigned int * depthBuffer, VoxelData * voxelBuffer,
int frameWidth, int frameHeight,
int animationFrameIndex,
int octreeLevel,
int const * startIndex, int const * endIndex,
int * travQueuePtr,
BFSJob * jobQueue
)
{
unsigned long int index = blockDim.x * blockIdx.x + threadIdx.x + ( * startIndex );
short int x, y, z, w = 2;
unsigned int depth;
__shared__ unsigned int sharedTravQueuePtr;
if (threadIdx.x == 0)
sharedTravQueuePtr = 0;
__syncthreads();
if( index < ( * endIndex ) )
{
BFSJob job = jobQueue[ index ];
BFSInnerNode node;
node.childPtr = 0;
node.mask = 0;
if( job.index < innerNodeCount )
{
node = innerNodes[ job.index ];
}
else
{
node.vd = leaves[ job.index - innerNodeCount ];
}
float gridCellDim = dimension / ( (float) ( 1 << octreeLevel ) );
float gridCellHalfDim = gridCellDim * 0.5f;
float minCoord = -0.5f * dimension;
float3 center = { fmaf(job.x, gridCellDim, minCoord + gridCellHalfDim),
fmaf(job.y, gridCellDim, minCoord + gridCellHalfDim),
fmaf(job.z, gridCellDim, minCoord + gridCellHalfDim) };
float3 skinnedCenter = make_float3( 0 );
unsigned char involvedBones = 0;
if (node.vd.boneWeights.x > 0.f)
{
skinnedCenter = (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex0 ]
) * node.vd.boneWeights.x;
++involvedBones;
}
if (node.vd.boneWeights.y > 0.f)
{
skinnedCenter += (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex1 ]
) * node.vd.boneWeights.y;
++involvedBones;
}
if (node.vd.boneWeights.z > 0.f)
{
skinnedCenter += (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex2 ]
) * node.vd.boneWeights.z;
++involvedBones;
}
if (node.vd.boneWeights.w > 0.f)
{
skinnedCenter += (
center *
animation[ animationFrameIndex * boneCount + node.vd.boneIndex3 ]
) * node.vd.boneWeights.w;
++involvedBones;
}
center = skinnedCenter;
float3 originalCenter = center;
// resizing of voxel to counter stretching.
gridCellHalfDim *= fminf(2.f, involvedBones);
center = center * world;
float3 eyeVec = normalize( camPos - center );
center = center * view;
float3 dimVec = make_float3( gridCellHalfDim, gridCellHalfDim, center.z );
center = center * projection;
dimVec = dimVec * projection;
//viewing frustum + clockwise culling
node.vd.normal = node.vd.normal * world;
// TODO: Add check whether adding the current node's children
// to the job queue would exceed the queue's size limit
if ( -1.f <= center.x + dimVec.x && center.x - dimVec.x <= 1.f &&
-1.f <= center.y + dimVec.x && center.y - dimVec.x <= 1.f &&
0.f <= center.z + dimVec.x && center.z - dimVec.x <= 1.f &&
( octreeLevel <= 8 || dot( node.vd.normal, eyeVec ) >= -0.4f ))
{
center.x = (center.x + 1.f) * frameWidth * 0.5f;
center.y = frameHeight - (center.y + 1.f) * frameHeight * 0.5f;
dimVec.x *= frameWidth;
dimVec.y *= frameHeight;
x = center.x;
y = center.y;
x = max(x, 0);
x = min(x, frameWidth - 1);
y = max(y, 0);
y = min(y, frameHeight - 1);
depth = center.z * INT_MAX;
index = x + y * frameWidth;
if ((dimVec.x > 1.f) && (z = d_getChildCountFromMask(node.mask)) != 0)
{
index = atomicAdd(&sharedTravQueuePtr, z);
w = 0;
}
else
{
atomicMin(depthBuffer + index, depth);
w = 1;
}
}
__syncthreads();
if( threadIdx.x == 0 )
{
sharedTravQueuePtr = atomicAdd( travQueuePtr, sharedTravQueuePtr );
}
__syncthreads();
if (w == 0)
{
index += sharedTravQueuePtr;
#pragma unroll 8
for (w = 0; w < 8; ++w)
{
if ((node.mask & (1u << w)) != 0)
{
x = 2 * job.x + (w & 1u);
y = 2 * job.y + ((w & 2u) >> 1);
z = 2 * job.z + ((w & 4u) >> 2);
jobQueue[ index++ ] = make_BFSJob( node.childPtr++, x, y, z );
}
}
}
else if (w == 1 && depth == depthBuffer[index])
{
VoxelData vd = { node.vd.normal,
node.vd.tangent * world,
make_float4( center.x, center.y, dimVec.x, dimVec.y ),
node.vd.texCoord,
eyeVec,
originalCenter };
voxelBuffer[index] = vd;
}
}
}
/**
* Draws an image of a rendered voxel model to the screen. For every pixel p visible
* on the screen it scans a certain number of neighboring pixels in the depth map for a voxel and
* selects the nearest voxel that covers p.
*
* This function could be easily implemented in the form of a shader by
* storing the voxel data in a set of textures (one for every voxel property like
* normals, texCoords, etc.) and send them to the GPU, which could combine this data with
* triangle meshes (since one can output depth information in pixel/fragment shaders).
*
* @param depthBuffer The depth buffer.
* @param colorBuffer The color buffer.
* @param voxelBuffer The voxel buffer.
* @param shadowMap The shadow map.
* @param light The light direction.
* @param lightWorldViewProjection light transform * model world transform * camera view transform * camera projection transform
* @param diffusPower The diffuse intensity of the light source.
*/
static __global__ void draw
(
uchar4 * colorBuffer,
VoxelData * voxelBuffer,
float * shadowMap,
int frameWidth, int frameHeight,
float3 light,
float4x4 lightWorldViewProjection,
float diffusePower,
cudaTextureObject_t depthBuffer,
cudaTextureObject_t diffuse,
cudaTextureObject_t illum,
cudaTextureObject_t normal,
cudaTextureObject_t spec
)
{
unsigned index = blockIdx.x * blockDim.x + threadIdx.x, index2;
unsigned minDepth = INT_MAX;
unsigned depth;
int startIndex, curIndex, x, y;
VoxelData vd, minVd;
if( index < frameWidth * frameHeight )
{
y = index / frameWidth;
x = index - y * frameWidth;
startIndex = index - frameWidth - 1;
curIndex = 0;
#pragma unroll 9
for (int i = 0; i < 9; ++i)
{
index2 = min(max(startIndex + curIndex, 0), frameWidth * frameHeight);
if( ( depth = tex1Dfetch< unsigned >( depthBuffer, index2 ) ) < minDepth )
{
vd = voxelBuffer[ index2 ];
if (fabsf(vd.pos.x - .5f - x) <= vd.pos.z)
if (fabsf(vd.pos.y - .5f - y) <= vd.pos.w)
{
minDepth = depth;
minVd = vd;
}
}
if (++curIndex == 3)
{
curIndex = 0;
startIndex += frameWidth;
}
}
if (minDepth < INT_MAX)
{
float4 color = make_float4(0.f, 0.f, 0.f, 0.f);
//shadow mapping
minVd.center = minVd.center * lightWorldViewProjection;
minVd.center.x = (minVd.center.x + 1.f) * frameWidth * 0.5f;
minVd.center.y = frameHeight - (minVd.center.y + 1.f) * frameHeight * 0.5f;
x = minVd.center.x;
y = minVd.center.y;
x = max(x, 0);
x = min(x, frameWidth - 1);
y = max(y, 0);
y = min(y, frameHeight - 1);
index2 = x + y * frameWidth;
float4 tempf;
if (minVd.center.z <= shadowMap[index2] + 0.01f) //not in shadow
{
//normal mapping
tempf = tex2D< float4 >( normal, minVd.texCoord.x, minVd.texCoord.y );
float3 tempv = cross( minVd.normal, minVd.tangent );
minVd.normal = normalize(
minVd.normal * tempf.z +
minVd.tangent * tempf.x +
tempv * tempf.y
);
tempf = tex2D< float4 >( illum, minVd.texCoord.x, minVd.texCoord.y );
float intensity = fmaxf( 0.f, dot( minVd.normal, light ) );
if (intensity > 0.f || diffusePower < 1.f)
{
color = tex2D< float4 >( diffuse, minVd.texCoord.x, minVd.texCoord.y );
color.x *= intensity * diffusePower + tempf.x + 1.0f - diffusePower;
color.y *= intensity * diffusePower + tempf.y + 1.0f - diffusePower;
color.z *= intensity * diffusePower + tempf.z + 1.0f - diffusePower;
}
tempv = normalize( lerp( minVd.eyeVec, light, 0.5f ) );
intensity = powf( fmaxf( 0.f, dot( tempv, minVd.normal ) ), 32.f );
if (intensity > 0.f)
{
tempf = tex2D< float4 >( spec, minVd.texCoord.x, minVd.texCoord.y );
color.x += diffusePower * intensity * tempf.x;
color.y += diffusePower * intensity * tempf.y;
color.z += diffusePower * intensity * tempf.z;
}
}
else
{
color = tex2D< float4 >( diffuse, minVd.texCoord.x, minVd.texCoord.y );
tempf = tex2D< float4 >( illum, minVd.texCoord.x, minVd.texCoord.y );
color.x *= tempf.x + 1.0f - diffusePower;
color.y *= tempf.y + 1.0f - diffusePower;
color.z *= tempf.z + 1.0f - diffusePower;
}
color.x = fminf(1.f, color.x);
color.y = fminf(1.f, color.y);
color.z = fminf(1.f, color.z);
colorBuffer[index] = make_uchar4(color.x * 255.f, color.y * 255.f, color.z * 255.f, 0);
}
}
}
/**
* @see draw
* Like draw but outputs a shadow map.
*
* @param depthBuffer The depth buffer.
* @param shadowMap The shadow map to output the data to.
* @param voxelBuffer The voxel buffer.
*/
static __global__ void drawShadowMap
(
cudaTextureObject_t depthBuffer,
float * shadowMap,
VoxelData * voxelBuffer,
int frameWidth, int frameHeight
)
{
unsigned int index = blockIdx.x * blockDim.x + threadIdx.x, index2, minDepth = INT_MAX, depth;
int startIndex, curIndex, x, y;
VoxelData vd;
if (index < frameWidth * frameHeight)
{
y = index / frameWidth;
x = index - y * frameWidth;
startIndex = index - frameWidth - 1;
curIndex = 0;
#pragma unroll 9
for (int i = 0; i < 9; ++i)
{
index2 = min(max(startIndex + curIndex, 0), frameWidth * frameHeight);
if( ( depth = tex1Dfetch< unsigned >( depthBuffer, index2 ) ) < minDepth )
{
vd = voxelBuffer[index2];
if (fabsf(vd.pos.x - .5f - x) <= vd.pos.z)
if (fabsf(vd.pos.y - .5f - y) <= vd.pos.w)
minDepth = depth;
}
if (++curIndex == 3)
{
curIndex = 0;
startIndex += frameWidth;
}
}
if (minDepth < INT_MAX)
{
float color = ((float)minDepth) / ((float)INT_MAX);
shadowMap[index] = color;
}
}
}
Renderer::Renderer( int frameWidthInPixels, int frameHeightInPixels, bool shadowMapping ) :
m_frameWidth( frameWidthInPixels ),
m_frameHeight( frameHeightInPixels ),
m_shadowMapping( shadowMapping )
{
// TODO: Dynamically resize queue if it gets too small instead of
// using a big conservative value
m_dJobQueue.resize( 10000000 );
m_dDepthBuffer.resize( resolution() );
m_dVoxelBuffer.resize( resolution() );
m_dShadowMap.resize( resolution() );
cudaResourceDesc depthBufferResDesc;
std::memset( & depthBufferResDesc, 0, sizeof( depthBufferResDesc ) );
depthBufferResDesc.resType = cudaResourceTypeLinear;
depthBufferResDesc.res.linear.desc = cudaCreateChannelDesc< unsigned >();
depthBufferResDesc.res.linear.devPtr = thrust::raw_pointer_cast( m_dDepthBuffer.data() );
depthBufferResDesc.res.linear.sizeInBytes = m_dDepthBuffer.size() * 4;
cudaTextureDesc depthBufferTexDesc;
std::memset( & depthBufferTexDesc, 0, sizeof( depthBufferTexDesc ) );
depthBufferTexDesc.addressMode[ 0 ] = cudaAddressModeClamp;
depthBufferTexDesc.filterMode = cudaFilterModePoint;
depthBufferTexDesc.normalizedCoords = false;
depthBufferTexDesc.readMode = cudaReadModeElementType;
cudaCreateTextureObject( & m_tDepthBuffer, & depthBufferResDesc, & depthBufferTexDesc, nullptr );
}
Renderer::~Renderer()
{
cudaDestroyTextureObject( m_tDepthBuffer );
}
void Renderer::render
(
Object3D const & obj,
Camera const & cam,
Light const & light,
int animationFrameIndex,
uchar4 * outColorBuffer
)
{
if( m_shadowMapping )
{
fillJobQueue( thrust::raw_pointer_cast( obj.data()->jobs().data() ), obj.data()->jobs().size() );
clearDepthBuffer();
clearShadowMap();
rasterize
(
obj,
light.camera(),
light,
animationFrameIndex,
true,
outColorBuffer
);
}
fillJobQueue( thrust::raw_pointer_cast( obj.data()->jobs().data() ), obj.data()->jobs().size() );
clearColorBuffer( outColorBuffer );
clearDepthBuffer();
if( ! m_shadowMapping )
{
clearShadowMap();
}
rasterize
(
obj,
cam,
light,
animationFrameIndex,
false,
outColorBuffer
);
}
void Renderer::rasterize
(
Object3D const & obj,
Camera const & cam,
Light const & light,
int animationFrameIndex,
bool shadowPass,
uchar4 * outColorBuffer
)
{
int hStartIndex = 0;
int hEndIndex = obj.data()->jobs().size();
// TODO: Extract into DeviceQueue class
thrust::device_vector< int > dStartIndex( 1 );
thrust::device_vector< int > dEndIndex( 1 );
thrust::device_vector< int > dTravQueuePtr( 1 );
dTravQueuePtr[ 0 ] = hEndIndex;
int octreeLevel = obj.data()->level();
do
{
dStartIndex[ 0 ] = hStartIndex;
dEndIndex[ 0 ] = hEndIndex;
traverse<<< nBlocks( hEndIndex - hStartIndex, nTHREADS_TRAV_KERNEL ), nTHREADS_TRAV_KERNEL >>>
(
obj.data()->innerNodes().size(),
thrust::raw_pointer_cast( obj.data()->innerNodes().data() ),
thrust::raw_pointer_cast( obj.data()->leaves().data() ),
obj.data()->dim(),
obj.transform(), cam.position(), cam.viewMatrix(), cam.projectionMatrix(),
thrust::raw_pointer_cast( obj.data()->animation().data() ),
obj.data()->boneCount(),
thrust::raw_pointer_cast( m_dDepthBuffer.data() ), thrust::raw_pointer_cast( m_dVoxelBuffer.data() ),
m_frameWidth, m_frameHeight,
animationFrameIndex,
octreeLevel,
thrust::raw_pointer_cast( dStartIndex.data() ), thrust::raw_pointer_cast( dEndIndex.data() ),
thrust::raw_pointer_cast( dTravQueuePtr.data() ),
thrust::raw_pointer_cast( m_dJobQueue.data() )
);
hStartIndex = hEndIndex;
hEndIndex = dTravQueuePtr[ 0 ];
octreeLevel++;
}
while( hEndIndex - hStartIndex > 0 );
if( shadowPass )
{
drawShadowMap<<< nBlocks( resolution(), nTHREADS_DRAW_SHADOW_KERNEL ), nTHREADS_DRAW_SHADOW_KERNEL >>>
(
m_tDepthBuffer,
thrust::raw_pointer_cast( m_dShadowMap.data() ),
thrust::raw_pointer_cast( m_dVoxelBuffer.data() ),
m_frameWidth, m_frameHeight
);
}
else
{
draw<<< nBlocks( resolution(), nTHREADS_DRAW_KERNEL ), nTHREADS_DRAW_KERNEL >>>
(
outColorBuffer,
thrust::raw_pointer_cast( m_dVoxelBuffer.data() ),
thrust::raw_pointer_cast( m_dShadowMap.data() ),
m_frameWidth, m_frameHeight,
light.direction(),
light.camera().viewProjectionMatrix(),
light.diffusePower(),
m_tDepthBuffer,
obj.data()->diffuse().textureObject(),
obj.data()->illum().textureObject(),
obj.data()->normal().textureObject(),
obj.data()->spec().textureObject()
);
}
}
void Renderer::clearColorBuffer( uchar4 * dpOutColorBuffer )
{
uchar4 const colorBufferClearValue = make_uchar4( 51, 51, 51, 255 );
thrust::device_ptr< uchar4 > wrappedPtr( dpOutColorBuffer );
thrust::fill
(
wrappedPtr,
wrappedPtr + resolution(),
colorBufferClearValue
);
}
void Renderer::clearDepthBuffer()
{
unsigned int const depthBufferClearValue = std::numeric_limits< unsigned int >::max();
m_dDepthBuffer.assign( m_dDepthBuffer.size(), depthBufferClearValue );
}
void Renderer::clearShadowMap()
{
float const shadowMapClearValue = 1;
m_dShadowMap.assign( m_dShadowMap.size(), shadowMapClearValue );
}
void Renderer::fillJobQueue( BFSJob const * dpJobs, int jobCount )
{
cudaMemcpy
(
thrust::raw_pointer_cast( m_dJobQueue.data() ),
dpJobs,
jobCount * sizeof( BFSJob ),
cudaMemcpyDeviceToDevice
);
}
int Renderer::resolution() const
{
return m_frameWidth * m_frameHeight;
}
// static
int Renderer::nBlocks( int nElements, int nThreadsPerBlock )
{
int result = nElements / nThreadsPerBlock;
return result + ( result * nThreadsPerBlock < nElements );
} |
32debd250b9663629e9d23fa2630284242a45c91.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__global__ void CalculateDiffSample( float *cur, float *pre, const int wts, const int hts ){
const int yts = blockIdx.y * blockDim.y + threadIdx.y;
const int xts = blockIdx.x * blockDim.x + threadIdx.x;
const int curst = wts * yts + xts;
if (yts < hts && xts < wts){
cur[curst*3+0] -= pre[curst*3+0];
cur[curst*3+1] -= pre[curst*3+1];
cur[curst*3+2] -= pre[curst*3+2];
pre[curst*3+0] = 0;
pre[curst*3+1] = 0;
pre[curst*3+2] = 0;
}
} | 32debd250b9663629e9d23fa2630284242a45c91.cu | #include "includes.h"
__global__ void CalculateDiffSample( float *cur, float *pre, const int wts, const int hts ){
const int yts = blockIdx.y * blockDim.y + threadIdx.y;
const int xts = blockIdx.x * blockDim.x + threadIdx.x;
const int curst = wts * yts + xts;
if (yts < hts && xts < wts){
cur[curst*3+0] -= pre[curst*3+0];
cur[curst*3+1] -= pre[curst*3+1];
cur[curst*3+2] -= pre[curst*3+2];
pre[curst*3+0] = 0;
pre[curst*3+1] = 0;
pre[curst*3+2] = 0;
}
} |
4678a59daea69c90e606d7415e4fc80fea49fa10.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
-- MAGMA (version 1.5.0-beta3) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
@date July 2014
@generated from zailu_chow_csr_s.cu normal z -> d, Fri Jul 18 17:34:28 2014
*/
#include "common_magma.h"
#include "../include/magmasparse_d.h"
#include "../../include/magma.h"
#define PRECISION_d
// every row is handled by one threadblock
__global__ void
magma_dailu_csr_s_kernel( magma_int_t Lnum_rows,
magma_int_t Lnnz,
const double * __restrict__ AL,
double *valL,
magma_index_t *rowptrL,
magma_index_t *rowidxL,
magma_index_t *colidxL,
magma_int_t Unum_rows,
magma_int_t Unnz,
const double * __restrict__ AU,
double *valU,
magma_index_t *rowptrU,
magma_index_t *rowidxU,
magma_index_t *colidxU ){
int i, j;
int k = blockDim.x * blockIdx.x + threadIdx.x;
double zero = MAGMA_D_MAKE(0.0, 0.0);
double s, sp;
int il, iu, jl, ju;
if (k < Lnnz)
{
i = (blockIdx.y == 0 ) ? rowidxL[k] : rowidxU[k] ;
j = (blockIdx.y == 0 ) ? colidxL[k] : colidxU[k] ;
#if (__CUDA_ARCH__ >= 350) && (defined(PRECISION_d) || defined(PRECISION_s))
s = (blockIdx.y == 0 ) ? __ldg( AL+k ) : __ldg( AU+k );
#else
s = (blockIdx.y == 0 ) ? AL[k] : AU[k] ;
#endif
il = rowptrL[i];
iu = rowptrU[j];
while (il < rowptrL[i+1] && iu < rowptrU[j+1])
{
sp = zero;
jl = colidxL[il];
ju = rowidxU[iu];
// avoid branching
sp = ( jl == ju ) ? valL[il] * valU[iu] : sp;
s = ( jl == ju ) ? s-sp : s;
il = ( jl <= ju ) ? il+1 : il;
iu = ( jl >= ju ) ? iu+1 : iu;
/*
if (jl < ju)
il++;
else if (ju < jl)
iu++;
else
{
// we are going to modify this u entry
sp = valL[il] * valU[iu];
s -= sp;
il++;
iu++;
}
*/
}
// undo the last operation (it must be the last)
s += sp;
__syncthreads();
// modify u entry
if (blockIdx.y == 0)
valL[k] = s / valU[rowptrU[j+1]-1];
else{
valU[k] = s;
}
}
}// kernel
/**
Purpose
-------
This routine computes the ILU approximation of a matrix iteratively.
The idea is according to Edmond Chow's presentation at SIAM 2014.
The input format of the matrix is Magma_CSRCOO for the upper and lower
triangular parts. Note however, that we flip col and rowidx for the
U-part.
Every component of L and U is handled by one thread.
Arguments
---------
@param
A_L magma_d_sparse_matrix
input matrix L
@param
A_U magma_d_sparse_matrix
input matrix U
@param
L magma_d_sparse_matrix
input/output matrix L containing the ILU approximation
@param
U magma_d_sparse_matrix
input/output matrix U containing the ILU approximation
@ingroup magmasparse_dgegpuk
********************************************************************/
extern "C" magma_int_t
magma_dailu_csr_s( magma_d_sparse_matrix A_L,
magma_d_sparse_matrix A_U,
magma_d_sparse_matrix L,
magma_d_sparse_matrix U ){
int blocksize1 = 256;
int blocksize2 = 1;
int dimgrid1 = ( A_L.nnz + blocksize1 -1 ) / blocksize1;
int dimgrid2 = 2;
int dimgrid3 = 1;
dim3 grid( dimgrid1, dimgrid2, dimgrid3 );
dim3 block( blocksize1, blocksize2, 1 );
hipLaunchKernelGGL(( magma_dailu_csr_s_kernel), dim3(grid), dim3(block), 0, magma_stream ,
A_L.num_rows, A_L.nnz, A_L.val, L.val, L.row, L.rowidx, L.col,
A_U.num_rows, A_U.nnz, A_U.val, U.val, U.row, U.col, U.rowidx );
return MAGMA_SUCCESS;
}
| 4678a59daea69c90e606d7415e4fc80fea49fa10.cu | /*
-- MAGMA (version 1.5.0-beta3) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
@date July 2014
@generated from zailu_chow_csr_s.cu normal z -> d, Fri Jul 18 17:34:28 2014
*/
#include "common_magma.h"
#include "../include/magmasparse_d.h"
#include "../../include/magma.h"
#define PRECISION_d
// every row is handled by one threadblock
__global__ void
magma_dailu_csr_s_kernel( magma_int_t Lnum_rows,
magma_int_t Lnnz,
const double * __restrict__ AL,
double *valL,
magma_index_t *rowptrL,
magma_index_t *rowidxL,
magma_index_t *colidxL,
magma_int_t Unum_rows,
magma_int_t Unnz,
const double * __restrict__ AU,
double *valU,
magma_index_t *rowptrU,
magma_index_t *rowidxU,
magma_index_t *colidxU ){
int i, j;
int k = blockDim.x * blockIdx.x + threadIdx.x;
double zero = MAGMA_D_MAKE(0.0, 0.0);
double s, sp;
int il, iu, jl, ju;
if (k < Lnnz)
{
i = (blockIdx.y == 0 ) ? rowidxL[k] : rowidxU[k] ;
j = (blockIdx.y == 0 ) ? colidxL[k] : colidxU[k] ;
#if (__CUDA_ARCH__ >= 350) && (defined(PRECISION_d) || defined(PRECISION_s))
s = (blockIdx.y == 0 ) ? __ldg( AL+k ) : __ldg( AU+k );
#else
s = (blockIdx.y == 0 ) ? AL[k] : AU[k] ;
#endif
il = rowptrL[i];
iu = rowptrU[j];
while (il < rowptrL[i+1] && iu < rowptrU[j+1])
{
sp = zero;
jl = colidxL[il];
ju = rowidxU[iu];
// avoid branching
sp = ( jl == ju ) ? valL[il] * valU[iu] : sp;
s = ( jl == ju ) ? s-sp : s;
il = ( jl <= ju ) ? il+1 : il;
iu = ( jl >= ju ) ? iu+1 : iu;
/*
if (jl < ju)
il++;
else if (ju < jl)
iu++;
else
{
// we are going to modify this u entry
sp = valL[il] * valU[iu];
s -= sp;
il++;
iu++;
}
*/
}
// undo the last operation (it must be the last)
s += sp;
__syncthreads();
// modify u entry
if (blockIdx.y == 0)
valL[k] = s / valU[rowptrU[j+1]-1];
else{
valU[k] = s;
}
}
}// kernel
/**
Purpose
-------
This routine computes the ILU approximation of a matrix iteratively.
The idea is according to Edmond Chow's presentation at SIAM 2014.
The input format of the matrix is Magma_CSRCOO for the upper and lower
triangular parts. Note however, that we flip col and rowidx for the
U-part.
Every component of L and U is handled by one thread.
Arguments
---------
@param
A_L magma_d_sparse_matrix
input matrix L
@param
A_U magma_d_sparse_matrix
input matrix U
@param
L magma_d_sparse_matrix
input/output matrix L containing the ILU approximation
@param
U magma_d_sparse_matrix
input/output matrix U containing the ILU approximation
@ingroup magmasparse_dgegpuk
********************************************************************/
extern "C" magma_int_t
magma_dailu_csr_s( magma_d_sparse_matrix A_L,
magma_d_sparse_matrix A_U,
magma_d_sparse_matrix L,
magma_d_sparse_matrix U ){
int blocksize1 = 256;
int blocksize2 = 1;
int dimgrid1 = ( A_L.nnz + blocksize1 -1 ) / blocksize1;
int dimgrid2 = 2;
int dimgrid3 = 1;
dim3 grid( dimgrid1, dimgrid2, dimgrid3 );
dim3 block( blocksize1, blocksize2, 1 );
magma_dailu_csr_s_kernel<<< grid, block, 0, magma_stream >>>
( A_L.num_rows, A_L.nnz, A_L.val, L.val, L.row, L.rowidx, L.col,
A_U.num_rows, A_U.nnz, A_U.val, U.val, U.row, U.col, U.rowidx );
return MAGMA_SUCCESS;
}
|
0928280d858cc126059532e30a5951749fec4014.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "bonsai.h"
// #include "support_kernels.cu0
#include <stdio.h>
#include "../profiling/bonsai_timing.h"
PROF_MODULE(dev_approximate_gravity);
#include "node_specs.h"
#ifdef WIN32
#define M_PI 3.14159265358979323846264338328
#endif
#define WARP_SIZE2 5
#define WARP_SIZE 32
#if NCRIT > 4*WARP_SIZE
#error "NCRIT in include/node_specs.h must be <= WARP_SIZE"
#endif
#define laneId (threadIdx.x & (WARP_SIZE - 1))
#define warpId (threadIdx.x >> WARP_SIZE2)
#define BTEST(x) (-(int)(x))
#if 1
#define _QUADRUPOLE_
#endif
/***********************************/
/***** DENSITY ******************/
static __device__ __forceinline__ void computeDensityAndNgb(
const float r2, const float hinv2, const float mass,
float &density, float &nb)
{
#if 0 /* full kernel for reference */
const float hinv = 1.0f/h;
const float hinv2 = hinv*hinv;
const float hinv3 = hinv*hinv2;
const float C = 3465.0f/(512.0f*M_PI)*hinv3;
const float q2 = r2*hinv2;
const float rho = fmaxf(0.0f, 1.0f - q2);
nb += ceilf(rho);
const float rho2 = rho*rho;
density += C * rho2*rho2;
#else
const float rho = fmaxf(0.0f, 1.0f - r2*hinv2); /* fma, fmax */
const float rho2 = rho*rho; /* fmul */
density += rho2*rho2; /* fma */
nb += ceilf(rho2); /* fadd, ceil */
/*2x fma, 1x fmul, 1x fadd, 1x ceil, 1x fmax */
/* total: 6 flops or 8 flops with ceil&fmax */
#endif
}
#if 0
static __device__ __forceinline__ float adjustH(const float h_old, const float nnb)
{
const float nbDesired = 42;
const float f = 0.5f * (1.0f + cbrtf(nbDesired / nnb));
const float fScale = max(min(f, 1.2), 0.8);
return (h_old*fScale);
}
#endif
/************************************/
/********* PREFIX SUM ***********/
/************************************/
static __device__ __forceinline__ uint shfl_scan_add_step(uint partial, uint up_offset)
{
uint result;
asm(
"{.reg .u32 r0;"
".reg .pred p;"
"shfl.up.b32 r0|p, %1, %2, 0;"
"@p add.u32 r0, r0, %3;"
"mov.u32 %0, r0;}"
: "=r"(result) : "r"(partial), "r"(up_offset), "r"(partial));
return result;
}
static __device__ __forceinline__ int lanemask_lt()
{
int mask;
asm("mov.u32 %0, %lanemask_lt;" : "=r" (mask));
return mask;
}
static __device__ __forceinline__ int lanemask_le()
{
int mask;
asm("mov.u32 %0, %lanemask_le;" : "=r" (mask));
return mask;
}
static __device__ __forceinline__ int ShflSegScanStepB(
int partial,
uint distance,
uint up_offset)
{
asm(
"{.reg .u32 r0;"
".reg .pred p;"
"shfl.up.b32 r0, %1, %2, 0;"
"setp.le.u32 p, %2, %3;"
"@p add.u32 %1, r0, %1;"
"mov.u32 %0, %1;}"
: "=r"(partial) : "r"(partial), "r"(up_offset), "r"(distance));
return partial;
}
template<const int SIZE2>
static __device__ __forceinline__ int inclusive_segscan_warp_step(int value, const int distance)
{
for (int i = 0; i < SIZE2; i++)
value = ShflSegScanStepB(value, distance, 1<<i);
return value;
}
template <const int levels>
static __device__ __forceinline__ uint inclusive_scan_warp(const int sum)
{
uint mysum = sum;
#pragma unroll
for(int i = 0; i < levels; ++i)
mysum = shfl_scan_add_step(mysum, 1 << i);
return mysum;
}
/*********************/
static __device__ __forceinline__ int2 warpIntExclusiveScan(const int value)
{
const int sum = inclusive_scan_warp<WARP_SIZE2>(value);
return make_int2(sum-value, __shfl(sum, WARP_SIZE-1, WARP_SIZE));
}
static __device__ __forceinline__ int2 warpBinExclusiveScan(const bool p)
{
const unsigned int b = __ballot(p);
return make_int2(__popc(b & lanemask_lt()), __popc(b));
}
static __device__ __forceinline__ int2 inclusive_segscan_warp(
const int packed_value, const int carryValue)
{
const int flag = packed_value < 0;
const int mask = -flag;
const int value = (~mask & packed_value) + (mask & (-1-packed_value));
const int flags = __ballot(flag);
const int dist_block = __clz(__brev(flags));
const int distance = __clz(flags & lanemask_le()) + laneId - 31;
const int val = inclusive_segscan_warp_step<WARP_SIZE2>(value, min(distance, laneId));
return make_int2(val + (carryValue & (-(laneId < dist_block))), __shfl(val, WARP_SIZE-1, WARP_SIZE));
}
/**** binary scans ****/
#if 0
static __device__ int warp_exclusive_scan(const bool p, int &psum)
{
const unsigned int b = __ballot(p);
psum = __popc(b & lanemask_lt());
return __popc(b);
}
static __device__ int warp_exclusive_scan(const bool p)
{
const int b = __ballot(p);
return __popc(b & lanemask_lt());
}
#endif
/**************************************/
/*************** Tree walk ************/
/**************************************/
template<int SHIFT>
__forceinline__ static __device__ int ringAddr(const int i)
{
return (i & ((CELL_LIST_MEM_PER_WARP<<SHIFT) - 1));
}
texture<float4, 1, hipReadModeElementType> texNodeSize;
texture<float4, 1, hipReadModeElementType> texNodeCenter;
texture<float4, 1, hipReadModeElementType> texMultipole;
texture<float4, 1, hipReadModeElementType> texBody;
//This function is called from the my_cuda_rt file. I could not get the
// references extern since g++ did not accept the texture objects
const void* getTexturePointer(const char* name)
{
if(strcmp(name, "texNodeSize") == 0)
return &texNodeSize;
if(strcmp(name, "texNodeCenter") == 0)
return &texNodeCenter;
if(strcmp(name, "texMultipole") == 0)
return &texMultipole;
if(strcmp(name, "texBody") == 0)
return &texBody;
return NULL;
}
/*********** Forces *************/
static __device__ __forceinline__ float4 add_acc(
float4 acc, const float4 pos,
const float massj, const float3 posj,
const float eps2,
float2 &density)
{
#if 1 // to test performance of a tree-walk
const float3 dr = make_float3(posj.x - pos.x, posj.y - pos.y, posj.z - pos.z);
const float r2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z;
const float r2eps = r2 + eps2;
const float rinv = rsqrtf(r2eps);
const float rinv2 = rinv*rinv;
const float mrinv = massj * rinv;
const float mrinv3 = mrinv * rinv2;
acc.w -= mrinv;
acc.x += mrinv3 * dr.x;
acc.y += mrinv3 * dr.y;
acc.z += mrinv3 * dr.z;
computeDensityAndNgb(r2,pos.w,massj,density.x,density.y);
#endif
return acc;
}
template<int NI, bool FULL>
static __device__ __forceinline__ void directAcc(
float4 acc_i[NI],
const float4 pos_i[NI],
const int ptclIdx,
const float eps2,
float2 density_i[NI])
{
const float4 M0 = (FULL || ptclIdx >= 0) ? tex1Dfetch(texBody, ptclIdx) : make_float4(0.0f, 0.0f, 0.0f, 0.0f);
//#pragma unroll
for (int j = 0; j < WARP_SIZE; j++)
{
const float4 jM0 = make_float4(__shfl(M0.x, j), __shfl(M0.y, j), __shfl(M0.z, j), __shfl(M0.w,j));
const float jmass = jM0.w;
const float3 jpos = make_float3(jM0.x, jM0.y, jM0.z);
#pragma unroll
for (int k = 0; k < NI; k++)
acc_i[k] = add_acc(acc_i[k], pos_i[k], jmass, jpos, eps2, density_i[k]);
}
}
#ifdef _QUADRUPOLE_
static __device__ __forceinline__ float4 add_acc(
float4 acc,
const float4 pos,
const float mass, const float3 com,
const float4 Q0, const float4 Q1, float eps2,
float2 &density)
{
#if 1
const float3 dr = make_float3(pos.x - com.x, pos.y - com.y, pos.z - com.z);
const float r2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z + eps2;
const float rinv = rsqrtf(r2);
const float rinv2 = rinv *rinv;
const float mrinv = mass*rinv;
const float mrinv3 = rinv2*mrinv;
const float mrinv5 = rinv2*mrinv3;
const float mrinv7 = rinv2*mrinv5; // 16
float D0 = mrinv;
float D1 = -mrinv3;
float D2 = mrinv5*( 3.0f);
float D3 = mrinv7*(-15.0f); // 3
const float q11 = Q0.x;
const float q22 = Q0.y;
const float q33 = Q0.z;
const float q12 = Q1.x;
const float q13 = Q1.y;
const float q23 = Q1.z;
const float q = q11 + q22 + q33;
const float3 qR = make_float3(
q11*dr.x + q12*dr.y + q13*dr.z,
q12*dr.x + q22*dr.y + q23*dr.z,
q13*dr.x + q23*dr.y + q33*dr.z);
const float qRR = qR.x*dr.x + qR.y*dr.y + qR.z*dr.z; // 22
acc.w -= D0 + 0.5f*(D1*q + D2*qRR);
float C = D1 + 0.5f*(D2*q + D3*qRR);
acc.x += C*dr.x + D2*qR.x;
acc.y += C*dr.y + D2*qR.y;
acc.z += C*dr.z + D2*qR.z; // 23
// total: 16 + 3 + 22 + 23 = 64 flops
return acc;
#endif
}
template<int NI, bool FULL>
static __device__ __forceinline__ void approxAcc(
float4 acc_i[NI],
const float4 pos_i[NI],
float2 dens_i[NI],
const int cellIdx,
const float eps2)
{
const int cellAddr = cellIdx + cellIdx + cellIdx;
float4 M0, Q0, Q1;
if (FULL || cellIdx >= 0)
{
M0 = tex1Dfetch(texMultipole, cellAddr);
Q0 = tex1Dfetch(texMultipole, cellAddr + 1);
Q1 = tex1Dfetch(texMultipole, cellAddr + 2);
}
else
M0 = Q0 = Q1 = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
for (int j = 0; j < WARP_SIZE; j++)
{
const float4 jM0 = make_float4(__shfl(M0.x, j), __shfl(M0.y, j), __shfl(M0.z, j), __shfl(M0.w,j));
const float4 jQ0 = make_float4(__shfl(Q0.x, j), __shfl(Q0.y, j), __shfl(Q0.z, j), 0.0f);
const float4 jQ1 = make_float4(__shfl(Q1.x, j), __shfl(Q1.y, j), __shfl(Q1.z, j), 0.0f);
const float jmass = jM0.w;
const float3 jpos = make_float3(jM0.x, jM0.y, jM0.z);
#pragma unroll
for (int k = 0; k < NI; k++)
acc_i[k] = add_acc(acc_i[k], pos_i[k], jmass, jpos, jQ0, jQ1, eps2, dens_i[k]);
}
}
#endif
/*******************************/
/****** Opening criterion ******/
/*******************************/
//Improved Barnes Hut criterium
static __device__ bool split_node_grav_impbh(
const float4 nodeCOM,
const float4 groupCenter,
const float4 groupSize)
{
//Compute the distance between the group and the cell
float3 dr = make_float3(
fabsf(groupCenter.x - nodeCOM.x) - (groupSize.x),
fabsf(groupCenter.y - nodeCOM.y) - (groupSize.y),
fabsf(groupCenter.z - nodeCOM.z) - (groupSize.z)
);
dr.x += fabsf(dr.x); dr.x *= 0.5f;
dr.y += fabsf(dr.y); dr.y *= 0.5f;
dr.z += fabsf(dr.z); dr.z *= 0.5f;
//Distance squared, no need to do sqrt since opening criteria has been squared
const float ds2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z;
return (ds2 <= fabsf(nodeCOM.w));
}
//Minimum distance
__device__ bool split_node_grav_md(
const float4 nodeCenter,
const float4 nodeSize,
const float4 groupCenter,
const float4 groupSize)
{
//Compute the distance between the group and the cell
float3 dr = {fabs(groupCenter.x - nodeCenter.x) - (groupSize.x + nodeSize.x),
fabs(groupCenter.y - nodeCenter.y) - (groupSize.y + nodeSize.y),
fabs(groupCenter.z - nodeCenter.z) - (groupSize.z + nodeSize.z)};
dr.x += fabs(dr.x); dr.x *= 0.5f;
dr.y += fabs(dr.y); dr.y *= 0.5f;
dr.z += fabs(dr.z); dr.z *= 0.5f;
//Distance squared, no need to do sqrt since opening criteria has been squared
float ds2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z;
return (ds2 <= fabs(nodeCenter.w));
}
#define TEXTURES
template<int SHIFT, int BLOCKDIM2, int NI, bool INTCOUNT>
static __device__
uint2 approximate_gravity(
float4 acc_i[NI],
const float4 _pos_i[NI],
const float4 groupPos,
const float eps2,
const uint2 top_cells,
int *shmem,
int *cellList,
const float4 groupSize,
float2 dens_i[NI])
{
const int laneIdx = threadIdx.x & (WARP_SIZE-1);
/* this helps to unload register pressure */
float4 pos_i[NI];
#pragma unroll 1
for (int i = 0; i < NI; i++)
pos_i[i] = _pos_i[i];
uint2 interactionCounters = {0}; /* # of approximate and exact force evaluations */
#pragma unroll 1
for (int i = 0; i < NI; i++)
dens_i[i] = make_float2(0,0);
volatile int *tmpList = shmem;
int approxCellIdx, directPtclIdx;
int directCounter = 0;
int approxCounter = 0;
for (int root_cell = top_cells.x; root_cell < top_cells.y; root_cell += WARP_SIZE)
if (root_cell + laneIdx < top_cells.y)
cellList[ringAddr<SHIFT>(root_cell - top_cells.x + laneIdx)] = root_cell + laneIdx;
int nCells = top_cells.y - top_cells.x;
int cellListBlock = 0;
int nextLevelCellCounter = 0;
unsigned int cellListOffset = 0;
/* process level with n_cells */
#if 1
while (nCells > 0)
{
/* extract cell index from the current level cell list */
const int cellListIdx = cellListBlock + laneIdx;
const bool useCell = cellListIdx < nCells;
const int cellIdx = cellList[ringAddr<SHIFT>(cellListOffset + cellListIdx)];
cellListBlock += min(WARP_SIZE, nCells - cellListBlock);
/* read from gmem cell's info */
const float4 cellSize = tex1Dfetch(texNodeSize, cellIdx);
const float4 cellPos = tex1Dfetch(texNodeCenter, cellIdx);
#if 1
const float4 cellCOM = tex1Dfetch(texMultipole, cellIdx+cellIdx+cellIdx);
/* check if cell opening condition is satisfied */
const float4 cellCOM1 = make_float4(cellCOM.x, cellCOM.y, cellCOM.z, cellPos.w);
bool splitCell = split_node_grav_impbh(cellCOM1, groupPos, groupSize);
#else /*added by egaburov, see compute_propertiesD.cu for matching code */
bool splitCell = split_node_grav_impbh(cellPos, groupPos, groupSize);
#endif
/* compute first child, either a cell if node or a particle if leaf */
const int cellData = __float_as_int(cellSize.w);
const int firstChild = cellData & 0x0FFFFFFF;
const int nChildren = (cellData & 0xF0000000) >> 28;
if(cellData == 0xFFFFFFFF)
splitCell = false;
/**********************************************/
/* split cells that satisfy opening condition */
/**********************************************/
const bool isNode = cellPos.w > 0.0f;
{
bool splitNode = isNode && splitCell && useCell;
/* use exclusive scan to compute scatter addresses for each of the child cells */
const int2 childScatter = warpIntExclusiveScan(nChildren & (-splitNode));
/* make sure we still have available stack space */
if (childScatter.y + nCells - cellListBlock > (CELL_LIST_MEM_PER_WARP<<SHIFT))
return make_uint2(0xFFFFFFFF,0xFFFFFFFF);
#if 1
/* if so populate next level stack in gmem */
if (splitNode)
{
const int scatterIdx = cellListOffset + nCells + nextLevelCellCounter + childScatter.x;
for (int i = 0; i < nChildren; i++)
cellList[ringAddr<SHIFT>(scatterIdx + i)] = firstChild + i;
}
#else /* use scan operation to accomplish steps above, doesn't bring performance benefit */
int nChildren = childScatter.y;
int nProcessed = 0;
int2 scanVal = {0};
const int offset = cellListOffset + nCells + nextLevelCellCounter;
while (nChildren > 0)
{
tmpList[laneIdx] = 1;
if (splitNode && (childScatter.x - nProcessed < WARP_SIZE))
{
splitNode = false;
tmpList[childScatter.x - nProcessed] = -1-firstChild;
}
scanVal = inclusive_segscan_warp(tmpList[laneIdx], scanVal.y);
if (laneIdx < nChildren)
cellList[ringAddr<SHIFT>(offset + nProcessed + laneIdx)] = scanVal.x;
nChildren -= WARP_SIZE;
nProcessed += WARP_SIZE;
}
#endif
nextLevelCellCounter += childScatter.y; /* increment nextLevelCounter by total # of children */
}
#if 1
{
/***********************************/
/****** APPROX ******/
/***********************************/
/* see which thread's cell can be used for approximate force calculation */
const bool approxCell = !splitCell && useCell;
const int2 approxScatter = warpBinExclusiveScan(approxCell);
/* store index of the cell */
const int scatterIdx = approxCounter + approxScatter.x;
tmpList[laneIdx] = approxCellIdx;
if (approxCell && scatterIdx < WARP_SIZE)
tmpList[scatterIdx] = cellIdx;
approxCounter += approxScatter.y;
/* compute approximate forces */
if (approxCounter >= WARP_SIZE)
{
/* evalute cells stored in shmem */
approxAcc<NI,true>(acc_i, pos_i, dens_i, tmpList[laneIdx], eps2);
approxCounter -= WARP_SIZE;
const int scatterIdx = approxCounter + approxScatter.x - approxScatter.y;
if (approxCell && scatterIdx >= 0)
tmpList[scatterIdx] = cellIdx;
if (INTCOUNT)
interactionCounters.x += WARP_SIZE*NI;
}
approxCellIdx = tmpList[laneIdx];
}
#endif
#if 1
{
/***********************************/
/****** DIRECT ******/
/***********************************/
const bool isLeaf = !isNode;
bool isDirect = splitCell && isLeaf && useCell;
const int firstBody = cellData & BODYMASK;
const int nBody = ((cellData & INVBMASK) >> LEAFBIT)+1;
const int2 childScatter = warpIntExclusiveScan(nBody & (-isDirect));
int nParticle = childScatter.y;
int nProcessed = 0;
int2 scanVal = {0};
/* conduct segmented scan for all leaves that need to be expanded */
while (nParticle > 0)
{
tmpList[laneIdx] = 1;
if (isDirect && (childScatter.x - nProcessed < WARP_SIZE))
{
isDirect = false;
tmpList[childScatter.x - nProcessed] = -1-firstBody;
}
scanVal = inclusive_segscan_warp(tmpList[laneIdx], scanVal.y);
const int ptclIdx = scanVal.x;
if (nParticle >= WARP_SIZE)
{
directAcc<NI,true>(acc_i, pos_i, ptclIdx, eps2, dens_i);
nParticle -= WARP_SIZE;
nProcessed += WARP_SIZE;
if (INTCOUNT)
interactionCounters.y += WARP_SIZE*NI;
}
else
{
const int scatterIdx = directCounter + laneIdx;
tmpList[laneIdx] = directPtclIdx;
if (scatterIdx < WARP_SIZE)
tmpList[scatterIdx] = ptclIdx;
directCounter += nParticle;
if (directCounter >= WARP_SIZE)
{
/* evalute cells stored in shmem */
directAcc<NI,true>(acc_i, pos_i, tmpList[laneIdx], eps2, dens_i);
directCounter -= WARP_SIZE;
const int scatterIdx = directCounter + laneIdx - nParticle;
if (scatterIdx >= 0)
tmpList[scatterIdx] = ptclIdx;
if (INTCOUNT)
interactionCounters.y += WARP_SIZE*NI;
}
directPtclIdx = tmpList[laneIdx];
nParticle = 0;
}
}
}
#endif
/* if the current level is processed, schedule the next level */
if (cellListBlock >= nCells)
{
cellListOffset += nCells;
nCells = nextLevelCellCounter;
cellListBlock = nextLevelCellCounter = 0;
}
} /* level completed */
#endif
if (approxCounter > 0)
{
approxAcc<NI,false>(acc_i, pos_i, dens_i, laneIdx < approxCounter ? approxCellIdx : -1, eps2);
if (INTCOUNT)
interactionCounters.x += approxCounter * NI;
approxCounter = 0;
}
if (directCounter > 0)
{
directAcc<NI,false>(acc_i, pos_i, laneIdx < directCounter ? directPtclIdx : -1, eps2, dens_i);
if (INTCOUNT)
interactionCounters.y += directCounter * NI;
directCounter = 0;
}
return interactionCounters;
}
template<int SHIFT2, int BLOCKDIM2, bool ACCUMULATE>
static __device__
bool treewalk(
const int bid,
const float eps2,
const uint2 node_begend,
const int *active_groups,
const real4 *group_body_pos,
const float4 *groupSizeInfo,
const float4 *groupCenterInfo,
int *shmem,
int *lmem,
float4 *acc_out,
int2 *interactions,
int *ngb_out,
int *active_inout,
float *body_h,
float2 *body_dens_out)
{
/*********** set necessary thread constants **********/
#ifdef DO_BLOCK_TIMESTEP
real4 curGroupSize = groupSizeInfo[active_groups[bid]];
#else
real4 curGroupSize = groupSizeInfo[bid];
#endif
const int groupData = __float_as_int(curGroupSize.w);
const uint body_addr = groupData & CRITMASK;
const uint nb_i = ((groupData & INVCMASK) >> CRITBIT) + 1;
#ifdef DO_BLOCK_TIMESTEP
real4 group_pos = groupCenterInfo[active_groups[bid]];
#else
real4 group_pos = groupCenterInfo[bid];
#endif
uint body_i[2];
const int ni = nb_i <= WARP_SIZE ? 1 : 2;
body_i[0] = body_addr + laneId%nb_i;
body_i[1] = body_addr + WARP_SIZE + laneId%(nb_i - WARP_SIZE);
float4 pos_i[2];
float4 acc_i[2];
float2 dens_i[2];
pos_i[0] = group_body_pos[body_i[0]];
pos_i[0].w = 1.0f/body_h[body_i[0]];
pos_i[0].w *= pos_i[0].w; /* .w stores 1/h^2 to speed up computations */
if(ni > 1){ //Only read if we actually have ni == 2
pos_i[1] = group_body_pos[body_i[1]];
pos_i[1].w = 1.0f/body_h[body_i[1]];
pos_i[1].w *= pos_i[1].w; /* .w stores 1/h^2 to speed up computations */
}
acc_i[0] = acc_i[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
dens_i[0] = dens_i[1] = make_float2(0.0f, 0.0f);
#if 0
const bool INTCOUNT = false;
#else
const bool INTCOUNT = true;
#endif
uint2 counters = {0};
{
if (ni == 1)
counters = approximate_gravity<SHIFT2, BLOCKDIM2, 1,INTCOUNT>(
acc_i,
pos_i,
group_pos,
eps2,
node_begend,
shmem,
lmem,
curGroupSize,
dens_i);
else
counters = approximate_gravity<SHIFT2, BLOCKDIM2, 2,INTCOUNT>(
acc_i,
pos_i,
group_pos,
eps2,
node_begend,
shmem,
lmem,
curGroupSize,
dens_i);
}
if(counters.x == 0xFFFFFFFF && counters.y == 0xFFFFFFFF)
return false;
#if 0
/* CUDA 8RC work around */
if(bid < 0) // bid ==0 && laneId < nb_i && && threadIdx.x == 0)
{
printf("TEST\n");
//printf("ON DEV [%d %d : %d %d ] ACC: %f %f %f %f INT: %d %d \n",
// bid, threadIdx.x, nb_i, body_i[0],
// acc_i[0].x,acc_i[0].y,acc_i[0].z,acc_i[0].w,
// counters.x, counters.y);
}
#endif
if (laneId < nb_i)
{
const int addr = body_i[0];
{
const float hinv = 1.0f/body_h[addr];
const float C = 3465.0f/(512.0f*M_PI)*hinv*hinv*hinv;
dens_i[0].x *= C; /* scale rho */
}
if (ACCUMULATE)
{
acc_out [addr].x += acc_i[0].x;
acc_out [addr].y += acc_i[0].y;
acc_out [addr].z += acc_i[0].z;
acc_out [addr].w += acc_i[0].w;
body_dens_out[addr].x += dens_i[0].x;
body_dens_out[addr].y += dens_i[0].y;
}
else
{
acc_out [addr] = acc_i[0];
body_dens_out[addr] = dens_i[0];
}
// ngb_out [addr] = ngb_i;
ngb_out [addr] = addr; //JB Fixed this for demo
active_inout[addr] = 1;
if (ACCUMULATE)
{
interactions[addr].x += counters.x / ni;
interactions[addr].y += counters.y / ni ;
}
else
{
interactions[addr].x = counters.x / ni;
interactions[addr].y = counters.y / ni ;
}
if (ni == 2)
{
const int addr = body_i[1];
{
const float hinv = 1.0f/body_h[addr];
const float C = 3465.0f/(512.0f*M_PI)*hinv*hinv*hinv;
dens_i[1].x *= C; /* scale rho */
}
if (ACCUMULATE)
{
acc_out [addr].x += acc_i[1].x;
acc_out [addr].y += acc_i[1].y;
acc_out [addr].z += acc_i[1].z;
acc_out [addr].w += acc_i[1].w;
body_dens_out[addr].x += dens_i[1].x;
body_dens_out[addr].y += dens_i[1].y;
}
else
{
acc_out [addr] = acc_i[1];
body_dens_out[addr] = dens_i[1];
// body_h[addr] = adjustH(body_h[addr], dens_i[1].y);
}
// ngb_out [addr] = ngb_i;
ngb_out [addr] = addr; //JB Fixed this for demo
active_inout[addr] = 1;
if (ACCUMULATE)
{
interactions[addr].x += counters.x / ni;
interactions[addr].y += counters.y / ni;
}
else
{
interactions[addr].x = counters.x / ni;
interactions[addr].y = counters.y / ni;
}
}
}
return true;
}
template<bool ACCUMULATE, int BLOCKDIM2>
static __device__
void approximate_gravity_main(
const int n_active_groups,
int n_bodies,
float eps2,
uint2 node_begend,
int *active_groups,
real4 *body_pos,
real4 *multipole_data,
float4 *acc_out,
real4 *group_body_pos, //This can be different from body_pos
int *ngb_out,
int *active_inout,
int2 *interactions,
float4 *boxSizeInfo,
float4 *groupSizeInfo,
float4 *boxCenterInfo,
float4 *groupCenterInfo,
real4 *body_vel,
int *MEM_BUF,
float *body_h,
float2 *body_dens)
{
const int blockDim2 = BLOCKDIM2;
const int shMemSize = 1 * (1 << blockDim2);
__shared__ int shmem_pool[shMemSize];
const int nWarps2 = blockDim2 - WARP_SIZE2;
const int sh_offs = (shMemSize >> nWarps2) * warpId;
int *shmem = shmem_pool + sh_offs;
volatile int *shmemv = shmem;
#if 0
#define SHMODE
#endif
#ifdef SHMODE
const int nWarps = 1<<nWarps2;
const int MAXFAILED = 64;
__shared__ int failedList[MAXFAILED];
__shared__ unsigned int failed;
if (threadIdx.x == 0)
failed = 0;
#endif
__syncthreads();
/*********** check if this block is linked to a leaf **********/
int bid = gridDim.x * blockIdx.y + blockIdx.x;
while(true)
{
if(laneId == 0)
{
bid = atomicAdd(&active_inout[n_bodies], 1);
shmemv[0] = bid;
}
bid = shmemv[0];
if (bid >= n_active_groups) return;
int *lmem = &MEM_BUF[(CELL_LIST_MEM_PER_WARP<<nWarps2)*blockIdx.x + CELL_LIST_MEM_PER_WARP*warpId];
const bool success = treewalk<0,blockDim2,ACCUMULATE>(
bid,
eps2,
node_begend,
active_groups,
group_body_pos,
groupSizeInfo,
groupCenterInfo,
shmem,
lmem,
acc_out,
interactions,
ngb_out,
active_inout,
body_h,
body_dens);
#if 0
if (bid % 10 == 0)
success = false;
#endif
#ifdef SHMODE
if (!success)
if (laneId == 0)
failedList[atomicAdd(&failed,1)] = bid;
if (failed + nWarps >= MAXFAILED)
{
__syncthreads();
if (warpId == 0)
{
int *lmem1 = &MEM_BUF[(CELL_LIST_MEM_PER_WARP<<nWarps2)*blockIdx.x];
const int n = failed;
failed = 0;
for (int it = 0; it < n; it++)
{
const bool success = treewalk<nWarp2,blockDim2,ACCUMULATE>(
failedList[it],
eps2,
node_begend,
active_groups,
group_body_pos,
groupSizeInfo,
groupCenterInfo,
shmem,
lmem1,
acc_out,
interactions,
ngb_out,
active_inout);
assert(success);
}
}
__syncthreads();
}
#else
//Try to get access to the big stack, only one block per time is allowed
if (!success)
{
if(laneId == 0)
{
int res = atomicExch(&active_inout[n_bodies+1], 1); //If the old value (res) is 0 we can go otherwise sleep
int waitCounter = 0;
while(res != 0)
{
//Sleep
for(int i=0; i < (1024); i++)
waitCounter += 1;
//Test again
shmem[0] = waitCounter;
res = atomicExch(&active_inout[n_bodies+1], 1);
}
}
int *lmem1 = &MEM_BUF[gridDim.x*(CELL_LIST_MEM_PER_WARP<<nWarps2)];
const bool success = treewalk<8,blockDim2,ACCUMULATE>(
bid,
eps2,
node_begend,
active_groups,
group_body_pos,
groupSizeInfo,
groupCenterInfo,
shmem,
lmem1,
acc_out,
interactions,
ngb_out,
active_inout,
body_h,
body_dens);
assert(success);
if(laneId == 0)
atomicExch(&active_inout[n_bodies+1], 0); //Release the lock
}
#endif /* SHMODE */
} //end while
#undef SHMODE
}
extern "C"
__launch_bounds__(NTHREAD,1024/NTHREAD)
__global__ void
dev_approximate_gravity(
const int n_active_groups,
int n_bodies,
float eps2,
uint2 node_begend,
int *active_groups,
real4 *body_pos,
real4 *multipole_data,
float4 *acc_out,
real4 *group_body_pos, //This can be different from body_pos
int *ngb_out,
int *active_inout,
int2 *interactions,
float4 *boxSizeInfo,
float4 *groupSizeInfo,
float4 *boxCenterInfo,
float4 *groupCenterInfo,
real4 *body_vel,
int *MEM_BUF,
float *body_h,
float2 *body_dens)
{
approximate_gravity_main<false, NTHREAD2>(
n_active_groups,
n_bodies,
eps2,
node_begend,
active_groups,
body_pos,
multipole_data,
acc_out,
group_body_pos, //This can be different from body_pos
ngb_out,
active_inout,
interactions,
boxSizeInfo,
groupSizeInfo,
boxCenterInfo,
groupCenterInfo,
body_vel,
MEM_BUF,
body_h,
body_dens);
}
extern "C"
__launch_bounds__(NTHREAD,1024/NTHREAD)
__global__ void
dev_approximate_gravity_let(
const int n_active_groups,
int n_bodies,
float eps2,
uint2 node_begend,
int *active_groups,
real4 *body_pos,
real4 *multipole_data,
float4 *acc_out,
real4 *group_body_pos, //This can be different from body_pos
int *ngb_out,
int *active_inout,
int2 *interactions,
float4 *boxSizeInfo,
float4 *groupSizeInfo,
float4 *boxCenterInfo,
float4 *groupCenterInfo,
real4 *body_vel,
int *MEM_BUF,
float *body_h,
float2 *body_dens)
{
approximate_gravity_main<true, NTHREAD2>(
n_active_groups,
n_bodies,
eps2,
node_begend,
active_groups,
body_pos,
multipole_data,
acc_out,
group_body_pos, //This can be different from body_pos
ngb_out,
active_inout,
interactions,
boxSizeInfo,
groupSizeInfo,
boxCenterInfo,
groupCenterInfo,
body_vel,
MEM_BUF,
body_h,
body_dens);
}
| 0928280d858cc126059532e30a5951749fec4014.cu | #include "bonsai.h"
// #include "support_kernels.cu0
#include <stdio.h>
#include "../profiling/bonsai_timing.h"
PROF_MODULE(dev_approximate_gravity);
#include "node_specs.h"
#ifdef WIN32
#define M_PI 3.14159265358979323846264338328
#endif
#define WARP_SIZE2 5
#define WARP_SIZE 32
#if NCRIT > 4*WARP_SIZE
#error "NCRIT in include/node_specs.h must be <= WARP_SIZE"
#endif
#define laneId (threadIdx.x & (WARP_SIZE - 1))
#define warpId (threadIdx.x >> WARP_SIZE2)
#define BTEST(x) (-(int)(x))
#if 1
#define _QUADRUPOLE_
#endif
/***********************************/
/***** DENSITY ******************/
static __device__ __forceinline__ void computeDensityAndNgb(
const float r2, const float hinv2, const float mass,
float &density, float &nb)
{
#if 0 /* full kernel for reference */
const float hinv = 1.0f/h;
const float hinv2 = hinv*hinv;
const float hinv3 = hinv*hinv2;
const float C = 3465.0f/(512.0f*M_PI)*hinv3;
const float q2 = r2*hinv2;
const float rho = fmaxf(0.0f, 1.0f - q2);
nb += ceilf(rho);
const float rho2 = rho*rho;
density += C * rho2*rho2;
#else
const float rho = fmaxf(0.0f, 1.0f - r2*hinv2); /* fma, fmax */
const float rho2 = rho*rho; /* fmul */
density += rho2*rho2; /* fma */
nb += ceilf(rho2); /* fadd, ceil */
/*2x fma, 1x fmul, 1x fadd, 1x ceil, 1x fmax */
/* total: 6 flops or 8 flops with ceil&fmax */
#endif
}
#if 0
static __device__ __forceinline__ float adjustH(const float h_old, const float nnb)
{
const float nbDesired = 42;
const float f = 0.5f * (1.0f + cbrtf(nbDesired / nnb));
const float fScale = max(min(f, 1.2), 0.8);
return (h_old*fScale);
}
#endif
/************************************/
/********* PREFIX SUM ***********/
/************************************/
static __device__ __forceinline__ uint shfl_scan_add_step(uint partial, uint up_offset)
{
uint result;
asm(
"{.reg .u32 r0;"
".reg .pred p;"
"shfl.up.b32 r0|p, %1, %2, 0;"
"@p add.u32 r0, r0, %3;"
"mov.u32 %0, r0;}"
: "=r"(result) : "r"(partial), "r"(up_offset), "r"(partial));
return result;
}
static __device__ __forceinline__ int lanemask_lt()
{
int mask;
asm("mov.u32 %0, %lanemask_lt;" : "=r" (mask));
return mask;
}
static __device__ __forceinline__ int lanemask_le()
{
int mask;
asm("mov.u32 %0, %lanemask_le;" : "=r" (mask));
return mask;
}
static __device__ __forceinline__ int ShflSegScanStepB(
int partial,
uint distance,
uint up_offset)
{
asm(
"{.reg .u32 r0;"
".reg .pred p;"
"shfl.up.b32 r0, %1, %2, 0;"
"setp.le.u32 p, %2, %3;"
"@p add.u32 %1, r0, %1;"
"mov.u32 %0, %1;}"
: "=r"(partial) : "r"(partial), "r"(up_offset), "r"(distance));
return partial;
}
template<const int SIZE2>
static __device__ __forceinline__ int inclusive_segscan_warp_step(int value, const int distance)
{
for (int i = 0; i < SIZE2; i++)
value = ShflSegScanStepB(value, distance, 1<<i);
return value;
}
template <const int levels>
static __device__ __forceinline__ uint inclusive_scan_warp(const int sum)
{
uint mysum = sum;
#pragma unroll
for(int i = 0; i < levels; ++i)
mysum = shfl_scan_add_step(mysum, 1 << i);
return mysum;
}
/*********************/
static __device__ __forceinline__ int2 warpIntExclusiveScan(const int value)
{
const int sum = inclusive_scan_warp<WARP_SIZE2>(value);
return make_int2(sum-value, __shfl(sum, WARP_SIZE-1, WARP_SIZE));
}
static __device__ __forceinline__ int2 warpBinExclusiveScan(const bool p)
{
const unsigned int b = __ballot(p);
return make_int2(__popc(b & lanemask_lt()), __popc(b));
}
static __device__ __forceinline__ int2 inclusive_segscan_warp(
const int packed_value, const int carryValue)
{
const int flag = packed_value < 0;
const int mask = -flag;
const int value = (~mask & packed_value) + (mask & (-1-packed_value));
const int flags = __ballot(flag);
const int dist_block = __clz(__brev(flags));
const int distance = __clz(flags & lanemask_le()) + laneId - 31;
const int val = inclusive_segscan_warp_step<WARP_SIZE2>(value, min(distance, laneId));
return make_int2(val + (carryValue & (-(laneId < dist_block))), __shfl(val, WARP_SIZE-1, WARP_SIZE));
}
/**** binary scans ****/
#if 0
static __device__ int warp_exclusive_scan(const bool p, int &psum)
{
const unsigned int b = __ballot(p);
psum = __popc(b & lanemask_lt());
return __popc(b);
}
static __device__ int warp_exclusive_scan(const bool p)
{
const int b = __ballot(p);
return __popc(b & lanemask_lt());
}
#endif
/**************************************/
/*************** Tree walk ************/
/**************************************/
template<int SHIFT>
__forceinline__ static __device__ int ringAddr(const int i)
{
return (i & ((CELL_LIST_MEM_PER_WARP<<SHIFT) - 1));
}
texture<float4, 1, cudaReadModeElementType> texNodeSize;
texture<float4, 1, cudaReadModeElementType> texNodeCenter;
texture<float4, 1, cudaReadModeElementType> texMultipole;
texture<float4, 1, cudaReadModeElementType> texBody;
//This function is called from the my_cuda_rt file. I could not get the
// references extern since g++ did not accept the texture objects
const void* getTexturePointer(const char* name)
{
if(strcmp(name, "texNodeSize") == 0)
return &texNodeSize;
if(strcmp(name, "texNodeCenter") == 0)
return &texNodeCenter;
if(strcmp(name, "texMultipole") == 0)
return &texMultipole;
if(strcmp(name, "texBody") == 0)
return &texBody;
return NULL;
}
/*********** Forces *************/
static __device__ __forceinline__ float4 add_acc(
float4 acc, const float4 pos,
const float massj, const float3 posj,
const float eps2,
float2 &density)
{
#if 1 // to test performance of a tree-walk
const float3 dr = make_float3(posj.x - pos.x, posj.y - pos.y, posj.z - pos.z);
const float r2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z;
const float r2eps = r2 + eps2;
const float rinv = rsqrtf(r2eps);
const float rinv2 = rinv*rinv;
const float mrinv = massj * rinv;
const float mrinv3 = mrinv * rinv2;
acc.w -= mrinv;
acc.x += mrinv3 * dr.x;
acc.y += mrinv3 * dr.y;
acc.z += mrinv3 * dr.z;
computeDensityAndNgb(r2,pos.w,massj,density.x,density.y);
#endif
return acc;
}
template<int NI, bool FULL>
static __device__ __forceinline__ void directAcc(
float4 acc_i[NI],
const float4 pos_i[NI],
const int ptclIdx,
const float eps2,
float2 density_i[NI])
{
const float4 M0 = (FULL || ptclIdx >= 0) ? tex1Dfetch(texBody, ptclIdx) : make_float4(0.0f, 0.0f, 0.0f, 0.0f);
//#pragma unroll
for (int j = 0; j < WARP_SIZE; j++)
{
const float4 jM0 = make_float4(__shfl(M0.x, j), __shfl(M0.y, j), __shfl(M0.z, j), __shfl(M0.w,j));
const float jmass = jM0.w;
const float3 jpos = make_float3(jM0.x, jM0.y, jM0.z);
#pragma unroll
for (int k = 0; k < NI; k++)
acc_i[k] = add_acc(acc_i[k], pos_i[k], jmass, jpos, eps2, density_i[k]);
}
}
#ifdef _QUADRUPOLE_
static __device__ __forceinline__ float4 add_acc(
float4 acc,
const float4 pos,
const float mass, const float3 com,
const float4 Q0, const float4 Q1, float eps2,
float2 &density)
{
#if 1
const float3 dr = make_float3(pos.x - com.x, pos.y - com.y, pos.z - com.z);
const float r2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z + eps2;
const float rinv = rsqrtf(r2);
const float rinv2 = rinv *rinv;
const float mrinv = mass*rinv;
const float mrinv3 = rinv2*mrinv;
const float mrinv5 = rinv2*mrinv3;
const float mrinv7 = rinv2*mrinv5; // 16
float D0 = mrinv;
float D1 = -mrinv3;
float D2 = mrinv5*( 3.0f);
float D3 = mrinv7*(-15.0f); // 3
const float q11 = Q0.x;
const float q22 = Q0.y;
const float q33 = Q0.z;
const float q12 = Q1.x;
const float q13 = Q1.y;
const float q23 = Q1.z;
const float q = q11 + q22 + q33;
const float3 qR = make_float3(
q11*dr.x + q12*dr.y + q13*dr.z,
q12*dr.x + q22*dr.y + q23*dr.z,
q13*dr.x + q23*dr.y + q33*dr.z);
const float qRR = qR.x*dr.x + qR.y*dr.y + qR.z*dr.z; // 22
acc.w -= D0 + 0.5f*(D1*q + D2*qRR);
float C = D1 + 0.5f*(D2*q + D3*qRR);
acc.x += C*dr.x + D2*qR.x;
acc.y += C*dr.y + D2*qR.y;
acc.z += C*dr.z + D2*qR.z; // 23
// total: 16 + 3 + 22 + 23 = 64 flops
return acc;
#endif
}
template<int NI, bool FULL>
static __device__ __forceinline__ void approxAcc(
float4 acc_i[NI],
const float4 pos_i[NI],
float2 dens_i[NI],
const int cellIdx,
const float eps2)
{
const int cellAddr = cellIdx + cellIdx + cellIdx;
float4 M0, Q0, Q1;
if (FULL || cellIdx >= 0)
{
M0 = tex1Dfetch(texMultipole, cellAddr);
Q0 = tex1Dfetch(texMultipole, cellAddr + 1);
Q1 = tex1Dfetch(texMultipole, cellAddr + 2);
}
else
M0 = Q0 = Q1 = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
for (int j = 0; j < WARP_SIZE; j++)
{
const float4 jM0 = make_float4(__shfl(M0.x, j), __shfl(M0.y, j), __shfl(M0.z, j), __shfl(M0.w,j));
const float4 jQ0 = make_float4(__shfl(Q0.x, j), __shfl(Q0.y, j), __shfl(Q0.z, j), 0.0f);
const float4 jQ1 = make_float4(__shfl(Q1.x, j), __shfl(Q1.y, j), __shfl(Q1.z, j), 0.0f);
const float jmass = jM0.w;
const float3 jpos = make_float3(jM0.x, jM0.y, jM0.z);
#pragma unroll
for (int k = 0; k < NI; k++)
acc_i[k] = add_acc(acc_i[k], pos_i[k], jmass, jpos, jQ0, jQ1, eps2, dens_i[k]);
}
}
#endif
/*******************************/
/****** Opening criterion ******/
/*******************************/
//Improved Barnes Hut criterium
static __device__ bool split_node_grav_impbh(
const float4 nodeCOM,
const float4 groupCenter,
const float4 groupSize)
{
//Compute the distance between the group and the cell
float3 dr = make_float3(
fabsf(groupCenter.x - nodeCOM.x) - (groupSize.x),
fabsf(groupCenter.y - nodeCOM.y) - (groupSize.y),
fabsf(groupCenter.z - nodeCOM.z) - (groupSize.z)
);
dr.x += fabsf(dr.x); dr.x *= 0.5f;
dr.y += fabsf(dr.y); dr.y *= 0.5f;
dr.z += fabsf(dr.z); dr.z *= 0.5f;
//Distance squared, no need to do sqrt since opening criteria has been squared
const float ds2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z;
return (ds2 <= fabsf(nodeCOM.w));
}
//Minimum distance
__device__ bool split_node_grav_md(
const float4 nodeCenter,
const float4 nodeSize,
const float4 groupCenter,
const float4 groupSize)
{
//Compute the distance between the group and the cell
float3 dr = {fabs(groupCenter.x - nodeCenter.x) - (groupSize.x + nodeSize.x),
fabs(groupCenter.y - nodeCenter.y) - (groupSize.y + nodeSize.y),
fabs(groupCenter.z - nodeCenter.z) - (groupSize.z + nodeSize.z)};
dr.x += fabs(dr.x); dr.x *= 0.5f;
dr.y += fabs(dr.y); dr.y *= 0.5f;
dr.z += fabs(dr.z); dr.z *= 0.5f;
//Distance squared, no need to do sqrt since opening criteria has been squared
float ds2 = dr.x*dr.x + dr.y*dr.y + dr.z*dr.z;
return (ds2 <= fabs(nodeCenter.w));
}
#define TEXTURES
template<int SHIFT, int BLOCKDIM2, int NI, bool INTCOUNT>
static __device__
uint2 approximate_gravity(
float4 acc_i[NI],
const float4 _pos_i[NI],
const float4 groupPos,
const float eps2,
const uint2 top_cells,
int *shmem,
int *cellList,
const float4 groupSize,
float2 dens_i[NI])
{
const int laneIdx = threadIdx.x & (WARP_SIZE-1);
/* this helps to unload register pressure */
float4 pos_i[NI];
#pragma unroll 1
for (int i = 0; i < NI; i++)
pos_i[i] = _pos_i[i];
uint2 interactionCounters = {0}; /* # of approximate and exact force evaluations */
#pragma unroll 1
for (int i = 0; i < NI; i++)
dens_i[i] = make_float2(0,0);
volatile int *tmpList = shmem;
int approxCellIdx, directPtclIdx;
int directCounter = 0;
int approxCounter = 0;
for (int root_cell = top_cells.x; root_cell < top_cells.y; root_cell += WARP_SIZE)
if (root_cell + laneIdx < top_cells.y)
cellList[ringAddr<SHIFT>(root_cell - top_cells.x + laneIdx)] = root_cell + laneIdx;
int nCells = top_cells.y - top_cells.x;
int cellListBlock = 0;
int nextLevelCellCounter = 0;
unsigned int cellListOffset = 0;
/* process level with n_cells */
#if 1
while (nCells > 0)
{
/* extract cell index from the current level cell list */
const int cellListIdx = cellListBlock + laneIdx;
const bool useCell = cellListIdx < nCells;
const int cellIdx = cellList[ringAddr<SHIFT>(cellListOffset + cellListIdx)];
cellListBlock += min(WARP_SIZE, nCells - cellListBlock);
/* read from gmem cell's info */
const float4 cellSize = tex1Dfetch(texNodeSize, cellIdx);
const float4 cellPos = tex1Dfetch(texNodeCenter, cellIdx);
#if 1
const float4 cellCOM = tex1Dfetch(texMultipole, cellIdx+cellIdx+cellIdx);
/* check if cell opening condition is satisfied */
const float4 cellCOM1 = make_float4(cellCOM.x, cellCOM.y, cellCOM.z, cellPos.w);
bool splitCell = split_node_grav_impbh(cellCOM1, groupPos, groupSize);
#else /*added by egaburov, see compute_propertiesD.cu for matching code */
bool splitCell = split_node_grav_impbh(cellPos, groupPos, groupSize);
#endif
/* compute first child, either a cell if node or a particle if leaf */
const int cellData = __float_as_int(cellSize.w);
const int firstChild = cellData & 0x0FFFFFFF;
const int nChildren = (cellData & 0xF0000000) >> 28;
if(cellData == 0xFFFFFFFF)
splitCell = false;
/**********************************************/
/* split cells that satisfy opening condition */
/**********************************************/
const bool isNode = cellPos.w > 0.0f;
{
bool splitNode = isNode && splitCell && useCell;
/* use exclusive scan to compute scatter addresses for each of the child cells */
const int2 childScatter = warpIntExclusiveScan(nChildren & (-splitNode));
/* make sure we still have available stack space */
if (childScatter.y + nCells - cellListBlock > (CELL_LIST_MEM_PER_WARP<<SHIFT))
return make_uint2(0xFFFFFFFF,0xFFFFFFFF);
#if 1
/* if so populate next level stack in gmem */
if (splitNode)
{
const int scatterIdx = cellListOffset + nCells + nextLevelCellCounter + childScatter.x;
for (int i = 0; i < nChildren; i++)
cellList[ringAddr<SHIFT>(scatterIdx + i)] = firstChild + i;
}
#else /* use scan operation to accomplish steps above, doesn't bring performance benefit */
int nChildren = childScatter.y;
int nProcessed = 0;
int2 scanVal = {0};
const int offset = cellListOffset + nCells + nextLevelCellCounter;
while (nChildren > 0)
{
tmpList[laneIdx] = 1;
if (splitNode && (childScatter.x - nProcessed < WARP_SIZE))
{
splitNode = false;
tmpList[childScatter.x - nProcessed] = -1-firstChild;
}
scanVal = inclusive_segscan_warp(tmpList[laneIdx], scanVal.y);
if (laneIdx < nChildren)
cellList[ringAddr<SHIFT>(offset + nProcessed + laneIdx)] = scanVal.x;
nChildren -= WARP_SIZE;
nProcessed += WARP_SIZE;
}
#endif
nextLevelCellCounter += childScatter.y; /* increment nextLevelCounter by total # of children */
}
#if 1
{
/***********************************/
/****** APPROX ******/
/***********************************/
/* see which thread's cell can be used for approximate force calculation */
const bool approxCell = !splitCell && useCell;
const int2 approxScatter = warpBinExclusiveScan(approxCell);
/* store index of the cell */
const int scatterIdx = approxCounter + approxScatter.x;
tmpList[laneIdx] = approxCellIdx;
if (approxCell && scatterIdx < WARP_SIZE)
tmpList[scatterIdx] = cellIdx;
approxCounter += approxScatter.y;
/* compute approximate forces */
if (approxCounter >= WARP_SIZE)
{
/* evalute cells stored in shmem */
approxAcc<NI,true>(acc_i, pos_i, dens_i, tmpList[laneIdx], eps2);
approxCounter -= WARP_SIZE;
const int scatterIdx = approxCounter + approxScatter.x - approxScatter.y;
if (approxCell && scatterIdx >= 0)
tmpList[scatterIdx] = cellIdx;
if (INTCOUNT)
interactionCounters.x += WARP_SIZE*NI;
}
approxCellIdx = tmpList[laneIdx];
}
#endif
#if 1
{
/***********************************/
/****** DIRECT ******/
/***********************************/
const bool isLeaf = !isNode;
bool isDirect = splitCell && isLeaf && useCell;
const int firstBody = cellData & BODYMASK;
const int nBody = ((cellData & INVBMASK) >> LEAFBIT)+1;
const int2 childScatter = warpIntExclusiveScan(nBody & (-isDirect));
int nParticle = childScatter.y;
int nProcessed = 0;
int2 scanVal = {0};
/* conduct segmented scan for all leaves that need to be expanded */
while (nParticle > 0)
{
tmpList[laneIdx] = 1;
if (isDirect && (childScatter.x - nProcessed < WARP_SIZE))
{
isDirect = false;
tmpList[childScatter.x - nProcessed] = -1-firstBody;
}
scanVal = inclusive_segscan_warp(tmpList[laneIdx], scanVal.y);
const int ptclIdx = scanVal.x;
if (nParticle >= WARP_SIZE)
{
directAcc<NI,true>(acc_i, pos_i, ptclIdx, eps2, dens_i);
nParticle -= WARP_SIZE;
nProcessed += WARP_SIZE;
if (INTCOUNT)
interactionCounters.y += WARP_SIZE*NI;
}
else
{
const int scatterIdx = directCounter + laneIdx;
tmpList[laneIdx] = directPtclIdx;
if (scatterIdx < WARP_SIZE)
tmpList[scatterIdx] = ptclIdx;
directCounter += nParticle;
if (directCounter >= WARP_SIZE)
{
/* evalute cells stored in shmem */
directAcc<NI,true>(acc_i, pos_i, tmpList[laneIdx], eps2, dens_i);
directCounter -= WARP_SIZE;
const int scatterIdx = directCounter + laneIdx - nParticle;
if (scatterIdx >= 0)
tmpList[scatterIdx] = ptclIdx;
if (INTCOUNT)
interactionCounters.y += WARP_SIZE*NI;
}
directPtclIdx = tmpList[laneIdx];
nParticle = 0;
}
}
}
#endif
/* if the current level is processed, schedule the next level */
if (cellListBlock >= nCells)
{
cellListOffset += nCells;
nCells = nextLevelCellCounter;
cellListBlock = nextLevelCellCounter = 0;
}
} /* level completed */
#endif
if (approxCounter > 0)
{
approxAcc<NI,false>(acc_i, pos_i, dens_i, laneIdx < approxCounter ? approxCellIdx : -1, eps2);
if (INTCOUNT)
interactionCounters.x += approxCounter * NI;
approxCounter = 0;
}
if (directCounter > 0)
{
directAcc<NI,false>(acc_i, pos_i, laneIdx < directCounter ? directPtclIdx : -1, eps2, dens_i);
if (INTCOUNT)
interactionCounters.y += directCounter * NI;
directCounter = 0;
}
return interactionCounters;
}
template<int SHIFT2, int BLOCKDIM2, bool ACCUMULATE>
static __device__
bool treewalk(
const int bid,
const float eps2,
const uint2 node_begend,
const int *active_groups,
const real4 *group_body_pos,
const float4 *groupSizeInfo,
const float4 *groupCenterInfo,
int *shmem,
int *lmem,
float4 *acc_out,
int2 *interactions,
int *ngb_out,
int *active_inout,
float *body_h,
float2 *body_dens_out)
{
/*********** set necessary thread constants **********/
#ifdef DO_BLOCK_TIMESTEP
real4 curGroupSize = groupSizeInfo[active_groups[bid]];
#else
real4 curGroupSize = groupSizeInfo[bid];
#endif
const int groupData = __float_as_int(curGroupSize.w);
const uint body_addr = groupData & CRITMASK;
const uint nb_i = ((groupData & INVCMASK) >> CRITBIT) + 1;
#ifdef DO_BLOCK_TIMESTEP
real4 group_pos = groupCenterInfo[active_groups[bid]];
#else
real4 group_pos = groupCenterInfo[bid];
#endif
uint body_i[2];
const int ni = nb_i <= WARP_SIZE ? 1 : 2;
body_i[0] = body_addr + laneId%nb_i;
body_i[1] = body_addr + WARP_SIZE + laneId%(nb_i - WARP_SIZE);
float4 pos_i[2];
float4 acc_i[2];
float2 dens_i[2];
pos_i[0] = group_body_pos[body_i[0]];
pos_i[0].w = 1.0f/body_h[body_i[0]];
pos_i[0].w *= pos_i[0].w; /* .w stores 1/h^2 to speed up computations */
if(ni > 1){ //Only read if we actually have ni == 2
pos_i[1] = group_body_pos[body_i[1]];
pos_i[1].w = 1.0f/body_h[body_i[1]];
pos_i[1].w *= pos_i[1].w; /* .w stores 1/h^2 to speed up computations */
}
acc_i[0] = acc_i[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
dens_i[0] = dens_i[1] = make_float2(0.0f, 0.0f);
#if 0
const bool INTCOUNT = false;
#else
const bool INTCOUNT = true;
#endif
uint2 counters = {0};
{
if (ni == 1)
counters = approximate_gravity<SHIFT2, BLOCKDIM2, 1,INTCOUNT>(
acc_i,
pos_i,
group_pos,
eps2,
node_begend,
shmem,
lmem,
curGroupSize,
dens_i);
else
counters = approximate_gravity<SHIFT2, BLOCKDIM2, 2,INTCOUNT>(
acc_i,
pos_i,
group_pos,
eps2,
node_begend,
shmem,
lmem,
curGroupSize,
dens_i);
}
if(counters.x == 0xFFFFFFFF && counters.y == 0xFFFFFFFF)
return false;
#if 0
/* CUDA 8RC work around */
if(bid < 0) // bid ==0 && laneId < nb_i && && threadIdx.x == 0)
{
printf("TEST\n");
//printf("ON DEV [%d %d : %d %d ] ACC: %f %f %f %f INT: %d %d \n",
// bid, threadIdx.x, nb_i, body_i[0],
// acc_i[0].x,acc_i[0].y,acc_i[0].z,acc_i[0].w,
// counters.x, counters.y);
}
#endif
if (laneId < nb_i)
{
const int addr = body_i[0];
{
const float hinv = 1.0f/body_h[addr];
const float C = 3465.0f/(512.0f*M_PI)*hinv*hinv*hinv;
dens_i[0].x *= C; /* scale rho */
}
if (ACCUMULATE)
{
acc_out [addr].x += acc_i[0].x;
acc_out [addr].y += acc_i[0].y;
acc_out [addr].z += acc_i[0].z;
acc_out [addr].w += acc_i[0].w;
body_dens_out[addr].x += dens_i[0].x;
body_dens_out[addr].y += dens_i[0].y;
}
else
{
acc_out [addr] = acc_i[0];
body_dens_out[addr] = dens_i[0];
}
// ngb_out [addr] = ngb_i;
ngb_out [addr] = addr; //JB Fixed this for demo
active_inout[addr] = 1;
if (ACCUMULATE)
{
interactions[addr].x += counters.x / ni;
interactions[addr].y += counters.y / ni ;
}
else
{
interactions[addr].x = counters.x / ni;
interactions[addr].y = counters.y / ni ;
}
if (ni == 2)
{
const int addr = body_i[1];
{
const float hinv = 1.0f/body_h[addr];
const float C = 3465.0f/(512.0f*M_PI)*hinv*hinv*hinv;
dens_i[1].x *= C; /* scale rho */
}
if (ACCUMULATE)
{
acc_out [addr].x += acc_i[1].x;
acc_out [addr].y += acc_i[1].y;
acc_out [addr].z += acc_i[1].z;
acc_out [addr].w += acc_i[1].w;
body_dens_out[addr].x += dens_i[1].x;
body_dens_out[addr].y += dens_i[1].y;
}
else
{
acc_out [addr] = acc_i[1];
body_dens_out[addr] = dens_i[1];
// body_h[addr] = adjustH(body_h[addr], dens_i[1].y);
}
// ngb_out [addr] = ngb_i;
ngb_out [addr] = addr; //JB Fixed this for demo
active_inout[addr] = 1;
if (ACCUMULATE)
{
interactions[addr].x += counters.x / ni;
interactions[addr].y += counters.y / ni;
}
else
{
interactions[addr].x = counters.x / ni;
interactions[addr].y = counters.y / ni;
}
}
}
return true;
}
template<bool ACCUMULATE, int BLOCKDIM2>
static __device__
void approximate_gravity_main(
const int n_active_groups,
int n_bodies,
float eps2,
uint2 node_begend,
int *active_groups,
real4 *body_pos,
real4 *multipole_data,
float4 *acc_out,
real4 *group_body_pos, //This can be different from body_pos
int *ngb_out,
int *active_inout,
int2 *interactions,
float4 *boxSizeInfo,
float4 *groupSizeInfo,
float4 *boxCenterInfo,
float4 *groupCenterInfo,
real4 *body_vel,
int *MEM_BUF,
float *body_h,
float2 *body_dens)
{
const int blockDim2 = BLOCKDIM2;
const int shMemSize = 1 * (1 << blockDim2);
__shared__ int shmem_pool[shMemSize];
const int nWarps2 = blockDim2 - WARP_SIZE2;
const int sh_offs = (shMemSize >> nWarps2) * warpId;
int *shmem = shmem_pool + sh_offs;
volatile int *shmemv = shmem;
#if 0
#define SHMODE
#endif
#ifdef SHMODE
const int nWarps = 1<<nWarps2;
const int MAXFAILED = 64;
__shared__ int failedList[MAXFAILED];
__shared__ unsigned int failed;
if (threadIdx.x == 0)
failed = 0;
#endif
__syncthreads();
/*********** check if this block is linked to a leaf **********/
int bid = gridDim.x * blockIdx.y + blockIdx.x;
while(true)
{
if(laneId == 0)
{
bid = atomicAdd(&active_inout[n_bodies], 1);
shmemv[0] = bid;
}
bid = shmemv[0];
if (bid >= n_active_groups) return;
int *lmem = &MEM_BUF[(CELL_LIST_MEM_PER_WARP<<nWarps2)*blockIdx.x + CELL_LIST_MEM_PER_WARP*warpId];
const bool success = treewalk<0,blockDim2,ACCUMULATE>(
bid,
eps2,
node_begend,
active_groups,
group_body_pos,
groupSizeInfo,
groupCenterInfo,
shmem,
lmem,
acc_out,
interactions,
ngb_out,
active_inout,
body_h,
body_dens);
#if 0
if (bid % 10 == 0)
success = false;
#endif
#ifdef SHMODE
if (!success)
if (laneId == 0)
failedList[atomicAdd(&failed,1)] = bid;
if (failed + nWarps >= MAXFAILED)
{
__syncthreads();
if (warpId == 0)
{
int *lmem1 = &MEM_BUF[(CELL_LIST_MEM_PER_WARP<<nWarps2)*blockIdx.x];
const int n = failed;
failed = 0;
for (int it = 0; it < n; it++)
{
const bool success = treewalk<nWarp2,blockDim2,ACCUMULATE>(
failedList[it],
eps2,
node_begend,
active_groups,
group_body_pos,
groupSizeInfo,
groupCenterInfo,
shmem,
lmem1,
acc_out,
interactions,
ngb_out,
active_inout);
assert(success);
}
}
__syncthreads();
}
#else
//Try to get access to the big stack, only one block per time is allowed
if (!success)
{
if(laneId == 0)
{
int res = atomicExch(&active_inout[n_bodies+1], 1); //If the old value (res) is 0 we can go otherwise sleep
int waitCounter = 0;
while(res != 0)
{
//Sleep
for(int i=0; i < (1024); i++)
waitCounter += 1;
//Test again
shmem[0] = waitCounter;
res = atomicExch(&active_inout[n_bodies+1], 1);
}
}
int *lmem1 = &MEM_BUF[gridDim.x*(CELL_LIST_MEM_PER_WARP<<nWarps2)];
const bool success = treewalk<8,blockDim2,ACCUMULATE>(
bid,
eps2,
node_begend,
active_groups,
group_body_pos,
groupSizeInfo,
groupCenterInfo,
shmem,
lmem1,
acc_out,
interactions,
ngb_out,
active_inout,
body_h,
body_dens);
assert(success);
if(laneId == 0)
atomicExch(&active_inout[n_bodies+1], 0); //Release the lock
}
#endif /* SHMODE */
} //end while
#undef SHMODE
}
extern "C"
__launch_bounds__(NTHREAD,1024/NTHREAD)
__global__ void
dev_approximate_gravity(
const int n_active_groups,
int n_bodies,
float eps2,
uint2 node_begend,
int *active_groups,
real4 *body_pos,
real4 *multipole_data,
float4 *acc_out,
real4 *group_body_pos, //This can be different from body_pos
int *ngb_out,
int *active_inout,
int2 *interactions,
float4 *boxSizeInfo,
float4 *groupSizeInfo,
float4 *boxCenterInfo,
float4 *groupCenterInfo,
real4 *body_vel,
int *MEM_BUF,
float *body_h,
float2 *body_dens)
{
approximate_gravity_main<false, NTHREAD2>(
n_active_groups,
n_bodies,
eps2,
node_begend,
active_groups,
body_pos,
multipole_data,
acc_out,
group_body_pos, //This can be different from body_pos
ngb_out,
active_inout,
interactions,
boxSizeInfo,
groupSizeInfo,
boxCenterInfo,
groupCenterInfo,
body_vel,
MEM_BUF,
body_h,
body_dens);
}
extern "C"
__launch_bounds__(NTHREAD,1024/NTHREAD)
__global__ void
dev_approximate_gravity_let(
const int n_active_groups,
int n_bodies,
float eps2,
uint2 node_begend,
int *active_groups,
real4 *body_pos,
real4 *multipole_data,
float4 *acc_out,
real4 *group_body_pos, //This can be different from body_pos
int *ngb_out,
int *active_inout,
int2 *interactions,
float4 *boxSizeInfo,
float4 *groupSizeInfo,
float4 *boxCenterInfo,
float4 *groupCenterInfo,
real4 *body_vel,
int *MEM_BUF,
float *body_h,
float2 *body_dens)
{
approximate_gravity_main<true, NTHREAD2>(
n_active_groups,
n_bodies,
eps2,
node_begend,
active_groups,
body_pos,
multipole_data,
acc_out,
group_body_pos, //This can be different from body_pos
ngb_out,
active_inout,
interactions,
boxSizeInfo,
groupSizeInfo,
boxCenterInfo,
groupCenterInfo,
body_vel,
MEM_BUF,
body_h,
body_dens);
}
|
d52e6f6a848c35df9211eaadc62d58d0b8c4e33e.hip | // !!! This is a file automatically generated by hipify!!!
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
// includes CUDA
#include <hip/hip_runtime.h>
extern "C" {
#include "MatUtil.h"
}
#define TILE_WIDTH 32
#define TILE_HEIGHT 32
__device__
int Min(int a, int b) { return a < b ? a : b; }
__global__
void SharedMemoryFloydWarshall(int* mat, int k, int N) {
__shared__ int dist_i_k[TILE_HEIGHT];
__shared__ int dist_k_j[TILE_WIDTH];
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < N && j < N) {
int dist_i_j = mat[i*N + j];
if (i % TILE_HEIGHT == 0) {
dist_k_j[j % TILE_WIDTH] = mat[k*N + j];
}
if (j % TILE_WIDTH == 0) {
dist_i_k[i % TILE_HEIGHT] = mat[i*N + k];
}
__syncthreads();
if (dist_i_k[i % TILE_HEIGHT] != -1 && dist_k_j[j % TILE_WIDTH] != -1) {
int new_dist = dist_i_k[i % TILE_HEIGHT] + dist_k_j[j % TILE_WIDTH];
if (dist_i_j != -1) {
new_dist = Min(new_dist, dist_i_j);
}
mat[i*N + j] = new_dist;
}
}
}
void SharedMemoryFloydWarshallDriver(int* mat, int N, dim3 thread_per_block) {
int* cuda_mat;
int size = sizeof(int) * N * N;
hipMalloc((void**) &cuda_mat, size);
hipMemcpy(cuda_mat, mat, size, hipMemcpyHostToDevice);
dim3 num_block(ceil(1.0*N/thread_per_block.x),
ceil(1.0*N/thread_per_block.y));
for (int k = 0; k < N; ++k) {
hipLaunchKernelGGL(( SharedMemoryFloydWarshall), dim3(num_block), dim3(thread_per_block), 0, 0, cuda_mat, k, N);
}
hipMemcpy(mat, cuda_mat, size, hipMemcpyDeviceToHost);
hipFree(cuda_mat);
}
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
if(argc != 3) {
printf("Usage: test {N} {run_sequential_check: 'T' or 'F'}\n");
exit(-1);
}
char run_sequential_check = argv[2][0];
dim3 thread_per_block(TILE_HEIGHT, TILE_WIDTH);
//generate a random matrix.
size_t N = atoi(argv[1]);
int *mat = (int*)malloc(sizeof(int)*N*N);
GenMatrix(mat, N);
//compute your results
int *result = (int*)malloc(sizeof(int)*N*N);
memcpy(result, mat, sizeof(int)*N*N);
//replace by parallel algorithm
SharedMemoryFloydWarshallDriver(result, N, thread_per_block);
//compare your result with reference result
if (run_sequential_check == 'T') {
int *ref = (int*)malloc(sizeof(int)*N*N);
memcpy(ref, mat, sizeof(int)*N*N);
ST_APSP(ref, N);
if(CmpArray(result, ref, N*N))
printf("Your result is correct.\n");
else
printf("Your result is wrong.\n");
#ifdef PRINT_MATRIX
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
printf("%d ", ref[i*N+j]);
}
printf("\n");
}
#endif
}
#ifdef PRINT_MATRIX
printf("==RESULT==\n");
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
printf("%d ", result[i*N+j]);
}
printf("\n");
}
#endif
}
| d52e6f6a848c35df9211eaadc62d58d0b8c4e33e.cu | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
// includes CUDA
#include <cuda_runtime.h>
extern "C" {
#include "MatUtil.h"
}
#define TILE_WIDTH 32
#define TILE_HEIGHT 32
__device__
int Min(int a, int b) { return a < b ? a : b; }
__global__
void SharedMemoryFloydWarshall(int* mat, int k, int N) {
__shared__ int dist_i_k[TILE_HEIGHT];
__shared__ int dist_k_j[TILE_WIDTH];
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < N && j < N) {
int dist_i_j = mat[i*N + j];
if (i % TILE_HEIGHT == 0) {
dist_k_j[j % TILE_WIDTH] = mat[k*N + j];
}
if (j % TILE_WIDTH == 0) {
dist_i_k[i % TILE_HEIGHT] = mat[i*N + k];
}
__syncthreads();
if (dist_i_k[i % TILE_HEIGHT] != -1 && dist_k_j[j % TILE_WIDTH] != -1) {
int new_dist = dist_i_k[i % TILE_HEIGHT] + dist_k_j[j % TILE_WIDTH];
if (dist_i_j != -1) {
new_dist = Min(new_dist, dist_i_j);
}
mat[i*N + j] = new_dist;
}
}
}
void SharedMemoryFloydWarshallDriver(int* mat, int N, dim3 thread_per_block) {
int* cuda_mat;
int size = sizeof(int) * N * N;
cudaMalloc((void**) &cuda_mat, size);
cudaMemcpy(cuda_mat, mat, size, cudaMemcpyHostToDevice);
dim3 num_block(ceil(1.0*N/thread_per_block.x),
ceil(1.0*N/thread_per_block.y));
for (int k = 0; k < N; ++k) {
SharedMemoryFloydWarshall<<<num_block, thread_per_block>>>(cuda_mat, k, N);
}
cudaMemcpy(mat, cuda_mat, size, cudaMemcpyDeviceToHost);
cudaFree(cuda_mat);
}
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
if(argc != 3) {
printf("Usage: test {N} {run_sequential_check: 'T' or 'F'}\n");
exit(-1);
}
char run_sequential_check = argv[2][0];
dim3 thread_per_block(TILE_HEIGHT, TILE_WIDTH);
//generate a random matrix.
size_t N = atoi(argv[1]);
int *mat = (int*)malloc(sizeof(int)*N*N);
GenMatrix(mat, N);
//compute your results
int *result = (int*)malloc(sizeof(int)*N*N);
memcpy(result, mat, sizeof(int)*N*N);
//replace by parallel algorithm
SharedMemoryFloydWarshallDriver(result, N, thread_per_block);
//compare your result with reference result
if (run_sequential_check == 'T') {
int *ref = (int*)malloc(sizeof(int)*N*N);
memcpy(ref, mat, sizeof(int)*N*N);
ST_APSP(ref, N);
if(CmpArray(result, ref, N*N))
printf("Your result is correct.\n");
else
printf("Your result is wrong.\n");
#ifdef PRINT_MATRIX
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
printf("%d ", ref[i*N+j]);
}
printf("\n");
}
#endif
}
#ifdef PRINT_MATRIX
printf("==RESULT==\n");
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
printf("%d ", result[i*N+j]);
}
printf("\n");
}
#endif
}
|
a24d7cf6f30efd59b359b31896ddd88dbfd117e3.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
extern "C" __global__ void hconv_updat_C128_K64(
float* param_Sum,
float* param_F,
const unsigned short* param_I,
const unsigned short* param_E,
float param_alpha,
float param_beta,
int param_flags,
int param_offset_K,
int param_N,
int param_K,
int param_D,
int param_H,
int param_W,
int param_WN,
int param_HWN,
int param_DHWN,
int param_C,
int param_CRST,
int param_RST,
int param_magic_RST,
int param_shift_RST,
int param_RS,
int param_magic_RS,
int param_shift_RS,
int param_S,
int param_magic_S,
int param_shift_S,
int param_pad_d,
int param_pad_h,
int param_pad_w,
int param_str_d,
int param_str_h,
int param_str_w,
int param_P,
int param_Q,
int param_PQ,
int param_QN,
int param_PQN,
int param_MPQN,
int param_magic_Q,
int param_shift_Q,
int param_magic_PQ,
int param_shift_PQ,
int param_part_P,
int param_part_Q,
int param_part_PQ
) {
__shared__ float share[(128*16 + 32)*2 + ( 64*16 + 32)*2 + 8];
*param_Sum = share[0];
}
| a24d7cf6f30efd59b359b31896ddd88dbfd117e3.cu |
extern "C" __global__ void hconv_updat_C128_K64(
float* param_Sum,
float* param_F,
const unsigned short* param_I,
const unsigned short* param_E,
float param_alpha,
float param_beta,
int param_flags,
int param_offset_K,
int param_N,
int param_K,
int param_D,
int param_H,
int param_W,
int param_WN,
int param_HWN,
int param_DHWN,
int param_C,
int param_CRST,
int param_RST,
int param_magic_RST,
int param_shift_RST,
int param_RS,
int param_magic_RS,
int param_shift_RS,
int param_S,
int param_magic_S,
int param_shift_S,
int param_pad_d,
int param_pad_h,
int param_pad_w,
int param_str_d,
int param_str_h,
int param_str_w,
int param_P,
int param_Q,
int param_PQ,
int param_QN,
int param_PQN,
int param_MPQN,
int param_magic_Q,
int param_shift_Q,
int param_magic_PQ,
int param_shift_PQ,
int param_part_P,
int param_part_Q,
int param_part_PQ
) {
__shared__ float share[(128*16 + 32)*2 + ( 64*16 + 32)*2 + 8];
*param_Sum = share[0];
}
|
e35b1b160bbe1dea44aed32931acfabb78cb8bfa.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#ifdef _TIMER_
#include "hip/hip_runtime_api.h"
#endif
#include "stdio.h"
#define FORMA_MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define max(a,b) FORMA_MAX(a,b)
#define FORMA_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define min(a,b) FORMA_MIN(a,b)
#define FORMA_CEIL(a,b) ( (a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1 )
#ifndef FORMA_MAX_BLOCKDIM_0
#define FORMA_MAX_BLOCKDIM_0 1024
#endif
#ifndef FORMA_MAX_BLOCKDIM_1
#define FORMA_MAX_BLOCKDIM_1 1024
#endif
#ifndef FORMA_MAX_BLOCKDIM_2
#define FORMA_MAX_BLOCKDIM_2 1024
#endif
#define GAPX (22)
#define GAPY (6)
#define GAPZ (2)
#define EXTENT (5)
template<typename T>
__global__ void __kernel_init__(T* input, T value)
{
int loc = (int)(blockIdx.x)*(int)(blockDim.x)+(int)(threadIdx.x);
input[loc] = value;
}
template<typename T>
void initialize_array(T* d_input, int size, T value)
{
dim3 init_grid(FORMA_CEIL(size,FORMA_MAX_BLOCKDIM_0));
dim3 init_block(FORMA_MAX_BLOCKDIM_0);
hipLaunchKernelGGL(( __kernel_init__), dim3(init_grid),dim3(init_block), 0, 0, d_input,value);
}
void Check_CUDA_Error(const char* message);
/*Texture references */
/*Shared Memory Variable */
extern __shared__ char __FORMA_SHARED_MEM__[];
/* Device code Begin */
/* X, Y, Z */
__global__ void __kernel___forma_kernel__0__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+1))))] = __temp_33__;
}
}
}
__syncthreads ();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2) || __iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2) || __iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+1))))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+1))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+1))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+2))))] = __temp_80__;
}
}
}
__syncthreads ();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2) || __iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2) || __iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+2))))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+2))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+2))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+3))))] = __temp_106__;
}
}
}
__syncthreads ();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2) || __iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2) || __iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+3))))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+3))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+3))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
}
}
}
}
int __blockSizeToSMemSize___kernel___forma_kernel__0__(dim3 blockDim){
int FORMA_BLOCKDIM_Z = (int)(blockDim.z);
int FORMA_BLOCKDIM_Y = (int)(blockDim.y);
int FORMA_BLOCKDIM_X = (int)(blockDim.x);
int SMemSize = 0;
SMemSize += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
SMemSize += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
return SMemSize;
}
/* X+GAP, Y, Z */
__global__ void __kernel___forma_kernel__1__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + (int)(FORMA_BLOCKDIM_X);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2) || __iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_11__ < FORMA_MAX((__iter_0__-1),1) || __iter_11__ > FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2) || __iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_20__ < FORMA_MAX((__iter_0__-2),1) || __iter_20__ > FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2) || __iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_29__ < FORMA_MAX((__iter_0__-3),1) || __iter_29__ > FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
}
}
}
}
/* X, Y+GAP, Z */
__global__ void __kernel___forma_kernel__2__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)(FORMA_BLOCKDIM_Y);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2) || __iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_10__ < FORMA_MAX((__iter_1__-1),1) || __iter_10__ > FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2))) {
__tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2) || __iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_19__ < FORMA_MAX((__iter_1__-2),1) || __iter_19__ > FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) {
__tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2) || __iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_28__ < FORMA_MAX((__iter_1__-3),1) || __iter_28__ > FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) {
__tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X, Y, Z+GAP */
__global__ void __kernel___forma_kernel__3__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + FORMA_BLOCKDIM_Z;
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2) || __iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)))) {
__tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2) || __iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+2+GAPZ)-1),(L-2)))) {
__tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2) || __iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)))) {
__tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X+GAP, Y+GAP, Z */
__global__ void __kernel___forma_kernel__4__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + (int)(FORMA_BLOCKDIM_X);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)(FORMA_BLOCKDIM_Y);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for(; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_10__ < FORMA_MAX((__iter_1__-1),1) || __iter_10__ > FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) || __iter_11__ < FORMA_MAX((__iter_0__-1),1) || __iter_11__ > FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_19__ < (FORMA_MAX((__iter_1__-2),1)) || __iter_19__ > (FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) || __iter_20__ < FORMA_MAX((__iter_0__-2),1) || __iter_20__ > FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_28__ < (FORMA_MAX((__iter_1__-3),1)) || __iter_28__ > (FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) || __iter_29__ < FORMA_MAX((__iter_0__-3),1) || __iter_29__ > FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
}
}
}
}
/* X, Y+GAP, Z+GAP */
__global__ void __kernel___forma_kernel__5__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)(FORMA_BLOCKDIM_Y);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + (int)(FORMA_BLOCKDIM_Z);
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2))) ||__iter_10__ < FORMA_MAX((__iter_1__-1),1) || __iter_10__ > FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2))) {
__tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2))) || __iter_19__ < FORMA_MAX((__iter_1__-2),1) || __iter_19__ > FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) {
__tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2))) || __iter_28__ < FORMA_MAX((__iter_1__-3),1) || __iter_28__ > FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) {
__tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X+GAP, Y, Z+GAP */
__global__ void __kernel___forma_kernel__6__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + FORMA_BLOCKDIM_X;
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + FORMA_BLOCKDIM_Z;
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
if (__iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2))) || __iter_11__ < (FORMA_MAX((__iter_0__-1),1)) || __iter_11__ > (FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
if (__iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+2+GAPZ)-1),(L-2))) || __iter_20__ < (FORMA_MAX((__iter_0__-2),1)) || __iter_20__ > (FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2))) || __iter_29__ < (FORMA_MAX((__iter_0__-3),1)) || __iter_29__ > (FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X+GAP, Y+GAP, Z+GAP */
__global__ void __kernel___forma_kernel__7__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + (int)FORMA_BLOCKDIM_X;
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)FORMA_BLOCKDIM_Y;
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + (int)FORMA_BLOCKDIM_Z;
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2))) || __iter_10__ < (FORMA_MAX((__iter_1__-1),1)) || __iter_10__ > (FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2))) || __iter_11__ < (FORMA_MAX((__iter_0__-1),1)) || __iter_11__ > (FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2))) || __iter_19__ < (FORMA_MAX((__iter_1__-2),1)) || __iter_19__ > (FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) || __iter_20__ < (FORMA_MAX((__iter_0__-2),1)) || __iter_20__ > (FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2))) || __iter_28__ < (FORMA_MAX((__iter_1__-3),1)) || __iter_28__ > (FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) || __iter_29__ < (FORMA_MAX((__iter_0__-3),1)) || __iter_29__ > (FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] at (%d,%d,%d) for block (%d,%d,%d) = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __iter_2__, __iter_1__, __iter_0__, blockIdx.x, blockIdx.y, blockIdx.z, __temp_132__);
}
}
}
}
/*Device code End */
/* Host Code Begin */
extern "C" void j3d7pt(float * h_input, int L, int M, int N, float * __var_0__){
/* Host allocation Begin */
float * input;
hipMalloc(&input,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : input\n");
hipPointerAttribute_t ptrAttrib_h_input;
hipMemcpyKind memcpy_kind_h_input = hipMemcpyHostToDevice;
if (hipPointerGetAttributes(&ptrAttrib_h_input, h_input) == hipSuccess)
if (ptrAttrib_h_input.memoryType == hipMemoryTypeDevice)
memcpy_kind_h_input = hipMemcpyDeviceToDevice;
hipGetLastError();
if( memcpy_kind_h_input != hipMemcpyDeviceToDevice ){
hipMemcpy(input,h_input,sizeof(float)*((L-0)*(M-0)*(N-0)), memcpy_kind_h_input);
}
float * __var_1__;
hipMalloc(&__var_1__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __var_1__\n");
float * __copy_arr_0__;
hipMalloc(&__copy_arr_0__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __copy_arr_0__\n");
float * __copy_arr_1__;
hipMalloc(&__copy_arr_1__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __copy_arr_1__\n");
float * __copy_arr_2__;
hipMalloc(&__copy_arr_2__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __copy_arr_2__\n");
/*Host Allocation End */
/* Kernel Launch Begin */
int __FORMA_MAX_SHARED_MEM__;
hipDeviceGetAttribute(&__FORMA_MAX_SHARED_MEM__,hipDeviceAttributeMaxSharedMemoryPerBlock,0);
#ifdef _TIMER_
hipEvent_t _forma_timer_start_,_forma_timer_stop_;
hipEventCreate(&_forma_timer_start_);
hipEventCreate(&_forma_timer_stop_);
hipEventRecord(_forma_timer_start_,0);
#endif
int __size_0___kernel___forma_kernel__0__ = ((N-1) - 0 ) + 1;
int __size_1___kernel___forma_kernel__0__ = ((M-1) - 0 ) + 1;
int __size_2___kernel___forma_kernel__0__ = ((L-1) - 0 ) + 1;
int __block_0___kernel___forma_kernel__0__ = 32;
int __block_1___kernel___forma_kernel__0__ = 16;
int __block_2___kernel___forma_kernel__0__ = 12;
dim3 __blockConfig___kernel___forma_kernel__0__(__block_0___kernel___forma_kernel__0__,__block_1___kernel___forma_kernel__0__,__block_2___kernel___forma_kernel__0__);
int __SMemSize___kernel___forma_kernel__0__ = 0;
__SMemSize___kernel___forma_kernel__0__ = __blockSizeToSMemSize___kernel___forma_kernel__0__(__blockConfig___kernel___forma_kernel__0__);
int __grid_0___kernel___forma_kernel__0__ = FORMA_CEIL(__size_0___kernel___forma_kernel__0__,__blockConfig___kernel___forma_kernel__0__.x+GAPX);
int __grid_1___kernel___forma_kernel__0__ = FORMA_CEIL(__size_1___kernel___forma_kernel__0__,__blockConfig___kernel___forma_kernel__0__.y+GAPY);
int __grid_2___kernel___forma_kernel__0__ = FORMA_CEIL(__size_2___kernel___forma_kernel__0__,__blockConfig___kernel___forma_kernel__0__.z+GAPZ);
dim3 __gridConfig___kernel___forma_kernel__0__(__grid_0___kernel___forma_kernel__0__,__grid_1___kernel___forma_kernel__0__,__grid_2___kernel___forma_kernel__0__);
dim3 unrollConfig (__blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y/4, __blockConfig___kernel___forma_kernel__0__.z/3);
hipLaunchKernelGGL(( __kernel___forma_kernel__0__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__0__\n");
hipLaunchKernelGGL(( __kernel___forma_kernel__1__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__1__\n");
hipLaunchKernelGGL(( __kernel___forma_kernel__2__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__2__\n");
hipLaunchKernelGGL(( __kernel___forma_kernel__3__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__3__\n");
hipLaunchKernelGGL(( __kernel___forma_kernel__4__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__4__\n");
hipLaunchKernelGGL(( __kernel___forma_kernel__5__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__5__\n");
hipLaunchKernelGGL(( __kernel___forma_kernel__6__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__6__\n");
hipLaunchKernelGGL(( __kernel___forma_kernel__7__), dim3(__gridConfig___kernel___forma_kernel__0__), dim3(unrollConfig), __SMemSize___kernel___forma_kernel__0__, 0, input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__7__\n");
hipPointerAttribute_t ptrAttrib___var_0__;
hipMemcpyKind memcpy_kind___var_0__ = hipMemcpyDeviceToHost;
if (hipPointerGetAttributes(&ptrAttrib___var_0__, __var_0__) == hipSuccess)
if (ptrAttrib___var_0__.memoryType == hipMemoryTypeDevice)
memcpy_kind___var_0__ = hipMemcpyDeviceToDevice;
hipGetLastError();
hipMemcpy(__var_0__,__var_1__, sizeof(float)*((L-0)*(M-0)*(N-0)), memcpy_kind___var_0__);
#ifdef _TIMER_
hipEventRecord(_forma_timer_stop_,0);
hipEventSynchronize(_forma_timer_stop_);
float elapsedTime;
hipEventElapsedTime(&elapsedTime,_forma_timer_start_,_forma_timer_stop_);
printf("[FORMA] Computation Time(ms) : %lf\n",elapsedTime);
hipEventDestroy(_forma_timer_start_);
hipEventDestroy(_forma_timer_stop_);
#endif
/*Kernel Launch End */
/* Host Free Begin */
hipFree(input);
hipFree(__var_1__);
hipFree(__copy_arr_0__);
hipFree(__copy_arr_1__);
hipFree(__copy_arr_2__);
}
/*Host Free End*/
| e35b1b160bbe1dea44aed32931acfabb78cb8bfa.cu | #include "cuda.h"
#ifdef _TIMER_
#include "cuda_profiler_api.h"
#endif
#include "stdio.h"
#define FORMA_MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define max(a,b) FORMA_MAX(a,b)
#define FORMA_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define min(a,b) FORMA_MIN(a,b)
#define FORMA_CEIL(a,b) ( (a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1 )
#ifndef FORMA_MAX_BLOCKDIM_0
#define FORMA_MAX_BLOCKDIM_0 1024
#endif
#ifndef FORMA_MAX_BLOCKDIM_1
#define FORMA_MAX_BLOCKDIM_1 1024
#endif
#ifndef FORMA_MAX_BLOCKDIM_2
#define FORMA_MAX_BLOCKDIM_2 1024
#endif
#define GAPX (22)
#define GAPY (6)
#define GAPZ (2)
#define EXTENT (5)
template<typename T>
__global__ void __kernel_init__(T* input, T value)
{
int loc = (int)(blockIdx.x)*(int)(blockDim.x)+(int)(threadIdx.x);
input[loc] = value;
}
template<typename T>
void initialize_array(T* d_input, int size, T value)
{
dim3 init_grid(FORMA_CEIL(size,FORMA_MAX_BLOCKDIM_0));
dim3 init_block(FORMA_MAX_BLOCKDIM_0);
__kernel_init__<<<init_grid,init_block>>>(d_input,value);
}
void Check_CUDA_Error(const char* message);
/*Texture references */
/*Shared Memory Variable */
extern __shared__ char __FORMA_SHARED_MEM__[];
/* Device code Begin */
/* X, Y, Z */
__global__ void __kernel___forma_kernel__0__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+1))))] = __temp_33__;
}
}
}
__syncthreads ();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2) || __iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2) || __iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+1))))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+1))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+1))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+1))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+1))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+1))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+2))))] = __temp_80__;
}
}
}
__syncthreads ();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2) || __iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2) || __iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+2))))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+2))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+2))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+2))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+2))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+2))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+3))))] = __temp_106__;
}
}
}
__syncthreads ();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2) || __iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2) || __iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+3))))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+3))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+3))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+3))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+3))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+3))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
}
}
}
}
int __blockSizeToSMemSize___kernel___forma_kernel__0__(dim3 blockDim){
int FORMA_BLOCKDIM_Z = (int)(blockDim.z);
int FORMA_BLOCKDIM_Y = (int)(blockDim.y);
int FORMA_BLOCKDIM_X = (int)(blockDim.x);
int SMemSize = 0;
SMemSize += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
SMemSize += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
return SMemSize;
}
/* X+GAP, Y, Z */
__global__ void __kernel___forma_kernel__1__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + (int)(FORMA_BLOCKDIM_X);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2) || __iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_11__ < FORMA_MAX((__iter_0__-1),1) || __iter_11__ > FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2) || __iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_20__ < FORMA_MAX((__iter_0__-2),1) || __iter_20__ > FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2) || __iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_29__ < FORMA_MAX((__iter_0__-3),1) || __iter_29__ > FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
}
}
}
}
/* X, Y+GAP, Z */
__global__ void __kernel___forma_kernel__2__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)(FORMA_BLOCKDIM_Y);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2) || __iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_10__ < FORMA_MAX((__iter_1__-1),1) || __iter_10__ > FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2))) {
__tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2) || __iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_19__ < FORMA_MAX((__iter_1__-2),1) || __iter_19__ > FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) {
__tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2) || __iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_28__ < FORMA_MAX((__iter_1__-3),1) || __iter_28__ > FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) {
__tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X, Y, Z+GAP */
__global__ void __kernel___forma_kernel__3__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + FORMA_BLOCKDIM_Z;
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2) || __iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)))) {
__tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2) || __iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+2+GAPZ)-1),(L-2)))) {
__tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2) || __iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)))) {
__tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X+GAP, Y+GAP, Z */
__global__ void __kernel___forma_kernel__4__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + (int)(FORMA_BLOCKDIM_X);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)(FORMA_BLOCKDIM_Y);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ);
int __iter_3__ = FORMA_MAX(__iter_2__,0) + (int)(threadIdx.z) ;
for(; __iter_3__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(0-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(0-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(0-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(0-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(0-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__+1),1)+2) || __iter_9__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__+1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-2),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_10__ < FORMA_MAX((__iter_1__-1),1) || __iter_10__ > FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) || __iter_11__ < FORMA_MAX((__iter_0__-1),1) || __iter_11__ > FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(0-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(0-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(0-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(0-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__+2),1)+2) || __iter_18__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__+2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-3),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_19__ < (FORMA_MAX((__iter_1__-2),1)) || __iter_19__ > (FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) || __iter_20__ < FORMA_MAX((__iter_0__-2),1) || __iter_20__ > FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(0-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(0-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(0-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(0-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__+3),1)+2) || __iter_27__ > (FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__+3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-4),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_28__ < (FORMA_MAX((__iter_1__-3),1)) || __iter_28__ > (FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) || __iter_29__ < FORMA_MAX((__iter_0__-3),1) || __iter_29__ > FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(0-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__+4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+FORMA_BLOCKDIM_Z)-5),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(0-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(0-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(0-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
}
}
}
}
/* X, Y+GAP, Z+GAP */
__global__ void __kernel___forma_kernel__5__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX);
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)(FORMA_BLOCKDIM_Y);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + (int)(FORMA_BLOCKDIM_Z);
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(0-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_11__ < (FORMA_MAX((__iter_0__+1),1)+2) || __iter_11__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__+1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-2),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2))) ||__iter_10__ < FORMA_MAX((__iter_1__-1),1) || __iter_10__ > FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2))) {
__tilevar_3__[__iter_11__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_20__ < (FORMA_MAX((__iter_0__+2),1)+2) || __iter_20__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__+2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-3),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2))) || __iter_19__ < FORMA_MAX((__iter_1__-2),1) || __iter_19__ > FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) {
__tilevar_4__[__iter_20__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_29__ < (FORMA_MAX((__iter_0__+3),1)+2) || __iter_29__ > (FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__+3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-4),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2))) || __iter_28__ < FORMA_MAX((__iter_1__-3),1) || __iter_28__ > FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) {
__tilevar_5__[__iter_29__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__+4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+FORMA_BLOCKDIM_X)-5),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(0-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X+GAP, Y, Z+GAP */
__global__ void __kernel___forma_kernel__6__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + FORMA_BLOCKDIM_X;
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY);
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + FORMA_BLOCKDIM_Z;
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(0-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
if (__iter_10__ < (FORMA_MAX((__iter_1__+1),1)+2) || __iter_10__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2))-2)) {
__copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))] = __tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__+1),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-2),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2))) || __iter_11__ < (FORMA_MAX((__iter_0__-1),1)) || __iter_11__ > (FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
if (__iter_19__ < (FORMA_MAX((__iter_1__+2),1)+2) || __iter_19__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2))-2)) {
__copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))] = __tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__+2),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-3),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+2+GAPZ)-1),(L-2))) || __iter_20__ < (FORMA_MAX((__iter_0__-2),1)) || __iter_20__ > (FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_28__ < (FORMA_MAX((__iter_1__+3),1)+2) || __iter_28__ > (FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2))-2)) {
__copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))] = __tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))];
}
}
}
}
__syncthreads();
__iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__+3),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-4),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2))) || __iter_29__ < (FORMA_MAX((__iter_0__-3),1)) || __iter_29__ > (FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__+4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+FORMA_BLOCKDIM_Y)-5),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(0-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __temp_132__);
}
}
}
}
/* X+GAP, Y+GAP, Z+GAP */
__global__ void __kernel___forma_kernel__7__(float * __restrict__ input, int L, int M, int N, float * __restrict__ __copy_arr_0__, float * __restrict__ __copy_arr_1__, float * __restrict__ __copy_arr_2__, int FORMA_BLOCKDIM_X, int FORMA_BLOCKDIM_Y, int FORMA_BLOCKDIM_Z, float * __restrict__ __var_1__){
int __FORMA_SHARED_MEM_OFFSET__ = 0;
float* __tilevar_0__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float* __tilevar_1__ = (float*)(__FORMA_SHARED_MEM__+__FORMA_SHARED_MEM_OFFSET__);
__FORMA_SHARED_MEM_OFFSET__ += sizeof(float)*(((FORMA_BLOCKDIM_Z-0)*(FORMA_BLOCKDIM_Y-0)*(FORMA_BLOCKDIM_X-0)));
float * __tilevar_2__ = __tilevar_0__;
float * __tilevar_3__ = __tilevar_1__;
float * __tilevar_4__ = __tilevar_0__;
float * __tilevar_5__ = __tilevar_1__;
int __iter_0__ = (int)(blockIdx.x)*((int)(FORMA_BLOCKDIM_X)+GAPX) + (int)FORMA_BLOCKDIM_X;
int __iter_1__ = (int)(blockIdx.y)*((int)(FORMA_BLOCKDIM_Y)+GAPY) + (int)FORMA_BLOCKDIM_Y;
int __iter_2__ = (int)(blockIdx.z)*((int)(FORMA_BLOCKDIM_Z)+GAPZ) + (int)FORMA_BLOCKDIM_Z;
int __iter_3__ = FORMA_MAX(__iter_2__-2,0) + (int)(threadIdx.z) ;
for( ; __iter_3__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-1)) ; __iter_3__+=(int)(blockDim.z) ){
int __iter_4__ = FORMA_MAX(__iter_1__-2,0) + (int)(threadIdx.y) ;
for(; __iter_4__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-1)) ; __iter_4__+=(int)(blockDim.y)){
int __iter_5__ = FORMA_MAX(__iter_0__-2,0) + (int)(threadIdx.x) ;
if( __iter_5__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-1)) ){
__tilevar_2__[__iter_5__+(EXTENT-__iter_0__)+(FORMA_BLOCKDIM_X-0)*(__iter_4__+(EXTENT-__iter_1__)+(FORMA_BLOCKDIM_Y-0)*(__iter_3__+(EXTENT-__iter_2__)))] = input[__iter_5__+(N-0)*(__iter_4__+(M-0)*(__iter_3__))];
}
}
}
__syncthreads();
int __iter_6__ = FORMA_MAX((__iter_2__-1),1) + (int)(threadIdx.z) ;
for( ; __iter_6__ <= FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2)) ; __iter_6__+=(int)(blockDim.z) ){
int __iter_7__ = FORMA_MAX((__iter_1__-1),1) + (int)(threadIdx.y) ;
for(; __iter_7__ <= FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2)) ; __iter_7__+=(int)(blockDim.y)){
int __iter_8__ = FORMA_MAX((__iter_0__-1),1) + (int)(threadIdx.x) ;
if( __iter_8__ <= FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)) ){
float __temp_3__ = (__tilevar_2__[__iter_8__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_7__ = (__tilevar_2__[__iter_8__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_8__ = (0.161000f * __temp_3__ + 0.162000f * __temp_7__);
float __temp_12__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_13__ = (__temp_8__ + 0.163000f * __temp_12__);
float __temp_17__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_18__ = (__temp_13__ + 0.164000f * __temp_17__);
float __temp_22__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_23__ = (__temp_18__ + 0.165000f * __temp_22__);
float __temp_27__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_28__ = (__temp_23__ + 0.166000f * __temp_27__);
float __temp_32__ = (__tilevar_2__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*( __iter_6__+(EXTENT-(__iter_2__+0))))]);
float __temp_33__ = (__temp_28__ - 1.670000f * __temp_32__);
__tilevar_3__[__iter_8__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_7__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_6__+(EXTENT-(__iter_2__+0))))] = __temp_33__;
}
}
}
__syncthreads();
int __iter_9__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_9__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_9__ += (int)(blockDim.z) ){
int __iter_10__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for(; __iter_10__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_10__ += (int)(blockDim.y)){
int __iter_11__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_11__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
if (__iter_9__ < (FORMA_MAX((__iter_2__-1),1)) || __iter_9__ > (FORMA_MIN(((__iter_2__+GAPZ+1)-1),(L-2))) || __iter_10__ < (FORMA_MAX((__iter_1__-1),1)) || __iter_10__ > (FORMA_MIN(((__iter_1__+GAPY+1)-1),(M-2))) || __iter_11__ < (FORMA_MAX((__iter_0__-1),1)) || __iter_11__ > (FORMA_MIN(((__iter_0__+GAPX+1)-1),(N-2)))) {
__tilevar_3__[__iter_11__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_10__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_9__+(EXTENT-(__iter_2__+0))))] = __copy_arr_0__[__iter_11__+(N-0)*(__iter_10__+(M-0)*(__iter_9__))];
}
}
}
}
__syncthreads();
int __iter_15__ = FORMA_MAX((__iter_2__-2),1) + (int)(threadIdx.z) ;
for( ; __iter_15__ <= FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2)) ; __iter_15__ += (int)(blockDim.z) ){
int __iter_16__ = FORMA_MAX((__iter_1__-2),1) + (int)(threadIdx.y) ;
for(; __iter_16__ <= FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2)) ; __iter_16__ += (int)(blockDim.y)){
int __iter_17__ = FORMA_MAX((__iter_0__-2),1) + (int)(threadIdx.x) ;
if( __iter_17__ <= FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)) ){
float __temp_50__ = (__tilevar_3__[__iter_17__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_54__ = (__tilevar_3__[__iter_17__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_55__ = (0.161000f * __temp_50__ + 0.162000f * __temp_54__);
float __temp_59__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_60__ = (__temp_55__ + 0.163000f * __temp_59__);
float __temp_64__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_65__ = (__temp_60__ + 0.164000f * __temp_64__);
float __temp_69__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_70__ = (__temp_65__ + 0.165000f * __temp_69__);
float __temp_74__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_75__ = (__temp_70__ + 0.166000f * __temp_74__);
float __temp_79__ = (__tilevar_3__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))]);
float __temp_80__ = (__temp_75__ - 1.670000f * __temp_79__);
__tilevar_4__[__iter_17__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_16__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_15__+(EXTENT-(__iter_2__+0))))] = __temp_80__;
}
}
}
__syncthreads();
int __iter_18__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_18__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_18__ += (int)(blockDim.z) ){
int __iter_19__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_19__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_19__ += (int)(blockDim.y) ){
int __iter_20__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_20__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
if (__iter_18__ < (FORMA_MAX((__iter_2__-2),1)) || __iter_18__ > (FORMA_MIN(((__iter_2__+GAPZ+2)-1),(L-2))) || __iter_19__ < (FORMA_MAX((__iter_1__-2),1)) || __iter_19__ > (FORMA_MIN(((__iter_1__+GAPY+2)-1),(M-2))) || __iter_20__ < (FORMA_MAX((__iter_0__-2),1)) || __iter_20__ > (FORMA_MIN(((__iter_0__+GAPX+2)-1),(N-2)))) {
__tilevar_4__[__iter_20__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_19__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_18__+(EXTENT-(__iter_2__+0))))] = __copy_arr_1__[__iter_20__+(N-0)*(__iter_19__+(M-0)*(__iter_18__))];
}
}
}
}
__syncthreads();
int __iter_24__ = FORMA_MAX((__iter_2__-3),1) + (int)(threadIdx.z) ;
for( ; __iter_24__ <= FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2)) ; __iter_24__ += (int)(blockDim.z) ){
int __iter_25__ = FORMA_MAX((__iter_1__-3),1) + (int)(threadIdx.y) ;
for (; __iter_25__ <= FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2)) ; __iter_25__ += (int)(blockDim.y)){
int __iter_26__ = FORMA_MAX((__iter_0__-3),1) + (int)(threadIdx.x) ;
if( __iter_26__ <= FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)) ){
float __temp_94__ = (__tilevar_4__[__iter_26__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_95__ = (__tilevar_4__[__iter_26__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_96__ = (0.161000f * __temp_94__ + 0.162000f * __temp_95__);
float __temp_97__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_98__ = (__temp_96__ + 0.163000f * __temp_97__);
float __temp_99__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_100__ = (__temp_98__ + 0.164000f * __temp_99__);
float __temp_101__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_102__ = (__temp_100__ + 0.165000f * __temp_101__);
float __temp_103__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_104__ = (__temp_102__ + 0.166000f * __temp_103__);
float __temp_105__ = (__tilevar_4__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))]);
float __temp_106__ = (__temp_104__ - 1.670000f * __temp_105__);
__tilevar_5__[__iter_26__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_25__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_24__+(EXTENT-(__iter_2__+0))))] = __temp_106__;
}
}
}
__syncthreads();
int __iter_27__ = FORMA_MAX((__iter_2__-5),1) + (int)(threadIdx.z) ;
for( ; __iter_27__ <= FORMA_MIN(((__iter_2__+GAPZ+5)-1),(L-2)) ; __iter_27__ += (int)(blockDim.z) ){
int __iter_28__ = FORMA_MAX((__iter_1__-5),1) + (int)(threadIdx.y) ;
for(; __iter_28__ <= FORMA_MIN(((__iter_1__+GAPY+5)-1),(M-2)) ; __iter_28__ += (int)(blockDim.y)){
int __iter_29__ = FORMA_MAX((__iter_0__-5),1) + (int)(threadIdx.x) ;
if( __iter_29__ <= FORMA_MIN(((__iter_0__+GAPX+5)-1),(N-2)) ){
if (__iter_27__ < (FORMA_MAX((__iter_2__-3),1)) || __iter_27__ > (FORMA_MIN(((__iter_2__+GAPZ+3)-1),(L-2))) || __iter_28__ < (FORMA_MAX((__iter_1__-3),1)) || __iter_28__ > (FORMA_MIN(((__iter_1__+GAPY+3)-1),(M-2))) || __iter_29__ < (FORMA_MAX((__iter_0__-3),1)) || __iter_29__ > (FORMA_MIN(((__iter_0__+GAPX+3)-1),(N-2)))) {
__tilevar_5__[__iter_29__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_28__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_27__+(EXTENT-(__iter_2__+0))))] = __copy_arr_2__[__iter_29__+(N-0)*(__iter_28__+(M-0)*(__iter_27__))];
}
}
}
}
__syncthreads();
int __iter_33__ = FORMA_MAX((__iter_2__-4),1) + (int)(threadIdx.z) ;
for( ; __iter_33__ <= FORMA_MIN(((__iter_2__+GAPZ+4)-1),(L-2)) ; __iter_33__ += (int)(blockDim.z) ){
int __iter_34__ = FORMA_MAX((__iter_1__-4),1) + (int)(threadIdx.y) ;
for(; __iter_34__ <= FORMA_MIN(((__iter_1__+GAPY+4)-1),(M-2)) ; __iter_34__ += (int)(blockDim.y)){
int __iter_35__ = FORMA_MAX((__iter_0__-4),1) + (int)(threadIdx.x) ;
if( __iter_35__ <= FORMA_MIN(((__iter_0__+GAPX+4)-1),(N-2)) ){
float __temp_120__ = (__tilevar_5__[__iter_35__+(1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_121__ = (__tilevar_5__[__iter_35__+(-1)+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_122__ = (0.161000f * __temp_120__ + 0.162000f * __temp_121__);
float __temp_123__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_124__ = (__temp_122__ + 0.163000f * __temp_123__);
float __temp_125__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(-1)+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_126__ = (__temp_124__ + 0.164000f * __temp_125__);
float __temp_127__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(1)+(EXTENT-(__iter_2__+0))))]);
float __temp_128__ = (__temp_126__ + 0.165000f * __temp_127__);
float __temp_129__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(-1)+(EXTENT-(__iter_2__+0))))]);
float __temp_130__ = (__temp_128__ + 0.166000f * __temp_129__);
float __temp_131__ = (__tilevar_5__[__iter_35__+(EXTENT-(__iter_0__+0))+(FORMA_BLOCKDIM_X-0)*(__iter_34__+(EXTENT-(__iter_1__+0))+(FORMA_BLOCKDIM_Y-0)*(__iter_33__+(EXTENT-(__iter_2__+0))))]);
float __temp_132__ = (__temp_130__ - 1.670000f * __temp_131__);
__var_1__[__iter_35__+(N-0)*(__iter_34__+(M-0)*(__iter_33__))] = __temp_132__;
//printf ("var1[%d][%d][%d] at (%d,%d,%d) for block (%d,%d,%d) = %.6f\n", __iter_33__, __iter_34__, __iter_35__, __iter_2__, __iter_1__, __iter_0__, blockIdx.x, blockIdx.y, blockIdx.z, __temp_132__);
}
}
}
}
/*Device code End */
/* Host Code Begin */
extern "C" void j3d7pt(float * h_input, int L, int M, int N, float * __var_0__){
/* Host allocation Begin */
float * input;
cudaMalloc(&input,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : input\n");
cudaPointerAttributes ptrAttrib_h_input;
cudaMemcpyKind memcpy_kind_h_input = cudaMemcpyHostToDevice;
if (cudaPointerGetAttributes(&ptrAttrib_h_input, h_input) == cudaSuccess)
if (ptrAttrib_h_input.memoryType == cudaMemoryTypeDevice)
memcpy_kind_h_input = cudaMemcpyDeviceToDevice;
cudaGetLastError();
if( memcpy_kind_h_input != cudaMemcpyDeviceToDevice ){
cudaMemcpy(input,h_input,sizeof(float)*((L-0)*(M-0)*(N-0)), memcpy_kind_h_input);
}
float * __var_1__;
cudaMalloc(&__var_1__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __var_1__\n");
float * __copy_arr_0__;
cudaMalloc(&__copy_arr_0__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __copy_arr_0__\n");
float * __copy_arr_1__;
cudaMalloc(&__copy_arr_1__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __copy_arr_1__\n");
float * __copy_arr_2__;
cudaMalloc(&__copy_arr_2__,sizeof(float)*((L-0)*(M-0)*(N-0)));
Check_CUDA_Error("Allocation Error!! : __copy_arr_2__\n");
/*Host Allocation End */
/* Kernel Launch Begin */
int __FORMA_MAX_SHARED_MEM__;
cudaDeviceGetAttribute(&__FORMA_MAX_SHARED_MEM__,cudaDevAttrMaxSharedMemoryPerBlock,0);
#ifdef _TIMER_
cudaEvent_t _forma_timer_start_,_forma_timer_stop_;
cudaEventCreate(&_forma_timer_start_);
cudaEventCreate(&_forma_timer_stop_);
cudaEventRecord(_forma_timer_start_,0);
#endif
int __size_0___kernel___forma_kernel__0__ = ((N-1) - 0 ) + 1;
int __size_1___kernel___forma_kernel__0__ = ((M-1) - 0 ) + 1;
int __size_2___kernel___forma_kernel__0__ = ((L-1) - 0 ) + 1;
int __block_0___kernel___forma_kernel__0__ = 32;
int __block_1___kernel___forma_kernel__0__ = 16;
int __block_2___kernel___forma_kernel__0__ = 12;
dim3 __blockConfig___kernel___forma_kernel__0__(__block_0___kernel___forma_kernel__0__,__block_1___kernel___forma_kernel__0__,__block_2___kernel___forma_kernel__0__);
int __SMemSize___kernel___forma_kernel__0__ = 0;
__SMemSize___kernel___forma_kernel__0__ = __blockSizeToSMemSize___kernel___forma_kernel__0__(__blockConfig___kernel___forma_kernel__0__);
int __grid_0___kernel___forma_kernel__0__ = FORMA_CEIL(__size_0___kernel___forma_kernel__0__,__blockConfig___kernel___forma_kernel__0__.x+GAPX);
int __grid_1___kernel___forma_kernel__0__ = FORMA_CEIL(__size_1___kernel___forma_kernel__0__,__blockConfig___kernel___forma_kernel__0__.y+GAPY);
int __grid_2___kernel___forma_kernel__0__ = FORMA_CEIL(__size_2___kernel___forma_kernel__0__,__blockConfig___kernel___forma_kernel__0__.z+GAPZ);
dim3 __gridConfig___kernel___forma_kernel__0__(__grid_0___kernel___forma_kernel__0__,__grid_1___kernel___forma_kernel__0__,__grid_2___kernel___forma_kernel__0__);
dim3 unrollConfig (__blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y/4, __blockConfig___kernel___forma_kernel__0__.z/3);
__kernel___forma_kernel__0__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__0__\n");
__kernel___forma_kernel__1__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__1__\n");
__kernel___forma_kernel__2__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__2__\n");
__kernel___forma_kernel__3__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__3__\n");
__kernel___forma_kernel__4__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__4__\n");
__kernel___forma_kernel__5__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__5__\n");
__kernel___forma_kernel__6__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__6__\n");
__kernel___forma_kernel__7__<<<__gridConfig___kernel___forma_kernel__0__, unrollConfig, __SMemSize___kernel___forma_kernel__0__>>> (input, L, M, N, __copy_arr_0__, __copy_arr_1__, __copy_arr_2__, __blockConfig___kernel___forma_kernel__0__.x, __blockConfig___kernel___forma_kernel__0__.y, __blockConfig___kernel___forma_kernel__0__.z, __var_1__);
Check_CUDA_Error("Kernel Launch Error!! : __kernel___forma_kernel__7__\n");
cudaPointerAttributes ptrAttrib___var_0__;
cudaMemcpyKind memcpy_kind___var_0__ = cudaMemcpyDeviceToHost;
if (cudaPointerGetAttributes(&ptrAttrib___var_0__, __var_0__) == cudaSuccess)
if (ptrAttrib___var_0__.memoryType == cudaMemoryTypeDevice)
memcpy_kind___var_0__ = cudaMemcpyDeviceToDevice;
cudaGetLastError();
cudaMemcpy(__var_0__,__var_1__, sizeof(float)*((L-0)*(M-0)*(N-0)), memcpy_kind___var_0__);
#ifdef _TIMER_
cudaEventRecord(_forma_timer_stop_,0);
cudaEventSynchronize(_forma_timer_stop_);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime,_forma_timer_start_,_forma_timer_stop_);
printf("[FORMA] Computation Time(ms) : %lf\n",elapsedTime);
cudaEventDestroy(_forma_timer_start_);
cudaEventDestroy(_forma_timer_stop_);
#endif
/*Kernel Launch End */
/* Host Free Begin */
cudaFree(input);
cudaFree(__var_1__);
cudaFree(__copy_arr_0__);
cudaFree(__copy_arr_1__);
cudaFree(__copy_arr_2__);
}
/*Host Free End*/
|
0ee08e544ed0ff900e68322bc73f19bbc2ab867e.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "gpu_runtime.h"
__global__ void sgd_update(float *param, const float *grad, float lr, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
param[ind] = param[ind] - lr * grad[ind];
}
int SGDOptimizerUpdate(DLArrayHandle param, const DLArrayHandle grad, float lr, DLStreamHandle stream_handle = NULL) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (stream_handle)
hipLaunchKernelGGL(( sgd_update), dim3(blocks), dim3(threads), 0, *(hipStream_t*)stream_handle->handle, param_data, grad_data, lr, size);
else
hipLaunchKernelGGL(( sgd_update), dim3(blocks), dim3(threads), 0, 0, param_data, grad_data, lr, size);
return 0;
}
__global__ void nesterov_momentum_update(float *param, const float *grad, float *velocity, float lr, float momentum, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
float temp = lr * grad[ind];
velocity[ind] = momentum * (velocity[ind] - temp);
param[ind] = param[ind] + velocity[ind] - temp;
}
__global__ void momentum_update(float *param, const float *grad, float *velocity, float lr, float momentum, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
velocity[ind] = momentum * velocity[ind] - lr * grad[ind];
param[ind] = param[ind] + velocity[ind];
}
int MomentumOptimizerUpdate(DLArrayHandle param, const DLArrayHandle grad, DLArrayHandle velocity, float lr, float momentum, bool nesterov, DLStreamHandle stream_handle = NULL) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
float *velocity_data = (float *) velocity->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (nesterov) {
if (stream_handle)
hipLaunchKernelGGL(( nesterov_momentum_update), dim3(blocks), dim3(threads), 0, *(hipStream_t*)stream_handle->handle, param_data, grad_data, velocity_data, lr, momentum, size);
else
hipLaunchKernelGGL(( nesterov_momentum_update), dim3(blocks), dim3(threads), 0, 0, param_data, grad_data, velocity_data, lr, momentum, size);
} else {
if (stream_handle)
hipLaunchKernelGGL(( momentum_update), dim3(blocks), dim3(threads), 0, *(hipStream_t*)stream_handle->handle, param_data, grad_data, velocity_data, lr, momentum, size);
else
hipLaunchKernelGGL(( momentum_update), dim3(blocks), dim3(threads), 0, 0, param_data, grad_data, velocity_data, lr, momentum, size);
}
return 0;
}
__global__ void adagrad_update(float *param, const float *grad, float *acc, float lr, float eps, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
acc[ind] = acc[ind] + grad[ind] * grad[ind];
param[ind] = param[ind] - lr * grad[ind] / (sqrtf(acc[ind]) + eps);
}
int AdaGradOptimizerUpdate(DLArrayHandle param, const DLArrayHandle grad, DLArrayHandle acc, float lr, float eps, DLStreamHandle stream_handle = NULL) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
float *acc_data = (float *) acc->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (stream_handle)
hipLaunchKernelGGL(( adagrad_update), dim3(blocks), dim3(threads), 0, *(hipStream_t*)stream_handle->handle, param_data, grad_data, acc_data, lr, eps, size);
else
hipLaunchKernelGGL(( adagrad_update), dim3(blocks), dim3(threads), 0, 0, param_data, grad_data, acc_data, lr, eps, size);
return 0;
}
__global__ void adam_update(float *param, const float *grad, float *m, float *v, float lr, float beta1, float beta2, float beta1t, float beta2t, float eps, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
m[ind] = beta1 * m[ind] + (1 - beta1) * grad[ind];
v[ind] = beta2 * v[ind] + (1 - beta2) * grad[ind] * grad[ind];
float m_local = m[ind] / (1 - beta1t);
float v_local = v[ind] / (1 - beta2t);
param[ind] = param[ind] - lr * m_local / (sqrtf(v_local) + eps);
}
int AdamOptimizerUpdate(
DLArrayHandle param, const DLArrayHandle grad, DLArrayHandle expavg, DLArrayHandle expavgsq,
float lr, float beta1, float beta2, float beta1t, float beta2t, float eps,
DLStreamHandle stream_handle = NULL
) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
float *m_data = (float *) expavg->data;
float *v_data = (float *) expavgsq->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (stream_handle)
hipLaunchKernelGGL(( adam_update), dim3(blocks), dim3(threads), 0, *(hipStream_t*)stream_handle->handle, param_data, grad_data, m_data, v_data, lr, beta1, beta2, beta1t, beta2t, eps, size);
else
hipLaunchKernelGGL(( adam_update), dim3(blocks), dim3(threads), 0, 0, param_data, grad_data, m_data, v_data, lr, beta1, beta2, beta1t, beta2t, eps, size);
return 0;
}
| 0ee08e544ed0ff900e68322bc73f19bbc2ab867e.cu | #include "gpu_runtime.h"
__global__ void sgd_update(float *param, const float *grad, float lr, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
param[ind] = param[ind] - lr * grad[ind];
}
int SGDOptimizerUpdate(DLArrayHandle param, const DLArrayHandle grad, float lr, DLStreamHandle stream_handle = NULL) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (stream_handle)
sgd_update<<<blocks, threads, 0, *(cudaStream_t*)stream_handle->handle>>>(param_data, grad_data, lr, size);
else
sgd_update<<<blocks, threads>>>(param_data, grad_data, lr, size);
return 0;
}
__global__ void nesterov_momentum_update(float *param, const float *grad, float *velocity, float lr, float momentum, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
float temp = lr * grad[ind];
velocity[ind] = momentum * (velocity[ind] - temp);
param[ind] = param[ind] + velocity[ind] - temp;
}
__global__ void momentum_update(float *param, const float *grad, float *velocity, float lr, float momentum, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
velocity[ind] = momentum * velocity[ind] - lr * grad[ind];
param[ind] = param[ind] + velocity[ind];
}
int MomentumOptimizerUpdate(DLArrayHandle param, const DLArrayHandle grad, DLArrayHandle velocity, float lr, float momentum, bool nesterov, DLStreamHandle stream_handle = NULL) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
float *velocity_data = (float *) velocity->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (nesterov) {
if (stream_handle)
nesterov_momentum_update<<<blocks, threads, 0, *(cudaStream_t*)stream_handle->handle>>>(param_data, grad_data, velocity_data, lr, momentum, size);
else
nesterov_momentum_update<<<blocks, threads>>>(param_data, grad_data, velocity_data, lr, momentum, size);
} else {
if (stream_handle)
momentum_update<<<blocks, threads, 0, *(cudaStream_t*)stream_handle->handle>>>(param_data, grad_data, velocity_data, lr, momentum, size);
else
momentum_update<<<blocks, threads>>>(param_data, grad_data, velocity_data, lr, momentum, size);
}
return 0;
}
__global__ void adagrad_update(float *param, const float *grad, float *acc, float lr, float eps, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
acc[ind] = acc[ind] + grad[ind] * grad[ind];
param[ind] = param[ind] - lr * grad[ind] / (sqrtf(acc[ind]) + eps);
}
int AdaGradOptimizerUpdate(DLArrayHandle param, const DLArrayHandle grad, DLArrayHandle acc, float lr, float eps, DLStreamHandle stream_handle = NULL) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
float *acc_data = (float *) acc->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (stream_handle)
adagrad_update<<<blocks, threads, 0, *(cudaStream_t*)stream_handle->handle>>>(param_data, grad_data, acc_data, lr, eps, size);
else
adagrad_update<<<blocks, threads>>>(param_data, grad_data, acc_data, lr, eps, size);
return 0;
}
__global__ void adam_update(float *param, const float *grad, float *m, float *v, float lr, float beta1, float beta2, float beta1t, float beta2t, float eps, size_t size) {
size_t ind = blockIdx.x * blockDim.x + threadIdx.x;
if (ind >= size) return;
m[ind] = beta1 * m[ind] + (1 - beta1) * grad[ind];
v[ind] = beta2 * v[ind] + (1 - beta2) * grad[ind] * grad[ind];
float m_local = m[ind] / (1 - beta1t);
float v_local = v[ind] / (1 - beta2t);
param[ind] = param[ind] - lr * m_local / (sqrtf(v_local) + eps);
}
int AdamOptimizerUpdate(
DLArrayHandle param, const DLArrayHandle grad, DLArrayHandle expavg, DLArrayHandle expavgsq,
float lr, float beta1, float beta2, float beta1t, float beta2t, float eps,
DLStreamHandle stream_handle = NULL
) {
size_t size = 1;
for (index_t i = 0; i < param->ndim; ++i) {
size *= param->shape[i];
}
dim3 blocks;
dim3 threads;
float *param_data = (float *) param->data;
const float *grad_data = (const float *) grad->data;
float *m_data = (float *) expavg->data;
float *v_data = (float *) expavgsq->data;
if (size <= 1024) {
threads.x = size;
blocks.x = 1;
} else {
threads.x = 1024;
blocks.x = (size + 1023) / 1024;
}
if (stream_handle)
adam_update<<<blocks, threads, 0, *(cudaStream_t*)stream_handle->handle>>>(param_data, grad_data, m_data, v_data, lr, beta1, beta2, beta1t, beta2t, eps, size);
else
adam_update<<<blocks, threads>>>(param_data, grad_data, m_data, v_data, lr, beta1, beta2, beta1t, beta2t, eps, size);
return 0;
}
|
3acfb7d9a5eb9bef9008286bae2d06ad03a177d1.hip | // !!! This is a file automatically generated by hipify!!!
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include <iostream>
#include <cassert>
#include <stdio.h>
using namespace std;
static const int BLOCK_SIZE = 128;
static const int WARP_SIZE = 32;
static const double MAX_RELATIVE_ERROR = .02;
static const int TEMP_BUFFER_SIZE = 1024;
enum kernelType{CSR_SCALAR, CSR_VECTOR, ELLPACKR};
texture<float, 1> vecTex; // vector textures
texture<int2, 1> vecTexD;
// Texture Readers (used so kernels can be templated)
struct texReaderSP {
__device__ __forceinline__ float operator()(const int idx) const
{
return tex1Dfetch(vecTex, idx);
}
};
struct texReaderDP {
__device__ __forceinline__ double operator()(const int idx) const
{
int2 v = tex1Dfetch(vecTexD, idx);
#if (__CUDA_ARCH__ < 130)
// Devices before arch 130 don't support DP, and having the
// __hiloint2double() intrinsic will cause compilation to fail.
// This return statement added as a workaround -- it will compile,
// but since the arch doesn't support DP, it will never be called
return 0;
#else
return __hiloint2double(v.y, v.x);
#endif
}
};
void initRandomMatrix(int *cols, int *rowDelimiters, const int n, const int dim)
{
int nnzAssigned = 0;
// Figure out the probability that a nonzero should be assigned to a given
// spot in the matrix
double prob = (double)n / ((double)dim * (double)dim);
// Seed random number generator
srand48(8675309L);
// Randomly decide whether entry i,j gets a value, but ensure n values
// are assigned
bool fillRemaining = false;
for (int i = 0; i < dim; i++)
{
rowDelimiters[i] = nnzAssigned;
for (int j = 0; j < dim; j++)
{
int numEntriesLeft = (dim * dim) - ((i * dim) + j);
int needToAssign = n - nnzAssigned;
if (numEntriesLeft <= needToAssign) {
fillRemaining = true;
}
if ((nnzAssigned < n && drand48() <= prob) || fillRemaining)
{
// Assign (i,j) a value
cols[nnzAssigned] = j;
nnzAssigned++;
}
}
}
// Observe the convention to put the number of non zeroes at the end of the
// row delimiters array
rowDelimiters[dim] = n;
assert(nnzAssigned == n);
}
template <typename floatType>
void fill(floatType *A, const int n, const float maxi)
{
for (int j = 0; j < n; j++)
{
A[j] = ((floatType) maxi * (rand() / (RAND_MAX + 1.0f)));
}
}
// Forward declarations for kernels
template <typename fpType, typename texReader>
__global__ void
spmv_csr_scalar_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out,
const fpType * __restrict__ vec);
template <typename fpType, typename texReader>
__global__ void
spmv_csr_vector_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out);
template <typename fpType>
__global__ void
zero(fpType * __restrict__ a, const int size);
// ****************************************************************************
// Function: spmvCpu
//
// Purpose:
// Runs sparse matrix vector multiplication on the CPU
//
// Arguements:
// val: array holding the non-zero values for the matrix
// cols: array of column indices for each element of A
// rowDelimiters: array of size dim+1 holding indices to rows of A;
// last element is the index one past the last
// element of A
// vec: dense vector of size dim to be used for multiplication
// dim: number of rows/columns in the matrix
// out: input - buffer of size dim
// output - result from the spmv calculation
//
// Programmer: Lukasz Wesolowski
// Creation: June 23, 2010
// Returns:
// nothing directly
// out indirectly through a pointer
// ****************************************************************************
template <typename floatType>
void spmvCpu(const floatType *val, const int *cols, const int *rowDelimiters,
const floatType *vec, int dim, floatType *out)
{
for (int i=0; i<dim; i++)
{
floatType t = 0;
for (int j = rowDelimiters[i]; j < rowDelimiters[i + 1]; j++)
{
int col = cols[j];
t += val[j] * vec[col];
}
out[i] = t;
}
}
template <typename floatType>
bool verifyResults(const floatType *cpuResults, const floatType *gpuResults,
const int size, const int pass = -1)
{
bool passed = true;
FILE *fcpu = fopen("cpu_results.txt", "w");
FILE *fgpu = fopen("gpu_results.txt", "w");
for (int i = 0; i < size; i++)
{
if (fabs(cpuResults[i] - gpuResults[i]) / cpuResults[i]
> MAX_RELATIVE_ERROR)
{
cout << "Mismatch at i: "<< i << " ref: " << cpuResults[i] <<
" dev: " << gpuResults[i] << endl;
passed = false;
}
fprintf(fcpu, "%f\n", cpuResults[i]);
fprintf(fgpu, "%f\n", gpuResults[i]);
}
fclose(fcpu);
fclose(fgpu);
if (pass != -1)
{
cout << "Pass "<<pass<<": ";
}
if (passed)
{
cout << "Passed" << endl;
}
else
{
cout << "---FAILED---" << endl;
}
return passed;
}
template <typename floatType, typename texReader>
void csrTest(floatType* h_val,
int* h_cols, int* h_rowDelimiters, floatType* h_vec, floatType* h_out,
int numRows, int numNonZeroes, floatType* refOut, bool padded)
{
// Device data structures
floatType *d_val, *d_vec, *d_out;
int *d_cols, *d_rowDelimiters;
// Allocate device memory
hipMalloc(&d_val, numNonZeroes * sizeof(floatType));
hipMalloc(&d_cols, numNonZeroes * sizeof(int));
hipMalloc(&d_vec, numRows * sizeof(floatType));
hipMalloc(&d_out, numRows * sizeof(floatType));
hipMalloc(&d_rowDelimiters, (numRows+1) * sizeof(int));
// Transfer data to device
hipMemcpy(d_val, h_val, numNonZeroes * sizeof(floatType),hipMemcpyHostToDevice);
hipMemcpy(d_cols, h_cols, numNonZeroes * sizeof(int),hipMemcpyHostToDevice);
hipMemcpy(d_vec, h_vec, numRows * sizeof(floatType),hipMemcpyHostToDevice);
hipMemcpy(d_rowDelimiters, h_rowDelimiters,(numRows+1) * sizeof(int), hipMemcpyHostToDevice);
// Bind texture for position
string suffix;
if (sizeof(floatType) == sizeof(float))
{
hipChannelFormatDesc channelDesc = hipCreateChannelDesc<float>();
hipBindTexture(0, vecTex, d_vec, channelDesc, numRows * sizeof(float));
suffix = "-SP";
}
else {
hipChannelFormatDesc channelDesc = hipCreateChannelDesc<int2>();
hipBindTexture(0, vecTexD, d_vec, channelDesc, numRows * sizeof(int2));
suffix = "-DP";
}
// Setup thread configuration
int nBlocksScalar = (int) ceil((floatType) numRows / BLOCK_SIZE);
int nBlocksVector = (int) ceil(numRows /
(floatType)(BLOCK_SIZE / WARP_SIZE));
int passes = 1;
int iters = 1;
// Results description info
char atts[TEMP_BUFFER_SIZE];
// sprintf(atts, "%d_elements_%d_rows", numNonZeroes, numRows);
string prefix = "";
prefix += (padded) ? "Padded_" : "";
cout << "CSR Scalar Kernel\n";
for (int k=0; k<passes; k++)
{
// Run Scalar Kernel
for (int j = 0; j < iters; j++)
{
hipLaunchKernelGGL(( spmv_csr_scalar_kernel<floatType, texReader>)
, dim3(nBlocksScalar), dim3(BLOCK_SIZE), 0, 0,
d_val, d_cols, d_rowDelimiters, numRows, d_out, d_vec);
}
// Transfer data back to host
hipMemcpy(h_out, d_out, numRows * sizeof(floatType),hipMemcpyDeviceToHost);
// Compare reference solution to GPU result
cout << "CSR Scalar Kernel Finished\n";
if (! verifyResults(refOut, h_out, numRows, k))
{
return; // If results don't match, don't report performance
}
}
cout << "CSR Scalar Done\n";
hipLaunchKernelGGL(( zero<floatType>), dim3(nBlocksScalar), dim3(BLOCK_SIZE), 0, 0, d_out, numRows);
hipDeviceSynchronize();
//cout << "CSR Vector Kernel\n";
//for (int k=0; k<passes; k++)
//{
// // Run Vector Kernel
// hipEventRecord(start, 0);
// for (int j = 0; j < iters; j++)
// {
// //spmv_csr_vector_kernel<floatType, texReader> <<<nBlocksVector, BLOCK_SIZE>>> (d_val, d_cols, d_rowDelimiters, numRows, d_out);
// }
// hipEventRecord(stop, 0);
// hipEventSynchronize(stop);
// float vectorKernelTime;
// hipEventElapsedTime(&vectorKernelTime, start, stop);
// hipMemcpy(h_out, d_out, numRows * sizeof(floatType),hipMemcpyDeviceToHost);
// hipDeviceSynchronize();
// Compare reference solution to GPU result
// if (! verifyResults(refOut, h_out, numRows, k))
// {
// return; // If results don't match, don't report performance
// }
// vectorKernelTime = (vectorKernelTime / (float)iters) * 1.e-3;
// string testName = prefix+"CSR-Vector"+suffix;
// double totalTransfer = iTransferTime + oTransferTime;
//}
// Free device memory
hipFree(d_rowDelimiters);
hipFree(d_vec);
hipFree(d_out);
hipFree(d_val);
hipFree(d_cols);
hipUnbindTexture(vecTexD);
hipUnbindTexture(vecTex);
}
template <typename floatType, typename texReader>
void RunTest(int nRows=0)
{
// Host data structures
// Array of values in the sparse matrix
floatType *h_val;
// Array of column indices for each value in h_val
int *h_cols;
// Array of indices to the start of each row in h_Val
int *h_rowDelimiters;
// Dense vector and space for dev/cpu reference solution
floatType *h_vec, *h_out, *refOut;
// nItems = number of non zero elems
int nItems, numRows;
// This benchmark either reads in a matrix market input file or
// generates a random matrix
numRows = nRows;
nItems = numRows * numRows / 100; // 1% of entries will be non-zero
hipHostMalloc(&h_val, nItems * sizeof(floatType));
hipHostMalloc(&h_cols, nItems * sizeof(int));
hipHostMalloc(&h_rowDelimiters, (numRows + 1) * sizeof(int));
fill(h_val, nItems, 10);
initRandomMatrix(h_cols, h_rowDelimiters, nItems, numRows);
// Set up remaining host data
hipHostMalloc(&h_vec, numRows * sizeof(floatType));
refOut = new floatType[numRows];
fill(h_vec, numRows, 10);
// Set up the padded data structures
int PAD_FACTOR = 16;
int paddedSize = numRows + (PAD_FACTOR - numRows % PAD_FACTOR);
hipHostMalloc(&h_out, paddedSize * sizeof(floatType));
// Compute reference solution
spmvCpu(h_val, h_cols, h_rowDelimiters, h_vec, numRows, refOut);
// Test CSR kernels on normal data
cout << "CSR Test\n";
csrTest<floatType, texReader>(h_val, h_cols,
h_rowDelimiters, h_vec, h_out, numRows, nItems, refOut, false);
delete[] refOut;
hipHostFree(h_val);
hipHostFree(h_cols);
hipHostFree(h_rowDelimiters);
hipHostFree(h_vec);
hipHostFree(h_out);
}
int main()
{
int probSizes[4] = {1024, 8192, 12288, 16384};
int sizeClass = 16384;
cout <<"Single precision tests:\n";
RunTest<float, texReaderSP>(sizeClass);
return 0;
}
template <typename fpType, typename texReader>
__global__ void
spmv_csr_scalar_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out,
const fpType * __restrict__ vec)
{
int myRow = blockIdx.x * blockDim.x + threadIdx.x;
texReader vecTexReader;
if (myRow < dim)
{
fpType t = 0.0f;
int start = rowDelimiters[myRow];
int end = rowDelimiters[myRow+1];
for (int j = start; j < end; j++)
{
int col = cols[j];
t += val[j] * vecTexReader(col);
//t += val[j] * vec[col];
}
out[myRow] = t;
}
}
/*
template <typename fpType, typename texReader>
__global__ void
spmv_csr_vector_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out)
{
// Thread ID in block
int t = threadIdx.x;
// Thread ID within warp
int id = t & (warpSize-1);
int warpsPerBlock = blockDim.x / warpSize;
// One row per warp
int myRow = (blockIdx.x * warpsPerBlock) + (t / warpSize);
// Texture reader for the dense vector
texReader vecTexReader;
__shared__ volatile fpType partialSums[BLOCK_SIZE];
if (myRow < dim)
{
int warpStart = rowDelimiters[myRow];
int warpEnd = rowDelimiters[myRow+1];
fpType mySum = 0;
for (int j = warpStart + id; j < warpEnd; j += warpSize)
{
int col = cols[j];
mySum += val[j] * vecTexReader(col);
}
partialSums[t] = mySum;
// Reduce partial sums
if (id < 16) partialSums[t] += partialSums[t+16];
if (id < 8) partialSums[t] += partialSums[t+ 8];
if (id < 4) partialSums[t] += partialSums[t+ 4];
if (id < 2) partialSums[t] += partialSums[t+ 2];
if (id < 1) partialSums[t] += partialSums[t+ 1];
// Write result
if (id == 0)
{
out[myRow] = partialSums[t];
}
}
}*/
template <typename fpType>
__global__ void
zero(fpType * __restrict__ a, const int size)
{
int t = blockIdx.x * blockDim.x + threadIdx.x;
if (t < size) a[t] = 0;
}
| 3acfb7d9a5eb9bef9008286bae2d06ad03a177d1.cu | #include <cuda.h>
#include <cuda_runtime_api.h>
#include <iostream>
#include <cassert>
#include <stdio.h>
using namespace std;
static const int BLOCK_SIZE = 128;
static const int WARP_SIZE = 32;
static const double MAX_RELATIVE_ERROR = .02;
static const int TEMP_BUFFER_SIZE = 1024;
enum kernelType{CSR_SCALAR, CSR_VECTOR, ELLPACKR};
texture<float, 1> vecTex; // vector textures
texture<int2, 1> vecTexD;
// Texture Readers (used so kernels can be templated)
struct texReaderSP {
__device__ __forceinline__ float operator()(const int idx) const
{
return tex1Dfetch(vecTex, idx);
}
};
struct texReaderDP {
__device__ __forceinline__ double operator()(const int idx) const
{
int2 v = tex1Dfetch(vecTexD, idx);
#if (__CUDA_ARCH__ < 130)
// Devices before arch 130 don't support DP, and having the
// __hiloint2double() intrinsic will cause compilation to fail.
// This return statement added as a workaround -- it will compile,
// but since the arch doesn't support DP, it will never be called
return 0;
#else
return __hiloint2double(v.y, v.x);
#endif
}
};
void initRandomMatrix(int *cols, int *rowDelimiters, const int n, const int dim)
{
int nnzAssigned = 0;
// Figure out the probability that a nonzero should be assigned to a given
// spot in the matrix
double prob = (double)n / ((double)dim * (double)dim);
// Seed random number generator
srand48(8675309L);
// Randomly decide whether entry i,j gets a value, but ensure n values
// are assigned
bool fillRemaining = false;
for (int i = 0; i < dim; i++)
{
rowDelimiters[i] = nnzAssigned;
for (int j = 0; j < dim; j++)
{
int numEntriesLeft = (dim * dim) - ((i * dim) + j);
int needToAssign = n - nnzAssigned;
if (numEntriesLeft <= needToAssign) {
fillRemaining = true;
}
if ((nnzAssigned < n && drand48() <= prob) || fillRemaining)
{
// Assign (i,j) a value
cols[nnzAssigned] = j;
nnzAssigned++;
}
}
}
// Observe the convention to put the number of non zeroes at the end of the
// row delimiters array
rowDelimiters[dim] = n;
assert(nnzAssigned == n);
}
template <typename floatType>
void fill(floatType *A, const int n, const float maxi)
{
for (int j = 0; j < n; j++)
{
A[j] = ((floatType) maxi * (rand() / (RAND_MAX + 1.0f)));
}
}
// Forward declarations for kernels
template <typename fpType, typename texReader>
__global__ void
spmv_csr_scalar_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out,
const fpType * __restrict__ vec);
template <typename fpType, typename texReader>
__global__ void
spmv_csr_vector_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out);
template <typename fpType>
__global__ void
zero(fpType * __restrict__ a, const int size);
// ****************************************************************************
// Function: spmvCpu
//
// Purpose:
// Runs sparse matrix vector multiplication on the CPU
//
// Arguements:
// val: array holding the non-zero values for the matrix
// cols: array of column indices for each element of A
// rowDelimiters: array of size dim+1 holding indices to rows of A;
// last element is the index one past the last
// element of A
// vec: dense vector of size dim to be used for multiplication
// dim: number of rows/columns in the matrix
// out: input - buffer of size dim
// output - result from the spmv calculation
//
// Programmer: Lukasz Wesolowski
// Creation: June 23, 2010
// Returns:
// nothing directly
// out indirectly through a pointer
// ****************************************************************************
template <typename floatType>
void spmvCpu(const floatType *val, const int *cols, const int *rowDelimiters,
const floatType *vec, int dim, floatType *out)
{
for (int i=0; i<dim; i++)
{
floatType t = 0;
for (int j = rowDelimiters[i]; j < rowDelimiters[i + 1]; j++)
{
int col = cols[j];
t += val[j] * vec[col];
}
out[i] = t;
}
}
template <typename floatType>
bool verifyResults(const floatType *cpuResults, const floatType *gpuResults,
const int size, const int pass = -1)
{
bool passed = true;
FILE *fcpu = fopen("cpu_results.txt", "w");
FILE *fgpu = fopen("gpu_results.txt", "w");
for (int i = 0; i < size; i++)
{
if (fabs(cpuResults[i] - gpuResults[i]) / cpuResults[i]
> MAX_RELATIVE_ERROR)
{
cout << "Mismatch at i: "<< i << " ref: " << cpuResults[i] <<
" dev: " << gpuResults[i] << endl;
passed = false;
}
fprintf(fcpu, "%f\n", cpuResults[i]);
fprintf(fgpu, "%f\n", gpuResults[i]);
}
fclose(fcpu);
fclose(fgpu);
if (pass != -1)
{
cout << "Pass "<<pass<<": ";
}
if (passed)
{
cout << "Passed" << endl;
}
else
{
cout << "---FAILED---" << endl;
}
return passed;
}
template <typename floatType, typename texReader>
void csrTest(floatType* h_val,
int* h_cols, int* h_rowDelimiters, floatType* h_vec, floatType* h_out,
int numRows, int numNonZeroes, floatType* refOut, bool padded)
{
// Device data structures
floatType *d_val, *d_vec, *d_out;
int *d_cols, *d_rowDelimiters;
// Allocate device memory
cudaMalloc(&d_val, numNonZeroes * sizeof(floatType));
cudaMalloc(&d_cols, numNonZeroes * sizeof(int));
cudaMalloc(&d_vec, numRows * sizeof(floatType));
cudaMalloc(&d_out, numRows * sizeof(floatType));
cudaMalloc(&d_rowDelimiters, (numRows+1) * sizeof(int));
// Transfer data to device
cudaMemcpy(d_val, h_val, numNonZeroes * sizeof(floatType),cudaMemcpyHostToDevice);
cudaMemcpy(d_cols, h_cols, numNonZeroes * sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(d_vec, h_vec, numRows * sizeof(floatType),cudaMemcpyHostToDevice);
cudaMemcpy(d_rowDelimiters, h_rowDelimiters,(numRows+1) * sizeof(int), cudaMemcpyHostToDevice);
// Bind texture for position
string suffix;
if (sizeof(floatType) == sizeof(float))
{
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<float>();
cudaBindTexture(0, vecTex, d_vec, channelDesc, numRows * sizeof(float));
suffix = "-SP";
}
else {
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<int2>();
cudaBindTexture(0, vecTexD, d_vec, channelDesc, numRows * sizeof(int2));
suffix = "-DP";
}
// Setup thread configuration
int nBlocksScalar = (int) ceil((floatType) numRows / BLOCK_SIZE);
int nBlocksVector = (int) ceil(numRows /
(floatType)(BLOCK_SIZE / WARP_SIZE));
int passes = 1;
int iters = 1;
// Results description info
char atts[TEMP_BUFFER_SIZE];
// sprintf(atts, "%d_elements_%d_rows", numNonZeroes, numRows);
string prefix = "";
prefix += (padded) ? "Padded_" : "";
cout << "CSR Scalar Kernel\n";
for (int k=0; k<passes; k++)
{
// Run Scalar Kernel
for (int j = 0; j < iters; j++)
{
spmv_csr_scalar_kernel<floatType, texReader>
<<<nBlocksScalar, BLOCK_SIZE>>>
(d_val, d_cols, d_rowDelimiters, numRows, d_out, d_vec);
}
// Transfer data back to host
cudaMemcpy(h_out, d_out, numRows * sizeof(floatType),cudaMemcpyDeviceToHost);
// Compare reference solution to GPU result
cout << "CSR Scalar Kernel Finished\n";
if (! verifyResults(refOut, h_out, numRows, k))
{
return; // If results don't match, don't report performance
}
}
cout << "CSR Scalar Done\n";
zero<floatType><<<nBlocksScalar, BLOCK_SIZE>>>(d_out, numRows);
cudaThreadSynchronize();
//cout << "CSR Vector Kernel\n";
//for (int k=0; k<passes; k++)
//{
// // Run Vector Kernel
// cudaEventRecord(start, 0);
// for (int j = 0; j < iters; j++)
// {
// //spmv_csr_vector_kernel<floatType, texReader> <<<nBlocksVector, BLOCK_SIZE>>> (d_val, d_cols, d_rowDelimiters, numRows, d_out);
// }
// cudaEventRecord(stop, 0);
// cudaEventSynchronize(stop);
// float vectorKernelTime;
// cudaEventElapsedTime(&vectorKernelTime, start, stop);
// cudaMemcpy(h_out, d_out, numRows * sizeof(floatType),cudaMemcpyDeviceToHost);
// cudaThreadSynchronize();
// Compare reference solution to GPU result
// if (! verifyResults(refOut, h_out, numRows, k))
// {
// return; // If results don't match, don't report performance
// }
// vectorKernelTime = (vectorKernelTime / (float)iters) * 1.e-3;
// string testName = prefix+"CSR-Vector"+suffix;
// double totalTransfer = iTransferTime + oTransferTime;
//}
// Free device memory
cudaFree(d_rowDelimiters);
cudaFree(d_vec);
cudaFree(d_out);
cudaFree(d_val);
cudaFree(d_cols);
cudaUnbindTexture(vecTexD);
cudaUnbindTexture(vecTex);
}
template <typename floatType, typename texReader>
void RunTest(int nRows=0)
{
// Host data structures
// Array of values in the sparse matrix
floatType *h_val;
// Array of column indices for each value in h_val
int *h_cols;
// Array of indices to the start of each row in h_Val
int *h_rowDelimiters;
// Dense vector and space for dev/cpu reference solution
floatType *h_vec, *h_out, *refOut;
// nItems = number of non zero elems
int nItems, numRows;
// This benchmark either reads in a matrix market input file or
// generates a random matrix
numRows = nRows;
nItems = numRows * numRows / 100; // 1% of entries will be non-zero
cudaMallocHost(&h_val, nItems * sizeof(floatType));
cudaMallocHost(&h_cols, nItems * sizeof(int));
cudaMallocHost(&h_rowDelimiters, (numRows + 1) * sizeof(int));
fill(h_val, nItems, 10);
initRandomMatrix(h_cols, h_rowDelimiters, nItems, numRows);
// Set up remaining host data
cudaMallocHost(&h_vec, numRows * sizeof(floatType));
refOut = new floatType[numRows];
fill(h_vec, numRows, 10);
// Set up the padded data structures
int PAD_FACTOR = 16;
int paddedSize = numRows + (PAD_FACTOR - numRows % PAD_FACTOR);
cudaMallocHost(&h_out, paddedSize * sizeof(floatType));
// Compute reference solution
spmvCpu(h_val, h_cols, h_rowDelimiters, h_vec, numRows, refOut);
// Test CSR kernels on normal data
cout << "CSR Test\n";
csrTest<floatType, texReader>(h_val, h_cols,
h_rowDelimiters, h_vec, h_out, numRows, nItems, refOut, false);
delete[] refOut;
cudaFreeHost(h_val);
cudaFreeHost(h_cols);
cudaFreeHost(h_rowDelimiters);
cudaFreeHost(h_vec);
cudaFreeHost(h_out);
}
int main()
{
int probSizes[4] = {1024, 8192, 12288, 16384};
int sizeClass = 16384;
cout <<"Single precision tests:\n";
RunTest<float, texReaderSP>(sizeClass);
return 0;
}
template <typename fpType, typename texReader>
__global__ void
spmv_csr_scalar_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out,
const fpType * __restrict__ vec)
{
int myRow = blockIdx.x * blockDim.x + threadIdx.x;
texReader vecTexReader;
if (myRow < dim)
{
fpType t = 0.0f;
int start = rowDelimiters[myRow];
int end = rowDelimiters[myRow+1];
for (int j = start; j < end; j++)
{
int col = cols[j];
t += val[j] * vecTexReader(col);
//t += val[j] * vec[col];
}
out[myRow] = t;
}
}
/*
template <typename fpType, typename texReader>
__global__ void
spmv_csr_vector_kernel(const fpType * __restrict__ val,
const int * __restrict__ cols,
const int * __restrict__ rowDelimiters,
const int dim, fpType * __restrict__ out)
{
// Thread ID in block
int t = threadIdx.x;
// Thread ID within warp
int id = t & (warpSize-1);
int warpsPerBlock = blockDim.x / warpSize;
// One row per warp
int myRow = (blockIdx.x * warpsPerBlock) + (t / warpSize);
// Texture reader for the dense vector
texReader vecTexReader;
__shared__ volatile fpType partialSums[BLOCK_SIZE];
if (myRow < dim)
{
int warpStart = rowDelimiters[myRow];
int warpEnd = rowDelimiters[myRow+1];
fpType mySum = 0;
for (int j = warpStart + id; j < warpEnd; j += warpSize)
{
int col = cols[j];
mySum += val[j] * vecTexReader(col);
}
partialSums[t] = mySum;
// Reduce partial sums
if (id < 16) partialSums[t] += partialSums[t+16];
if (id < 8) partialSums[t] += partialSums[t+ 8];
if (id < 4) partialSums[t] += partialSums[t+ 4];
if (id < 2) partialSums[t] += partialSums[t+ 2];
if (id < 1) partialSums[t] += partialSums[t+ 1];
// Write result
if (id == 0)
{
out[myRow] = partialSums[t];
}
}
}*/
template <typename fpType>
__global__ void
zero(fpType * __restrict__ a, const int size)
{
int t = blockIdx.x * blockDim.x + threadIdx.x;
if (t < size) a[t] = 0;
}
|
e96f20abc07b1f6df32698d47bf1b8fb22a21a07.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* Copyright (c) 2018, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <tests/utilities/legacy/cudf_test_fixtures.h>
#include <cudf/utilities/legacy/type_dispatcher.hpp>
#include <cudf/cudf.h>
#include <thrust/device_vector.h>
#include <gtest/gtest.h>
#include <cstdint>
/**
* @file dispatcher_test.cu
* @brief Tests the type_dispatcher
*/
struct DispatcherTest : public GdfTest {
/**---------------------------------------------------------------------------*
* @brief Lists every gdf_dtype that the type_dispatcher supports.
*
* This vector *must* list every gdf_dtype supported by the type_dispatcher.
*
* If a new type gdf_dtype is added, but this list is not updated, then the
* tests will fail.
*
*---------------------------------------------------------------------------**/
std::vector<gdf_dtype> supported_dtypes{
GDF_INT8, GDF_INT16, GDF_INT32, GDF_INT64,
GDF_FLOAT32, GDF_FLOAT64, GDF_DATE32, GDF_DATE64,
GDF_TIMESTAMP, GDF_CATEGORY, GDF_STRING_CATEGORY, GDF_BOOL8};
// These types are not supported by the type_dispatcher
std::vector<gdf_dtype> unsupported_dtypes{GDF_invalid, GDF_STRING};
};
using TestTypes = ::testing::Types<int8_t, int16_t, int32_t, int64_t, float,
double, cudf::date32, cudf::date64,
cudf::timestamp, cudf::category,
cudf::nvstring_category, cudf::bool8>;
template <typename T>
struct TypedDispatcherTest : DispatcherTest {};
TYPED_TEST_CASE(TypedDispatcherTest, TestTypes);
namespace {
template <typename ExpectedType>
struct type_tester {
template <typename DispatchedType>
bool operator()() {
return std::is_same<ExpectedType, DispatchedType>::value;
}
};
} // namespace
// Ensure that the type_to_gdf_dtype trait maps to the correct gdf_dtype
TYPED_TEST(TypedDispatcherTest, TraitsTest) {
EXPECT_TRUE(cudf::type_dispatcher(cudf::gdf_dtype_of<TypeParam>(),
type_tester<TypeParam>{}));
}
TEST_F(DispatcherTest, NumberOfTypesTest) {
// N_GDF_TYPES indicates how many enums there are in `gdf_dtype`,
// therefore, if a gdf_dtype is added without updating this test, the test
// will fail
const size_t expected_num_supported_dtypes =
N_GDF_TYPES - unsupported_dtypes.size();
// Note: If this test fails, that means a type was added to gdf_dtype
// without adding it to the `supported_dtypes` list in this test fixture
ASSERT_EQ(expected_num_supported_dtypes, supported_dtypes.size())
<< "Number of supported types does not match what was expected.";
}
namespace {
struct test_functor {
template <typename T>
__host__ __device__ bool operator()(gdf_dtype type_id) {
return (type_id == cudf::gdf_dtype_of<T>());
}
};
__global__ void dispatch_test_kernel(gdf_dtype type, bool* d_result) {
if (0 == threadIdx.x + blockIdx.x * blockDim.x)
*d_result = cudf::type_dispatcher(type, test_functor{}, type);
}
} // namespace
// Every supported gdf_dtype should dispatch the correct type
TEST_F(DispatcherTest, HostDispatchFunctor) {
for (auto const& t : this->supported_dtypes) {
bool result = cudf::type_dispatcher(t, test_functor{}, t);
EXPECT_TRUE(result);
}
}
TEST_F(DispatcherTest, DeviceDispatchFunctor) {
thrust::device_vector<bool> result(1);
for (auto const& t : this->supported_dtypes) {
hipLaunchKernelGGL(( dispatch_test_kernel), dim3(1), dim3(1), 0, 0, t, result.data().get());
hipDeviceSynchronize();
EXPECT_EQ(true, result[0]);
}
}
// Unsuported gdf_dtypes should throw std::runtime_error in host code
TEST_F(DispatcherTest, UnsuportedTypesTest) {
for (auto const& t : unsupported_dtypes) {
EXPECT_THROW(cudf::type_dispatcher(t, test_functor{}, t),
std::runtime_error);
}
}
using DispatcherDeathTest = DispatcherTest;
// Unsuported gdf_dtypes in device code should set appropriate error code
// and invalidates device context
TEST_F(DispatcherDeathTest, DeviceDispatchFunctor) {
testing::FLAGS_gtest_death_test_style = "threadsafe";
thrust::device_vector<bool> result(1);
auto call_kernel = [&result](gdf_dtype t) {
hipLaunchKernelGGL(( dispatch_test_kernel), dim3(1), dim3(1), 0, 0, t, result.data().get());
auto error_code = hipDeviceSynchronize();
// Kernel should fail with `hipErrorAssert` on an unsupported gdf_dtype
// This error invalidates the current device context, so we need to kill
// the current process. Running with EXPECT_DEATH spawns a new process for
// each attempted kernel launch
EXPECT_EQ(hipErrorAssert, error_code);
exit(-1);
};
for (auto const& t : unsupported_dtypes) {
EXPECT_DEATH(call_kernel(t), "");
}
}
| e96f20abc07b1f6df32698d47bf1b8fb22a21a07.cu | /*
* Copyright (c) 2018, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <tests/utilities/legacy/cudf_test_fixtures.h>
#include <cudf/utilities/legacy/type_dispatcher.hpp>
#include <cudf/cudf.h>
#include <thrust/device_vector.h>
#include <gtest/gtest.h>
#include <cstdint>
/**
* @file dispatcher_test.cu
* @brief Tests the type_dispatcher
*/
struct DispatcherTest : public GdfTest {
/**---------------------------------------------------------------------------*
* @brief Lists every gdf_dtype that the type_dispatcher supports.
*
* This vector *must* list every gdf_dtype supported by the type_dispatcher.
*
* If a new type gdf_dtype is added, but this list is not updated, then the
* tests will fail.
*
*---------------------------------------------------------------------------**/
std::vector<gdf_dtype> supported_dtypes{
GDF_INT8, GDF_INT16, GDF_INT32, GDF_INT64,
GDF_FLOAT32, GDF_FLOAT64, GDF_DATE32, GDF_DATE64,
GDF_TIMESTAMP, GDF_CATEGORY, GDF_STRING_CATEGORY, GDF_BOOL8};
// These types are not supported by the type_dispatcher
std::vector<gdf_dtype> unsupported_dtypes{GDF_invalid, GDF_STRING};
};
using TestTypes = ::testing::Types<int8_t, int16_t, int32_t, int64_t, float,
double, cudf::date32, cudf::date64,
cudf::timestamp, cudf::category,
cudf::nvstring_category, cudf::bool8>;
template <typename T>
struct TypedDispatcherTest : DispatcherTest {};
TYPED_TEST_CASE(TypedDispatcherTest, TestTypes);
namespace {
template <typename ExpectedType>
struct type_tester {
template <typename DispatchedType>
bool operator()() {
return std::is_same<ExpectedType, DispatchedType>::value;
}
};
} // namespace
// Ensure that the type_to_gdf_dtype trait maps to the correct gdf_dtype
TYPED_TEST(TypedDispatcherTest, TraitsTest) {
EXPECT_TRUE(cudf::type_dispatcher(cudf::gdf_dtype_of<TypeParam>(),
type_tester<TypeParam>{}));
}
TEST_F(DispatcherTest, NumberOfTypesTest) {
// N_GDF_TYPES indicates how many enums there are in `gdf_dtype`,
// therefore, if a gdf_dtype is added without updating this test, the test
// will fail
const size_t expected_num_supported_dtypes =
N_GDF_TYPES - unsupported_dtypes.size();
// Note: If this test fails, that means a type was added to gdf_dtype
// without adding it to the `supported_dtypes` list in this test fixture
ASSERT_EQ(expected_num_supported_dtypes, supported_dtypes.size())
<< "Number of supported types does not match what was expected.";
}
namespace {
struct test_functor {
template <typename T>
__host__ __device__ bool operator()(gdf_dtype type_id) {
return (type_id == cudf::gdf_dtype_of<T>());
}
};
__global__ void dispatch_test_kernel(gdf_dtype type, bool* d_result) {
if (0 == threadIdx.x + blockIdx.x * blockDim.x)
*d_result = cudf::type_dispatcher(type, test_functor{}, type);
}
} // namespace
// Every supported gdf_dtype should dispatch the correct type
TEST_F(DispatcherTest, HostDispatchFunctor) {
for (auto const& t : this->supported_dtypes) {
bool result = cudf::type_dispatcher(t, test_functor{}, t);
EXPECT_TRUE(result);
}
}
TEST_F(DispatcherTest, DeviceDispatchFunctor) {
thrust::device_vector<bool> result(1);
for (auto const& t : this->supported_dtypes) {
dispatch_test_kernel<<<1, 1>>>(t, result.data().get());
cudaDeviceSynchronize();
EXPECT_EQ(true, result[0]);
}
}
// Unsuported gdf_dtypes should throw std::runtime_error in host code
TEST_F(DispatcherTest, UnsuportedTypesTest) {
for (auto const& t : unsupported_dtypes) {
EXPECT_THROW(cudf::type_dispatcher(t, test_functor{}, t),
std::runtime_error);
}
}
using DispatcherDeathTest = DispatcherTest;
// Unsuported gdf_dtypes in device code should set appropriate error code
// and invalidates device context
TEST_F(DispatcherDeathTest, DeviceDispatchFunctor) {
testing::FLAGS_gtest_death_test_style = "threadsafe";
thrust::device_vector<bool> result(1);
auto call_kernel = [&result](gdf_dtype t) {
dispatch_test_kernel<<<1, 1>>>(t, result.data().get());
auto error_code = cudaDeviceSynchronize();
// Kernel should fail with `cudaErrorAssert` on an unsupported gdf_dtype
// This error invalidates the current device context, so we need to kill
// the current process. Running with EXPECT_DEATH spawns a new process for
// each attempted kernel launch
EXPECT_EQ(cudaErrorAssert, error_code);
exit(-1);
};
for (auto const& t : unsupported_dtypes) {
EXPECT_DEATH(call_kernel(t), "");
}
}
|
7bd962d2fbb844ef7821bae69099f61280f0cc75.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
//Udacity HW 4
//Radix Sorting
#include "utils.h"
#include <thrust/host_vector.h>
/* Red Eye Removal
===============
For this assignment we are implementing red eye removal. This is
accomplished by first creating a score for every pixel that tells us how
likely it is to be a red eye pixel. We have already done this for you - you
are receiving the scores and need to sort them in ascending order so that we
know which pixels to alter to remove the red eye.
Note: ascending order == smallest to largest
Each score is associated with a position, when you sort the scores, you must
also move the positions accordingly.
Implementing Parallel Radix Sort with CUDA
==========================================
The basic idea is to construct a histogram on each pass of how many of each
"digit" there are. Then we scan this histogram so that we know where to put
the output of each digit. For example, the first 1 must come after all the
0s so we have to know how many 0s there are to be able to start moving 1s
into the correct position.
1) Histogram of the number of occurrences of each digit
2) Exclusive Prefix Sum of Histogram
3) Determine relative offset of each digit
For example [0 0 1 1 0 0 1]
-> [0 1 0 1 2 3 2]
4) Combine the results of steps 2 & 3 to determine the final
output location for each element and move it there
LSB Radix sort is an out-of-place sort and you will need to ping-pong values
between the input and output buffers we have provided. Make sure the final
sorted results end up in the output buffer! Hint: You may need to do a copy
at the end.
*/
__global__
void scan_kernel(unsigned *d_in, unsigned int *d_out, const size_t size) {
int mid = threadIdx.x + blockDim.x * blockIdx.x;
if(mid >= size)
return;
d_out[mid] = d_in[mid];
__syncthreads();
for(int s = 1; s <= size; s *= 2) {
int spot = mid - s;
unsigned int val = 0;
if(spot >= 0)
val = d_out[spot];
__syncthreads();
if(spot >= 0)
d_out[mid] += val;
__syncthreads();
}
d_out[mid] = d_out[mid] - d_in[mid];
}
__global__
void exclusive_scan_kernel(unsigned *d_in, unsigned int *d_out, const size_t size) {
// 1d of blockDim
int index = threadIdx.x + blockDim.x * blockIdx.x;
if(index >= size)
return;
d_out[index] = 1; //d_in[index];
__syncthreads();
size_t s = 0;
for(s=1; s<size; s<<=1) {
if((index + 1)%(2*s) == 0) {
if(index - s >= 0) {
d_out[index] = d_out[index] + d_out[index - s];
}
}
__syncthreads();
}
// downsweep
if(index == size-1) {
d_out[index] = 0;
}
__syncthreads();
for(s = s/2; s>0; s>>=1) {
if((index + 1) % (2*s) == 0) {
if(index - s >=0) {
int tmp = d_out[index - s];
d_out[index - s] = d_out[index];
d_out[index] = d_out[index] + tmp;
}
}
__syncthreads();
}
}
__global__
void predicate_kernel(unsigned int *d_in,
unsigned int *d_out,
const size_t size, unsigned int mask, int *count) {
int id = threadIdx.x + blockDim.x * blockIdx.x;
if(id >= size)
return;
unsigned int bit = d_in[id] & mask;
if(count) { // get 0
d_out[id] = bit == 0 ? 1 : 0;
if(bit == 0)
atomicAdd(count, 1);
} else {
d_out[id] = bit == 1 ? 1 : 0;
}
}
__global__
void scatter_kernel(unsigned int* const d_inputVals,
unsigned int* const d_inputPos,
unsigned int* const d_outputVals,
unsigned int* const d_outputPos,
const size_t size,
unsigned int *scan_in,
unsigned int *offset_in, int* offset) {
int id = threadIdx.x + blockDim.x * blockIdx.x;
if(id >= size)
return;
if(scan_in[id] == 1) {
int addr = offset_in[id] + offset == NULL?0:(*offset);
d_outputVals[addr] = d_inputVals[id];
d_outputPos[addr] = d_inputPos[id];
}
}
#include <stdio.h>
// gives you a good max size for n/d
int get_max_size(int n, int d) {
return (int)ceil( (float)n/(float)d ) + 1;
}
void your_sort(unsigned int* const d_inputVals,
unsigned int* const d_inputPos,
unsigned int* const d_outputVals,
unsigned int* const d_outputPos,
const size_t numElems)
{
//TODO
//PUT YOUR SORT HERE
unsigned int *in = (unsigned int *)calloc(1, numElems * sizeof(unsigned int));
unsigned int *offset = (unsigned int *)calloc(1, numElems * sizeof(unsigned int));
checkCudaErrors(hipMemcpy(in, d_inputVals, sizeof(unsigned int) * numElems, hipMemcpyDeviceToHost));
printf("numElems %d \n", (int)numElems);
for(int i=0; i<50; i++) {
//printf("%d \n", in[i]);
}
dim3 blockdim(1024);
dim3 griddim(numElems / 1024 + 1);
unsigned int *d_in, *d_inPos, *d_out, *d_outPos, *d_scan, *d_offset;
checkCudaErrors(hipMalloc(&d_in, sizeof(int) * numElems));
checkCudaErrors(hipMalloc(&d_inPos, sizeof(int) * numElems));
checkCudaErrors(hipMalloc(&d_out, sizeof(int) * numElems));
checkCudaErrors(hipMemset(d_out, 0, sizeof(int) * numElems));
checkCudaErrors(hipMalloc(&d_outPos, sizeof(int) * numElems));
checkCudaErrors(hipMemset(d_outPos, 0, sizeof(int) * numElems));
checkCudaErrors(hipMalloc(&d_scan, sizeof(int) * numElems));
checkCudaErrors(hipMemset(d_scan, 0, sizeof(int) * numElems));
checkCudaErrors(hipMalloc(&d_offset, sizeof(int) * numElems));
checkCudaErrors(hipMemset(d_offset, 0, sizeof(int) * numElems));
checkCudaErrors(hipMemcpy(d_in, d_inputVals, sizeof(int) * numElems, hipMemcpyDeviceToDevice));
checkCudaErrors(hipMemcpy(d_inPos, d_inputPos, sizeof(int) * numElems, hipMemcpyDeviceToDevice));
int *d_count;
int count;
checkCudaErrors(hipMalloc(&d_count, sizeof(int)));
unsigned int mask = 0x01;
unsigned int *tmp;
for(int j=0; j<32; j++) {
// predicative kernel
printf("j is %d 111111111111\n", j);
mask <<= j;
// bit 0
count = 0;
checkCudaErrors(hipMemcpy(d_count, &count, sizeof(int), hipMemcpyHostToDevice));
checkCudaErrors(hipGetLastError());
checkCudaErrors(hipMemcpy(in, d_in, sizeof(int) * numElems, hipMemcpyDeviceToHost));
printf("numElems %d \n", (int)numElems);
for(int i=0; i<10; i++) {
//printf("%d \n", in[i]);
}
hipLaunchKernelGGL(( predicate_kernel), dim3(griddim), dim3(blockdim), 0, 0, d_in, d_scan, numElems, mask , d_count);
hipDeviceSynchronize();
checkCudaErrors(hipMemcpy(offset, d_scan, sizeof(unsigned int) * numElems, hipMemcpyDeviceToHost));
printf("0 1 array \n");
for(int i=0; i<10; i++) {
printf("%d \n", offset[i]);
}
checkCudaErrors(hipGetLastError());
for(int i = 0; i < get_max_size(numElems, blockdim.x); i++) {
hipLaunchKernelGGL(( exclusive_scan_kernel), dim3(dim3(1)), dim3(blockdim), 0, 0, d_scan, d_offset, numElems);
hipDeviceSynchronize(); checkCudaErrors(hipGetLastError());
}
hipDeviceSynchronize();
checkCudaErrors(hipGetLastError());
checkCudaErrors(hipMemcpy(offset, d_offset, sizeof(unsigned int) * numElems, hipMemcpyDeviceToHost));
printf("offset \n");
for(int i=0; i<10; i++) {
printf("%d \n", offset[i]);
}
checkCudaErrors(hipMemcpy(&count, d_count, sizeof(int), hipMemcpyDeviceToHost));
printf("count is %d \n", count);
hipLaunchKernelGGL(( scatter_kernel), dim3(griddim), dim3(blockdim), 0, 0, d_in, d_inPos,
d_out, d_outPos,
numElems,
d_scan,
d_offset, NULL);
hipDeviceSynchronize();
checkCudaErrors(hipGetLastError());
// bit 1
hipLaunchKernelGGL(( predicate_kernel), dim3(griddim), dim3(blockdim), 0, 0, d_in, d_scan, numElems, mask , NULL);
hipDeviceSynchronize();
checkCudaErrors(hipGetLastError());
for(int i = 0; i < get_max_size(numElems, blockdim.x); i++) {
hipLaunchKernelGGL(( exclusive_scan_kernel), dim3(dim3(1)), dim3(blockdim), 0, 0, d_scan, d_offset, numElems);
hipDeviceSynchronize(); checkCudaErrors(hipGetLastError());
}
hipDeviceSynchronize();
checkCudaErrors(hipGetLastError());
hipLaunchKernelGGL(( scatter_kernel), dim3(griddim), dim3(blockdim), 0, 0, d_in, d_inPos,
d_out, d_outPos,
numElems,
d_scan,
d_offset, d_count);
hipDeviceSynchronize();
checkCudaErrors(hipGetLastError());
tmp = d_in;
d_in = d_out;
d_out = tmp;
tmp = d_inPos;
d_inPos = d_outPos;
d_outPos = tmp;
}
hipMemcpy(d_outputVals, d_out, sizeof(unsigned int)*numElems, hipMemcpyDeviceToDevice);
hipMemcpy(d_outputPos, d_outPos, sizeof(unsigned int)*numElems, hipMemcpyDeviceToDevice);
if(d_in) {
checkCudaErrors(hipFree(d_in));
}
if(d_out) {
checkCudaErrors(hipFree(d_out));
}
if(d_inPos) {
checkCudaErrors(hipFree(d_inPos));
}
if(d_outPos) {
checkCudaErrors(hipFree(d_outPos));
}
if(d_scan) {
checkCudaErrors(hipFree(d_scan));
}
if(d_offset) {
checkCudaErrors(hipFree(d_offset));
}
if(d_count) {
checkCudaErrors(hipFree(d_count));
}
}
| 7bd962d2fbb844ef7821bae69099f61280f0cc75.cu | //Udacity HW 4
//Radix Sorting
#include "utils.h"
#include <thrust/host_vector.h>
/* Red Eye Removal
===============
For this assignment we are implementing red eye removal. This is
accomplished by first creating a score for every pixel that tells us how
likely it is to be a red eye pixel. We have already done this for you - you
are receiving the scores and need to sort them in ascending order so that we
know which pixels to alter to remove the red eye.
Note: ascending order == smallest to largest
Each score is associated with a position, when you sort the scores, you must
also move the positions accordingly.
Implementing Parallel Radix Sort with CUDA
==========================================
The basic idea is to construct a histogram on each pass of how many of each
"digit" there are. Then we scan this histogram so that we know where to put
the output of each digit. For example, the first 1 must come after all the
0s so we have to know how many 0s there are to be able to start moving 1s
into the correct position.
1) Histogram of the number of occurrences of each digit
2) Exclusive Prefix Sum of Histogram
3) Determine relative offset of each digit
For example [0 0 1 1 0 0 1]
-> [0 1 0 1 2 3 2]
4) Combine the results of steps 2 & 3 to determine the final
output location for each element and move it there
LSB Radix sort is an out-of-place sort and you will need to ping-pong values
between the input and output buffers we have provided. Make sure the final
sorted results end up in the output buffer! Hint: You may need to do a copy
at the end.
*/
__global__
void scan_kernel(unsigned *d_in, unsigned int *d_out, const size_t size) {
int mid = threadIdx.x + blockDim.x * blockIdx.x;
if(mid >= size)
return;
d_out[mid] = d_in[mid];
__syncthreads();
for(int s = 1; s <= size; s *= 2) {
int spot = mid - s;
unsigned int val = 0;
if(spot >= 0)
val = d_out[spot];
__syncthreads();
if(spot >= 0)
d_out[mid] += val;
__syncthreads();
}
d_out[mid] = d_out[mid] - d_in[mid];
}
__global__
void exclusive_scan_kernel(unsigned *d_in, unsigned int *d_out, const size_t size) {
// 1d of blockDim
int index = threadIdx.x + blockDim.x * blockIdx.x;
if(index >= size)
return;
d_out[index] = 1; //d_in[index];
__syncthreads();
size_t s = 0;
for(s=1; s<size; s<<=1) {
if((index + 1)%(2*s) == 0) {
if(index - s >= 0) {
d_out[index] = d_out[index] + d_out[index - s];
}
}
__syncthreads();
}
// downsweep
if(index == size-1) {
d_out[index] = 0;
}
__syncthreads();
for(s = s/2; s>0; s>>=1) {
if((index + 1) % (2*s) == 0) {
if(index - s >=0) {
int tmp = d_out[index - s];
d_out[index - s] = d_out[index];
d_out[index] = d_out[index] + tmp;
}
}
__syncthreads();
}
}
__global__
void predicate_kernel(unsigned int *d_in,
unsigned int *d_out,
const size_t size, unsigned int mask, int *count) {
int id = threadIdx.x + blockDim.x * blockIdx.x;
if(id >= size)
return;
unsigned int bit = d_in[id] & mask;
if(count) { // get 0
d_out[id] = bit == 0 ? 1 : 0;
if(bit == 0)
atomicAdd(count, 1);
} else {
d_out[id] = bit == 1 ? 1 : 0;
}
}
__global__
void scatter_kernel(unsigned int* const d_inputVals,
unsigned int* const d_inputPos,
unsigned int* const d_outputVals,
unsigned int* const d_outputPos,
const size_t size,
unsigned int *scan_in,
unsigned int *offset_in, int* offset) {
int id = threadIdx.x + blockDim.x * blockIdx.x;
if(id >= size)
return;
if(scan_in[id] == 1) {
int addr = offset_in[id] + offset == NULL?0:(*offset);
d_outputVals[addr] = d_inputVals[id];
d_outputPos[addr] = d_inputPos[id];
}
}
#include <stdio.h>
// gives you a good max size for n/d
int get_max_size(int n, int d) {
return (int)ceil( (float)n/(float)d ) + 1;
}
void your_sort(unsigned int* const d_inputVals,
unsigned int* const d_inputPos,
unsigned int* const d_outputVals,
unsigned int* const d_outputPos,
const size_t numElems)
{
//TODO
//PUT YOUR SORT HERE
unsigned int *in = (unsigned int *)calloc(1, numElems * sizeof(unsigned int));
unsigned int *offset = (unsigned int *)calloc(1, numElems * sizeof(unsigned int));
checkCudaErrors(cudaMemcpy(in, d_inputVals, sizeof(unsigned int) * numElems, cudaMemcpyDeviceToHost));
printf("numElems %d \n", (int)numElems);
for(int i=0; i<50; i++) {
//printf("%d \n", in[i]);
}
dim3 blockdim(1024);
dim3 griddim(numElems / 1024 + 1);
unsigned int *d_in, *d_inPos, *d_out, *d_outPos, *d_scan, *d_offset;
checkCudaErrors(cudaMalloc(&d_in, sizeof(int) * numElems));
checkCudaErrors(cudaMalloc(&d_inPos, sizeof(int) * numElems));
checkCudaErrors(cudaMalloc(&d_out, sizeof(int) * numElems));
checkCudaErrors(cudaMemset(d_out, 0, sizeof(int) * numElems));
checkCudaErrors(cudaMalloc(&d_outPos, sizeof(int) * numElems));
checkCudaErrors(cudaMemset(d_outPos, 0, sizeof(int) * numElems));
checkCudaErrors(cudaMalloc(&d_scan, sizeof(int) * numElems));
checkCudaErrors(cudaMemset(d_scan, 0, sizeof(int) * numElems));
checkCudaErrors(cudaMalloc(&d_offset, sizeof(int) * numElems));
checkCudaErrors(cudaMemset(d_offset, 0, sizeof(int) * numElems));
checkCudaErrors(cudaMemcpy(d_in, d_inputVals, sizeof(int) * numElems, cudaMemcpyDeviceToDevice));
checkCudaErrors(cudaMemcpy(d_inPos, d_inputPos, sizeof(int) * numElems, cudaMemcpyDeviceToDevice));
int *d_count;
int count;
checkCudaErrors(cudaMalloc(&d_count, sizeof(int)));
unsigned int mask = 0x01;
unsigned int *tmp;
for(int j=0; j<32; j++) {
// predicative kernel
printf("j is %d 111111111111\n", j);
mask <<= j;
// bit 0
count = 0;
checkCudaErrors(cudaMemcpy(d_count, &count, sizeof(int), cudaMemcpyHostToDevice));
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaMemcpy(in, d_in, sizeof(int) * numElems, cudaMemcpyDeviceToHost));
printf("numElems %d \n", (int)numElems);
for(int i=0; i<10; i++) {
//printf("%d \n", in[i]);
}
predicate_kernel<<<griddim, blockdim>>>(d_in, d_scan, numElems, mask , d_count);
cudaDeviceSynchronize();
checkCudaErrors(cudaMemcpy(offset, d_scan, sizeof(unsigned int) * numElems, cudaMemcpyDeviceToHost));
printf("0 1 array \n");
for(int i=0; i<10; i++) {
printf("%d \n", offset[i]);
}
checkCudaErrors(cudaGetLastError());
for(int i = 0; i < get_max_size(numElems, blockdim.x); i++) {
exclusive_scan_kernel<<<dim3(1), blockdim>>>(d_scan, d_offset, numElems);
cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
}
cudaDeviceSynchronize();
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaMemcpy(offset, d_offset, sizeof(unsigned int) * numElems, cudaMemcpyDeviceToHost));
printf("offset \n");
for(int i=0; i<10; i++) {
printf("%d \n", offset[i]);
}
checkCudaErrors(cudaMemcpy(&count, d_count, sizeof(int), cudaMemcpyDeviceToHost));
printf("count is %d \n", count);
scatter_kernel<<<griddim, blockdim>>>(d_in, d_inPos,
d_out, d_outPos,
numElems,
d_scan,
d_offset, NULL);
cudaDeviceSynchronize();
checkCudaErrors(cudaGetLastError());
// bit 1
predicate_kernel<<<griddim, blockdim>>>(d_in, d_scan, numElems, mask , NULL);
cudaDeviceSynchronize();
checkCudaErrors(cudaGetLastError());
for(int i = 0; i < get_max_size(numElems, blockdim.x); i++) {
exclusive_scan_kernel<<<dim3(1), blockdim>>>(d_scan, d_offset, numElems);
cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
}
cudaDeviceSynchronize();
checkCudaErrors(cudaGetLastError());
scatter_kernel<<<griddim, blockdim>>>(d_in, d_inPos,
d_out, d_outPos,
numElems,
d_scan,
d_offset, d_count);
cudaDeviceSynchronize();
checkCudaErrors(cudaGetLastError());
tmp = d_in;
d_in = d_out;
d_out = tmp;
tmp = d_inPos;
d_inPos = d_outPos;
d_outPos = tmp;
}
cudaMemcpy(d_outputVals, d_out, sizeof(unsigned int)*numElems, cudaMemcpyDeviceToDevice);
cudaMemcpy(d_outputPos, d_outPos, sizeof(unsigned int)*numElems, cudaMemcpyDeviceToDevice);
if(d_in) {
checkCudaErrors(cudaFree(d_in));
}
if(d_out) {
checkCudaErrors(cudaFree(d_out));
}
if(d_inPos) {
checkCudaErrors(cudaFree(d_inPos));
}
if(d_outPos) {
checkCudaErrors(cudaFree(d_outPos));
}
if(d_scan) {
checkCudaErrors(cudaFree(d_scan));
}
if(d_offset) {
checkCudaErrors(cudaFree(d_offset));
}
if(d_count) {
checkCudaErrors(cudaFree(d_count));
}
}
|
cb189149ce0f2a8d1ac6e7ec3a7bc5ddf4439c66.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <nvbench/nvbench.cuh>
// Grab some testing kernels from NVBench:
#include <nvbench/test_kernels.cuh>
void simple(nvbench::state &state)
{
state.exec([](nvbench::launch &launch) {
// Sleep for 1 millisecond:
hipLaunchKernelGGL(( nvbench::sleep_kernel), dim3(1), dim3(1), 0, launch.get_stream(), 1e-3);
});
}
NVBENCH_BENCH(simple);
| cb189149ce0f2a8d1ac6e7ec3a7bc5ddf4439c66.cu | #include <nvbench/nvbench.cuh>
// Grab some testing kernels from NVBench:
#include <nvbench/test_kernels.cuh>
void simple(nvbench::state &state)
{
state.exec([](nvbench::launch &launch) {
// Sleep for 1 millisecond:
nvbench::sleep_kernel<<<1, 1, 0, launch.get_stream()>>>(1e-3);
});
}
NVBENCH_BENCH(simple);
|
cecd0f9f7f4c3aa239eea6b3b2d76e4c72f5458a.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "includes.h"
__global__ void computePointHessian1(float *x, float *y, float *z, int points_num, int *valid_points, int valid_points_num, double *dh_ang, double *ph124, double *ph134, double *ph144, double *ph154, double *ph125, double *ph164, double *ph135, double *ph174, double *ph145)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
int stride = blockDim.x * gridDim.x;
__shared__ double h_ang[18];
if (threadIdx.x < 18) {
h_ang[threadIdx.x] = dh_ang[18 + threadIdx.x];
}
__syncthreads();
for (int i = id; i < valid_points_num; i += stride) {
int pid = valid_points[i];
//Orignal coordinates
double o_x = static_cast<double>(x[pid]);
double o_y = static_cast<double>(y[pid]);
double o_z = static_cast<double>(z[pid]);
ph124[i] = o_x * h_ang[0] + o_y * h_ang[1] + o_z * h_ang[2];
ph134[i] = o_x * h_ang[3] + o_y * h_ang[4] + o_z * h_ang[5];
ph144[i] = o_x * h_ang[6] + o_y * h_ang[7] + o_z * h_ang[8];
ph154[i] = ph125[i] = o_x * h_ang[9] + o_y * h_ang[10] + o_z * h_ang[11];
ph164[i] = ph135[i] = o_x * h_ang[12] + o_y * h_ang[13] + o_z * h_ang[14];
ph174[i] = ph145[i] = o_x * h_ang[15] + o_y * h_ang[16] + o_z * h_ang[17];
}
} | cecd0f9f7f4c3aa239eea6b3b2d76e4c72f5458a.cu | #include "includes.h"
__global__ void computePointHessian1(float *x, float *y, float *z, int points_num, int *valid_points, int valid_points_num, double *dh_ang, double *ph124, double *ph134, double *ph144, double *ph154, double *ph125, double *ph164, double *ph135, double *ph174, double *ph145)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
int stride = blockDim.x * gridDim.x;
__shared__ double h_ang[18];
if (threadIdx.x < 18) {
h_ang[threadIdx.x] = dh_ang[18 + threadIdx.x];
}
__syncthreads();
for (int i = id; i < valid_points_num; i += stride) {
int pid = valid_points[i];
//Orignal coordinates
double o_x = static_cast<double>(x[pid]);
double o_y = static_cast<double>(y[pid]);
double o_z = static_cast<double>(z[pid]);
ph124[i] = o_x * h_ang[0] + o_y * h_ang[1] + o_z * h_ang[2];
ph134[i] = o_x * h_ang[3] + o_y * h_ang[4] + o_z * h_ang[5];
ph144[i] = o_x * h_ang[6] + o_y * h_ang[7] + o_z * h_ang[8];
ph154[i] = ph125[i] = o_x * h_ang[9] + o_y * h_ang[10] + o_z * h_ang[11];
ph164[i] = ph135[i] = o_x * h_ang[12] + o_y * h_ang[13] + o_z * h_ang[14];
ph174[i] = ph145[i] = o_x * h_ang[15] + o_y * h_ang[16] + o_z * h_ang[17];
}
} |
9807c8c60b747c55424b12d11a92eed1f38ad4e3.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* Copyright 2011-2016 Maxim Milakov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "rectified_linear_layer_updater_cuda.h"
#include "util_cuda.h"
namespace nnforge
{
namespace cuda
{
__global__ void rectified_linear_upd_kernel(
const float4 * __restrict input,
float4 * __restrict output,
uint4 * __restrict bits_buffer,
int elem_count)
{
int elem_id = blockDim.x * blockIdx.x + threadIdx.x;
if (elem_id < elem_count)
{
float4 val = input[elem_id];
uint4 bits;
bits.x = __ballot(val.x > 0.0F ? 1 : 0);
bits.y = __ballot(val.y > 0.0F ? 1 : 0);
bits.z = __ballot(val.z > 0.0F ? 1 : 0);
bits.w = __ballot(val.w > 0.0F ? 1 : 0);
int lane_id = elem_id & 31;
if (lane_id == 0)
bits_buffer[elem_id >> 5] = bits;
val.x = max(val.x, 0.0F);
val.y = max(val.y, 0.0F);
val.z = max(val.z, 0.0F);
val.w = max(val.w, 0.0F);
output[elem_id] = val;
}
}
__global__ void rectified_linear_backprop_upd_kernel(
float4 * __restrict input_errors,
const float4 * __restrict output_errors,
const uint4 * __restrict bits_buffer,
bool add_update_to_destination,
int elem_count)
{
int elem_id = blockDim.x * blockIdx.x + threadIdx.x;
if (elem_id < elem_count)
{
float4 val = output_errors[elem_id];
uint4 bits = bits_buffer[elem_id >> 5];
int lane_id = elem_id & 31;
unsigned int mask = (1 << lane_id);
if ((bits.x & mask) == 0)
val.x = 0.0F;
if ((bits.y & mask) == 0)
val.y = 0.0F;
if ((bits.z & mask) == 0)
val.z = 0.0F;
if ((bits.w & mask) == 0)
val.w = 0.0F;
if (add_update_to_destination)
{
float4 prv = input_errors[elem_id];
val.x += prv.x;
val.y += prv.y;
val.z += prv.z;
val.w += prv.w;
}
input_errors[elem_id] = val;
}
}
void rectified_linear_layer_updater_cuda::enqueue_forward_propagation(
hipStream_t stream_id,
cuda_linear_buffer_device::ptr output_buffer,
const std::vector<cuda_linear_buffer_device::const_ptr>& schema_data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data_custom,
const std::vector<cuda_linear_buffer_device::const_ptr>& input_buffers,
const std::vector<cuda_linear_buffer_device::const_ptr>& persistent_working_data,
cuda_linear_buffer_device::ptr temporary_working_fixed_buffer,
cuda_linear_buffer_device::ptr temporary_working_per_entry_buffer,
cuda_linear_buffer_device::ptr temporary_fixed_buffer,
cuda_linear_buffer_device::ptr temporary_per_entry_buffer,
unsigned int entry_count)
{
int elem_count = (output_elem_count_per_entry * entry_count + 3) / 4;
std::pair<dim3, dim3> kernel_dims = cuda_util::get_grid_and_threadblock_sizes_sequential_access(
*cuda_config,
elem_count,
1,
1,
32);
hipLaunchKernelGGL(( rectified_linear_upd_kernel), dim3(kernel_dims.first), dim3(kernel_dims.second), 0, stream_id,
*input_buffers[0],
*output_buffer,
*temporary_per_entry_buffer,
elem_count);
}
void rectified_linear_layer_updater_cuda::enqueue_backward_data_propagation(
hipStream_t stream_id,
unsigned int input_index,
cuda_linear_buffer_device::ptr input_errors_buffer,
cuda_linear_buffer_device::const_ptr output_errors_buffer,
const std::vector<cuda_linear_buffer_device::const_ptr>& schema_data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data_custom,
const std::vector<cuda_linear_buffer_device::const_ptr>& input_neurons_buffers,
cuda_linear_buffer_device::const_ptr output_neurons_buffer,
const std::vector<cuda_linear_buffer_device::const_ptr>& persistent_working_data,
cuda_linear_buffer_device::ptr temporary_working_fixed_buffer,
cuda_linear_buffer_device::ptr temporary_working_per_entry_buffer,
cuda_linear_buffer_device::const_ptr temporary_fixed_buffer,
cuda_linear_buffer_device::const_ptr temporary_per_entry_buffer,
bool add_update_to_destination,
unsigned int entry_count)
{
int elem_count = (output_elem_count_per_entry * entry_count + 3) / 4;
std::pair<dim3, dim3> kernel_dims = cuda_util::get_grid_and_threadblock_sizes_sequential_access(
*cuda_config,
elem_count,
1,
1,
32);
hipLaunchKernelGGL(( rectified_linear_backprop_upd_kernel), dim3(kernel_dims.first), dim3(kernel_dims.second), 0, stream_id,
*input_errors_buffer,
*output_errors_buffer,
*temporary_per_entry_buffer,
add_update_to_destination,
elem_count);
}
int rectified_linear_layer_updater_cuda::get_input_index_layer_can_write(const layer_action& action) const
{
return 0;
}
bool rectified_linear_layer_updater_cuda::is_backward_data_dependent_on_input_buffer(unsigned int action_input_index, unsigned int data_input_index) const
{
return false;
}
bool rectified_linear_layer_updater_cuda::is_backward_data_dependent_on_output_buffer(unsigned int action_input_index) const
{
return false;
}
bool rectified_linear_layer_updater_cuda::is_backward_data_dependent_on_temporary_per_entry_buffer(unsigned int action_input_index) const
{
return true;
}
size_t rectified_linear_layer_updater_cuda::get_temporary_per_entry_buffer_size() const
{
return ((output_elem_count_per_entry + 128 - 1) / 128) * sizeof(uint4);
}
}
}
| 9807c8c60b747c55424b12d11a92eed1f38ad4e3.cu | /*
* Copyright 2011-2016 Maxim Milakov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "rectified_linear_layer_updater_cuda.h"
#include "util_cuda.h"
namespace nnforge
{
namespace cuda
{
__global__ void rectified_linear_upd_kernel(
const float4 * __restrict input,
float4 * __restrict output,
uint4 * __restrict bits_buffer,
int elem_count)
{
int elem_id = blockDim.x * blockIdx.x + threadIdx.x;
if (elem_id < elem_count)
{
float4 val = input[elem_id];
uint4 bits;
bits.x = __ballot(val.x > 0.0F ? 1 : 0);
bits.y = __ballot(val.y > 0.0F ? 1 : 0);
bits.z = __ballot(val.z > 0.0F ? 1 : 0);
bits.w = __ballot(val.w > 0.0F ? 1 : 0);
int lane_id = elem_id & 31;
if (lane_id == 0)
bits_buffer[elem_id >> 5] = bits;
val.x = max(val.x, 0.0F);
val.y = max(val.y, 0.0F);
val.z = max(val.z, 0.0F);
val.w = max(val.w, 0.0F);
output[elem_id] = val;
}
}
__global__ void rectified_linear_backprop_upd_kernel(
float4 * __restrict input_errors,
const float4 * __restrict output_errors,
const uint4 * __restrict bits_buffer,
bool add_update_to_destination,
int elem_count)
{
int elem_id = blockDim.x * blockIdx.x + threadIdx.x;
if (elem_id < elem_count)
{
float4 val = output_errors[elem_id];
uint4 bits = bits_buffer[elem_id >> 5];
int lane_id = elem_id & 31;
unsigned int mask = (1 << lane_id);
if ((bits.x & mask) == 0)
val.x = 0.0F;
if ((bits.y & mask) == 0)
val.y = 0.0F;
if ((bits.z & mask) == 0)
val.z = 0.0F;
if ((bits.w & mask) == 0)
val.w = 0.0F;
if (add_update_to_destination)
{
float4 prv = input_errors[elem_id];
val.x += prv.x;
val.y += prv.y;
val.z += prv.z;
val.w += prv.w;
}
input_errors[elem_id] = val;
}
}
void rectified_linear_layer_updater_cuda::enqueue_forward_propagation(
cudaStream_t stream_id,
cuda_linear_buffer_device::ptr output_buffer,
const std::vector<cuda_linear_buffer_device::const_ptr>& schema_data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data_custom,
const std::vector<cuda_linear_buffer_device::const_ptr>& input_buffers,
const std::vector<cuda_linear_buffer_device::const_ptr>& persistent_working_data,
cuda_linear_buffer_device::ptr temporary_working_fixed_buffer,
cuda_linear_buffer_device::ptr temporary_working_per_entry_buffer,
cuda_linear_buffer_device::ptr temporary_fixed_buffer,
cuda_linear_buffer_device::ptr temporary_per_entry_buffer,
unsigned int entry_count)
{
int elem_count = (output_elem_count_per_entry * entry_count + 3) / 4;
std::pair<dim3, dim3> kernel_dims = cuda_util::get_grid_and_threadblock_sizes_sequential_access(
*cuda_config,
elem_count,
1,
1,
32);
rectified_linear_upd_kernel<<<kernel_dims.first, kernel_dims.second, 0, stream_id>>>(
*input_buffers[0],
*output_buffer,
*temporary_per_entry_buffer,
elem_count);
}
void rectified_linear_layer_updater_cuda::enqueue_backward_data_propagation(
cudaStream_t stream_id,
unsigned int input_index,
cuda_linear_buffer_device::ptr input_errors_buffer,
cuda_linear_buffer_device::const_ptr output_errors_buffer,
const std::vector<cuda_linear_buffer_device::const_ptr>& schema_data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data,
const std::vector<cuda_linear_buffer_device::const_ptr>& data_custom,
const std::vector<cuda_linear_buffer_device::const_ptr>& input_neurons_buffers,
cuda_linear_buffer_device::const_ptr output_neurons_buffer,
const std::vector<cuda_linear_buffer_device::const_ptr>& persistent_working_data,
cuda_linear_buffer_device::ptr temporary_working_fixed_buffer,
cuda_linear_buffer_device::ptr temporary_working_per_entry_buffer,
cuda_linear_buffer_device::const_ptr temporary_fixed_buffer,
cuda_linear_buffer_device::const_ptr temporary_per_entry_buffer,
bool add_update_to_destination,
unsigned int entry_count)
{
int elem_count = (output_elem_count_per_entry * entry_count + 3) / 4;
std::pair<dim3, dim3> kernel_dims = cuda_util::get_grid_and_threadblock_sizes_sequential_access(
*cuda_config,
elem_count,
1,
1,
32);
rectified_linear_backprop_upd_kernel<<<kernel_dims.first, kernel_dims.second, 0, stream_id>>>(
*input_errors_buffer,
*output_errors_buffer,
*temporary_per_entry_buffer,
add_update_to_destination,
elem_count);
}
int rectified_linear_layer_updater_cuda::get_input_index_layer_can_write(const layer_action& action) const
{
return 0;
}
bool rectified_linear_layer_updater_cuda::is_backward_data_dependent_on_input_buffer(unsigned int action_input_index, unsigned int data_input_index) const
{
return false;
}
bool rectified_linear_layer_updater_cuda::is_backward_data_dependent_on_output_buffer(unsigned int action_input_index) const
{
return false;
}
bool rectified_linear_layer_updater_cuda::is_backward_data_dependent_on_temporary_per_entry_buffer(unsigned int action_input_index) const
{
return true;
}
size_t rectified_linear_layer_updater_cuda::get_temporary_per_entry_buffer_size() const
{
return ((output_elem_count_per_entry + 128 - 1) / 128) * sizeof(uint4);
}
}
}
|
27c013819747b8abd5ab0a0c9f954388a0c9bb09.hip | // !!! This is a file automatically generated by hipify!!!
#include <stdio.h>
#include "cudacommon.h"
#include "OptionParser.h"
#include "ResultDatabase.h"
// ****************************************************************************
// Function: addBenchmarkSpecOptions
//
// Purpose:
// Add benchmark specific command line argument parsing.
//
// -nopinned
// This option controls whether page-locked or "pinned" memory is used.
// The use of pinned memory typically results in higher bandwidth for data
// transfer between host and device.
//
// Arguments:
// op: the options parser / parameter database
//
// Returns: nothing
//
// Programmer: Jeremy Meredith
// Creation: September 08, 2009
//
// Modifications:
//
// ****************************************************************************
void addBenchmarkSpecOptions(OptionParser &op)
{
op.addOption("nopinned", OPT_BOOL, "",
"disable usage of pinned (pagelocked) memory", 'p');
}
// ****************************************************************************
// Function: runBenchmark
//
// Purpose:
// Measures the bandwidth of the bus connecting the host processor to the
// OpenCL device. This benchmark repeatedly transfers data chunks of various
// sizes across the bus to the OpenCL device, and calculates the bandwidth.
//
//
// Arguments:
// resultDB: the benchmark stores its results in this ResultDatabase
// op: the options parser / parameter database
//
// Returns: nothing
//
// Programmer: Jeremy Meredith
// Creation: September 08, 2009
//
// Modifications:
// Jeremy Meredith, Wed Dec 1 17:05:27 EST 2010
// Added calculation of latency estimate.
//
// ****************************************************************************
void RunBenchmark(ResultDatabase &resultDB,
OptionParser &op)
{
const bool verbose = op.getOptionBool("verbose");
const bool pinned = !op.getOptionBool("nopinned");
// Sizes are in kb
int nSizes = 20;
int sizes[20] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,
32768,65536,131072,262144,524288};
long long numMaxFloats = 1024 * (sizes[nSizes-1]) / 4;
// Create some host memory pattern
float *hostMem = NULL;
if (pinned)
{
hipHostMalloc((void**)&hostMem, sizeof(float) * numMaxFloats);
while (hipGetLastError() != hipSuccess)
{
// drop the size and try again
if (verbose) cout << " - dropping size allocating pinned mem\n";
--nSizes;
if (nSizes < 1)
{
cerr << "Error: Couldn't allocated any pinned buffer\n";
return;
}
numMaxFloats = 1024 * (sizes[nSizes-1]) / 4;
hipHostMalloc((void**)&hostMem, sizeof(float) * numMaxFloats);
}
}
else
{
hostMem = new float[numMaxFloats];
}
for (int i = 0; i < numMaxFloats; i++)
{
hostMem[i] = i % 77;
}
float *device;
hipMalloc((void**)&device, sizeof(float) * numMaxFloats);
while (hipGetLastError() != hipSuccess)
{
// drop the size and try again
if (verbose) cout << " - dropping size allocating device mem\n";
--nSizes;
if (nSizes < 1)
{
cerr << "Error: Couldn't allocated any device buffer\n";
return;
}
numMaxFloats = 1024 * (sizes[nSizes-1]) / 4;
hipMalloc((void**)&device, sizeof(float) * numMaxFloats);
}
const unsigned int passes = op.getOptionInt("passes");
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);
CHECK_CUDA_ERROR();
// Three passes, forward and backward both
for (int pass = 0; pass < passes; pass++)
{
// store the times temporarily to estimate latency
//float times[nSizes];
// Step through sizes forward on even passes and backward on odd
for (int i = 0; i < nSizes; i++)
{
int sizeIndex;
if ((pass % 2) == 0)
sizeIndex = i;
else
sizeIndex = (nSizes - 1) - i;
int nbytes = sizes[sizeIndex] * 1024;
hipEventRecord(start, 0);
hipMemcpy(device, hostMem, nbytes, hipMemcpyHostToDevice);
hipEventRecord(stop, 0);
hipEventSynchronize(stop);
float t = 0;
hipEventElapsedTime(&t, start, stop);
//times[sizeIndex] = t;
// Convert to GB/sec
if (verbose)
{
cerr << "size " << sizes[sizeIndex] << "k took " << t <<
" ms\n";
}
double speed = (double(sizes[sizeIndex]) * 1024. / (1000*1000)) / t;
char sizeStr[256];
sprintf(sizeStr, "% 7dkB", sizes[sizeIndex]);
resultDB.AddResult("DownloadSpeed", sizeStr, "GB/sec", speed);
resultDB.AddResult("DownloadTime", sizeStr, "ms", t);
}
//resultDB.AddResult("DownloadLatencyEstimate", "1-2kb", "ms", times[0]-(times[1]-times[0])/1.);
//resultDB.AddResult("DownloadLatencyEstimate", "1-4kb", "ms", times[0]-(times[2]-times[0])/3.);
//resultDB.AddResult("DownloadLatencyEstimate", "2-4kb", "ms", times[1]-(times[2]-times[1])/1.);
}
// Cleanup
hipFree((void*)device);
CHECK_CUDA_ERROR();
if (pinned)
{
hipHostFree((void*)hostMem);
CHECK_CUDA_ERROR();
}
else
{
delete[] hostMem;
}
hipEventDestroy(start);
hipEventDestroy(stop);
}
| 27c013819747b8abd5ab0a0c9f954388a0c9bb09.cu | #include <stdio.h>
#include "cudacommon.h"
#include "OptionParser.h"
#include "ResultDatabase.h"
// ****************************************************************************
// Function: addBenchmarkSpecOptions
//
// Purpose:
// Add benchmark specific command line argument parsing.
//
// -nopinned
// This option controls whether page-locked or "pinned" memory is used.
// The use of pinned memory typically results in higher bandwidth for data
// transfer between host and device.
//
// Arguments:
// op: the options parser / parameter database
//
// Returns: nothing
//
// Programmer: Jeremy Meredith
// Creation: September 08, 2009
//
// Modifications:
//
// ****************************************************************************
void addBenchmarkSpecOptions(OptionParser &op)
{
op.addOption("nopinned", OPT_BOOL, "",
"disable usage of pinned (pagelocked) memory", 'p');
}
// ****************************************************************************
// Function: runBenchmark
//
// Purpose:
// Measures the bandwidth of the bus connecting the host processor to the
// OpenCL device. This benchmark repeatedly transfers data chunks of various
// sizes across the bus to the OpenCL device, and calculates the bandwidth.
//
//
// Arguments:
// resultDB: the benchmark stores its results in this ResultDatabase
// op: the options parser / parameter database
//
// Returns: nothing
//
// Programmer: Jeremy Meredith
// Creation: September 08, 2009
//
// Modifications:
// Jeremy Meredith, Wed Dec 1 17:05:27 EST 2010
// Added calculation of latency estimate.
//
// ****************************************************************************
void RunBenchmark(ResultDatabase &resultDB,
OptionParser &op)
{
const bool verbose = op.getOptionBool("verbose");
const bool pinned = !op.getOptionBool("nopinned");
// Sizes are in kb
int nSizes = 20;
int sizes[20] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,
32768,65536,131072,262144,524288};
long long numMaxFloats = 1024 * (sizes[nSizes-1]) / 4;
// Create some host memory pattern
float *hostMem = NULL;
if (pinned)
{
cudaMallocHost((void**)&hostMem, sizeof(float) * numMaxFloats);
while (cudaGetLastError() != cudaSuccess)
{
// drop the size and try again
if (verbose) cout << " - dropping size allocating pinned mem\n";
--nSizes;
if (nSizes < 1)
{
cerr << "Error: Couldn't allocated any pinned buffer\n";
return;
}
numMaxFloats = 1024 * (sizes[nSizes-1]) / 4;
cudaMallocHost((void**)&hostMem, sizeof(float) * numMaxFloats);
}
}
else
{
hostMem = new float[numMaxFloats];
}
for (int i = 0; i < numMaxFloats; i++)
{
hostMem[i] = i % 77;
}
float *device;
cudaMalloc((void**)&device, sizeof(float) * numMaxFloats);
while (cudaGetLastError() != cudaSuccess)
{
// drop the size and try again
if (verbose) cout << " - dropping size allocating device mem\n";
--nSizes;
if (nSizes < 1)
{
cerr << "Error: Couldn't allocated any device buffer\n";
return;
}
numMaxFloats = 1024 * (sizes[nSizes-1]) / 4;
cudaMalloc((void**)&device, sizeof(float) * numMaxFloats);
}
const unsigned int passes = op.getOptionInt("passes");
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
CHECK_CUDA_ERROR();
// Three passes, forward and backward both
for (int pass = 0; pass < passes; pass++)
{
// store the times temporarily to estimate latency
//float times[nSizes];
// Step through sizes forward on even passes and backward on odd
for (int i = 0; i < nSizes; i++)
{
int sizeIndex;
if ((pass % 2) == 0)
sizeIndex = i;
else
sizeIndex = (nSizes - 1) - i;
int nbytes = sizes[sizeIndex] * 1024;
cudaEventRecord(start, 0);
cudaMemcpy(device, hostMem, nbytes, cudaMemcpyHostToDevice);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float t = 0;
cudaEventElapsedTime(&t, start, stop);
//times[sizeIndex] = t;
// Convert to GB/sec
if (verbose)
{
cerr << "size " << sizes[sizeIndex] << "k took " << t <<
" ms\n";
}
double speed = (double(sizes[sizeIndex]) * 1024. / (1000*1000)) / t;
char sizeStr[256];
sprintf(sizeStr, "% 7dkB", sizes[sizeIndex]);
resultDB.AddResult("DownloadSpeed", sizeStr, "GB/sec", speed);
resultDB.AddResult("DownloadTime", sizeStr, "ms", t);
}
//resultDB.AddResult("DownloadLatencyEstimate", "1-2kb", "ms", times[0]-(times[1]-times[0])/1.);
//resultDB.AddResult("DownloadLatencyEstimate", "1-4kb", "ms", times[0]-(times[2]-times[0])/3.);
//resultDB.AddResult("DownloadLatencyEstimate", "2-4kb", "ms", times[1]-(times[2]-times[1])/1.);
}
// Cleanup
cudaFree((void*)device);
CHECK_CUDA_ERROR();
if (pinned)
{
cudaFreeHost((void*)hostMem);
CHECK_CUDA_ERROR();
}
else
{
delete[] hostMem;
}
cudaEventDestroy(start);
cudaEventDestroy(stop);
}
|
3ad4c4ad30554592c666c20b878ed2f9adda0849.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
//
// auto-generated by ops.py
//
__constant__ int xdim0_update_halo_kernel2_xvel_plus_4_bot;
int xdim0_update_halo_kernel2_xvel_plus_4_bot_h = -1;
__constant__ int ydim0_update_halo_kernel2_xvel_plus_4_bot;
int ydim0_update_halo_kernel2_xvel_plus_4_bot_h = -1;
__constant__ int xdim1_update_halo_kernel2_xvel_plus_4_bot;
int xdim1_update_halo_kernel2_xvel_plus_4_bot_h = -1;
__constant__ int ydim1_update_halo_kernel2_xvel_plus_4_bot;
int ydim1_update_halo_kernel2_xvel_plus_4_bot_h = -1;
#undef OPS_ACC0
#undef OPS_ACC1
#define OPS_ACC0(x, y, z) \
(x + xdim0_update_halo_kernel2_xvel_plus_4_bot * (y) + \
xdim0_update_halo_kernel2_xvel_plus_4_bot * \
ydim0_update_halo_kernel2_xvel_plus_4_bot * (z))
#define OPS_ACC1(x, y, z) \
(x + xdim1_update_halo_kernel2_xvel_plus_4_bot * (y) + \
xdim1_update_halo_kernel2_xvel_plus_4_bot * \
ydim1_update_halo_kernel2_xvel_plus_4_bot * (z))
// user function
__device__
inline void
update_halo_kernel2_xvel_plus_4_bot_gpu(double *xvel0, double *xvel1,
const int *fields) {
if (fields[FIELD_XVEL0] == 1)
xvel0[OPS_ACC0(0, 0, 0)] = xvel0[OPS_ACC0(0, 4, 0)];
if (fields[FIELD_XVEL1] == 1)
xvel1[OPS_ACC1(0, 0, 0)] = xvel1[OPS_ACC1(0, 4, 0)];
}
#undef OPS_ACC0
#undef OPS_ACC1
__global__ void ops_update_halo_kernel2_xvel_plus_4_bot(
double *__restrict arg0, double *__restrict arg1,
const int *__restrict arg2, int size0, int size1, int size2) {
int idx_z = blockDim.z * blockIdx.z + threadIdx.z;
int idx_y = blockDim.y * blockIdx.y + threadIdx.y;
int idx_x = blockDim.x * blockIdx.x + threadIdx.x;
arg0 += idx_x * 1 * 1 +
idx_y * 1 * 1 * xdim0_update_halo_kernel2_xvel_plus_4_bot +
idx_z * 1 * 1 * xdim0_update_halo_kernel2_xvel_plus_4_bot *
ydim0_update_halo_kernel2_xvel_plus_4_bot;
arg1 += idx_x * 1 * 1 +
idx_y * 1 * 1 * xdim1_update_halo_kernel2_xvel_plus_4_bot +
idx_z * 1 * 1 * xdim1_update_halo_kernel2_xvel_plus_4_bot *
ydim1_update_halo_kernel2_xvel_plus_4_bot;
if (idx_x < size0 && idx_y < size1 && idx_z < size2) {
update_halo_kernel2_xvel_plus_4_bot_gpu(arg0, arg1, arg2);
}
}
// host stub function
void ops_par_loop_update_halo_kernel2_xvel_plus_4_bot(char const *name,
ops_block block, int dim,
int *range, ops_arg arg0,
ops_arg arg1,
ops_arg arg2) {
// Timing
double t1, t2, c1, c2;
ops_arg args[3] = {arg0, arg1, arg2};
#ifdef CHECKPOINTING
if (!ops_checkpointing_before(args, 3, range, 68))
return;
#endif
if (OPS_diags > 1) {
ops_timing_realloc(68, "update_halo_kernel2_xvel_plus_4_bot");
OPS_kernels[68].count++;
ops_timers_core(&c1, &t1);
}
// compute locally allocated range for the sub-block
int start[3];
int end[3];
#ifdef OPS_MPI
sub_block_list sb = OPS_sub_block_list[block->index];
if (!sb->owned)
return;
for (int n = 0; n < 3; n++) {
start[n] = sb->decomp_disp[n];
end[n] = sb->decomp_disp[n] + sb->decomp_size[n];
if (start[n] >= range[2 * n]) {
start[n] = 0;
} else {
start[n] = range[2 * n] - start[n];
}
if (sb->id_m[n] == MPI_PROC_NULL && range[2 * n] < 0)
start[n] = range[2 * n];
if (end[n] >= range[2 * n + 1]) {
end[n] = range[2 * n + 1] - sb->decomp_disp[n];
} else {
end[n] = sb->decomp_size[n];
}
if (sb->id_p[n] == MPI_PROC_NULL &&
(range[2 * n + 1] > sb->decomp_disp[n] + sb->decomp_size[n]))
end[n] += (range[2 * n + 1] - sb->decomp_disp[n] - sb->decomp_size[n]);
}
#else
for (int n = 0; n < 3; n++) {
start[n] = range[2 * n];
end[n] = range[2 * n + 1];
}
#endif
int x_size = MAX(0, end[0] - start[0]);
int y_size = MAX(0, end[1] - start[1]);
int z_size = MAX(0, end[2] - start[2]);
int xdim0 = args[0].dat->size[0];
int ydim0 = args[0].dat->size[1];
int xdim1 = args[1].dat->size[0];
int ydim1 = args[1].dat->size[1];
if (xdim0 != xdim0_update_halo_kernel2_xvel_plus_4_bot_h ||
ydim0 != ydim0_update_halo_kernel2_xvel_plus_4_bot_h ||
xdim1 != xdim1_update_halo_kernel2_xvel_plus_4_bot_h ||
ydim1 != ydim1_update_halo_kernel2_xvel_plus_4_bot_h) {
hipMemcpyToSymbol(xdim0_update_halo_kernel2_xvel_plus_4_bot, &xdim0,
sizeof(int));
xdim0_update_halo_kernel2_xvel_plus_4_bot_h = xdim0;
hipMemcpyToSymbol(ydim0_update_halo_kernel2_xvel_plus_4_bot, &ydim0,
sizeof(int));
ydim0_update_halo_kernel2_xvel_plus_4_bot_h = ydim0;
hipMemcpyToSymbol(xdim1_update_halo_kernel2_xvel_plus_4_bot, &xdim1,
sizeof(int));
xdim1_update_halo_kernel2_xvel_plus_4_bot_h = xdim1;
hipMemcpyToSymbol(ydim1_update_halo_kernel2_xvel_plus_4_bot, &ydim1,
sizeof(int));
ydim1_update_halo_kernel2_xvel_plus_4_bot_h = ydim1;
}
int *arg2h = (int *)arg2.data;
dim3 grid((x_size - 1) / OPS_block_size_x + 1,
(y_size - 1) / OPS_block_size_y + 1, z_size);
dim3 tblock(OPS_block_size_x, OPS_block_size_y, 1);
int consts_bytes = 0;
consts_bytes += ROUND_UP(NUM_FIELDS * sizeof(int));
reallocConstArrays(consts_bytes);
consts_bytes = 0;
arg2.data = OPS_consts_h + consts_bytes;
arg2.data_d = OPS_consts_d + consts_bytes;
for (int d = 0; d < NUM_FIELDS; d++)
((int *)arg2.data)[d] = arg2h[d];
consts_bytes += ROUND_UP(NUM_FIELDS * sizeof(int));
mvConstArraysToDevice(consts_bytes);
int dat0 = args[0].dat->elem_size;
int dat1 = args[1].dat->elem_size;
char *p_a[3];
// set up initial pointers
int d_m[OPS_MAX_DIM];
#ifdef OPS_MPI
for (int d = 0; d < dim; d++)
d_m[d] =
args[0].dat->d_m[d] + OPS_sub_dat_list[args[0].dat->index]->d_im[d];
#else
for (int d = 0; d < dim; d++)
d_m[d] = args[0].dat->d_m[d];
#endif
int base0 = dat0 * 1 * (start[0] * args[0].stencil->stride[0] -
args[0].dat->base[0] - d_m[0]);
base0 = base0 +
dat0 * args[0].dat->size[0] * (start[1] * args[0].stencil->stride[1] -
args[0].dat->base[1] - d_m[1]);
base0 = base0 +
dat0 * args[0].dat->size[0] * args[0].dat->size[1] *
(start[2] * args[0].stencil->stride[2] - args[0].dat->base[2] -
d_m[2]);
p_a[0] = (char *)args[0].data_d + base0;
#ifdef OPS_MPI
for (int d = 0; d < dim; d++)
d_m[d] =
args[1].dat->d_m[d] + OPS_sub_dat_list[args[1].dat->index]->d_im[d];
#else
for (int d = 0; d < dim; d++)
d_m[d] = args[1].dat->d_m[d];
#endif
int base1 = dat1 * 1 * (start[0] * args[1].stencil->stride[0] -
args[1].dat->base[0] - d_m[0]);
base1 = base1 +
dat1 * args[1].dat->size[0] * (start[1] * args[1].stencil->stride[1] -
args[1].dat->base[1] - d_m[1]);
base1 = base1 +
dat1 * args[1].dat->size[0] * args[1].dat->size[1] *
(start[2] * args[1].stencil->stride[2] - args[1].dat->base[2] -
d_m[2]);
p_a[1] = (char *)args[1].data_d + base1;
ops_H_D_exchanges_device(args, 3);
ops_halo_exchanges(args, 3, range);
if (OPS_diags > 1) {
ops_timers_core(&c2, &t2);
OPS_kernels[68].mpi_time += t2 - t1;
}
// call kernel wrapper function, passing in pointers to data
hipLaunchKernelGGL(( ops_update_halo_kernel2_xvel_plus_4_bot), dim3(grid), dim3(tblock), 0, 0,
(double *)p_a[0], (double *)p_a[1], (int *)arg2.data_d, x_size, y_size,
z_size);
if (OPS_diags > 1) {
cutilSafeCall(hipDeviceSynchronize());
ops_timers_core(&c1, &t1);
OPS_kernels[68].time += t1 - t2;
}
ops_set_dirtybit_device(args, 3);
ops_set_halo_dirtybit3(&args[0], range);
ops_set_halo_dirtybit3(&args[1], range);
if (OPS_diags > 1) {
// Update kernel record
ops_timers_core(&c2, &t2);
OPS_kernels[68].mpi_time += t2 - t1;
OPS_kernels[68].transfer += ops_compute_transfer(dim, start, end, &arg0);
OPS_kernels[68].transfer += ops_compute_transfer(dim, start, end, &arg1);
}
}
| 3ad4c4ad30554592c666c20b878ed2f9adda0849.cu | //
// auto-generated by ops.py
//
__constant__ int xdim0_update_halo_kernel2_xvel_plus_4_bot;
int xdim0_update_halo_kernel2_xvel_plus_4_bot_h = -1;
__constant__ int ydim0_update_halo_kernel2_xvel_plus_4_bot;
int ydim0_update_halo_kernel2_xvel_plus_4_bot_h = -1;
__constant__ int xdim1_update_halo_kernel2_xvel_plus_4_bot;
int xdim1_update_halo_kernel2_xvel_plus_4_bot_h = -1;
__constant__ int ydim1_update_halo_kernel2_xvel_plus_4_bot;
int ydim1_update_halo_kernel2_xvel_plus_4_bot_h = -1;
#undef OPS_ACC0
#undef OPS_ACC1
#define OPS_ACC0(x, y, z) \
(x + xdim0_update_halo_kernel2_xvel_plus_4_bot * (y) + \
xdim0_update_halo_kernel2_xvel_plus_4_bot * \
ydim0_update_halo_kernel2_xvel_plus_4_bot * (z))
#define OPS_ACC1(x, y, z) \
(x + xdim1_update_halo_kernel2_xvel_plus_4_bot * (y) + \
xdim1_update_halo_kernel2_xvel_plus_4_bot * \
ydim1_update_halo_kernel2_xvel_plus_4_bot * (z))
// user function
__device__
inline void
update_halo_kernel2_xvel_plus_4_bot_gpu(double *xvel0, double *xvel1,
const int *fields) {
if (fields[FIELD_XVEL0] == 1)
xvel0[OPS_ACC0(0, 0, 0)] = xvel0[OPS_ACC0(0, 4, 0)];
if (fields[FIELD_XVEL1] == 1)
xvel1[OPS_ACC1(0, 0, 0)] = xvel1[OPS_ACC1(0, 4, 0)];
}
#undef OPS_ACC0
#undef OPS_ACC1
__global__ void ops_update_halo_kernel2_xvel_plus_4_bot(
double *__restrict arg0, double *__restrict arg1,
const int *__restrict arg2, int size0, int size1, int size2) {
int idx_z = blockDim.z * blockIdx.z + threadIdx.z;
int idx_y = blockDim.y * blockIdx.y + threadIdx.y;
int idx_x = blockDim.x * blockIdx.x + threadIdx.x;
arg0 += idx_x * 1 * 1 +
idx_y * 1 * 1 * xdim0_update_halo_kernel2_xvel_plus_4_bot +
idx_z * 1 * 1 * xdim0_update_halo_kernel2_xvel_plus_4_bot *
ydim0_update_halo_kernel2_xvel_plus_4_bot;
arg1 += idx_x * 1 * 1 +
idx_y * 1 * 1 * xdim1_update_halo_kernel2_xvel_plus_4_bot +
idx_z * 1 * 1 * xdim1_update_halo_kernel2_xvel_plus_4_bot *
ydim1_update_halo_kernel2_xvel_plus_4_bot;
if (idx_x < size0 && idx_y < size1 && idx_z < size2) {
update_halo_kernel2_xvel_plus_4_bot_gpu(arg0, arg1, arg2);
}
}
// host stub function
void ops_par_loop_update_halo_kernel2_xvel_plus_4_bot(char const *name,
ops_block block, int dim,
int *range, ops_arg arg0,
ops_arg arg1,
ops_arg arg2) {
// Timing
double t1, t2, c1, c2;
ops_arg args[3] = {arg0, arg1, arg2};
#ifdef CHECKPOINTING
if (!ops_checkpointing_before(args, 3, range, 68))
return;
#endif
if (OPS_diags > 1) {
ops_timing_realloc(68, "update_halo_kernel2_xvel_plus_4_bot");
OPS_kernels[68].count++;
ops_timers_core(&c1, &t1);
}
// compute locally allocated range for the sub-block
int start[3];
int end[3];
#ifdef OPS_MPI
sub_block_list sb = OPS_sub_block_list[block->index];
if (!sb->owned)
return;
for (int n = 0; n < 3; n++) {
start[n] = sb->decomp_disp[n];
end[n] = sb->decomp_disp[n] + sb->decomp_size[n];
if (start[n] >= range[2 * n]) {
start[n] = 0;
} else {
start[n] = range[2 * n] - start[n];
}
if (sb->id_m[n] == MPI_PROC_NULL && range[2 * n] < 0)
start[n] = range[2 * n];
if (end[n] >= range[2 * n + 1]) {
end[n] = range[2 * n + 1] - sb->decomp_disp[n];
} else {
end[n] = sb->decomp_size[n];
}
if (sb->id_p[n] == MPI_PROC_NULL &&
(range[2 * n + 1] > sb->decomp_disp[n] + sb->decomp_size[n]))
end[n] += (range[2 * n + 1] - sb->decomp_disp[n] - sb->decomp_size[n]);
}
#else
for (int n = 0; n < 3; n++) {
start[n] = range[2 * n];
end[n] = range[2 * n + 1];
}
#endif
int x_size = MAX(0, end[0] - start[0]);
int y_size = MAX(0, end[1] - start[1]);
int z_size = MAX(0, end[2] - start[2]);
int xdim0 = args[0].dat->size[0];
int ydim0 = args[0].dat->size[1];
int xdim1 = args[1].dat->size[0];
int ydim1 = args[1].dat->size[1];
if (xdim0 != xdim0_update_halo_kernel2_xvel_plus_4_bot_h ||
ydim0 != ydim0_update_halo_kernel2_xvel_plus_4_bot_h ||
xdim1 != xdim1_update_halo_kernel2_xvel_plus_4_bot_h ||
ydim1 != ydim1_update_halo_kernel2_xvel_plus_4_bot_h) {
cudaMemcpyToSymbol(xdim0_update_halo_kernel2_xvel_plus_4_bot, &xdim0,
sizeof(int));
xdim0_update_halo_kernel2_xvel_plus_4_bot_h = xdim0;
cudaMemcpyToSymbol(ydim0_update_halo_kernel2_xvel_plus_4_bot, &ydim0,
sizeof(int));
ydim0_update_halo_kernel2_xvel_plus_4_bot_h = ydim0;
cudaMemcpyToSymbol(xdim1_update_halo_kernel2_xvel_plus_4_bot, &xdim1,
sizeof(int));
xdim1_update_halo_kernel2_xvel_plus_4_bot_h = xdim1;
cudaMemcpyToSymbol(ydim1_update_halo_kernel2_xvel_plus_4_bot, &ydim1,
sizeof(int));
ydim1_update_halo_kernel2_xvel_plus_4_bot_h = ydim1;
}
int *arg2h = (int *)arg2.data;
dim3 grid((x_size - 1) / OPS_block_size_x + 1,
(y_size - 1) / OPS_block_size_y + 1, z_size);
dim3 tblock(OPS_block_size_x, OPS_block_size_y, 1);
int consts_bytes = 0;
consts_bytes += ROUND_UP(NUM_FIELDS * sizeof(int));
reallocConstArrays(consts_bytes);
consts_bytes = 0;
arg2.data = OPS_consts_h + consts_bytes;
arg2.data_d = OPS_consts_d + consts_bytes;
for (int d = 0; d < NUM_FIELDS; d++)
((int *)arg2.data)[d] = arg2h[d];
consts_bytes += ROUND_UP(NUM_FIELDS * sizeof(int));
mvConstArraysToDevice(consts_bytes);
int dat0 = args[0].dat->elem_size;
int dat1 = args[1].dat->elem_size;
char *p_a[3];
// set up initial pointers
int d_m[OPS_MAX_DIM];
#ifdef OPS_MPI
for (int d = 0; d < dim; d++)
d_m[d] =
args[0].dat->d_m[d] + OPS_sub_dat_list[args[0].dat->index]->d_im[d];
#else
for (int d = 0; d < dim; d++)
d_m[d] = args[0].dat->d_m[d];
#endif
int base0 = dat0 * 1 * (start[0] * args[0].stencil->stride[0] -
args[0].dat->base[0] - d_m[0]);
base0 = base0 +
dat0 * args[0].dat->size[0] * (start[1] * args[0].stencil->stride[1] -
args[0].dat->base[1] - d_m[1]);
base0 = base0 +
dat0 * args[0].dat->size[0] * args[0].dat->size[1] *
(start[2] * args[0].stencil->stride[2] - args[0].dat->base[2] -
d_m[2]);
p_a[0] = (char *)args[0].data_d + base0;
#ifdef OPS_MPI
for (int d = 0; d < dim; d++)
d_m[d] =
args[1].dat->d_m[d] + OPS_sub_dat_list[args[1].dat->index]->d_im[d];
#else
for (int d = 0; d < dim; d++)
d_m[d] = args[1].dat->d_m[d];
#endif
int base1 = dat1 * 1 * (start[0] * args[1].stencil->stride[0] -
args[1].dat->base[0] - d_m[0]);
base1 = base1 +
dat1 * args[1].dat->size[0] * (start[1] * args[1].stencil->stride[1] -
args[1].dat->base[1] - d_m[1]);
base1 = base1 +
dat1 * args[1].dat->size[0] * args[1].dat->size[1] *
(start[2] * args[1].stencil->stride[2] - args[1].dat->base[2] -
d_m[2]);
p_a[1] = (char *)args[1].data_d + base1;
ops_H_D_exchanges_device(args, 3);
ops_halo_exchanges(args, 3, range);
if (OPS_diags > 1) {
ops_timers_core(&c2, &t2);
OPS_kernels[68].mpi_time += t2 - t1;
}
// call kernel wrapper function, passing in pointers to data
ops_update_halo_kernel2_xvel_plus_4_bot<<<grid, tblock>>>(
(double *)p_a[0], (double *)p_a[1], (int *)arg2.data_d, x_size, y_size,
z_size);
if (OPS_diags > 1) {
cutilSafeCall(cudaDeviceSynchronize());
ops_timers_core(&c1, &t1);
OPS_kernels[68].time += t1 - t2;
}
ops_set_dirtybit_device(args, 3);
ops_set_halo_dirtybit3(&args[0], range);
ops_set_halo_dirtybit3(&args[1], range);
if (OPS_diags > 1) {
// Update kernel record
ops_timers_core(&c2, &t2);
OPS_kernels[68].mpi_time += t2 - t1;
OPS_kernels[68].transfer += ops_compute_transfer(dim, start, end, &arg0);
OPS_kernels[68].transfer += ops_compute_transfer(dim, start, end, &arg1);
}
}
|
c28d365b73126e3b74fa53c8ac271f67f4ecbca1.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
-- MAGMA (version 1.3.0) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
November 2012
@generated s Wed Nov 14 22:53:51 2012
*/
#include "common_magma.h"
#define PRECISION_s
#include "commonblas.h"
__global__ void stranspose_32( float *B, int ldb, const float *A, int lda )
{
__shared__ float a[32][SSIZE_1SHARED+1];
int inx = threadIdx.x;
int iny = threadIdx.y;
int ibx = blockIdx.x*32;
int iby = blockIdx.y*32;
A += ibx + inx + __mul24( iby + iny, lda );
B += iby + inx + __mul24( ibx + iny, ldb );
a[iny+0][inx] = A[0*lda];
a[iny+8][inx] = A[8*lda];
a[iny+16][inx] = A[16*lda];
a[iny+24][inx] = A[24*lda];
__syncthreads();
#if defined(PRECISION_s) || defined(PRECISION_d) || defined(PRECISION_c)
B[0*ldb] = a[inx][iny+0];
B[8*ldb] = a[inx][iny+8];
B[16*ldb] = a[inx][iny+16];
B[24*ldb] = a[inx][iny+24];
#else /* defined(PRECISION_z) */
B[0*ldb] = a[inx][iny+0];
B[8*ldb] = a[inx][iny+8];
B[0*ldb+16] = a[inx+16][iny+0];
B[8*ldb+16] = a[inx+16][iny+8];
__syncthreads();
A += SSIZE_1SHARED;
B += __mul24( 16, ldb);
a[iny+0][inx] = A[0*lda];
a[iny+8][inx] = A[8*lda];
a[iny+16][inx] = A[16*lda];
a[iny+24][inx] = A[24*lda];
__syncthreads();
B[0*ldb] = a[inx][iny+0];
B[8*ldb] = a[inx][iny+8];
B[0*ldb+16] = a[inx+16][iny+0];
B[8*ldb+16] = a[inx+16][iny+8];
#endif
}
//
// m, n - dimensions in the source matrix
// This version works when m and n are divisible by 32.
//
extern "C" void
magmablas_stranspose(float *odata, magma_int_t ldo,
const float *idata, magma_int_t ldi,
magma_int_t m, magma_int_t n )
{
//assert( (m%32) == 0 && (n%32) == 0, "misaligned transpose" );
dim3 threads( SSIZE_1SHARED, 8, 1 );
dim3 grid( m/32, n/32, 1 );
hipLaunchKernelGGL(( stranspose_32), dim3(grid), dim3(threads), 0, magma_stream , odata, ldo, idata, ldi );
}
| c28d365b73126e3b74fa53c8ac271f67f4ecbca1.cu | /*
-- MAGMA (version 1.3.0) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
November 2012
@generated s Wed Nov 14 22:53:51 2012
*/
#include "common_magma.h"
#define PRECISION_s
#include "commonblas.h"
__global__ void stranspose_32( float *B, int ldb, const float *A, int lda )
{
__shared__ float a[32][SSIZE_1SHARED+1];
int inx = threadIdx.x;
int iny = threadIdx.y;
int ibx = blockIdx.x*32;
int iby = blockIdx.y*32;
A += ibx + inx + __mul24( iby + iny, lda );
B += iby + inx + __mul24( ibx + iny, ldb );
a[iny+0][inx] = A[0*lda];
a[iny+8][inx] = A[8*lda];
a[iny+16][inx] = A[16*lda];
a[iny+24][inx] = A[24*lda];
__syncthreads();
#if defined(PRECISION_s) || defined(PRECISION_d) || defined(PRECISION_c)
B[0*ldb] = a[inx][iny+0];
B[8*ldb] = a[inx][iny+8];
B[16*ldb] = a[inx][iny+16];
B[24*ldb] = a[inx][iny+24];
#else /* defined(PRECISION_z) */
B[0*ldb] = a[inx][iny+0];
B[8*ldb] = a[inx][iny+8];
B[0*ldb+16] = a[inx+16][iny+0];
B[8*ldb+16] = a[inx+16][iny+8];
__syncthreads();
A += SSIZE_1SHARED;
B += __mul24( 16, ldb);
a[iny+0][inx] = A[0*lda];
a[iny+8][inx] = A[8*lda];
a[iny+16][inx] = A[16*lda];
a[iny+24][inx] = A[24*lda];
__syncthreads();
B[0*ldb] = a[inx][iny+0];
B[8*ldb] = a[inx][iny+8];
B[0*ldb+16] = a[inx+16][iny+0];
B[8*ldb+16] = a[inx+16][iny+8];
#endif
}
//
// m, n - dimensions in the source matrix
// This version works when m and n are divisible by 32.
//
extern "C" void
magmablas_stranspose(float *odata, magma_int_t ldo,
const float *idata, magma_int_t ldi,
magma_int_t m, magma_int_t n )
{
//assert( (m%32) == 0 && (n%32) == 0, "misaligned transpose" );
dim3 threads( SSIZE_1SHARED, 8, 1 );
dim3 grid( m/32, n/32, 1 );
stranspose_32<<< grid, threads, 0, magma_stream >>>( odata, ldo, idata, ldi );
}
|
c50d09f307c55e66433cb1da2fe51ceccdf7a77a.hip | // !!! This is a file automatically generated by hipify!!!
#include <stdio.h>
#include <stdlib.h>
#include <hip/hip_runtime.h>
#include <time.h>
#define DATA_SIZE 1048576
bool InitCUDA()
{
int count;
hipGetDeviceCount(&count);
if(count == 0) {
fprintf(stderr, "There is no device.\n");
return false;
}
int i;
for(i = 0; i < count; i++) {
hipDeviceProp_t prop;
if(hipGetDeviceProperties(&prop, i) == hipSuccess) {
if(prop.major >= 1) {
break;
}
}
}
if(i == count) {
fprintf(stderr, "There is no device supporting CUDA 1.x.\n");
return false;
}
hipSetDevice(i);
return true;
}
void GenerateNumbers(int *number, int size)
{
for(int i = 0; i < size; i++) {
number[i] = rand() % 10;
}
}
__global__ static void sumOfSquares(int *num, int* result, clock_t* time)
{
int sum = 0;
int i;
clock_t start = clock();
for(i = 0; i < DATA_SIZE; i++) {
sum += num[i] * num[i];
}
*result = sum;
*time = clock() - start;
}
int main()
{
if(!InitCUDA()) {
return 0;
}
printf("CUDA initialized.\n");
int data[DATA_SIZE];
GenerateNumbers(data, DATA_SIZE);
int* gpudata, *result;
clock_t* time;
clock_t start_g, stop_g;
start_g = clock();
hipMalloc((void**) &gpudata, sizeof(int) * DATA_SIZE);
hipMalloc((void**) &result, sizeof(int));
hipMalloc((void**) &time, sizeof(clock_t));
hipMemcpy(gpudata, data, sizeof(int) * DATA_SIZE, hipMemcpyHostToDevice);
hipLaunchKernelGGL(( sumOfSquares), dim3(1), dim3(1), 0, 0, gpudata, result, time);
int sum;
clock_t time_used;
hipMemcpy(&sum, result, sizeof(int), hipMemcpyDeviceToHost);
hipMemcpy(&time_used, time, sizeof(clock_t), hipMemcpyDeviceToHost);
hipFree(gpudata);
hipFree(result);
hipFree(time);
stop_g = (clock() - start_g);
printf("sum (GPU): %d time: %f timeg: %f \n", sum, (double)time_used / CLOCKS_PER_SEC, (double) stop_g / CLOCKS_PER_SEC);
clock_t start, stop;
start = clock();
sum = 0;
for(int i = 0; i < DATA_SIZE; i++) {
sum += data[i] * data[i];
}
stop = clock() - start;
printf("sum (CPU): %d time: %f \n", sum, (double)stop / CLOCKS_PER_SEC);
return 0;
}
| c50d09f307c55e66433cb1da2fe51ceccdf7a77a.cu | #include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
#include <time.h>
#define DATA_SIZE 1048576
bool InitCUDA()
{
int count;
cudaGetDeviceCount(&count);
if(count == 0) {
fprintf(stderr, "There is no device.\n");
return false;
}
int i;
for(i = 0; i < count; i++) {
cudaDeviceProp prop;
if(cudaGetDeviceProperties(&prop, i) == cudaSuccess) {
if(prop.major >= 1) {
break;
}
}
}
if(i == count) {
fprintf(stderr, "There is no device supporting CUDA 1.x.\n");
return false;
}
cudaSetDevice(i);
return true;
}
void GenerateNumbers(int *number, int size)
{
for(int i = 0; i < size; i++) {
number[i] = rand() % 10;
}
}
__global__ static void sumOfSquares(int *num, int* result, clock_t* time)
{
int sum = 0;
int i;
clock_t start = clock();
for(i = 0; i < DATA_SIZE; i++) {
sum += num[i] * num[i];
}
*result = sum;
*time = clock() - start;
}
int main()
{
if(!InitCUDA()) {
return 0;
}
printf("CUDA initialized.\n");
int data[DATA_SIZE];
GenerateNumbers(data, DATA_SIZE);
int* gpudata, *result;
clock_t* time;
clock_t start_g, stop_g;
start_g = clock();
cudaMalloc((void**) &gpudata, sizeof(int) * DATA_SIZE);
cudaMalloc((void**) &result, sizeof(int));
cudaMalloc((void**) &time, sizeof(clock_t));
cudaMemcpy(gpudata, data, sizeof(int) * DATA_SIZE, cudaMemcpyHostToDevice);
sumOfSquares<<<1, 1, 0>>>(gpudata, result, time);
int sum;
clock_t time_used;
cudaMemcpy(&sum, result, sizeof(int), cudaMemcpyDeviceToHost);
cudaMemcpy(&time_used, time, sizeof(clock_t), cudaMemcpyDeviceToHost);
cudaFree(gpudata);
cudaFree(result);
cudaFree(time);
stop_g = (clock() - start_g);
printf("sum (GPU): %d time: %f timeg: %f \n", sum, (double)time_used / CLOCKS_PER_SEC, (double) stop_g / CLOCKS_PER_SEC);
clock_t start, stop;
start = clock();
sum = 0;
for(int i = 0; i < DATA_SIZE; i++) {
sum += data[i] * data[i];
}
stop = clock() - start;
printf("sum (CPU): %d time: %f \n", sum, (double)stop / CLOCKS_PER_SEC);
return 0;
}
|
de6e71e50517f9f47006b4c38747edf6b24c0c1f.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/* Copyright (c) 2011-2017, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <matrix.h>
#include <cutil.h>
#include <util.h>
#include <solvers/solver.h>
#include <thrust/transform_reduce.h>
#include <thrust/functional.h>
#include <thrust/device_ptr.h>
#include <thrust/sort.h>
#include <thrust/gather.h>
#include <vector_thrust_allocator.h>
#include <cusp/detail/format_utils.h>
#include <permute.h>
#include <multiply.h>
#include <amgx_types/util.h>
#include <algorithm>
template<typename T>
struct row_length : public amgx::thrust::unary_function<T, T>
{
__host__ __device__ T operator()(const T &x) const
{
const T *next_ptr = &x;
next_ptr++;
return (*next_ptr) - x;
}
};
namespace amgx
{
__global__ void computeRowOffsetsKernel(INDEX_TYPE num_rows, INDEX_TYPE num_nz, const INDEX_TYPE *row_indices, INDEX_TYPE *row_offsets )
{
//one thread per non-zero
int nz = blockIdx.x * blockDim.x + threadIdx.x;
if (nz == 0)
{
row_offsets[0] = 0;
row_offsets[num_rows] = num_nz;
}
while (nz < num_nz - 1)
{
int row = row_indices[nz];
int next_row = row_indices[nz + 1];
while (row < next_row) //this loop should probably always execute once, but I'm making it a loop just in case...
{
row_offsets[++row] = nz + 1;
}
nz += blockDim.x * gridDim.x;
}
}
__global__ void computeRowIndicesKernel(INDEX_TYPE num_rows, const INDEX_TYPE *row_offsets, INDEX_TYPE *row_indices )
{
//one warp per row //possible optimziation: multiple warps per row
int row = (blockIdx.x * blockDim.x + threadIdx.x) / AMGX_WARP_SIZE;
int warp_id = threadIdx.x % AMGX_WARP_SIZE;
while (row < num_rows)
{
int start = row_offsets[row] + warp_id;
int end = row_offsets[row + 1];
for (int nz = start; nz < end; nz += AMGX_WARP_SIZE)
{
row_indices[nz] = row;
}
row += blockDim.x * gridDim.x / AMGX_WARP_SIZE;
}
}
__global__ void computeDiagonalKernelCOO(INDEX_TYPE num_nz, INDEX_TYPE *row_indices, INDEX_TYPE *col_indices, INDEX_TYPE *diag, INDEX_TYPE *diag_end_offsets)
{
//BLOCKY*BLOCKX threads per nz
INDEX_TYPE nz = (blockIdx.x * blockDim.x + threadIdx.x);
while (nz < num_nz)
{
INDEX_TYPE row = row_indices[nz];
INDEX_TYPE col = col_indices[nz];
if (row == col)
{
//copy block to diag
diag[row] = nz;
diag_end_offsets[row] = nz + 1;
}
nz += blockDim.x * gridDim.x;
}
}
__global__ void computeDiagonalKernelCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *col_indices, INDEX_TYPE *diag, INDEX_TYPE null_index, INDEX_TYPE *diag_end_offsets)
{
INDEX_TYPE row = (blockIdx.x * blockDim.x + threadIdx.x);
while (row < num_rows)
{
int nz = row_offsets[row];
int last_nz = row_offsets[row + 1];
while (nz < last_nz)
{
int col = col_indices[nz];
if (row == col)
{
diag[row] = nz;
diag_end_offsets[row] = nz + 1;
break;
}
nz++;
}
row += blockDim.x * gridDim.x;
}
}
__global__ void computeColorOffsetsKernelCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *col_indices, const INDEX_TYPE *row_colors, INDEX_TYPE *smaller_color_offsets, INDEX_TYPE *larger_color_offsets, INDEX_TYPE *diag)
{
INDEX_TYPE row = (blockIdx.x * blockDim.x + threadIdx.x);
while (row < num_rows)
{
int my_color = row_colors[row];
int nz = row_offsets[row];
int last_nz = row_offsets[row + 1];
int location_small = -1;
int location_large = -1;
while (nz < last_nz)
{
int col = col_indices[nz];
if (row_colors[col] >= my_color && location_small == -1)
{
location_small = nz;
}
if (row_colors[col] > my_color && location_large == -1)
{
location_large = nz;
break;
}
nz++;
}
if (location_large == -1) { location_large = last_nz + 1; }
if (location_small == -1) { location_small = last_nz + 1; }
larger_color_offsets[row] = location_large;
smaller_color_offsets[row] = location_small;
row += blockDim.x * gridDim.x;
}
}
__global__ void computeDiagonalKernelDiagProp (INDEX_TYPE num_rows, INDEX_TYPE num_nz, INDEX_TYPE *diag, INDEX_TYPE *diag_end_offsets)
{
INDEX_TYPE r = (blockIdx.x * blockDim.x + threadIdx.x);
while (r < num_rows)
{
diag[r] = num_nz + r;
diag_end_offsets[r] = num_nz + r + 1;
r += blockDim.x * gridDim.x;
}
}
template <class T>
__global__ void reorderElements (INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, T *data, T *temp, INDEX_TYPE max_row, INDEX_TYPE blockSize)
{
INDEX_TYPE rowId = blockIdx.x;
while (rowId < num_rows)
{
INDEX_TYPE rowStart = row_offsets[rowId];
INDEX_TYPE rowLen = row_offsets[rowId + 1] - rowStart;
int i = threadIdx.x;
//copy and reorder into temp storage
while (i < rowLen * blockSize)
{
temp[max_row * blockIdx.x + i] = data[(permutation[rowStart + i / blockSize]) * blockSize + i % blockSize];
i += blockDim.x;
}
__syncthreads();
//copy back
i = threadIdx.x;
while (i < rowLen * blockSize)
{
data[rowStart * blockSize + i] = temp[max_row * blockIdx.x + i];
i += blockDim.x;
}
rowId += gridDim.x;
}
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::apply(const Vector<TConfig> &v, Vector<TConfig> &res, ViewType view)
{
Vector<TConfig> &v_ = const_cast<Vector<TConfig>&>(v);
multiply(*this, v_, res, view);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::apply(const Vector<TConfig> &v, Vector<TConfig> &res, ViewType view)
{
Vector<TConfig> &v_ = const_cast<Vector<TConfig>&>(v);
multiply(*this, v_, res, view);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::print(char *f, char *s, int srows, int erows, int trank)
{
typedef typename TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec>::MatPrec ValueType;
int rank = 0;
int level = 0;
char filename[1024];
FILE *fid = NULL;
int printRowsStart, printRowsEnd;
int i, j, ii, xdim, ydim, tnnz;
ValueType a;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//check target rank
if (rank == trank)
{
//check whether to ouput to stdout or file
if (f == NULL)
{
fid = stdout;
}
else
{
level = this->amg_level_index;
#ifdef _WIN32
_snprintf_s(filename, 1024, 1024, "%s_l%d_r%d.mtx", f, level, rank);
#else
snprintf(filename, 1024, "%s_l%d_r%d.mtx", f, level, rank);
#endif
fid = fopen(filename, "w");
}
hipDeviceSynchronize();
cudaCheckError();
printRowsStart = (srows < 0) ? 0 : srows;
printRowsEnd = (erows < 0) ? this->get_num_rows() : erows;
tnnz = this->get_num_nz() * this->get_block_size();
//matrix might have separate diagonal (need to accoutn for it in nnz)
if (this->hasProps(DIAG, this->props))
{
//matrix might be non-square so take std::min of # of rows and cols
tnnz += ::min(this->get_num_rows(), this->get_num_cols());
}
auto trafI = [&](auto const &I, auto const &i) { return I * this->get_block_dimy() + i + 1; };
auto trafJ = [&](auto const &J, auto const &j) { return J * this->get_block_dimx() + j + 1; };
fprintf(fid, "%%%%MatrixMarket matrix coordinate real general\n");
fprintf(fid, "%% %s\n", s);
fprintf(fid, "%d %d %d\n", this->get_num_rows() * this->get_block_dimx(), this->get_num_cols() * this->get_block_dimy(), tnnz);
for (i = printRowsStart; i < printRowsEnd; i++)
{
for (ydim = 0; ydim < this->get_block_dimy(); ydim++)
{
if (this->hasProps(DIAG, this->props))
{
if (i < ::min(this->get_num_rows(), this->get_num_cols()))
{
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[this->diag[i] * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", trafI(i, ydim), trafI(i, xdim));
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
for (ii = this->row_offsets[i]; ii < this->row_offsets[i + 1]; ii++)
{
j = this->col_indices[ii];
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[ii * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", trafI(i, ydim), trafJ(j, xdim));
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
}
hipDeviceSynchronize();
hipGetLastError();
if (fid != stdout)
{
fclose(fid);
}
}
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::printToFile(char *f, char *s, int srows, int erows)
{
int rank = 0;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//notice that print will be called with different (target) rank on different on different ranks/processes
this->print(f, s, srows, erows, rank);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::print(char *f, char *s, int srows, int erows, int trank)
{
typedef typename TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec>::MatPrec ValueType;
int rank = 0;
int level = 0;
char filename[1024];
FILE *fid = NULL;
int printRowsStart, printRowsEnd;
int i, j, ii, xdim, ydim, tnnz;
ValueType a;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//check target rank
if (rank == trank)
{
//check whether to ouput to stdout or file
if (f == NULL)
{
fid = stdout;
}
else
{
level = this->amg_level_index;
#ifdef _WIN32
_snprintf_s(filename, 1024, 1024, "%s_r%d_l%d.mtx", f, rank, level);
#else
snprintf(filename, 1024, "%s_r%d_l%d.mtx", f, rank, level);
#endif
fid = fopen(filename, "w");
}
hipDeviceSynchronize();
cudaCheckError();
printRowsStart = (srows < 0) ? 0 : srows;
printRowsEnd = (erows < 0) ? this->get_num_rows() : erows;
tnnz = this->get_num_nz() * this->get_block_size();
//matrix might have separate diagonal (need to accoutn for it in nnz)
if (this->hasProps(DIAG, this->props))
{
//matrix might be non-square so take min of # of rows and cols
tnnz += ::min(this->get_num_rows(), this->get_num_cols()) * this->get_block_size();
}
fprintf(fid, "%%%%MatrixMarket matrix coordinate real general\n");
fprintf(fid, "%% %s\n", s);
fprintf(fid, "%d %d %d\n", this->get_num_rows() * this->get_block_dimx(), this->get_num_cols() * this->get_block_dimy(), tnnz);
auto trafI = [&](auto const &I, auto const &i) { return I * this->get_block_dimy() + i + 1; };
auto trafJ = [&](auto const &J, auto const &j) { return J * this->get_block_dimx() + j + 1; };
for (i = printRowsStart; i < printRowsEnd; i++)
{
for (ydim = 0; ydim < this->get_block_dimy(); ydim++)
{
if (this->hasProps(DIAG, this->props))
{
if (i < ::min(this->get_num_rows(), this->get_num_cols()))
{
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[this->diag[i] * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", trafI(i, ydim), trafI(i, xdim));
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
for (ii = this->row_offsets[i]; ii < this->row_offsets[i + 1]; ii++)
{
j = this->col_indices[ii];
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[ii * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", i + 1, j + 1);
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
}
hipDeviceSynchronize();
hipGetLastError();
if (fid != stdout)
{
fclose(fid);
}
}
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::printToFile(char *f, char *s, int srows, int erows)
{
int rank = 0;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//notice that print will be called with different (target) rank on different on different ranks/processes
this->print(f, s, srows, erows, rank);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> > ::convert( const Matrix<TConfig> &mat, unsigned int new_props, int block_dimy, int block_dimx )
{
if ( !mat.is_initialized() )
{
FatalError("Trying to convert from the uninitialized matrix", AMGX_ERR_BAD_PARAMETERS);
}
this->set_initialized(0);
this->addProps(new_props);
index_type block_size = block_dimx * block_dimy;
index_type new_num_rows = ( mat.get_num_rows() * mat.block_dimy + block_dimy - 1 ) / block_dimy;
index_type new_num_cols = ( mat.get_num_cols() * mat.block_dimx + block_dimx - 1 ) / block_dimx;
MVector new_values;
IVector new_col_indices;
index_type new_num_nnz = 0;
IVector new_row_indices;
IVector new_row_offsets;
MVector new_dia_values;
new_dia_values.resize( new_num_rows * block_size, types::util<value_type>::get_zero() );
if ( mat.hasProps(COO) )
{
std::map< std::pair<index_type, index_type>, index_type> ind;
for ( index_type i = 0; i < mat.get_num_nz(); i++ )
for ( index_type loc_row = 0; loc_row < mat.block_dimy; loc_row++ )
for ( index_type loc_col = 0; loc_col < mat.block_dimx; loc_col++ )
{
index_type in_row = mat.row_indices[i] * mat.block_dimy + loc_row;
index_type in_col = mat.col_indices[i] * mat.block_dimx + loc_col;
value_type in_val = mat.values[i * mat.block_size + loc_row * mat.block_dimx + loc_col];
if ( types::util<value_type>::is_zero(in_val) ) { continue; } // skip zero entries
index_type out_br = in_row / block_dimy;
index_type out_bc = in_col / block_dimx;
index_type out_lr = in_row % block_dimy;
index_type out_lc = in_col % block_dimx;
if ( ind.find( std::pair<index_type, index_type>( out_br, out_bc ) ) == ind.end() )
{
// allocate a new block
ind.insert( std::pair< std::pair<index_type, index_type>, index_type>( std::pair<index_type, index_type>( out_br, out_bc ), new_num_nnz ) );
if (out_br != out_bc || !this->hasProps(DIAG))
{
new_row_indices.push_back( out_br );
new_col_indices.push_back( out_bc );
new_num_nnz++;
for ( int b = 0; b < block_size; b++ )
{
new_values.push_back( types::util<value_type>::get_zero() );
}
}
}
if ( out_br != out_bc || !this->hasProps(DIAG) )
{
new_values[ ind[std::pair<index_type, index_type>( out_br, out_bc )] * block_size + out_lr * block_dimx + out_lc ] = in_val;
}
else
{
new_dia_values[ out_br * block_size + out_lr * block_dimx + out_lc ] = in_val;
}
}
} // ( mat.hasProps(COO) )
else if ( mat.hasProps(CSR))
{
new_num_nnz = 0;
//MVector new_dia_values;
//new_dia_values.resize( new_num_rows*block_size, 0.0 );
new_row_offsets.resize( new_num_rows + 1 );
// process each output block row
for ( index_type i = 0; i < new_num_rows; i++ )
{
new_row_offsets[i] = new_num_nnz;
// count non zero column blocks
IVector non_zero_blocks( new_num_cols );
for ( index_type j = i * block_dimy; j < (i + 1) * block_dimy && j < mat.get_num_rows() * mat.block_dimy; j++ )
{
// input row block / local position
index_type in_br = j / mat.block_dimy;
index_type in_lr = j % mat.block_dimy;
// loop through block columns
for ( index_type r = mat.row_offsets[in_br]; r < mat.row_offsets[in_br + 1] + ( mat.hasProps(DIAG) ); r++ )
{
index_type in_bc = ( r == mat.row_offsets[in_br + 1] ) ? in_br : mat.col_indices[r];
// loop through local columns
for ( index_type in_lc = 0; in_lc < mat.block_dimx; in_lc++ )
{
index_type in_col = in_bc * mat.block_dimx + in_lc;
index_type out_bc = in_col / block_dimx;
// fetch input entry value
value_type val = ( r == mat.row_offsets[in_br + 1] ) ?
mat.values[mat.diag[in_br] * mat.block_size + in_lr * mat.block_dimx + in_lc] :
mat.values[r * mat.block_size + in_lr * mat.block_dimx + in_lc];
if ( types::util<value_type>::is_zero(val) ) { continue; } // skip zero entries
// mark non_zero column
non_zero_blocks[out_bc] = 1;
}
}
}
// populate non zero column blocks
for ( int bc = 0; bc < new_num_cols; bc++ )
if ( non_zero_blocks[bc] != 0 )
{
if ( i != bc || !this->hasProps(DIAG) ) // off-diagonal for DIAG
{
non_zero_blocks[bc] = new_num_nnz++;
new_col_indices.push_back( bc );
for ( int b = 0; b < block_size; b++ )
{
new_values.push_back( types::util<value_type>::get_zero() );
}
}
}
// fill non zero values
for ( index_type j = i * block_dimy; j < (i + 1) * block_dimy && j < mat.get_num_rows() * mat.block_dimy; j++ )
{
// output row block/local position
index_type out_br = j / block_dimy;
index_type out_lr = j % block_dimy;
// input row block/local position
index_type in_br = j / mat.block_dimy;
index_type in_lr = j % mat.block_dimy;
// loop through block columns
for ( index_type r = mat.row_offsets[in_br]; r < mat.row_offsets[in_br + 1] + ( mat.hasProps(DIAG) ); r++ )
{
index_type in_bc = ( r == mat.row_offsets[in_br + 1] ) ? in_br : mat.col_indices[r];
// loop through local columns
for ( index_type in_lc = 0; in_lc < mat.block_dimx; in_lc++ )
{
index_type in_col = in_bc * mat.block_dimx + in_lc;
index_type out_bc = in_col / block_dimx;
index_type out_lc = in_col % block_dimx;
// fetch input entry value
value_type val = ( r == mat.row_offsets[in_br + 1] ) ?
mat.values[mat.diag[in_br] * mat.block_size + in_lr * mat.block_dimx + in_lc] :
mat.values[r * mat.block_size + in_lr * mat.block_dimx + in_lc];
if ( types::util<value_type>::is_zero(val) ) { continue; } // skip zero entries
// write to new matrix
if ( out_br != out_bc || !this->hasProps(DIAG) )
{
new_values[ non_zero_blocks[out_bc] * block_size + out_lr * block_dimx + out_lc] = val;
}
else
{
new_dia_values[ out_br * block_size + out_lr * block_dimx + out_lc ] = val;
}
}
}
}
} // for( i < new_num_rows )
// fill extra diagonal for the last block
int extra_start = ( mat.get_num_rows() * mat.block_dimy ) % block_dimy;
if ( extra_start > 0 )
{
for ( int r = extra_start; r < block_dimy; r++ )
if ( this->hasProps(DIAG) )
{
new_dia_values[ (new_num_rows - 1) * block_size + r * block_dimx + r] = types::util<value_type>::get_one();
}
else
{
new_values[ (new_num_nnz - 1) * block_size + r * block_dimx + r] = types::util<value_type>::get_one();
}
}
new_row_offsets[new_num_rows] = new_num_nnz;
} // ( mat.hasProps(CSR) )
else
{
FatalError("Input matrix for conversion doesn't have COO or CSR format", AMGX_ERR_CONFIGURATION);
}
if ( this->hasProps(DIAG) )
{
new_values.insert(new_values.end(), new_dia_values.begin(), new_dia_values.end());
}
else
for ( int b = 0; b < block_size; b++ )
{
new_values.push_back( types::util<value_type>::get_zero() );
}
this->resize( new_num_rows, new_num_cols, new_num_nnz, block_dimy, block_dimx );
this->values.copy( new_values );
this->values.set_block_dimx(block_dimx);
this->values.set_block_dimy(block_dimy);
this->col_indices.copy( new_col_indices );
if ( mat.hasProps(COO) )
{
this->row_indices.copy( new_row_indices );
this->props |= COO;
}
if ( mat.hasProps(CSR) )
{
this->row_offsets.copy( new_row_offsets );
this->props |= CSR;
}
if (this->hasProps(COO) && this->row_indices.size() == 0)
{
this->row_indices.resize(new_num_nnz);
computeRowIndices();
}
if (this->hasProps(CSR) && this->row_offsets.size() == 0)
{
this->row_offsets.resize(new_num_rows + 1);
computeRowOffsets();
}
computeDiagonal();
this->set_initialized(1);
}
template <class T_Config> class MatrixBase;
template<class T_Config>
AMGX_ERROR
MatrixBase<T_Config>::resize(index_type num_rows, index_type num_cols, index_type num_nz, int skipDiaCompute)
{
if (this->is_initialized())
{
FatalError("Debug throw: resizing already initialized matrix\n", AMGX_ERR_BAD_PARAMETERS);
}
{
this->num_rows = num_rows;
this->num_cols = num_cols;
this->num_nz = num_nz;
if ( hasProps(DIAG) )
{
values.resize(num_nz * block_size + num_rows * block_size);
}
else
{
values.resize((num_nz + 1)*block_size);
//amgx::thrust::fill(values.begin() + num_nz*block_size, values.end(), static_cast<value_type>(0.0));
}
diag.resize(num_rows);
m_diag_end_offsets.resize(num_rows);
col_indices.resize(num_nz);
//if( props == NONE ) {props = CSR; props |= DIAG;}
if ( hasProps(COO) ) { row_indices.resize(num_nz); }
if ( hasProps(CSR) ) { row_offsets.resize(num_rows + 1); }
m_seq_offsets.resize(num_rows + 1);
amgx::thrust::sequence(m_seq_offsets.begin(), m_seq_offsets.end());
cudaCheckError();
if (!skipDiaCompute )
{
computeDiagonal();
}
}
return AMGX_OK;
}
template<class T_Config>
void
MatrixBase<T_Config>::setupMatrix(Solver<T_Config> *outer_solver, AMG_Config &cfg, bool reuse_matrix_structure)
{
// Check that matrix is initialized
if (!this->is_initialized())
{
FatalError("Trying to setup from the uninitialized matrix", AMGX_ERR_BAD_PARAMETERS);
}
this->set_initialized(0);
m_separation_interior = cfg.getParameter<ViewType>("separation_interior", "default");
m_separation_exterior = cfg.getParameter<ViewType>("separation_exterior", "default");
if (m_separation_interior > m_separation_exterior) { FatalError("Interior separation cannot be wider than the exterior separation", AMGX_ERR_CONFIGURATION); }
// If latency hiding is disabled, the interior is overwritten
if(!isLatencyHidingEnabled(cfg))
{
m_separation_interior = m_separation_exterior;
}
bool is_coloring_needed = outer_solver->isColoringNeeded();
if (!reuse_matrix_structure)
{
// Color the matrix since the structure has changed
if ( is_coloring_needed )
{
// Get the scope of the solver that needs coloring
std::string cfg_scope_for_coloring;
outer_solver->getColoringScope(cfg_scope_for_coloring);
this->colorMatrix(cfg, cfg_scope_for_coloring);
}
}
// Set the matrix block format
BlockFormat block_format = cfg.getParameter<BlockFormat>( "block_format", "default" );
if ( this->getBlockFormat() != block_format )
{
this->setBlockFormat( block_format );
}
// Permute the values and the column indices (if necessary)
bool reorder_cols_by_color = outer_solver->getReorderColsByColorDesired();
bool insert_diagonal = outer_solver->getInsertDiagonalDesired();
if (reorder_cols_by_color)
{
if (reuse_matrix_structure) // Only permute the values
{
this->permuteValues();
}
else // Permute the values and the columns
{
this->reorderColumnsByColor(insert_diagonal);
this->permuteValues();
}
}
this->set_initialized(1);
m_is_matrix_setup = true;
}
template<class T_Config>
bool MatrixBase<T_Config>::isLatencyHidingEnabled(AMG_Config &cfg)
{
const int min_rows_latency_hiding =
cfg.getParameter<int>("min_rows_latency_hiding", "default");
// Test all partitions to check if they all fall below the threshold
if (!is_matrix_singleGPU() && min_rows_latency_hiding >= 0)
{
const auto& nrows_per_part = manager->getNumRowsPerPart();
// Look at all partitions to check whether the number of rows falls
// below the user defined minimum
for(auto& nrpp : nrows_per_part)
{
// If any partitions still have a large enough set of rows,
// continue latency hiding
if(nrpp >= min_rows_latency_hiding)
{
return true;
}
}
}
return false;
}
template<class T_Config>
void
MatrixBase<T_Config>::reorderColumnsByColor(bool insert_diagonal)
{
// If columns already reordered, don't reorder again
if (this->m_cols_reordered_by_color)
{
return;
}
// Check if matrix is colored
if (!this->hasProps(COLORING))
{
FatalError("Matrix must be colored in order to be reordered by colors. Try setting coloring_level=1 in the configuration file", AMGX_ERR_CONFIGURATION);
}
set_initialized(0);
// Compute the row indices
addProps(COO);
set_allow_recompute_diag(false);
index_type num_non_zeros = num_nz;
if (hasProps(DIAG) && insert_diagonal) // Diagonal stored separetely
{
num_non_zeros += num_rows;
}
// Append the diagonal if stored separately
// The new matrix will have inside diagonal
if (hasProps(DIAG) && insert_diagonal)
{
amgx::thrust::counting_iterator<int> first(0);
amgx::thrust::counting_iterator<int> last = first + num_rows;
// Create new row_indices with appended diagonal
IVector new_row_indices(num_non_zeros);
IVector new_col_indices(num_non_zeros);
amgx::thrust::copy(row_indices.begin(), row_indices.end(), new_row_indices.begin());
amgx::thrust::copy(first, last, new_row_indices.begin() + num_nz);
// Create new col_indices with appended diagonal
amgx::thrust::copy(col_indices.begin(), col_indices.end(), new_col_indices.begin());
amgx::thrust::copy(first, last, new_col_indices.begin() + num_nz);
row_indices.swap(new_row_indices);
col_indices.swap(new_col_indices);
new_row_indices.clear();
new_row_indices.shrink_to_fit();
new_col_indices.clear();
new_col_indices.shrink_to_fit();
}
// Compute the color of every column
IVector element_colors(num_non_zeros);
amgx::thrust::copy(amgx::thrust::make_permutation_iterator(this->getMatrixColoring().getRowColors().begin(), col_indices.begin()),
amgx::thrust::make_permutation_iterator(this->getMatrixColoring().getRowColors().begin(), col_indices.end()),
element_colors.begin());
// Compute the permutation vector by sorting by rows and columns
m_values_permutation_vector.resize(num_non_zeros);
amgx::thrust::sequence(m_values_permutation_vector.begin(), m_values_permutation_vector.end());
cusp::detail::sort_by_row_and_column(row_indices, element_colors, m_values_permutation_vector);
cudaCheckError();
element_colors.clear();
element_colors.shrink_to_fit();
// Compute the new column indices sorted by color
IVector new_column_indices(num_non_zeros);
amgx::thrust::copy(amgx::thrust::make_permutation_iterator(col_indices.begin(), m_values_permutation_vector.begin()),
amgx::thrust::make_permutation_iterator(col_indices.begin(), m_values_permutation_vector.end()),
new_column_indices.begin());
col_indices.swap(new_column_indices);
new_column_indices.clear();
new_column_indices.shrink_to_fit();
if (hasProps(DIAG) && insert_diagonal)
{
// Change the number of nonzeros
set_num_nz(num_non_zeros);
values.resize( (num_non_zeros + 1)*this->get_block_size());
this->m_is_permutation_inplace = false;
}
else
{
this->m_is_permutation_inplace = true;
}
if (hasProps(DIAG) && insert_diagonal)
{
delProps(DIAG);
// Force recomputation of row offsets
delProps(CSR);
}
// Compute row offsets if input matrix only had COO format or if diagonal was inserted
addProps(CSR);
// Recompute the diagonal
set_allow_recompute_diag(true);
computeDiagonal();
// Compute the color offsets
m_smaller_color_offsets.resize(this->get_num_rows());
m_larger_color_offsets.resize(this->get_num_rows());
computeColorOffsets();
this->m_cols_reordered_by_color = true;
set_initialized(1);
}
template<class T_Config>
void
MatrixBase<T_Config>::sortByRowAndColumn()
{
this->set_initialized(0);
// Add row_indices array
this->addProps(COO);
this->set_allow_recompute_diag(false);
if (this->get_block_dimx() != 1 || this->get_block_dimy() != 1)
{
FatalError("sortByRowAndColumn only works for scalar matrices", AMGX_ERR_NOT_IMPLEMENTED);
}
size_t N = this->row_indices.size();
IVector permutation(N);
amgx::thrust::sequence(permutation.begin(), permutation.end());
cudaCheckError();
// compute permutation and sort by (I,J)
{
IVector temp(this->col_indices);
amgx::thrust::stable_sort_by_key(temp.begin(), temp.end(), permutation.begin());
temp = this->row_indices;
amgx::thrust::gather(permutation.begin(), permutation.end(), temp.begin(), this->row_indices.begin());
amgx::thrust::stable_sort_by_key(this->row_indices.begin(), this->row_indices.end(), permutation.begin());
temp = this->col_indices;
amgx::thrust::gather(permutation.begin(), permutation.end(), temp.begin(), this->col_indices.begin());
}
cudaCheckError();
// use permutation to reorder the values
{
MVector temp(this->values);
amgx::thrust::gather(permutation.begin(), permutation.end(), temp.begin(), this->values.begin());
}
cudaCheckError();
this->set_allow_recompute_diag(true);
this->addProps(CSR);
// remove row indices array
this->delProps(COO);
this->computeDiagonal();
this->set_initialized(1);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix<TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::computeDiagonal()
{
ViewType oldView = this->currentView();
if (this->m_initialized) { this->setView(ALL); }
if (this->allow_recompute_diag)
{
index_type num_rows = this->get_num_rows();
index_type num_nz = this->get_num_nz();
IVector &row_offsets = this->row_offsets;
IVector &row_indices = this->row_indices;
IVector &col_indices = this->col_indices;
IVector &diag = this->diag;
if (this->diag.size() != this->get_num_rows()) { this->diag.resize(this->get_num_rows()); }
if (this->m_diag_end_offsets.size() != this->get_num_rows()) { this->m_diag_end_offsets.resize(this->get_num_rows()); }
if ( this->hasProps(DIAG) )
{
int first = num_nz;
for (int r = 0; r < num_rows; r++)
{
diag[r] = first++;
}
}
else
{
index_type null_index = this->get_num_nz();
if ( this->hasProps(CSR) )
{
for (int r = 0; r < num_rows; r++)
{
int start = row_offsets[r];
int end = row_offsets[r + 1];
diag[r] = null_index;
for (int j = start; j < end; j++)
{
if (col_indices[j] == r)
{
diag[r] = j;
break;
}
}
}
}
else if (this->hasProps(COO) )
{
for (int i = 0; i < num_rows; i++)
{
diag[i] = null_index;
}
for (int j = 0; j < num_nz; j++)
{
int r = row_indices[j];
if (r == col_indices[j])
{
diag[r] = j;
}
}
}
}
for (int r = 0; r < num_rows; r++)
{
this->m_diag_end_offsets[r] = diag[r] + 1;
}
}
this->setView(oldView);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void Matrix<TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::computeDiagonal()
{
ViewType oldView;
index_type null_index = 0; //this->get_num_nz();
if (!this->allow_recompute_diag || !(this->get_num_rows() > 0))
{
return;
}
if (this->m_initialized)
{
oldView = this->currentView();
this->setView(ALL);
}
if (this->diag.size() < this->get_num_rows())
{
this->diag.resize(this->get_num_rows());
}
if (this->m_diag_end_offsets.size() < this->get_num_rows())
{
this->m_diag_end_offsets.resize(this->get_num_rows());
}
if (this->hasProps(DIAG))
{
int num_blocks = ::min(4096, (this->get_num_rows() + 511) / 512);
hipLaunchKernelGGL(( computeDiagonalKernelDiagProp) , dim3(num_blocks), dim3(512), 0, amgx::thrust::global_thread_handle::get_stream(), this->get_num_rows(), this->get_num_nz(), this->diag.raw(), this->m_diag_end_offsets.raw());
}
else if (this->hasProps(COO))
{
int num_blocks = ::min(4096, (this->get_num_nz() + 511) / 512);
hipLaunchKernelGGL(( computeDiagonalKernelCOO) , dim3(num_blocks), dim3(512), 0, 0, this->get_num_nz(), this->row_indices.raw(), this->col_indices.raw(), this->diag.raw(), this->m_diag_end_offsets.raw());
}
else
{
int num_blocks = ::min(4096, (this->get_num_rows() + 511) / 512);
hipLaunchKernelGGL(( computeDiagonalKernelCSR) , dim3(num_blocks), dim3(512), 0, 0, this->get_num_rows(), this->row_offsets.raw(), this->col_indices.raw(), this->diag.raw(), null_index, this->m_diag_end_offsets.raw());
}
cudaCheckError();
if (this->m_initialized)
{
this->setView(oldView);
}
#ifdef DEBUG
if (this->diag_copy.size() == 0)
{
this->diag_copy = this->diag;
}
else
{
if ((this->diag.size() != this->diag_copy.size()) || (this->diag.size() == 1)) { return; }
IVector_h h_diag = this->diag;
IVector_h h_diag_copy = this->diag_copy;
bool equal = true;
for (unsigned int i = 0; i < this->diag.size(); ++i)
{
if (h_diag[i] != h_diag_copy[i])
{
equal = false;
break;
}
}
if (equal)
{
FatalError("ComputeDiagonal was called, but diagonal hasn't changed", AMGX_ERR_UNKNOWN);
}
}
#endif
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix<TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::permuteValues()
{
if (this->m_cols_reordered_by_color && this->m_is_permutation_inplace)
{
reorderValuesInPlace();
}
else if (this->m_cols_reordered_by_color && !this->m_is_permutation_inplace )
{
// might use a lot of memory
MVector temp_values;
temp_values.resize(this->values.size());
temp_values.set_block_dimx(this->values.get_block_dimx());
temp_values.set_block_dimy(this->values.get_block_dimy());
amgx::unpermuteVector(this->values, temp_values, this->m_values_permutation_vector, (this->get_num_nz()) * (this->get_block_size()));
this->values.swap(temp_values);
temp_values.clear();
temp_values.shrink_to_fit();
}
else
{
FatalError("Invalid reordering level in permuteValues", AMGX_ERR_CONFIGURATION);
}
}
void computeRowOffsetsDevice(int num_blocks, INDEX_TYPE num_rows, INDEX_TYPE num_nz, const INDEX_TYPE *row_indices, INDEX_TYPE *row_offsets, INDEX_TYPE block_size )
{
hipLaunchKernelGGL(( computeRowOffsetsKernel) , dim3(num_blocks), dim3(512), 0, 0, num_rows, num_nz, row_indices, row_offsets);
cudaCheckError();
}
extern void computeRowIndicesDevice(int num_blocks, INDEX_TYPE num_rows, const INDEX_TYPE *row_offsets, INDEX_TYPE *row_indices, INDEX_TYPE block_size )
{
hipLaunchKernelGGL(( computeRowIndicesKernel) , dim3(num_blocks), dim3(512), 0, 0, num_rows, row_offsets, row_indices);
cudaCheckError();
}
void computeColorOffsetsDeviceCSR(int num_blocks, INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *col_indices, const INDEX_TYPE *row_colors, INDEX_TYPE *smaller_color_offsets, INDEX_TYPE *larger_color_offsets, INDEX_TYPE block_size, INDEX_TYPE *diag )
{
hipLaunchKernelGGL(( computeColorOffsetsKernelCSR) , dim3(num_blocks), dim3(512), 0, 0, num_rows, row_offsets, col_indices, row_colors, smaller_color_offsets, larger_color_offsets, diag);
cudaCheckError();
}
template <typename T>
void reorderElementsDeviceCSR(INDEX_TYPE num_rows,
INDEX_TYPE *row_offsets,
INDEX_TYPE *permutation,
INDEX_TYPE *col_indices,
T *values,
INDEX_TYPE block_size)
{
amgx::thrust::device_ptr<INDEX_TYPE> dev_ptr = amgx::thrust::device_pointer_cast(row_offsets);
INDEX_TYPE max_row_length = ::max(1, amgx::thrust::transform_reduce(dev_ptr, dev_ptr + num_rows, row_length<INDEX_TYPE>(), 0, amgx::thrust::maximum<INDEX_TYPE>()));
//TODO: optimise this in terms of storage
INDEX_TYPE storage_space = 100 * 1024 * 1024 * sizeof(T) / sizeof(hipDoubleComplex); // because we allocate as for hipComplex
INDEX_TYPE blocks = 1500 < storage_space / (max_row_length * block_size * sizeof(T)) ? 1500 : storage_space / (max_row_length * block_size * sizeof(T));
blocks = blocks < num_rows ? blocks : num_rows;
INDEX_TYPE aligned_space = ((max_row_length * block_size * sizeof(T) / 128 + 1) * 128) / sizeof(T); //pad to 128 bytes
Vector<amgx::TemplateConfig<AMGX_device, AMGX_vecDoubleComplex, AMGX_matDoubleComplex, AMGX_indInt> > tempstorage(blocks * aligned_space);
hipLaunchKernelGGL(( reorderElements) , dim3(blocks), dim3(256), 0, 0, num_rows, row_offsets, permutation, values, (T *)tempstorage.raw(), aligned_space, block_size);
cudaCheckError();
}
// explicitly instantiate reorderElementsDeviceCSR, since we call it from header and it's not a part of some class
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, float *values, INDEX_TYPE block_size);
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, double *values, INDEX_TYPE block_size);
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, hipComplex *values, INDEX_TYPE block_size);
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, hipDoubleComplex *values, INDEX_TYPE block_size);
/****************************************
* Explict instantiations
***************************************/
#define AMGX_CASE_LINE(CASE) template class MatrixBase<TemplateMode<CASE>::Type>;
AMGX_FORALL_BUILDS(AMGX_CASE_LINE)
AMGX_FORCOMPLEX_BUILDS(AMGX_CASE_LINE)
#undef AMGX_CASE_LINE
#define AMGX_CASE_LINE(CASE) template class Matrix<TemplateMode<CASE>::Type>;
AMGX_FORALL_BUILDS(AMGX_CASE_LINE)
AMGX_FORCOMPLEX_BUILDS(AMGX_CASE_LINE)
#undef AMGX_CASE_LINE
}//end namespace amgx
| de6e71e50517f9f47006b4c38747edf6b24c0c1f.cu | /* Copyright (c) 2011-2017, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <matrix.h>
#include <cutil.h>
#include <util.h>
#include <solvers/solver.h>
#include <thrust/transform_reduce.h>
#include <thrust/functional.h>
#include <thrust/device_ptr.h>
#include <thrust/sort.h>
#include <thrust/gather.h>
#include <vector_thrust_allocator.h>
#include <cusp/detail/format_utils.h>
#include <permute.h>
#include <multiply.h>
#include <amgx_types/util.h>
#include <algorithm>
template<typename T>
struct row_length : public amgx::thrust::unary_function<T, T>
{
__host__ __device__ T operator()(const T &x) const
{
const T *next_ptr = &x;
next_ptr++;
return (*next_ptr) - x;
}
};
namespace amgx
{
__global__ void computeRowOffsetsKernel(INDEX_TYPE num_rows, INDEX_TYPE num_nz, const INDEX_TYPE *row_indices, INDEX_TYPE *row_offsets )
{
//one thread per non-zero
int nz = blockIdx.x * blockDim.x + threadIdx.x;
if (nz == 0)
{
row_offsets[0] = 0;
row_offsets[num_rows] = num_nz;
}
while (nz < num_nz - 1)
{
int row = row_indices[nz];
int next_row = row_indices[nz + 1];
while (row < next_row) //this loop should probably always execute once, but I'm making it a loop just in case...
{
row_offsets[++row] = nz + 1;
}
nz += blockDim.x * gridDim.x;
}
}
__global__ void computeRowIndicesKernel(INDEX_TYPE num_rows, const INDEX_TYPE *row_offsets, INDEX_TYPE *row_indices )
{
//one warp per row //possible optimziation: multiple warps per row
int row = (blockIdx.x * blockDim.x + threadIdx.x) / AMGX_WARP_SIZE;
int warp_id = threadIdx.x % AMGX_WARP_SIZE;
while (row < num_rows)
{
int start = row_offsets[row] + warp_id;
int end = row_offsets[row + 1];
for (int nz = start; nz < end; nz += AMGX_WARP_SIZE)
{
row_indices[nz] = row;
}
row += blockDim.x * gridDim.x / AMGX_WARP_SIZE;
}
}
__global__ void computeDiagonalKernelCOO(INDEX_TYPE num_nz, INDEX_TYPE *row_indices, INDEX_TYPE *col_indices, INDEX_TYPE *diag, INDEX_TYPE *diag_end_offsets)
{
//BLOCKY*BLOCKX threads per nz
INDEX_TYPE nz = (blockIdx.x * blockDim.x + threadIdx.x);
while (nz < num_nz)
{
INDEX_TYPE row = row_indices[nz];
INDEX_TYPE col = col_indices[nz];
if (row == col)
{
//copy block to diag
diag[row] = nz;
diag_end_offsets[row] = nz + 1;
}
nz += blockDim.x * gridDim.x;
}
}
__global__ void computeDiagonalKernelCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *col_indices, INDEX_TYPE *diag, INDEX_TYPE null_index, INDEX_TYPE *diag_end_offsets)
{
INDEX_TYPE row = (blockIdx.x * blockDim.x + threadIdx.x);
while (row < num_rows)
{
int nz = row_offsets[row];
int last_nz = row_offsets[row + 1];
while (nz < last_nz)
{
int col = col_indices[nz];
if (row == col)
{
diag[row] = nz;
diag_end_offsets[row] = nz + 1;
break;
}
nz++;
}
row += blockDim.x * gridDim.x;
}
}
__global__ void computeColorOffsetsKernelCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *col_indices, const INDEX_TYPE *row_colors, INDEX_TYPE *smaller_color_offsets, INDEX_TYPE *larger_color_offsets, INDEX_TYPE *diag)
{
INDEX_TYPE row = (blockIdx.x * blockDim.x + threadIdx.x);
while (row < num_rows)
{
int my_color = row_colors[row];
int nz = row_offsets[row];
int last_nz = row_offsets[row + 1];
int location_small = -1;
int location_large = -1;
while (nz < last_nz)
{
int col = col_indices[nz];
if (row_colors[col] >= my_color && location_small == -1)
{
location_small = nz;
}
if (row_colors[col] > my_color && location_large == -1)
{
location_large = nz;
break;
}
nz++;
}
if (location_large == -1) { location_large = last_nz + 1; }
if (location_small == -1) { location_small = last_nz + 1; }
larger_color_offsets[row] = location_large;
smaller_color_offsets[row] = location_small;
row += blockDim.x * gridDim.x;
}
}
__global__ void computeDiagonalKernelDiagProp (INDEX_TYPE num_rows, INDEX_TYPE num_nz, INDEX_TYPE *diag, INDEX_TYPE *diag_end_offsets)
{
INDEX_TYPE r = (blockIdx.x * blockDim.x + threadIdx.x);
while (r < num_rows)
{
diag[r] = num_nz + r;
diag_end_offsets[r] = num_nz + r + 1;
r += blockDim.x * gridDim.x;
}
}
template <class T>
__global__ void reorderElements (INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, T *data, T *temp, INDEX_TYPE max_row, INDEX_TYPE blockSize)
{
INDEX_TYPE rowId = blockIdx.x;
while (rowId < num_rows)
{
INDEX_TYPE rowStart = row_offsets[rowId];
INDEX_TYPE rowLen = row_offsets[rowId + 1] - rowStart;
int i = threadIdx.x;
//copy and reorder into temp storage
while (i < rowLen * blockSize)
{
temp[max_row * blockIdx.x + i] = data[(permutation[rowStart + i / blockSize]) * blockSize + i % blockSize];
i += blockDim.x;
}
__syncthreads();
//copy back
i = threadIdx.x;
while (i < rowLen * blockSize)
{
data[rowStart * blockSize + i] = temp[max_row * blockIdx.x + i];
i += blockDim.x;
}
rowId += gridDim.x;
}
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::apply(const Vector<TConfig> &v, Vector<TConfig> &res, ViewType view)
{
Vector<TConfig> &v_ = const_cast<Vector<TConfig>&>(v);
multiply(*this, v_, res, view);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::apply(const Vector<TConfig> &v, Vector<TConfig> &res, ViewType view)
{
Vector<TConfig> &v_ = const_cast<Vector<TConfig>&>(v);
multiply(*this, v_, res, view);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::print(char *f, char *s, int srows, int erows, int trank)
{
typedef typename TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec>::MatPrec ValueType;
int rank = 0;
int level = 0;
char filename[1024];
FILE *fid = NULL;
int printRowsStart, printRowsEnd;
int i, j, ii, xdim, ydim, tnnz;
ValueType a;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//check target rank
if (rank == trank)
{
//check whether to ouput to stdout or file
if (f == NULL)
{
fid = stdout;
}
else
{
level = this->amg_level_index;
#ifdef _WIN32
_snprintf_s(filename, 1024, 1024, "%s_l%d_r%d.mtx", f, level, rank);
#else
snprintf(filename, 1024, "%s_l%d_r%d.mtx", f, level, rank);
#endif
fid = fopen(filename, "w");
}
cudaDeviceSynchronize();
cudaCheckError();
printRowsStart = (srows < 0) ? 0 : srows;
printRowsEnd = (erows < 0) ? this->get_num_rows() : erows;
tnnz = this->get_num_nz() * this->get_block_size();
//matrix might have separate diagonal (need to accoutn for it in nnz)
if (this->hasProps(DIAG, this->props))
{
//matrix might be non-square so take std::min of # of rows and cols
tnnz += std::min(this->get_num_rows(), this->get_num_cols());
}
auto trafI = [&](auto const &I, auto const &i) { return I * this->get_block_dimy() + i + 1; };
auto trafJ = [&](auto const &J, auto const &j) { return J * this->get_block_dimx() + j + 1; };
fprintf(fid, "%%%%MatrixMarket matrix coordinate real general\n");
fprintf(fid, "%% %s\n", s);
fprintf(fid, "%d %d %d\n", this->get_num_rows() * this->get_block_dimx(), this->get_num_cols() * this->get_block_dimy(), tnnz);
for (i = printRowsStart; i < printRowsEnd; i++)
{
for (ydim = 0; ydim < this->get_block_dimy(); ydim++)
{
if (this->hasProps(DIAG, this->props))
{
if (i < std::min(this->get_num_rows(), this->get_num_cols()))
{
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[this->diag[i] * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", trafI(i, ydim), trafI(i, xdim));
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
for (ii = this->row_offsets[i]; ii < this->row_offsets[i + 1]; ii++)
{
j = this->col_indices[ii];
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[ii * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", trafI(i, ydim), trafJ(j, xdim));
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
}
cudaDeviceSynchronize();
cudaGetLastError();
if (fid != stdout)
{
fclose(fid);
}
}
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::printToFile(char *f, char *s, int srows, int erows)
{
int rank = 0;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//notice that print will be called with different (target) rank on different on different ranks/processes
this->print(f, s, srows, erows, rank);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::print(char *f, char *s, int srows, int erows, int trank)
{
typedef typename TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec>::MatPrec ValueType;
int rank = 0;
int level = 0;
char filename[1024];
FILE *fid = NULL;
int printRowsStart, printRowsEnd;
int i, j, ii, xdim, ydim, tnnz;
ValueType a;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//check target rank
if (rank == trank)
{
//check whether to ouput to stdout or file
if (f == NULL)
{
fid = stdout;
}
else
{
level = this->amg_level_index;
#ifdef _WIN32
_snprintf_s(filename, 1024, 1024, "%s_r%d_l%d.mtx", f, rank, level);
#else
snprintf(filename, 1024, "%s_r%d_l%d.mtx", f, rank, level);
#endif
fid = fopen(filename, "w");
}
cudaDeviceSynchronize();
cudaCheckError();
printRowsStart = (srows < 0) ? 0 : srows;
printRowsEnd = (erows < 0) ? this->get_num_rows() : erows;
tnnz = this->get_num_nz() * this->get_block_size();
//matrix might have separate diagonal (need to accoutn for it in nnz)
if (this->hasProps(DIAG, this->props))
{
//matrix might be non-square so take min of # of rows and cols
tnnz += std::min(this->get_num_rows(), this->get_num_cols()) * this->get_block_size();
}
fprintf(fid, "%%%%MatrixMarket matrix coordinate real general\n");
fprintf(fid, "%% %s\n", s);
fprintf(fid, "%d %d %d\n", this->get_num_rows() * this->get_block_dimx(), this->get_num_cols() * this->get_block_dimy(), tnnz);
auto trafI = [&](auto const &I, auto const &i) { return I * this->get_block_dimy() + i + 1; };
auto trafJ = [&](auto const &J, auto const &j) { return J * this->get_block_dimx() + j + 1; };
for (i = printRowsStart; i < printRowsEnd; i++)
{
for (ydim = 0; ydim < this->get_block_dimy(); ydim++)
{
if (this->hasProps(DIAG, this->props))
{
if (i < std::min(this->get_num_rows(), this->get_num_cols()))
{
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[this->diag[i] * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", trafI(i, ydim), trafI(i, xdim));
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
for (ii = this->row_offsets[i]; ii < this->row_offsets[i + 1]; ii++)
{
j = this->col_indices[ii];
for (xdim = 0; xdim < this->get_block_dimx(); xdim++)
{
a = this->values[ii * this->get_block_dimx() * this->get_block_dimy() + this->get_block_dimy() * ydim + xdim];
fprintf(fid, "%d %d ", i + 1, j + 1);
types::util<value_type>::fprintf(fid, "%20.16f", a);
fprintf(fid, "\n");
}
}
}
}
cudaDeviceSynchronize();
cudaGetLastError();
if (fid != stdout)
{
fclose(fid);
}
}
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::printToFile(char *f, char *s, int srows, int erows)
{
int rank = 0;
#ifdef AMGX_WITH_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
//notice that print will be called with different (target) rank on different on different ranks/processes
this->print(f, s, srows, erows, rank);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix< TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> > ::convert( const Matrix<TConfig> &mat, unsigned int new_props, int block_dimy, int block_dimx )
{
if ( !mat.is_initialized() )
{
FatalError("Trying to convert from the uninitialized matrix", AMGX_ERR_BAD_PARAMETERS);
}
this->set_initialized(0);
this->addProps(new_props);
index_type block_size = block_dimx * block_dimy;
index_type new_num_rows = ( mat.get_num_rows() * mat.block_dimy + block_dimy - 1 ) / block_dimy;
index_type new_num_cols = ( mat.get_num_cols() * mat.block_dimx + block_dimx - 1 ) / block_dimx;
MVector new_values;
IVector new_col_indices;
index_type new_num_nnz = 0;
IVector new_row_indices;
IVector new_row_offsets;
MVector new_dia_values;
new_dia_values.resize( new_num_rows * block_size, types::util<value_type>::get_zero() );
if ( mat.hasProps(COO) )
{
std::map< std::pair<index_type, index_type>, index_type> ind;
for ( index_type i = 0; i < mat.get_num_nz(); i++ )
for ( index_type loc_row = 0; loc_row < mat.block_dimy; loc_row++ )
for ( index_type loc_col = 0; loc_col < mat.block_dimx; loc_col++ )
{
index_type in_row = mat.row_indices[i] * mat.block_dimy + loc_row;
index_type in_col = mat.col_indices[i] * mat.block_dimx + loc_col;
value_type in_val = mat.values[i * mat.block_size + loc_row * mat.block_dimx + loc_col];
if ( types::util<value_type>::is_zero(in_val) ) { continue; } // skip zero entries
index_type out_br = in_row / block_dimy;
index_type out_bc = in_col / block_dimx;
index_type out_lr = in_row % block_dimy;
index_type out_lc = in_col % block_dimx;
if ( ind.find( std::pair<index_type, index_type>( out_br, out_bc ) ) == ind.end() )
{
// allocate a new block
ind.insert( std::pair< std::pair<index_type, index_type>, index_type>( std::pair<index_type, index_type>( out_br, out_bc ), new_num_nnz ) );
if (out_br != out_bc || !this->hasProps(DIAG))
{
new_row_indices.push_back( out_br );
new_col_indices.push_back( out_bc );
new_num_nnz++;
for ( int b = 0; b < block_size; b++ )
{
new_values.push_back( types::util<value_type>::get_zero() );
}
}
}
if ( out_br != out_bc || !this->hasProps(DIAG) )
{
new_values[ ind[std::pair<index_type, index_type>( out_br, out_bc )] * block_size + out_lr * block_dimx + out_lc ] = in_val;
}
else
{
new_dia_values[ out_br * block_size + out_lr * block_dimx + out_lc ] = in_val;
}
}
} // ( mat.hasProps(COO) )
else if ( mat.hasProps(CSR))
{
new_num_nnz = 0;
//MVector new_dia_values;
//new_dia_values.resize( new_num_rows*block_size, 0.0 );
new_row_offsets.resize( new_num_rows + 1 );
// process each output block row
for ( index_type i = 0; i < new_num_rows; i++ )
{
new_row_offsets[i] = new_num_nnz;
// count non zero column blocks
IVector non_zero_blocks( new_num_cols );
for ( index_type j = i * block_dimy; j < (i + 1) * block_dimy && j < mat.get_num_rows() * mat.block_dimy; j++ )
{
// input row block / local position
index_type in_br = j / mat.block_dimy;
index_type in_lr = j % mat.block_dimy;
// loop through block columns
for ( index_type r = mat.row_offsets[in_br]; r < mat.row_offsets[in_br + 1] + ( mat.hasProps(DIAG) ); r++ )
{
index_type in_bc = ( r == mat.row_offsets[in_br + 1] ) ? in_br : mat.col_indices[r];
// loop through local columns
for ( index_type in_lc = 0; in_lc < mat.block_dimx; in_lc++ )
{
index_type in_col = in_bc * mat.block_dimx + in_lc;
index_type out_bc = in_col / block_dimx;
// fetch input entry value
value_type val = ( r == mat.row_offsets[in_br + 1] ) ?
mat.values[mat.diag[in_br] * mat.block_size + in_lr * mat.block_dimx + in_lc] :
mat.values[r * mat.block_size + in_lr * mat.block_dimx + in_lc];
if ( types::util<value_type>::is_zero(val) ) { continue; } // skip zero entries
// mark non_zero column
non_zero_blocks[out_bc] = 1;
}
}
}
// populate non zero column blocks
for ( int bc = 0; bc < new_num_cols; bc++ )
if ( non_zero_blocks[bc] != 0 )
{
if ( i != bc || !this->hasProps(DIAG) ) // off-diagonal for DIAG
{
non_zero_blocks[bc] = new_num_nnz++;
new_col_indices.push_back( bc );
for ( int b = 0; b < block_size; b++ )
{
new_values.push_back( types::util<value_type>::get_zero() );
}
}
}
// fill non zero values
for ( index_type j = i * block_dimy; j < (i + 1) * block_dimy && j < mat.get_num_rows() * mat.block_dimy; j++ )
{
// output row block/local position
index_type out_br = j / block_dimy;
index_type out_lr = j % block_dimy;
// input row block/local position
index_type in_br = j / mat.block_dimy;
index_type in_lr = j % mat.block_dimy;
// loop through block columns
for ( index_type r = mat.row_offsets[in_br]; r < mat.row_offsets[in_br + 1] + ( mat.hasProps(DIAG) ); r++ )
{
index_type in_bc = ( r == mat.row_offsets[in_br + 1] ) ? in_br : mat.col_indices[r];
// loop through local columns
for ( index_type in_lc = 0; in_lc < mat.block_dimx; in_lc++ )
{
index_type in_col = in_bc * mat.block_dimx + in_lc;
index_type out_bc = in_col / block_dimx;
index_type out_lc = in_col % block_dimx;
// fetch input entry value
value_type val = ( r == mat.row_offsets[in_br + 1] ) ?
mat.values[mat.diag[in_br] * mat.block_size + in_lr * mat.block_dimx + in_lc] :
mat.values[r * mat.block_size + in_lr * mat.block_dimx + in_lc];
if ( types::util<value_type>::is_zero(val) ) { continue; } // skip zero entries
// write to new matrix
if ( out_br != out_bc || !this->hasProps(DIAG) )
{
new_values[ non_zero_blocks[out_bc] * block_size + out_lr * block_dimx + out_lc] = val;
}
else
{
new_dia_values[ out_br * block_size + out_lr * block_dimx + out_lc ] = val;
}
}
}
}
} // for( i < new_num_rows )
// fill extra diagonal for the last block
int extra_start = ( mat.get_num_rows() * mat.block_dimy ) % block_dimy;
if ( extra_start > 0 )
{
for ( int r = extra_start; r < block_dimy; r++ )
if ( this->hasProps(DIAG) )
{
new_dia_values[ (new_num_rows - 1) * block_size + r * block_dimx + r] = types::util<value_type>::get_one();
}
else
{
new_values[ (new_num_nnz - 1) * block_size + r * block_dimx + r] = types::util<value_type>::get_one();
}
}
new_row_offsets[new_num_rows] = new_num_nnz;
} // ( mat.hasProps(CSR) )
else
{
FatalError("Input matrix for conversion doesn't have COO or CSR format", AMGX_ERR_CONFIGURATION);
}
if ( this->hasProps(DIAG) )
{
new_values.insert(new_values.end(), new_dia_values.begin(), new_dia_values.end());
}
else
for ( int b = 0; b < block_size; b++ )
{
new_values.push_back( types::util<value_type>::get_zero() );
}
this->resize( new_num_rows, new_num_cols, new_num_nnz, block_dimy, block_dimx );
this->values.copy( new_values );
this->values.set_block_dimx(block_dimx);
this->values.set_block_dimy(block_dimy);
this->col_indices.copy( new_col_indices );
if ( mat.hasProps(COO) )
{
this->row_indices.copy( new_row_indices );
this->props |= COO;
}
if ( mat.hasProps(CSR) )
{
this->row_offsets.copy( new_row_offsets );
this->props |= CSR;
}
if (this->hasProps(COO) && this->row_indices.size() == 0)
{
this->row_indices.resize(new_num_nnz);
computeRowIndices();
}
if (this->hasProps(CSR) && this->row_offsets.size() == 0)
{
this->row_offsets.resize(new_num_rows + 1);
computeRowOffsets();
}
computeDiagonal();
this->set_initialized(1);
}
template <class T_Config> class MatrixBase;
template<class T_Config>
AMGX_ERROR
MatrixBase<T_Config>::resize(index_type num_rows, index_type num_cols, index_type num_nz, int skipDiaCompute)
{
if (this->is_initialized())
{
FatalError("Debug throw: resizing already initialized matrix\n", AMGX_ERR_BAD_PARAMETERS);
}
{
this->num_rows = num_rows;
this->num_cols = num_cols;
this->num_nz = num_nz;
if ( hasProps(DIAG) )
{
values.resize(num_nz * block_size + num_rows * block_size);
}
else
{
values.resize((num_nz + 1)*block_size);
//amgx::thrust::fill(values.begin() + num_nz*block_size, values.end(), static_cast<value_type>(0.0));
}
diag.resize(num_rows);
m_diag_end_offsets.resize(num_rows);
col_indices.resize(num_nz);
//if( props == NONE ) {props = CSR; props |= DIAG;}
if ( hasProps(COO) ) { row_indices.resize(num_nz); }
if ( hasProps(CSR) ) { row_offsets.resize(num_rows + 1); }
m_seq_offsets.resize(num_rows + 1);
amgx::thrust::sequence(m_seq_offsets.begin(), m_seq_offsets.end());
cudaCheckError();
if (!skipDiaCompute )
{
computeDiagonal();
}
}
return AMGX_OK;
}
template<class T_Config>
void
MatrixBase<T_Config>::setupMatrix(Solver<T_Config> *outer_solver, AMG_Config &cfg, bool reuse_matrix_structure)
{
// Check that matrix is initialized
if (!this->is_initialized())
{
FatalError("Trying to setup from the uninitialized matrix", AMGX_ERR_BAD_PARAMETERS);
}
this->set_initialized(0);
m_separation_interior = cfg.getParameter<ViewType>("separation_interior", "default");
m_separation_exterior = cfg.getParameter<ViewType>("separation_exterior", "default");
if (m_separation_interior > m_separation_exterior) { FatalError("Interior separation cannot be wider than the exterior separation", AMGX_ERR_CONFIGURATION); }
// If latency hiding is disabled, the interior is overwritten
if(!isLatencyHidingEnabled(cfg))
{
m_separation_interior = m_separation_exterior;
}
bool is_coloring_needed = outer_solver->isColoringNeeded();
if (!reuse_matrix_structure)
{
// Color the matrix since the structure has changed
if ( is_coloring_needed )
{
// Get the scope of the solver that needs coloring
std::string cfg_scope_for_coloring;
outer_solver->getColoringScope(cfg_scope_for_coloring);
this->colorMatrix(cfg, cfg_scope_for_coloring);
}
}
// Set the matrix block format
BlockFormat block_format = cfg.getParameter<BlockFormat>( "block_format", "default" );
if ( this->getBlockFormat() != block_format )
{
this->setBlockFormat( block_format );
}
// Permute the values and the column indices (if necessary)
bool reorder_cols_by_color = outer_solver->getReorderColsByColorDesired();
bool insert_diagonal = outer_solver->getInsertDiagonalDesired();
if (reorder_cols_by_color)
{
if (reuse_matrix_structure) // Only permute the values
{
this->permuteValues();
}
else // Permute the values and the columns
{
this->reorderColumnsByColor(insert_diagonal);
this->permuteValues();
}
}
this->set_initialized(1);
m_is_matrix_setup = true;
}
template<class T_Config>
bool MatrixBase<T_Config>::isLatencyHidingEnabled(AMG_Config &cfg)
{
const int min_rows_latency_hiding =
cfg.getParameter<int>("min_rows_latency_hiding", "default");
// Test all partitions to check if they all fall below the threshold
if (!is_matrix_singleGPU() && min_rows_latency_hiding >= 0)
{
const auto& nrows_per_part = manager->getNumRowsPerPart();
// Look at all partitions to check whether the number of rows falls
// below the user defined minimum
for(auto& nrpp : nrows_per_part)
{
// If any partitions still have a large enough set of rows,
// continue latency hiding
if(nrpp >= min_rows_latency_hiding)
{
return true;
}
}
}
return false;
}
template<class T_Config>
void
MatrixBase<T_Config>::reorderColumnsByColor(bool insert_diagonal)
{
// If columns already reordered, don't reorder again
if (this->m_cols_reordered_by_color)
{
return;
}
// Check if matrix is colored
if (!this->hasProps(COLORING))
{
FatalError("Matrix must be colored in order to be reordered by colors. Try setting coloring_level=1 in the configuration file", AMGX_ERR_CONFIGURATION);
}
set_initialized(0);
// Compute the row indices
addProps(COO);
set_allow_recompute_diag(false);
index_type num_non_zeros = num_nz;
if (hasProps(DIAG) && insert_diagonal) // Diagonal stored separetely
{
num_non_zeros += num_rows;
}
// Append the diagonal if stored separately
// The new matrix will have inside diagonal
if (hasProps(DIAG) && insert_diagonal)
{
amgx::thrust::counting_iterator<int> first(0);
amgx::thrust::counting_iterator<int> last = first + num_rows;
// Create new row_indices with appended diagonal
IVector new_row_indices(num_non_zeros);
IVector new_col_indices(num_non_zeros);
amgx::thrust::copy(row_indices.begin(), row_indices.end(), new_row_indices.begin());
amgx::thrust::copy(first, last, new_row_indices.begin() + num_nz);
// Create new col_indices with appended diagonal
amgx::thrust::copy(col_indices.begin(), col_indices.end(), new_col_indices.begin());
amgx::thrust::copy(first, last, new_col_indices.begin() + num_nz);
row_indices.swap(new_row_indices);
col_indices.swap(new_col_indices);
new_row_indices.clear();
new_row_indices.shrink_to_fit();
new_col_indices.clear();
new_col_indices.shrink_to_fit();
}
// Compute the color of every column
IVector element_colors(num_non_zeros);
amgx::thrust::copy(amgx::thrust::make_permutation_iterator(this->getMatrixColoring().getRowColors().begin(), col_indices.begin()),
amgx::thrust::make_permutation_iterator(this->getMatrixColoring().getRowColors().begin(), col_indices.end()),
element_colors.begin());
// Compute the permutation vector by sorting by rows and columns
m_values_permutation_vector.resize(num_non_zeros);
amgx::thrust::sequence(m_values_permutation_vector.begin(), m_values_permutation_vector.end());
cusp::detail::sort_by_row_and_column(row_indices, element_colors, m_values_permutation_vector);
cudaCheckError();
element_colors.clear();
element_colors.shrink_to_fit();
// Compute the new column indices sorted by color
IVector new_column_indices(num_non_zeros);
amgx::thrust::copy(amgx::thrust::make_permutation_iterator(col_indices.begin(), m_values_permutation_vector.begin()),
amgx::thrust::make_permutation_iterator(col_indices.begin(), m_values_permutation_vector.end()),
new_column_indices.begin());
col_indices.swap(new_column_indices);
new_column_indices.clear();
new_column_indices.shrink_to_fit();
if (hasProps(DIAG) && insert_diagonal)
{
// Change the number of nonzeros
set_num_nz(num_non_zeros);
values.resize( (num_non_zeros + 1)*this->get_block_size());
this->m_is_permutation_inplace = false;
}
else
{
this->m_is_permutation_inplace = true;
}
if (hasProps(DIAG) && insert_diagonal)
{
delProps(DIAG);
// Force recomputation of row offsets
delProps(CSR);
}
// Compute row offsets if input matrix only had COO format or if diagonal was inserted
addProps(CSR);
// Recompute the diagonal
set_allow_recompute_diag(true);
computeDiagonal();
// Compute the color offsets
m_smaller_color_offsets.resize(this->get_num_rows());
m_larger_color_offsets.resize(this->get_num_rows());
computeColorOffsets();
this->m_cols_reordered_by_color = true;
set_initialized(1);
}
template<class T_Config>
void
MatrixBase<T_Config>::sortByRowAndColumn()
{
this->set_initialized(0);
// Add row_indices array
this->addProps(COO);
this->set_allow_recompute_diag(false);
if (this->get_block_dimx() != 1 || this->get_block_dimy() != 1)
{
FatalError("sortByRowAndColumn only works for scalar matrices", AMGX_ERR_NOT_IMPLEMENTED);
}
size_t N = this->row_indices.size();
IVector permutation(N);
amgx::thrust::sequence(permutation.begin(), permutation.end());
cudaCheckError();
// compute permutation and sort by (I,J)
{
IVector temp(this->col_indices);
amgx::thrust::stable_sort_by_key(temp.begin(), temp.end(), permutation.begin());
temp = this->row_indices;
amgx::thrust::gather(permutation.begin(), permutation.end(), temp.begin(), this->row_indices.begin());
amgx::thrust::stable_sort_by_key(this->row_indices.begin(), this->row_indices.end(), permutation.begin());
temp = this->col_indices;
amgx::thrust::gather(permutation.begin(), permutation.end(), temp.begin(), this->col_indices.begin());
}
cudaCheckError();
// use permutation to reorder the values
{
MVector temp(this->values);
amgx::thrust::gather(permutation.begin(), permutation.end(), temp.begin(), this->values.begin());
}
cudaCheckError();
this->set_allow_recompute_diag(true);
this->addProps(CSR);
// remove row indices array
this->delProps(COO);
this->computeDiagonal();
this->set_initialized(1);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix<TemplateConfig<AMGX_host, t_vecPrec, t_matPrec, t_indPrec> >::computeDiagonal()
{
ViewType oldView = this->currentView();
if (this->m_initialized) { this->setView(ALL); }
if (this->allow_recompute_diag)
{
index_type num_rows = this->get_num_rows();
index_type num_nz = this->get_num_nz();
IVector &row_offsets = this->row_offsets;
IVector &row_indices = this->row_indices;
IVector &col_indices = this->col_indices;
IVector &diag = this->diag;
if (this->diag.size() != this->get_num_rows()) { this->diag.resize(this->get_num_rows()); }
if (this->m_diag_end_offsets.size() != this->get_num_rows()) { this->m_diag_end_offsets.resize(this->get_num_rows()); }
if ( this->hasProps(DIAG) )
{
int first = num_nz;
for (int r = 0; r < num_rows; r++)
{
diag[r] = first++;
}
}
else
{
index_type null_index = this->get_num_nz();
if ( this->hasProps(CSR) )
{
for (int r = 0; r < num_rows; r++)
{
int start = row_offsets[r];
int end = row_offsets[r + 1];
diag[r] = null_index;
for (int j = start; j < end; j++)
{
if (col_indices[j] == r)
{
diag[r] = j;
break;
}
}
}
}
else if (this->hasProps(COO) )
{
for (int i = 0; i < num_rows; i++)
{
diag[i] = null_index;
}
for (int j = 0; j < num_nz; j++)
{
int r = row_indices[j];
if (r == col_indices[j])
{
diag[r] = j;
}
}
}
}
for (int r = 0; r < num_rows; r++)
{
this->m_diag_end_offsets[r] = diag[r] + 1;
}
}
this->setView(oldView);
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void Matrix<TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::computeDiagonal()
{
ViewType oldView;
index_type null_index = 0; //this->get_num_nz();
if (!this->allow_recompute_diag || !(this->get_num_rows() > 0))
{
return;
}
if (this->m_initialized)
{
oldView = this->currentView();
this->setView(ALL);
}
if (this->diag.size() < this->get_num_rows())
{
this->diag.resize(this->get_num_rows());
}
if (this->m_diag_end_offsets.size() < this->get_num_rows())
{
this->m_diag_end_offsets.resize(this->get_num_rows());
}
if (this->hasProps(DIAG))
{
int num_blocks = std::min(4096, (this->get_num_rows() + 511) / 512);
computeDiagonalKernelDiagProp <<< num_blocks, 512, 0, amgx::thrust::global_thread_handle::get_stream()>>>(this->get_num_rows(), this->get_num_nz(), this->diag.raw(), this->m_diag_end_offsets.raw());
}
else if (this->hasProps(COO))
{
int num_blocks = std::min(4096, (this->get_num_nz() + 511) / 512);
computeDiagonalKernelCOO <<< num_blocks, 512>>>(this->get_num_nz(), this->row_indices.raw(), this->col_indices.raw(), this->diag.raw(), this->m_diag_end_offsets.raw());
}
else
{
int num_blocks = std::min(4096, (this->get_num_rows() + 511) / 512);
computeDiagonalKernelCSR <<< num_blocks, 512>>>(this->get_num_rows(), this->row_offsets.raw(), this->col_indices.raw(), this->diag.raw(), null_index, this->m_diag_end_offsets.raw());
}
cudaCheckError();
if (this->m_initialized)
{
this->setView(oldView);
}
#ifdef DEBUG
if (this->diag_copy.size() == 0)
{
this->diag_copy = this->diag;
}
else
{
if ((this->diag.size() != this->diag_copy.size()) || (this->diag.size() == 1)) { return; }
IVector_h h_diag = this->diag;
IVector_h h_diag_copy = this->diag_copy;
bool equal = true;
for (unsigned int i = 0; i < this->diag.size(); ++i)
{
if (h_diag[i] != h_diag_copy[i])
{
equal = false;
break;
}
}
if (equal)
{
FatalError("ComputeDiagonal was called, but diagonal hasn't changed", AMGX_ERR_UNKNOWN);
}
}
#endif
}
template <AMGX_VecPrecision t_vecPrec, AMGX_MatPrecision t_matPrec, AMGX_IndPrecision t_indPrec>
void
Matrix<TemplateConfig<AMGX_device, t_vecPrec, t_matPrec, t_indPrec> >::permuteValues()
{
if (this->m_cols_reordered_by_color && this->m_is_permutation_inplace)
{
reorderValuesInPlace();
}
else if (this->m_cols_reordered_by_color && !this->m_is_permutation_inplace )
{
// might use a lot of memory
MVector temp_values;
temp_values.resize(this->values.size());
temp_values.set_block_dimx(this->values.get_block_dimx());
temp_values.set_block_dimy(this->values.get_block_dimy());
amgx::unpermuteVector(this->values, temp_values, this->m_values_permutation_vector, (this->get_num_nz()) * (this->get_block_size()));
this->values.swap(temp_values);
temp_values.clear();
temp_values.shrink_to_fit();
}
else
{
FatalError("Invalid reordering level in permuteValues", AMGX_ERR_CONFIGURATION);
}
}
void computeRowOffsetsDevice(int num_blocks, INDEX_TYPE num_rows, INDEX_TYPE num_nz, const INDEX_TYPE *row_indices, INDEX_TYPE *row_offsets, INDEX_TYPE block_size )
{
computeRowOffsetsKernel <<< num_blocks, 512>>>(num_rows, num_nz, row_indices, row_offsets);
cudaCheckError();
}
extern void computeRowIndicesDevice(int num_blocks, INDEX_TYPE num_rows, const INDEX_TYPE *row_offsets, INDEX_TYPE *row_indices, INDEX_TYPE block_size )
{
computeRowIndicesKernel <<< num_blocks, 512>>>(num_rows, row_offsets, row_indices);
cudaCheckError();
}
void computeColorOffsetsDeviceCSR(int num_blocks, INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *col_indices, const INDEX_TYPE *row_colors, INDEX_TYPE *smaller_color_offsets, INDEX_TYPE *larger_color_offsets, INDEX_TYPE block_size, INDEX_TYPE *diag )
{
computeColorOffsetsKernelCSR <<< num_blocks, 512>>>(num_rows, row_offsets, col_indices, row_colors, smaller_color_offsets, larger_color_offsets, diag);
cudaCheckError();
}
template <typename T>
void reorderElementsDeviceCSR(INDEX_TYPE num_rows,
INDEX_TYPE *row_offsets,
INDEX_TYPE *permutation,
INDEX_TYPE *col_indices,
T *values,
INDEX_TYPE block_size)
{
amgx::thrust::device_ptr<INDEX_TYPE> dev_ptr = amgx::thrust::device_pointer_cast(row_offsets);
INDEX_TYPE max_row_length = std::max(1, amgx::thrust::transform_reduce(dev_ptr, dev_ptr + num_rows, row_length<INDEX_TYPE>(), 0, amgx::thrust::maximum<INDEX_TYPE>()));
//TODO: optimise this in terms of storage
INDEX_TYPE storage_space = 100 * 1024 * 1024 * sizeof(T) / sizeof(cuDoubleComplex); // because we allocate as for cuComplex
INDEX_TYPE blocks = 1500 < storage_space / (max_row_length * block_size * sizeof(T)) ? 1500 : storage_space / (max_row_length * block_size * sizeof(T));
blocks = blocks < num_rows ? blocks : num_rows;
INDEX_TYPE aligned_space = ((max_row_length * block_size * sizeof(T) / 128 + 1) * 128) / sizeof(T); //pad to 128 bytes
Vector<amgx::TemplateConfig<AMGX_device, AMGX_vecDoubleComplex, AMGX_matDoubleComplex, AMGX_indInt> > tempstorage(blocks * aligned_space);
reorderElements <<< blocks, 256>>>(num_rows, row_offsets, permutation, values, (T *)tempstorage.raw(), aligned_space, block_size);
cudaCheckError();
}
// explicitly instantiate reorderElementsDeviceCSR, since we call it from header and it's not a part of some class
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, float *values, INDEX_TYPE block_size);
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, double *values, INDEX_TYPE block_size);
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, cuComplex *values, INDEX_TYPE block_size);
template void reorderElementsDeviceCSR(INDEX_TYPE num_rows, INDEX_TYPE *row_offsets, INDEX_TYPE *permutation, INDEX_TYPE *col_indices, cuDoubleComplex *values, INDEX_TYPE block_size);
/****************************************
* Explict instantiations
***************************************/
#define AMGX_CASE_LINE(CASE) template class MatrixBase<TemplateMode<CASE>::Type>;
AMGX_FORALL_BUILDS(AMGX_CASE_LINE)
AMGX_FORCOMPLEX_BUILDS(AMGX_CASE_LINE)
#undef AMGX_CASE_LINE
#define AMGX_CASE_LINE(CASE) template class Matrix<TemplateMode<CASE>::Type>;
AMGX_FORALL_BUILDS(AMGX_CASE_LINE)
AMGX_FORCOMPLEX_BUILDS(AMGX_CASE_LINE)
#undef AMGX_CASE_LINE
}//end namespace amgx
|
d265eb276031cc2ac08a15b3614617c08d03e319.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include<stdio.h>
#include<cuda.h>
#include<cuda_runtime.h>
#define N 512
#define BLOCK_SIZE 16
__global__ void MatAdd(float *A, float *B,
float *C)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
int j = blockIdx.y * blockDim.y + threadIdx.y;
// C = A + B (write down your codes)
if(i < N && j < N)
{
}
}
int main()
{
float *h_A, *h_B, *h_C;
float *d_A, *d_B, *d_C;
int i;
h_A = (float*)malloc(N * N * sizeof(float));
h_B = (float*)malloc(N * N * sizeof(float));
h_C = (float*)malloc(N * N * sizeof(float));
// init data
for(i = 0; i < (N * N); i++)
{
h_A[i] = 1.0;
h_B[i] = 2.0;
h_C[i] = 0.0;
}
// allocate device memory
hipMalloc((void**)&d_A, N * N * sizeof(float));
hipMalloc((void**)&d_B, N * N * sizeof(float));
hipMalloc((void**)&d_C, N * N * sizeof(float));
// transfer data to device
hipMemcpy(d_A, h_A, N * N * sizeof(float), hipMemcpyHostToDevice);
// d_B (write down your codes)
// d_C (write down your codes)
// fill in correct thread/blocks
dim3 blockSize( , );
dim3 numBlock( , );
// MatAdd kernel
hipLaunchKernelGGL(( MatAdd), dim3(numBlock), dim3(blockSize), 0, 0, d_A, d_B, d_C);
hipDeviceSynchronize();
// transfer data back to host
// write down your codes
for(i = 0; i < (N * N); i++)
{
if(h_C[i]!= 3.0)
{
printf("Error:%f, idx:%d\n", h_C[i], i);
break;
}
}
printf("PASS\n");
// free memory
free(h_A);
free(h_B);
free(h_C);
hipFree(d_A);
hipFree(d_B);
hipFree(d_C);
return 0;
}
| d265eb276031cc2ac08a15b3614617c08d03e319.cu | #include<stdio.h>
#include<cuda.h>
#include<cuda_runtime.h>
#define N 512
#define BLOCK_SIZE 16
__global__ void MatAdd(float *A, float *B,
float *C)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
int j = blockIdx.y * blockDim.y + threadIdx.y;
// C = A + B (write down your codes)
if(i < N && j < N)
{
}
}
int main()
{
float *h_A, *h_B, *h_C;
float *d_A, *d_B, *d_C;
int i;
h_A = (float*)malloc(N * N * sizeof(float));
h_B = (float*)malloc(N * N * sizeof(float));
h_C = (float*)malloc(N * N * sizeof(float));
// init data
for(i = 0; i < (N * N); i++)
{
h_A[i] = 1.0;
h_B[i] = 2.0;
h_C[i] = 0.0;
}
// allocate device memory
cudaMalloc((void**)&d_A, N * N * sizeof(float));
cudaMalloc((void**)&d_B, N * N * sizeof(float));
cudaMalloc((void**)&d_C, N * N * sizeof(float));
// transfer data to device
cudaMemcpy(d_A, h_A, N * N * sizeof(float), cudaMemcpyHostToDevice);
// d_B (write down your codes)
// d_C (write down your codes)
// fill in correct thread/blocks
dim3 blockSize( , );
dim3 numBlock( , );
// MatAdd kernel
MatAdd<<<numBlock, blockSize>>>(d_A, d_B, d_C);
cudaDeviceSynchronize();
// transfer data back to host
// write down your codes
for(i = 0; i < (N * N); i++)
{
if(h_C[i]!= 3.0)
{
printf("Error:%f, idx:%d\n", h_C[i], i);
break;
}
}
printf("PASS\n");
// free memory
free(h_A);
free(h_B);
free(h_C);
cudaFree(d_A);
cudaFree(d_B);
cudaFree(d_C);
return 0;
}
|
2a6e00de6fd8745873215abd69e04bb30050e88e.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include "hiprand/hiprand.h"
#include "rocblas.h"
extern float* data_svm[10];
int cnt1;
extern int cnt2;
extern int flag_ok;
extern "C" {
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include "network.h"
#include "data.h"
#include "utils.h"
#include "parser.h"
#include "crop_layer.h"
#include "connected_layer.h"
#include "rnn_layer.h"
#include "gru_layer.h"
#include "crnn_layer.h"
#include "detection_layer.h"
#include "region_layer.h"
#include "convolutional_layer.h"
#include "activation_layer.h"
#include "maxpool_layer.h"
#include "reorg_layer.h"
#include "avgpool_layer.h"
#include "normalization_layer.h"
#include "batchnorm_layer.h"
#include "cost_layer.h"
#include "local_layer.h"
#include "softmax_layer.h"
#include "dropout_layer.h"
#include "route_layer.h"
#include "shortcut_layer.h"
#include "blas.h"
}
bool flag=true;
float * get_network_output_gpu_layer(network net, int i);
float * get_network_delta_gpu_layer(network net, int i);
float * get_network_output_gpu(network net);
void forward_network_gpu(network net, network_state state)
{
state.workspace = net.workspace;
int i;
for(i = 0; i < net.n; ++i){
state.index = i;
layer l = net.layers[i];
if(l.delta_gpu){
fill_ongpu(l.outputs * l.batch, 0, l.delta_gpu, 1);
}
//if(l.c ==3 && i > 5) state.input = *net.input_gpu;
l.forward_gpu(l, state);
/*freopen("out.txt","a",stdout);
printf("%f ",net.layers[i].output2[1]);
freopen("/dev/tty","w",stdout);*/
state.input = l.output_gpu;
if(l.truth) state.truth = l.output_gpu;
}
}
void backward_network_gpu(network net, network_state state)
{
state.workspace = net.workspace;
int i;
float * original_input = state.input;
float * original_delta = state.delta;
for(i = net.n-1; i >= 0; --i){
state.index = i;
layer l = net.layers[i];
if(l.stopbackward) break;
if(i == 0){
state.input = original_input;
state.delta = original_delta;
}else{
layer prev = net.layers[i-1];
state.input = prev.output_gpu;
state.delta = prev.delta_gpu;
}
l.backward_gpu(l, state);
}
}
void update_network_gpu(network net)
{
cuda_set_device(net.gpu_index);
int i;
int update_batch = net.batch*net.subdivisions;
float rate = get_current_rate(net);
for(i = 0; i < net.n; ++i){
layer l = net.layers[i];
l.t = get_current_batch(net);
if(l.update_gpu){
l.update_gpu(l, update_batch, rate*l.learning_rate_scale, net.momentum, net.decay);
}
}
}
void harmless_update_network_gpu(network net)
{
net.learning_rate = 0;
net.momentum = 1;
update_network_gpu(net);
}
void forward_backward_network_gpu(network net, float *x, float *y)
{
network_state state;
state.index = 0;
state.net = net;
int x_size = get_network_input_size(net)*net.batch;
int y_size = get_network_output_size(net)*net.batch;
if(net.layers[net.n-1].truths) y_size = net.layers[net.n-1].truths*net.batch;
if(!*net.input_gpu){
*net.input_gpu = cuda_make_array(x, x_size);
if(!net.notruth) *net.truth_gpu = cuda_make_array(y, y_size);
}else{
cuda_push_array(*net.input_gpu, x, x_size);
if(!net.notruth) cuda_push_array(*net.truth_gpu, y, y_size);
}
state.input = *net.input_gpu;
state.delta = 0;
state.truth = *net.truth_gpu;
state.train = 1;
forward_network_gpu(net, state);
backward_network_gpu(net, state);
}
float train_network_datum_gpu(network net, float *x, float *y)
{
*net.seen += net.batch;
forward_backward_network_gpu(net, x, y);
float error = get_network_cost(net);
if (((*net.seen) / net.batch) % net.subdivisions == 0) update_network_gpu(net);
return error;
}
typedef struct {
network net;
data d;
float *err;
} train_args;
void *train_thread(void *ptr)
{
train_args args = *(train_args*)ptr;
free(ptr);
cuda_set_device(args.net.gpu_index);
*args.err = train_network(args.net, args.d);
return 0;
}
pthread_t train_network_in_thread(network net, data d, float *err)
{
pthread_t thread;
train_args *ptr = (train_args *)calloc(1, sizeof(train_args));
ptr->net = net;
ptr->d = d;
ptr->err = err;
if(pthread_create(&thread, 0, train_thread, ptr)) error("Thread creation failed");
return thread;
}
void pull_updates(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.n);
cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.n*l.size*l.size*l.c);
if(l.scale_updates) cuda_pull_array(l.scale_updates_gpu, l.scale_updates, l.n);
} else if(l.type == CONNECTED){
cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.outputs);
cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.outputs*l.inputs);
}
}
void push_updates(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.n);
cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.n*l.size*l.size*l.c);
if(l.scale_updates) cuda_push_array(l.scale_updates_gpu, l.scale_updates, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.outputs);
cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.outputs*l.inputs);
}
}
void update_layer(layer l, network net)
{
int update_batch = net.batch*net.subdivisions;
float rate = get_current_rate(net);
l.t = get_current_batch(net);
if(l.update_gpu){
l.update_gpu(l, update_batch, rate*l.learning_rate_scale, net.momentum, net.decay);
}
}
void merge_weights(layer l, layer base)
{
if (l.type == CONVOLUTIONAL) {
axpy_cpu(l.n, 1, l.biases, 1, base.biases, 1);
axpy_cpu(l.n*l.size*l.size*l.c, 1, l.weights, 1, base.weights, 1);
if (l.scales) {
axpy_cpu(l.n, 1, l.scales, 1, base.scales, 1);
}
} else if(l.type == CONNECTED) {
axpy_cpu(l.outputs, 1, l.biases, 1, base.biases, 1);
axpy_cpu(l.outputs*l.inputs, 1, l.weights, 1, base.weights, 1);
}
}
void scale_weights(layer l, float s)
{
if (l.type == CONVOLUTIONAL) {
scal_cpu(l.n, s, l.biases, 1);
scal_cpu(l.n*l.size*l.size*l.c, s, l.weights, 1);
if (l.scales) {
scal_cpu(l.n, s, l.scales, 1);
}
} else if(l.type == CONNECTED) {
scal_cpu(l.outputs, s, l.biases, 1);
scal_cpu(l.outputs*l.inputs, s, l.weights, 1);
}
}
void pull_weights(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_pull_array(l.biases_gpu, l.biases, l.n);
cuda_pull_array(l.weights_gpu, l.weights, l.n*l.size*l.size*l.c);
if(l.scales) cuda_pull_array(l.scales_gpu, l.scales, l.n);
} else if(l.type == CONNECTED){
cuda_pull_array(l.biases_gpu, l.biases, l.outputs);
cuda_pull_array(l.weights_gpu, l.weights, l.outputs*l.inputs);
}
}
void push_weights(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.biases_gpu, l.biases, l.n);
cuda_push_array(l.weights_gpu, l.weights, l.n*l.size*l.size*l.c);
if(l.scales) cuda_push_array(l.scales_gpu, l.scales, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.biases_gpu, l.biases, l.outputs);
cuda_push_array(l.weights_gpu, l.weights, l.outputs*l.inputs);
}
}
void distribute_weights(layer l, layer base)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.biases_gpu, base.biases, l.n);
cuda_push_array(l.weights_gpu, base.weights, l.n*l.size*l.size*l.c);
if(base.scales) cuda_push_array(l.scales_gpu, base.scales, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.biases_gpu, base.biases, l.outputs);
cuda_push_array(l.weights_gpu, base.weights, l.outputs*l.inputs);
}
}
void merge_updates(layer l, layer base)
{
if (l.type == CONVOLUTIONAL) {
axpy_cpu(l.n, 1, l.bias_updates, 1, base.bias_updates, 1);
axpy_cpu(l.n*l.size*l.size*l.c, 1, l.weight_updates, 1, base.weight_updates, 1);
if (l.scale_updates) {
axpy_cpu(l.n, 1, l.scale_updates, 1, base.scale_updates, 1);
}
} else if(l.type == CONNECTED) {
axpy_cpu(l.outputs, 1, l.bias_updates, 1, base.bias_updates, 1);
axpy_cpu(l.outputs*l.inputs, 1, l.weight_updates, 1, base.weight_updates, 1);
}
}
void distribute_updates(layer l, layer base)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.bias_updates_gpu, base.bias_updates, l.n);
cuda_push_array(l.weight_updates_gpu, base.weight_updates, l.n*l.size*l.size*l.c);
if(base.scale_updates) cuda_push_array(l.scale_updates_gpu, base.scale_updates, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.bias_updates_gpu, base.bias_updates, l.outputs);
cuda_push_array(l.weight_updates_gpu, base.weight_updates, l.outputs*l.inputs);
}
}
void sync_layer(network *nets, int n, int j)
{
//printf("Syncing layer %d\n", j);
int i;
network net = nets[0];
layer base = net.layers[j];
cuda_set_device(net.gpu_index);
pull_weights(base);
for (i = 1; i < n; ++i) {
cuda_set_device(nets[i].gpu_index);
layer l = nets[i].layers[j];
pull_weights(l);
merge_weights(l, base);
}
scale_weights(base, 1./n);
for (i = 0; i < n; ++i) {
cuda_set_device(nets[i].gpu_index);
layer l = nets[i].layers[j];
distribute_weights(l, base);
}
//printf("Done syncing layer %d\n", j);
}
typedef struct{
network *nets;
int n;
int j;
} sync_args;
void *sync_layer_thread(void *ptr)
{
sync_args args = *(sync_args*)ptr;
sync_layer(args.nets, args.n, args.j);
free(ptr);
return 0;
}
pthread_t sync_layer_in_thread(network *nets, int n, int j)
{
pthread_t thread;
sync_args *ptr = (sync_args *)calloc(1, sizeof(sync_args));
ptr->nets = nets;
ptr->n = n;
ptr->j = j;
if(pthread_create(&thread, 0, sync_layer_thread, ptr)) error("Thread creation failed");
return thread;
}
void sync_nets(network *nets, int n, int interval)
{
int j;
int layers = nets[0].n;
pthread_t *threads = (pthread_t *) calloc(layers, sizeof(pthread_t));
*nets[0].seen += interval * (n-1) * nets[0].batch * nets[0].subdivisions;
for (j = 0; j < n; ++j){
*nets[j].seen = *nets[0].seen;
}
for (j = 0; j < layers; ++j) {
threads[j] = sync_layer_in_thread(nets, n, j);
}
for (j = 0; j < layers; ++j) {
pthread_join(threads[j], 0);
}
free(threads);
}
float train_networks(network *nets, int n, data d, int interval)
{
int i;
int batch = nets[0].batch;
int subdivisions = nets[0].subdivisions;
assert(batch * subdivisions * n == d.X.rows);
pthread_t *threads = (pthread_t *) calloc(n, sizeof(pthread_t));
float *errors = (float *) calloc(n, sizeof(float));
float sum = 0;
for(i = 0; i < n; ++i){
data p = get_data_part(d, i, n);
threads[i] = train_network_in_thread(nets[i], p, errors + i);
}
for(i = 0; i < n; ++i){
pthread_join(threads[i], 0);
//printf("%f\n", errors[i]);
sum += errors[i];
}
//hipDeviceSynchronize();
if (get_current_batch(nets[0]) % interval == 0) {
printf("Syncing... ");
fflush(stdout);
sync_nets(nets, n, interval);
printf("Done!\n");
}
//hipDeviceSynchronize();
free(threads);
free(errors);
return (float)sum/(n);
}
float *get_network_output_layer_gpu(network net, int i)
{
layer l = net.layers[i];
if(l.type != REGION) cuda_pull_array(l.output_gpu, l.output, l.outputs*l.batch);
return l.output;
}
float *get_network_output_gpu(network net)
{
int i;
for(i = net.n-1; i > 0; --i) if(net.layers[i].type != COST) break;
return get_network_output_layer_gpu(net, i);
}
float *network_predict_gpu(network net, float *input)
{
cuda_set_device(net.gpu_index);
int size = get_network_input_size(net) * net.batch;
network_state state;
state.index = 0;
state.net = net;
state.input = cuda_make_array(input, size);
state.truth = 0;
state.train = 0;
state.delta = 0;
forward_network_gpu(net, state);
layer l=net.layers[31];
float *out = get_network_output_gpu(net);
if(cnt1==2)
{
cnt1=0;
float *midoutput=get_network_output_layer_gpu(net,30);
int i,j,k,m;
m=0;
for (i=0;i<1690;i++)
{
data_svm[(cnt2+9)%10][i]=midoutput[i];
}
cnt2=(cnt2+1)%10;
if(cnt2==9)
flag_ok=1;
}
cnt1++;
cuda_free(state.input);
return out;
}
float *mynetwork_predict_gpu(network net, float *input,char*name)
{
cuda_set_device(net.gpu_index);
int size = get_network_input_size(net) * net.batch;
network_state state;
state.index = 0;
state.net = net;
state.input = cuda_make_array(input, size);
state.truth = 0;
state.train = 0;
state.delta = 0;
forward_network_gpu(net, state);
int nl=18;
layer l=net.layers[nl];
//printf("%d\n ",l.outputs);
float *out = get_network_output_layer_gpu(net, nl);
// printf("Data is writing\n");
char*sout=name;
/* char *sout=name+50;
int v=strlen(sout);
sout[v-3]='d';
sout[v-2]='a';
sout[v-1]='t';*/
freopen(sout,"a",stdout);
int i;
for ( i=0;i<3380;i++)
{
if(i%20==0)
printf("\n");
printf("%f ",out[i]);
}
freopen("/dev/tty","w",stdout);
cuda_free(state.input);
return out;
}
| 2a6e00de6fd8745873215abd69e04bb30050e88e.cu | #include "cuda_runtime.h"
#include "curand.h"
#include "cublas_v2.h"
extern float* data_svm[10];
int cnt1;
extern int cnt2;
extern int flag_ok;
extern "C" {
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include "network.h"
#include "data.h"
#include "utils.h"
#include "parser.h"
#include "crop_layer.h"
#include "connected_layer.h"
#include "rnn_layer.h"
#include "gru_layer.h"
#include "crnn_layer.h"
#include "detection_layer.h"
#include "region_layer.h"
#include "convolutional_layer.h"
#include "activation_layer.h"
#include "maxpool_layer.h"
#include "reorg_layer.h"
#include "avgpool_layer.h"
#include "normalization_layer.h"
#include "batchnorm_layer.h"
#include "cost_layer.h"
#include "local_layer.h"
#include "softmax_layer.h"
#include "dropout_layer.h"
#include "route_layer.h"
#include "shortcut_layer.h"
#include "blas.h"
}
bool flag=true;
float * get_network_output_gpu_layer(network net, int i);
float * get_network_delta_gpu_layer(network net, int i);
float * get_network_output_gpu(network net);
void forward_network_gpu(network net, network_state state)
{
state.workspace = net.workspace;
int i;
for(i = 0; i < net.n; ++i){
state.index = i;
layer l = net.layers[i];
if(l.delta_gpu){
fill_ongpu(l.outputs * l.batch, 0, l.delta_gpu, 1);
}
//if(l.c ==3 && i > 5) state.input = *net.input_gpu;
l.forward_gpu(l, state);
/*freopen("out.txt","a",stdout);
printf("%f ",net.layers[i].output2[1]);
freopen("/dev/tty","w",stdout);*/
state.input = l.output_gpu;
if(l.truth) state.truth = l.output_gpu;
}
}
void backward_network_gpu(network net, network_state state)
{
state.workspace = net.workspace;
int i;
float * original_input = state.input;
float * original_delta = state.delta;
for(i = net.n-1; i >= 0; --i){
state.index = i;
layer l = net.layers[i];
if(l.stopbackward) break;
if(i == 0){
state.input = original_input;
state.delta = original_delta;
}else{
layer prev = net.layers[i-1];
state.input = prev.output_gpu;
state.delta = prev.delta_gpu;
}
l.backward_gpu(l, state);
}
}
void update_network_gpu(network net)
{
cuda_set_device(net.gpu_index);
int i;
int update_batch = net.batch*net.subdivisions;
float rate = get_current_rate(net);
for(i = 0; i < net.n; ++i){
layer l = net.layers[i];
l.t = get_current_batch(net);
if(l.update_gpu){
l.update_gpu(l, update_batch, rate*l.learning_rate_scale, net.momentum, net.decay);
}
}
}
void harmless_update_network_gpu(network net)
{
net.learning_rate = 0;
net.momentum = 1;
update_network_gpu(net);
}
void forward_backward_network_gpu(network net, float *x, float *y)
{
network_state state;
state.index = 0;
state.net = net;
int x_size = get_network_input_size(net)*net.batch;
int y_size = get_network_output_size(net)*net.batch;
if(net.layers[net.n-1].truths) y_size = net.layers[net.n-1].truths*net.batch;
if(!*net.input_gpu){
*net.input_gpu = cuda_make_array(x, x_size);
if(!net.notruth) *net.truth_gpu = cuda_make_array(y, y_size);
}else{
cuda_push_array(*net.input_gpu, x, x_size);
if(!net.notruth) cuda_push_array(*net.truth_gpu, y, y_size);
}
state.input = *net.input_gpu;
state.delta = 0;
state.truth = *net.truth_gpu;
state.train = 1;
forward_network_gpu(net, state);
backward_network_gpu(net, state);
}
float train_network_datum_gpu(network net, float *x, float *y)
{
*net.seen += net.batch;
forward_backward_network_gpu(net, x, y);
float error = get_network_cost(net);
if (((*net.seen) / net.batch) % net.subdivisions == 0) update_network_gpu(net);
return error;
}
typedef struct {
network net;
data d;
float *err;
} train_args;
void *train_thread(void *ptr)
{
train_args args = *(train_args*)ptr;
free(ptr);
cuda_set_device(args.net.gpu_index);
*args.err = train_network(args.net, args.d);
return 0;
}
pthread_t train_network_in_thread(network net, data d, float *err)
{
pthread_t thread;
train_args *ptr = (train_args *)calloc(1, sizeof(train_args));
ptr->net = net;
ptr->d = d;
ptr->err = err;
if(pthread_create(&thread, 0, train_thread, ptr)) error("Thread creation failed");
return thread;
}
void pull_updates(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.n);
cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.n*l.size*l.size*l.c);
if(l.scale_updates) cuda_pull_array(l.scale_updates_gpu, l.scale_updates, l.n);
} else if(l.type == CONNECTED){
cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.outputs);
cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.outputs*l.inputs);
}
}
void push_updates(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.n);
cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.n*l.size*l.size*l.c);
if(l.scale_updates) cuda_push_array(l.scale_updates_gpu, l.scale_updates, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.outputs);
cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.outputs*l.inputs);
}
}
void update_layer(layer l, network net)
{
int update_batch = net.batch*net.subdivisions;
float rate = get_current_rate(net);
l.t = get_current_batch(net);
if(l.update_gpu){
l.update_gpu(l, update_batch, rate*l.learning_rate_scale, net.momentum, net.decay);
}
}
void merge_weights(layer l, layer base)
{
if (l.type == CONVOLUTIONAL) {
axpy_cpu(l.n, 1, l.biases, 1, base.biases, 1);
axpy_cpu(l.n*l.size*l.size*l.c, 1, l.weights, 1, base.weights, 1);
if (l.scales) {
axpy_cpu(l.n, 1, l.scales, 1, base.scales, 1);
}
} else if(l.type == CONNECTED) {
axpy_cpu(l.outputs, 1, l.biases, 1, base.biases, 1);
axpy_cpu(l.outputs*l.inputs, 1, l.weights, 1, base.weights, 1);
}
}
void scale_weights(layer l, float s)
{
if (l.type == CONVOLUTIONAL) {
scal_cpu(l.n, s, l.biases, 1);
scal_cpu(l.n*l.size*l.size*l.c, s, l.weights, 1);
if (l.scales) {
scal_cpu(l.n, s, l.scales, 1);
}
} else if(l.type == CONNECTED) {
scal_cpu(l.outputs, s, l.biases, 1);
scal_cpu(l.outputs*l.inputs, s, l.weights, 1);
}
}
void pull_weights(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_pull_array(l.biases_gpu, l.biases, l.n);
cuda_pull_array(l.weights_gpu, l.weights, l.n*l.size*l.size*l.c);
if(l.scales) cuda_pull_array(l.scales_gpu, l.scales, l.n);
} else if(l.type == CONNECTED){
cuda_pull_array(l.biases_gpu, l.biases, l.outputs);
cuda_pull_array(l.weights_gpu, l.weights, l.outputs*l.inputs);
}
}
void push_weights(layer l)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.biases_gpu, l.biases, l.n);
cuda_push_array(l.weights_gpu, l.weights, l.n*l.size*l.size*l.c);
if(l.scales) cuda_push_array(l.scales_gpu, l.scales, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.biases_gpu, l.biases, l.outputs);
cuda_push_array(l.weights_gpu, l.weights, l.outputs*l.inputs);
}
}
void distribute_weights(layer l, layer base)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.biases_gpu, base.biases, l.n);
cuda_push_array(l.weights_gpu, base.weights, l.n*l.size*l.size*l.c);
if(base.scales) cuda_push_array(l.scales_gpu, base.scales, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.biases_gpu, base.biases, l.outputs);
cuda_push_array(l.weights_gpu, base.weights, l.outputs*l.inputs);
}
}
void merge_updates(layer l, layer base)
{
if (l.type == CONVOLUTIONAL) {
axpy_cpu(l.n, 1, l.bias_updates, 1, base.bias_updates, 1);
axpy_cpu(l.n*l.size*l.size*l.c, 1, l.weight_updates, 1, base.weight_updates, 1);
if (l.scale_updates) {
axpy_cpu(l.n, 1, l.scale_updates, 1, base.scale_updates, 1);
}
} else if(l.type == CONNECTED) {
axpy_cpu(l.outputs, 1, l.bias_updates, 1, base.bias_updates, 1);
axpy_cpu(l.outputs*l.inputs, 1, l.weight_updates, 1, base.weight_updates, 1);
}
}
void distribute_updates(layer l, layer base)
{
if(l.type == CONVOLUTIONAL){
cuda_push_array(l.bias_updates_gpu, base.bias_updates, l.n);
cuda_push_array(l.weight_updates_gpu, base.weight_updates, l.n*l.size*l.size*l.c);
if(base.scale_updates) cuda_push_array(l.scale_updates_gpu, base.scale_updates, l.n);
} else if(l.type == CONNECTED){
cuda_push_array(l.bias_updates_gpu, base.bias_updates, l.outputs);
cuda_push_array(l.weight_updates_gpu, base.weight_updates, l.outputs*l.inputs);
}
}
void sync_layer(network *nets, int n, int j)
{
//printf("Syncing layer %d\n", j);
int i;
network net = nets[0];
layer base = net.layers[j];
cuda_set_device(net.gpu_index);
pull_weights(base);
for (i = 1; i < n; ++i) {
cuda_set_device(nets[i].gpu_index);
layer l = nets[i].layers[j];
pull_weights(l);
merge_weights(l, base);
}
scale_weights(base, 1./n);
for (i = 0; i < n; ++i) {
cuda_set_device(nets[i].gpu_index);
layer l = nets[i].layers[j];
distribute_weights(l, base);
}
//printf("Done syncing layer %d\n", j);
}
typedef struct{
network *nets;
int n;
int j;
} sync_args;
void *sync_layer_thread(void *ptr)
{
sync_args args = *(sync_args*)ptr;
sync_layer(args.nets, args.n, args.j);
free(ptr);
return 0;
}
pthread_t sync_layer_in_thread(network *nets, int n, int j)
{
pthread_t thread;
sync_args *ptr = (sync_args *)calloc(1, sizeof(sync_args));
ptr->nets = nets;
ptr->n = n;
ptr->j = j;
if(pthread_create(&thread, 0, sync_layer_thread, ptr)) error("Thread creation failed");
return thread;
}
void sync_nets(network *nets, int n, int interval)
{
int j;
int layers = nets[0].n;
pthread_t *threads = (pthread_t *) calloc(layers, sizeof(pthread_t));
*nets[0].seen += interval * (n-1) * nets[0].batch * nets[0].subdivisions;
for (j = 0; j < n; ++j){
*nets[j].seen = *nets[0].seen;
}
for (j = 0; j < layers; ++j) {
threads[j] = sync_layer_in_thread(nets, n, j);
}
for (j = 0; j < layers; ++j) {
pthread_join(threads[j], 0);
}
free(threads);
}
float train_networks(network *nets, int n, data d, int interval)
{
int i;
int batch = nets[0].batch;
int subdivisions = nets[0].subdivisions;
assert(batch * subdivisions * n == d.X.rows);
pthread_t *threads = (pthread_t *) calloc(n, sizeof(pthread_t));
float *errors = (float *) calloc(n, sizeof(float));
float sum = 0;
for(i = 0; i < n; ++i){
data p = get_data_part(d, i, n);
threads[i] = train_network_in_thread(nets[i], p, errors + i);
}
for(i = 0; i < n; ++i){
pthread_join(threads[i], 0);
//printf("%f\n", errors[i]);
sum += errors[i];
}
//cudaDeviceSynchronize();
if (get_current_batch(nets[0]) % interval == 0) {
printf("Syncing... ");
fflush(stdout);
sync_nets(nets, n, interval);
printf("Done!\n");
}
//cudaDeviceSynchronize();
free(threads);
free(errors);
return (float)sum/(n);
}
float *get_network_output_layer_gpu(network net, int i)
{
layer l = net.layers[i];
if(l.type != REGION) cuda_pull_array(l.output_gpu, l.output, l.outputs*l.batch);
return l.output;
}
float *get_network_output_gpu(network net)
{
int i;
for(i = net.n-1; i > 0; --i) if(net.layers[i].type != COST) break;
return get_network_output_layer_gpu(net, i);
}
float *network_predict_gpu(network net, float *input)
{
cuda_set_device(net.gpu_index);
int size = get_network_input_size(net) * net.batch;
network_state state;
state.index = 0;
state.net = net;
state.input = cuda_make_array(input, size);
state.truth = 0;
state.train = 0;
state.delta = 0;
forward_network_gpu(net, state);
layer l=net.layers[31];
float *out = get_network_output_gpu(net);
if(cnt1==2)
{
cnt1=0;
float *midoutput=get_network_output_layer_gpu(net,30);
int i,j,k,m;
m=0;
for (i=0;i<1690;i++)
{
data_svm[(cnt2+9)%10][i]=midoutput[i];
}
cnt2=(cnt2+1)%10;
if(cnt2==9)
flag_ok=1;
}
cnt1++;
cuda_free(state.input);
return out;
}
float *mynetwork_predict_gpu(network net, float *input,char*name)
{
cuda_set_device(net.gpu_index);
int size = get_network_input_size(net) * net.batch;
network_state state;
state.index = 0;
state.net = net;
state.input = cuda_make_array(input, size);
state.truth = 0;
state.train = 0;
state.delta = 0;
forward_network_gpu(net, state);
int nl=18;
layer l=net.layers[nl];
//printf("%d\n ",l.outputs);
float *out = get_network_output_layer_gpu(net, nl);
// printf("Data is writing\n");
char*sout=name;
/* char *sout=name+50;
int v=strlen(sout);
sout[v-3]='d';
sout[v-2]='a';
sout[v-1]='t';*/
freopen(sout,"a",stdout);
int i;
for ( i=0;i<3380;i++)
{
if(i%20==0)
printf("\n");
printf("%f ",out[i]);
}
freopen("/dev/tty","w",stdout);
cuda_free(state.input);
return out;
}
|
92f43d2934e317d5d52cd807b9b241bf9a245a96.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
* calcCurvatureWCL.cu
*
* Created on: 02-09-2013
* Author: Kamil Szewc (kamil.szewc@gmail.com)
*/
#include "../../sph.h"
#include "../../hlp.h"
#include "../../methods/kernels.cuh"
#include "../../methods/interactions.cuh"
__device__ static real4 interaction(uint i, uint j, real3 dpos, real3 dvel, Particle *p, Parameters *par)
{
real q = sqrt(pow2(dpos.x) + pow2(dpos.y) + pow2(dpos.z)) * par->I_H;
if ((q < 2.0) && ((i != j) || ((i == j) && (q > 0.001f*par->H)))
&& ((p[i].na == 1) && (p[j].na == 1)))
{
real diffx = ((p[i].n.x / p[i].n.w) - (p[j].n.x / p[j].n.w)) * grad_of_kern(dpos.x, q, par->GKNORM);
real diffy = ((p[i].n.y / p[i].n.w) - (p[j].n.y / p[j].n.w)) * grad_of_kern(dpos.y, q, par->GKNORM);
real diffz = ((p[i].n.z / p[i].n.w) - (p[j].n.z / p[j].n.w)) * grad_of_kern(dpos.z, q, par->GKNORM);
real vol = p[j].m / p[j].d;
return MAKE_REAL4(diffx * vol, diffy * vol, diffz * vol, kern(q, par->KNORM) * vol);
}
else {
return MAKE_REAL4(0.0, 0.0, 0.0, 0.0);
}
}
__global__ void calcCurvatureWCL(Particle *p,
uint *gridParticleIndex,
uint *cellStart,
uint *cellEnd,
Parameters *par)
{
uint index = threadIdx.x + blockIdx.x*blockDim.x;
if (index < par->N) {
register real4 result = MAKE_REAL4(0.0, 0.0, 0.0, 0.0);
#include "../../methods/interactions/interactionsPositiveOnWallNoSlip.cuh"
if (result.w > 0.0) {
p[index].cu = (result.x + result.y + result.z) / result.w;
p[index].cw = result.w;
}
real help = par->SURFACE_TENSION * p[index].cu / p[index].d;
p[index].st.x = help * p[index].n.x;
p[index].st.y = help * p[index].n.y;
p[index].st.z = help * p[index].n.z;
}
}
| 92f43d2934e317d5d52cd807b9b241bf9a245a96.cu | /*
* calcCurvatureWCL.cu
*
* Created on: 02-09-2013
* Author: Kamil Szewc (kamil.szewc@gmail.com)
*/
#include "../../sph.h"
#include "../../hlp.h"
#include "../../methods/kernels.cuh"
#include "../../methods/interactions.cuh"
__device__ static real4 interaction(uint i, uint j, real3 dpos, real3 dvel, Particle *p, Parameters *par)
{
real q = sqrt(pow2(dpos.x) + pow2(dpos.y) + pow2(dpos.z)) * par->I_H;
if ((q < 2.0) && ((i != j) || ((i == j) && (q > 0.001f*par->H)))
&& ((p[i].na == 1) && (p[j].na == 1)))
{
real diffx = ((p[i].n.x / p[i].n.w) - (p[j].n.x / p[j].n.w)) * grad_of_kern(dpos.x, q, par->GKNORM);
real diffy = ((p[i].n.y / p[i].n.w) - (p[j].n.y / p[j].n.w)) * grad_of_kern(dpos.y, q, par->GKNORM);
real diffz = ((p[i].n.z / p[i].n.w) - (p[j].n.z / p[j].n.w)) * grad_of_kern(dpos.z, q, par->GKNORM);
real vol = p[j].m / p[j].d;
return MAKE_REAL4(diffx * vol, diffy * vol, diffz * vol, kern(q, par->KNORM) * vol);
}
else {
return MAKE_REAL4(0.0, 0.0, 0.0, 0.0);
}
}
__global__ void calcCurvatureWCL(Particle *p,
uint *gridParticleIndex,
uint *cellStart,
uint *cellEnd,
Parameters *par)
{
uint index = threadIdx.x + blockIdx.x*blockDim.x;
if (index < par->N) {
register real4 result = MAKE_REAL4(0.0, 0.0, 0.0, 0.0);
#include "../../methods/interactions/interactionsPositiveOnWallNoSlip.cuh"
if (result.w > 0.0) {
p[index].cu = (result.x + result.y + result.z) / result.w;
p[index].cw = result.w;
}
real help = par->SURFACE_TENSION * p[index].cu / p[index].d;
p[index].st.x = help * p[index].n.x;
p[index].st.y = help * p[index].n.y;
p[index].st.z = help * p[index].n.z;
}
}
|
1c4136adc4821f69381d8aa982d573f3d181ad5b.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <stdio.h>
#include <iostream>
__global__ void kernel (void){
}
int do_cuda_stuff(void) {
hipLaunchKernelGGL(( kernel), dim3(1),dim3(1), 0, 0, );
printf("Hello, World!\n");
return 0;
}
| 1c4136adc4821f69381d8aa982d573f3d181ad5b.cu | #include <stdio.h>
#include <iostream>
__global__ void kernel (void){
}
int do_cuda_stuff(void) {
kernel<<<1,1>>>();
printf("Hello, World!\n");
return 0;
}
|
e0a57f1eae82a47b7e4fe251ba17a1d81775e4c2.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/* jacobi.c - Poisson problem in 3d
*
*/
#ifdef _OPENMP
#include <omp.h>
#endif
#include <math.h>
#include <stdio.h>
__global__ void
initmat(int N, double* U, double* Uold, double* F,double deltasq){
int jmp=N+2;
int idx;
for(int i = 0; i<(N+2); i++){
for(int j = 0; j<(N+2); j++){
for(int k = 0; k<(N+2); k++){
idx = jmp*jmp*i+jmp*j+k;
Uold[idx] = U[idx];
F[idx] *= deltasq;
}
}
}
}
__global__ void
updmat(int N, double* U, double* Uold){
int jmp=N+2;
int idx;
for(int i = 1; i<(N+1); i++){
for(int j = 1; j<(N+1); j++){
for(int k = 1; k<(N+1); k++){
idx = jmp*jmp*i+jmp*j+k;
Uold[idx] = U[idx];
}
}
}
}
__global__ void
jacgpu(int N, double* U, double* Uold, double* F){
int jmp=N+2;
int idx;
double onesixth = 1.0/6.0;
for(int i = 1; i<(N+1); i++){
for(int j = 1; j<(N+1); j++){
for(int k = 1; k<(N+1); k++){
idx = jmp*jmp*i+jmp*j+k;
U[idx] = onesixth*(Uold[idx-1]+Uold[idx+1]+Uold[idx-jmp]\
+Uold[idx+jmp]+Uold[idx-jmp*jmp]+Uold[idx+jmp*jmp]+F[idx]);
}
}
}
}
void
jacobiseq(double *U, double *F, double *Uold, int N, int iter_max) {
double ts, te; // for timing
double deltasq = 4.0/((double) N * (double) N);
//define norm and max_iter and Uold and iter and threshold
int iter = 0;
// update Uold = U
hipLaunchKernelGGL(( initmat), dim3(1),dim3(1), 0, 0, N, U,Uold,F,deltasq);
hipDeviceSynchronize();
ts = omp_get_wtime();
//while condition is not satisfied
while((iter < iter_max))
{
hipLaunchKernelGGL(( jacgpu), dim3(1),dim3(1), 0, 0, N, U, Uold, F);
hipDeviceSynchronize();
// update iteration and Uold
iter ++;
//pointer swap instead
hipLaunchKernelGGL(( updmat), dim3(1),dim3(1), 0, 0, N, U, Uold);
hipDeviceSynchronize();
}
te = omp_get_wtime() - ts;
printf("Number of iterations: %d\n", iter);
printf("Elapsed time: %lf\n", te);
printf("Iterations per second: %lf\n", iter/te);
printf("Gflop/s: %.3f\n",1e-9*7*N*N*N*iter/te);
//printf("%.5lf, %.5lf\n", te, 1e-6*11*N*N*N*iter/te);
}
| e0a57f1eae82a47b7e4fe251ba17a1d81775e4c2.cu | /* jacobi.c - Poisson problem in 3d
*
*/
#ifdef _OPENMP
#include <omp.h>
#endif
#include <math.h>
#include <stdio.h>
__global__ void
initmat(int N, double* U, double* Uold, double* F,double deltasq){
int jmp=N+2;
int idx;
for(int i = 0; i<(N+2); i++){
for(int j = 0; j<(N+2); j++){
for(int k = 0; k<(N+2); k++){
idx = jmp*jmp*i+jmp*j+k;
Uold[idx] = U[idx];
F[idx] *= deltasq;
}
}
}
}
__global__ void
updmat(int N, double* U, double* Uold){
int jmp=N+2;
int idx;
for(int i = 1; i<(N+1); i++){
for(int j = 1; j<(N+1); j++){
for(int k = 1; k<(N+1); k++){
idx = jmp*jmp*i+jmp*j+k;
Uold[idx] = U[idx];
}
}
}
}
__global__ void
jacgpu(int N, double* U, double* Uold, double* F){
int jmp=N+2;
int idx;
double onesixth = 1.0/6.0;
for(int i = 1; i<(N+1); i++){
for(int j = 1; j<(N+1); j++){
for(int k = 1; k<(N+1); k++){
idx = jmp*jmp*i+jmp*j+k;
U[idx] = onesixth*(Uold[idx-1]+Uold[idx+1]+Uold[idx-jmp]\
+Uold[idx+jmp]+Uold[idx-jmp*jmp]+Uold[idx+jmp*jmp]+F[idx]);
}
}
}
}
void
jacobiseq(double *U, double *F, double *Uold, int N, int iter_max) {
double ts, te; // for timing
double deltasq = 4.0/((double) N * (double) N);
//define norm and max_iter and Uold and iter and threshold
int iter = 0;
// update Uold = U
initmat<<<1,1>>>(N, U,Uold,F,deltasq);
cudaDeviceSynchronize();
ts = omp_get_wtime();
//while condition is not satisfied
while((iter < iter_max))
{
jacgpu<<<1,1>>>(N, U, Uold, F);
cudaDeviceSynchronize();
// update iteration and Uold
iter ++;
//pointer swap instead
updmat<<<1,1>>>(N, U, Uold);
cudaDeviceSynchronize();
}
te = omp_get_wtime() - ts;
printf("Number of iterations: %d\n", iter);
printf("Elapsed time: %lf\n", te);
printf("Iterations per second: %lf\n", iter/te);
printf("Gflop/s: %.3f\n",1e-9*7*N*N*N*iter/te);
//printf("%.5lf, %.5lf\n", te, 1e-6*11*N*N*N*iter/te);
}
|
cacebb98c745ab46b924915b83a551e6578e1a3a.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
extern "C" {
#include "hough.h"
#include <stdint.h>
}
//#include <hipcub/hipcub.hpp>
/****** PARAMETERS ********/
#define MARGIN 20
// needs to be a power of 2 as well
//#define STEP_SIZE 2
#define RAD_COUNT 32
// diff should be a multiple of 2 to exploit warp size efficiently (> 32)
//#define MIN_RAD 6
//#define MAX_RAD 500//262
#define PI 3.141592654
//#define THREAD_COUNT (MAX_RAD - MIN_RAD)
//#define WARP_SIZE 32
texture<float, hipTextureType2D> phi_tex;
texture<float, hipTextureType2D> abs_tex;
/*
* Warp reduce sum: http://devblogs.nvidia.com/parallelforall/faster-parallel-reductions-kepler/
**/
__inline__ __device__
int warpReduceSum(int val) {
for (int offset = warpSize / 2; offset > 0; offset /= 2)
val += __shfl_down(val,offset);
return val;
}
__inline__ __device__
int blockReduceSum(int val) {
static __shared__ int shared[32]; // Shared mem for 32 partial sums
int lane = threadIdx.x % warpSize;
int wid = threadIdx.x / warpSize;
val = warpReduceSum(val); // Each warp performs partial reduction
if (lane==0) shared[wid]=val; // Write reduced value to shared memory
__syncthreads(); // Wait for all partial reductions
//read from shared memory only if that warp existed
val = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
if (wid==0) val = warpReduceSum(val); //Final reduce within first warp
return val;
}
__global__ void hough_transform(int result_p, int *result, float min_rad, float max_rad) {
float dx, dy;
int radius_index = threadIdx.x;
float rad = min_rad + (float)radius_index * (max_rad - min_rad) / (float)RAD_COUNT;
int x = MARGIN + blockIdx.x;
int y = MARGIN + blockIdx.y;
//int width = MARGIN + gridDim.x;
int local_acc = int(0);
int phi;
#pragma unroll
for (phi = -120; phi < 120; phi++) {
float phi_f = (float)phi * PI / 120.0;
dx = rad * __cosf(phi_f);
dy = rad * __sinf(phi_f);
if (tex2D(abs_tex, x + dx, y + dy) > 20) {
float grad = tex2D(phi_tex, x + dx, y + dy) - phi_f;
if (-PI / 12.0 < grad && grad < PI / 12.0)
local_acc++;
}
}
local_acc = blockReduceSum(local_acc * local_acc * local_acc);
if (threadIdx.x == 0)
result[result_p * y + x] = local_acc;
}
//#include <stdio.h>
extern "C" void cu_hough(int img_w, int img_h, int abs_p, void *gm_abs, int phi_p, void *gm_phi, int hough_p, void *gm_hough, float min_rad, float max_rad)
{
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);
hipChannelFormatDesc desc = hipCreateChannelDesc<float>();
hipBindTexture2D(NULL, abs_tex, gm_abs, desc, img_w, img_h, abs_p * 4);
hipBindTexture2D(NULL, phi_tex, gm_phi, desc, img_w, img_h, phi_p * 4);
hipMemset(gm_hough, 0, img_w * img_h * sizeof(int));
hipEventRecord(start);
dim3 grid(img_w - (2 * MARGIN), img_h - (2 * MARGIN));
dim3 threads(RAD_COUNT);
hipLaunchKernelGGL(( hough_transform), dim3(grid), dim3(threads), 0, 0, hough_p, (int *)gm_hough, min_rad, max_rad);
hipEventRecord(stop);
hipEventSynchronize(stop);
float elapsed_time = 0;
hipEventElapsedTime(&elapsed_time, start, stop);
//fprintf(stderr, "Took %f ms to compute Hough-Transform\n", elapsed_time);
}
__global__ void center_detection(int img_w, int img_h, int *accumulator) {
const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y;
const int lane = (threadIdx.x + threadIdx.y * blockDim.x) % warpSize;
//check for uint type
__shared__ float block_x, block_y, block_c;
float center_x = 0,
center_y = 0,
c = 0;
//intit shared variable
if (threadIdx.x == 0 && threadIdx.y == 0)
block_x = 0; block_y = 0, block_c = 0;
__syncthreads();
//warp reduction
unsigned int cond = accumulator[y * img_w + x] > (1 << 22);
c = __popc(__ballot(cond));
center_x = warpReduceSum(cond * x);
center_y = warpReduceSum(cond * y);
//block reduction
if (lane == 0) {
atomicAdd(&block_x, center_x);
atomicAdd(&block_y, center_y);
atomicAdd(&block_c, c);
}
__syncthreads();
if (threadIdx.x == 0 && threadIdx.y == 0 && c != 0) {
accumulator[2*(blockIdx.x + gridDim.x * blockIdx.y)] = block_x/block_c;
accumulator[2*(blockIdx.x + gridDim.x * blockIdx.y) + 1] = block_y/block_c;
}
}
/**
*
*
**/
__global__ void arithmetic_reduce(int *in, int2 *out) {
int sumX = 0, sumY = 0;
__shared__ int cX, cY;
if (threadIdx.x == 0)
cX = 0, cY = 0;
sumX = blockReduceSum(in[2 * threadIdx.x]);
sumY = blockReduceSum(in[2 * threadIdx.x + 1]);
if (in[2 * threadIdx.x] > 0) {
atomicAdd(&cX, 1);
}
if (in[2 * threadIdx.x + 1] > 0) {
atomicAdd(&cY, 1);
}
__syncthreads();
if(threadIdx.x == 0) {
out->x = sumX/cX;
out->y = sumY/cY;
}
}
/**
*
* Thread size is limited to 1024. This limits the potential image dimensions if we keep
* the block size of 8 * 8 = 64!
*
**/
extern "C" void cu_center_detection(int img_w, int img_h, void *gm_hough, int *center_x, int *center_y) {
const int N = 8;
dim3 blocks(img_w / N, img_h / N);
dim3 threads(N, N);
int2 center = make_int2(0,0);
int2 *gm_center;
hipLaunchKernelGGL(( center_detection), dim3(blocks), dim3(threads), 0, 0, img_w, img_h, (int *) gm_hough);
dim3 red_threads((img_w / N) * (img_h / N));
hipMalloc(&gm_center, sizeof(int2));
hipLaunchKernelGGL(( arithmetic_reduce), dim3(1), dim3(red_threads), 0, 0, (int *)gm_hough, gm_center);
hipMemcpy(¢er, gm_center, sizeof(int2), hipMemcpyDeviceToHost);
*center_x = center.x;
*center_y = center.y;
}
| cacebb98c745ab46b924915b83a551e6578e1a3a.cu | extern "C" {
#include "hough.h"
#include <stdint.h>
}
//#include <cub/cub.cuh>
/****** PARAMETERS ********/
#define MARGIN 20
// needs to be a power of 2 as well
//#define STEP_SIZE 2
#define RAD_COUNT 32
// diff should be a multiple of 2 to exploit warp size efficiently (> 32)
//#define MIN_RAD 6
//#define MAX_RAD 500//262
#define PI 3.141592654
//#define THREAD_COUNT (MAX_RAD - MIN_RAD)
//#define WARP_SIZE 32
texture<float, cudaTextureType2D> phi_tex;
texture<float, cudaTextureType2D> abs_tex;
/*
* Warp reduce sum: http://devblogs.nvidia.com/parallelforall/faster-parallel-reductions-kepler/
**/
__inline__ __device__
int warpReduceSum(int val) {
for (int offset = warpSize / 2; offset > 0; offset /= 2)
val += __shfl_down(val,offset);
return val;
}
__inline__ __device__
int blockReduceSum(int val) {
static __shared__ int shared[32]; // Shared mem for 32 partial sums
int lane = threadIdx.x % warpSize;
int wid = threadIdx.x / warpSize;
val = warpReduceSum(val); // Each warp performs partial reduction
if (lane==0) shared[wid]=val; // Write reduced value to shared memory
__syncthreads(); // Wait for all partial reductions
//read from shared memory only if that warp existed
val = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
if (wid==0) val = warpReduceSum(val); //Final reduce within first warp
return val;
}
__global__ void hough_transform(int result_p, int *result, float min_rad, float max_rad) {
float dx, dy;
int radius_index = threadIdx.x;
float rad = min_rad + (float)radius_index * (max_rad - min_rad) / (float)RAD_COUNT;
int x = MARGIN + blockIdx.x;
int y = MARGIN + blockIdx.y;
//int width = MARGIN + gridDim.x;
int local_acc = int(0);
int phi;
#pragma unroll
for (phi = -120; phi < 120; phi++) {
float phi_f = (float)phi * PI / 120.0;
dx = rad * __cosf(phi_f);
dy = rad * __sinf(phi_f);
if (tex2D(abs_tex, x + dx, y + dy) > 20) {
float grad = tex2D(phi_tex, x + dx, y + dy) - phi_f;
if (-PI / 12.0 < grad && grad < PI / 12.0)
local_acc++;
}
}
local_acc = blockReduceSum(local_acc * local_acc * local_acc);
if (threadIdx.x == 0)
result[result_p * y + x] = local_acc;
}
//#include <stdio.h>
extern "C" void cu_hough(int img_w, int img_h, int abs_p, void *gm_abs, int phi_p, void *gm_phi, int hough_p, void *gm_hough, float min_rad, float max_rad)
{
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaChannelFormatDesc desc = cudaCreateChannelDesc<float>();
cudaBindTexture2D(NULL, abs_tex, gm_abs, desc, img_w, img_h, abs_p * 4);
cudaBindTexture2D(NULL, phi_tex, gm_phi, desc, img_w, img_h, phi_p * 4);
cudaMemset(gm_hough, 0, img_w * img_h * sizeof(int));
cudaEventRecord(start);
dim3 grid(img_w - (2 * MARGIN), img_h - (2 * MARGIN));
dim3 threads(RAD_COUNT);
hough_transform<<<grid, threads>>>(hough_p, (int *)gm_hough, min_rad, max_rad);
cudaEventRecord(stop);
cudaEventSynchronize(stop);
float elapsed_time = 0;
cudaEventElapsedTime(&elapsed_time, start, stop);
//fprintf(stderr, "Took %f ms to compute Hough-Transform\n", elapsed_time);
}
__global__ void center_detection(int img_w, int img_h, int *accumulator) {
const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y;
const int lane = (threadIdx.x + threadIdx.y * blockDim.x) % warpSize;
//check for uint type
__shared__ float block_x, block_y, block_c;
float center_x = 0,
center_y = 0,
c = 0;
//intit shared variable
if (threadIdx.x == 0 && threadIdx.y == 0)
block_x = 0; block_y = 0, block_c = 0;
__syncthreads();
//warp reduction
unsigned int cond = accumulator[y * img_w + x] > (1 << 22);
c = __popc(__ballot(cond));
center_x = warpReduceSum(cond * x);
center_y = warpReduceSum(cond * y);
//block reduction
if (lane == 0) {
atomicAdd(&block_x, center_x);
atomicAdd(&block_y, center_y);
atomicAdd(&block_c, c);
}
__syncthreads();
if (threadIdx.x == 0 && threadIdx.y == 0 && c != 0) {
accumulator[2*(blockIdx.x + gridDim.x * blockIdx.y)] = block_x/block_c;
accumulator[2*(blockIdx.x + gridDim.x * blockIdx.y) + 1] = block_y/block_c;
}
}
/**
*
*
**/
__global__ void arithmetic_reduce(int *in, int2 *out) {
int sumX = 0, sumY = 0;
__shared__ int cX, cY;
if (threadIdx.x == 0)
cX = 0, cY = 0;
sumX = blockReduceSum(in[2 * threadIdx.x]);
sumY = blockReduceSum(in[2 * threadIdx.x + 1]);
if (in[2 * threadIdx.x] > 0) {
atomicAdd(&cX, 1);
}
if (in[2 * threadIdx.x + 1] > 0) {
atomicAdd(&cY, 1);
}
__syncthreads();
if(threadIdx.x == 0) {
out->x = sumX/cX;
out->y = sumY/cY;
}
}
/**
*
* Thread size is limited to 1024. This limits the potential image dimensions if we keep
* the block size of 8 * 8 = 64!
*
**/
extern "C" void cu_center_detection(int img_w, int img_h, void *gm_hough, int *center_x, int *center_y) {
const int N = 8;
dim3 blocks(img_w / N, img_h / N);
dim3 threads(N, N);
int2 center = make_int2(0,0);
int2 *gm_center;
center_detection<<<blocks, threads>>>(img_w, img_h, (int *) gm_hough);
dim3 red_threads((img_w / N) * (img_h / N));
cudaMalloc(&gm_center, sizeof(int2));
arithmetic_reduce<<<1, red_threads>>>((int *)gm_hough, gm_center);
cudaMemcpy(¢er, gm_center, sizeof(int2), cudaMemcpyDeviceToHost);
*center_x = center.x;
*center_y = center.y;
}
|
2b2401c7ce44da0dd30d94d611ba7c3376e2f06b.hip | // !!! This is a file automatically generated by hipify!!!
/*
* Copyright (c) 2019, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <graph_contracting_visitor.hxx>
namespace nvgraph
{
//------------------------- Graph Contraction: ----------------------
//
CsrGraph<int>* contract_graph_csr_sum(CsrGraph<int>& graph,
int* pV, size_t n,
hipStream_t stream,
const int& VCombine,
const int& VReduce,
const int& ECombine,
const int& EReduce)
{
return contract_from_aggregates_t<int, double, SemiRingFctrSelector<Sum, double>::FctrType >(graph, pV, n, stream,
static_cast<SemiRingFunctorTypes>(VCombine),
static_cast<SemiRingFunctorTypes>(VReduce),
static_cast<SemiRingFunctorTypes>(ECombine),
static_cast<SemiRingFunctorTypes>(EReduce));
}
}
| 2b2401c7ce44da0dd30d94d611ba7c3376e2f06b.cu | /*
* Copyright (c) 2019, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <graph_contracting_visitor.hxx>
namespace nvgraph
{
//------------------------- Graph Contraction: ----------------------
//
CsrGraph<int>* contract_graph_csr_sum(CsrGraph<int>& graph,
int* pV, size_t n,
cudaStream_t stream,
const int& VCombine,
const int& VReduce,
const int& ECombine,
const int& EReduce)
{
return contract_from_aggregates_t<int, double, SemiRingFctrSelector<Sum, double>::FctrType >(graph, pV, n, stream,
static_cast<SemiRingFunctorTypes>(VCombine),
static_cast<SemiRingFunctorTypes>(VReduce),
static_cast<SemiRingFunctorTypes>(ECombine),
static_cast<SemiRingFunctorTypes>(EReduce));
}
}
|
2d4aec43ac93e880a7ac5cc8ea3b0b88039e4565.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
/*
-- MAGMA (version 1.6.1) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
@date January 2015
@generated from zlaswp_batched.cu normal z -> s, Fri Jan 30 19:00:10 2015
@author Azzam Haidar
@author Tingxing Dong
*/
#include "common_magma.h"
#include "batched_kernel_param.h"
#define BLK_SIZE 256
// SWP_WIDTH is number of threads in a block
// 64 and 256 are better on Kepler;
extern __shared__ float shared_data[];
//=================================================================================================
static __device__
void slaswp_rowparallel_devfunc(
int n, int width, int height,
float *dA, int lda,
float *dout, int ldo,
magma_int_t* pivinfo)
{
//int height = k2- k1;
//int height = blockDim.x;
unsigned int tid = threadIdx.x;
dA += SWP_WIDTH * blockIdx.x * lda;
dout += SWP_WIDTH * blockIdx.x * ldo;
float *sdata = shared_data;
if(blockIdx.x == gridDim.x -1)
{
width = n - blockIdx.x * SWP_WIDTH;
}
if(tid < height)
{
int mynewroworig = pivinfo[tid]-1; //-1 to get the index in C
int itsreplacement = pivinfo[mynewroworig] -1 ; //-1 to get the index in C
#pragma unroll
for(int i=0; i<width; i++)
{
sdata[ tid + i * height ] = dA[ mynewroworig + i * lda ];
dA[ mynewroworig + i * lda ] = dA[ itsreplacement + i * lda ];
}
}
__syncthreads();
if(tid < height)
{
// copy back the upper swapped portion of A to dout
#pragma unroll
for(int i=0; i<width; i++)
{
dout[tid + i * ldo] = sdata[tid + i * height];
}
}
}
//=================================================================================================
// parallel swap the swaped dA(1:nb,i:n) is stored in dout
//=================================================================================================
__global__
void slaswp_rowparallel_kernel(
int n, int width, int height,
float *dinput, int ldi,
float *doutput, int ldo,
magma_int_t* pivinfo)
{
slaswp_rowparallel_devfunc(n, width, height, dinput, ldi, doutput, ldo, pivinfo);
}
//=================================================================================================
__global__
void slaswp_rowparallel_kernel_batched(
int n, int width, int height,
float **input_array, int ldi,
float **output_array, int ldo,
magma_int_t** pivinfo_array)
{
int batchid = blockIdx.z;
slaswp_rowparallel_devfunc(n, width, height, input_array[batchid], ldi, output_array[batchid], ldo, pivinfo_array[batchid]);
}
//=================================================================================================
//=================================================================================================
extern "C" void
magma_slaswp_rowparallel_batched( magma_int_t n,
float** input_array, magma_int_t ldi,
float** output_array, magma_int_t ldo,
magma_int_t k1, magma_int_t k2,
magma_int_t **pivinfo_array,
magma_int_t batchCount, magma_queue_t queue)
{
if(n == 0 ) return ;
int height = k2-k1;
if( height > 1024)
{
printf(" n=%d > 1024, not supported \n", n);
}
int blocks = (n-1)/ SWP_WIDTH + 1;
dim3 grid(blocks, 1, batchCount);
if( n < SWP_WIDTH)
{
hipLaunchKernelGGL(( slaswp_rowparallel_kernel_batched), dim3(grid), dim3(height), sizeof(float) * height * n, queue ,
n, n, height, input_array, ldi, output_array, ldo, pivinfo_array );
}
else
{
hipLaunchKernelGGL(( slaswp_rowparallel_kernel_batched), dim3(grid), dim3(height), sizeof(float) * height * SWP_WIDTH , queue ,
n, SWP_WIDTH, height, input_array, ldi, output_array, ldo, pivinfo_array );
}
}
//=================================================================================================
//=================================================================================================
extern "C" void
magma_slaswp_rowparallel_q( magma_int_t n,
float* input, magma_int_t ldi,
float* output, magma_int_t ldo,
magma_int_t k1, magma_int_t k2,
magma_int_t *pivinfo,
magma_queue_t queue)
{
if(n == 0 ) return ;
int height = k2-k1;
if( height > MAX_NTHREADS)
{
printf(" height=%d > %d, magma_slaswp_rowparallel_q not supported \n", n,MAX_NTHREADS);
}
int blocks = (n-1)/ SWP_WIDTH + 1;
dim3 grid(blocks, 1, 1);
if( n < SWP_WIDTH)
{
hipLaunchKernelGGL(( slaswp_rowparallel_kernel), dim3(grid), dim3(height), sizeof(float) * height * n, queue ,
n, n, height, input, ldi, output, ldo, pivinfo );
}
else
{
hipLaunchKernelGGL(( slaswp_rowparallel_kernel), dim3(grid), dim3(height), sizeof(float) * height * SWP_WIDTH , queue ,
n, SWP_WIDTH, height, input, ldi, output, ldo, pivinfo );
}
}
//=================================================================================================
extern "C" void
magma_slaswp_rowparallel( magma_int_t n, float* input, magma_int_t ldi,
float* output, magma_int_t ldo,
magma_int_t k1, magma_int_t k2,
magma_int_t *pivinfo)
{
magma_slaswp_rowparallel_q(n, input, ldi, output, ldo, k1, k2, pivinfo, magma_stream);
}
//=================================================================================================
//=================================================================================================
// serial swap that does swapping one row by one row
//=================================================================================================
__global__ void slaswp_rowserial_kernel_batched( int n, float **dA_array, int lda, int k1, int k2, magma_int_t** ipiv_array )
{
float* dA = dA_array[blockIdx.z];
magma_int_t *d_ipiv = ipiv_array[blockIdx.z];
unsigned int tid = threadIdx.x + blockDim.x*blockIdx.x;
k1--;
k2--;
if( tid < n) {
float A1;
for( int i1 = k1; i1 < k2; i1++ )
{
int i2 = d_ipiv[i1] - 1; // Fortran index, switch i1 and i2
if( i2 != i1)
{
A1 = dA[i1 + tid * lda];
dA[i1 + tid * lda] = dA[i2 + tid * lda];
dA[i2 + tid * lda] = A1;
}
}
}
}
//=================================================================================================
// serial swap that does swapping one row by one row, similar to LAPACK
// K1, K2 are in Fortran indexing
//=================================================================================================
extern "C" void
magma_slaswp_rowserial_batched(magma_int_t n, float** dA_array, magma_int_t lda,
magma_int_t k1, magma_int_t k2,
magma_int_t **ipiv_array,
magma_int_t batchCount, magma_queue_t queue)
{
if(n == 0 ) return ;
int blocks = (n-1)/ BLK_SIZE + 1;
dim3 grid(blocks, 1, batchCount);
hipLaunchKernelGGL(( slaswp_rowserial_kernel_batched), dim3(grid), dim3(max(BLK_SIZE, n)), 0, queue ,
n, dA_array, lda, k1, k2, ipiv_array);
}
//=================================================================================================
// serial swap that does swapping one column by one column
//=================================================================================================
__global__ void slaswp_columnserial_kernel_batched( int n, float **dA_array, int lda, int k1, int k2, magma_int_t** ipiv_array )
{
float* dA = dA_array[blockIdx.z];
magma_int_t *d_ipiv = ipiv_array[blockIdx.z];
unsigned int tid = threadIdx.x + blockDim.x*blockIdx.x;
k1--;
k2--;
if( k1 < 0 || k2 < 0 ) return;
if( tid < n) {
float A1;
if(k1 <= k2)
{
for( int i1 = k1; i1 <= k2; i1++ )
{
int i2 = d_ipiv[i1] - 1; // Fortran index, switch i1 and i2
if( i2 != i1)
{
A1 = dA[i1 * lda + tid];
dA[i1 * lda + tid] = dA[i2 * lda + tid];
dA[i2 * lda + tid] = A1;
}
}
}else
{
for( int i1 = k1; i1 >= k2; i1-- )
{
int i2 = d_ipiv[i1] - 1; // Fortran index, switch i1 and i2
if( i2 != i1)
{
A1 = dA[i1 * lda + tid];
dA[i1 * lda + tid] = dA[i2 * lda + tid];
dA[i2 * lda + tid] = A1;
}
}
}
}
}
//=================================================================================================
// serial swap that does swapping one column by one column
// K1, K2 are in Fortran indexing
//=================================================================================================
extern "C" void
magma_slaswp_columnserial_batched(magma_int_t n, float** dA_array, magma_int_t lda,
magma_int_t k1, magma_int_t k2,
magma_int_t **ipiv_array,
magma_int_t batchCount, magma_queue_t queue)
{
if(n == 0 ) return ;
int blocks = (n-1)/ BLK_SIZE + 1;
dim3 grid(blocks, 1, batchCount);
hipLaunchKernelGGL(( slaswp_columnserial_kernel_batched), dim3(grid), dim3(min(BLK_SIZE, n)), 0, queue ,
n, dA_array, lda, k1, k2, ipiv_array);
}
| 2d4aec43ac93e880a7ac5cc8ea3b0b88039e4565.cu | /*
-- MAGMA (version 1.6.1) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
@date January 2015
@generated from zlaswp_batched.cu normal z -> s, Fri Jan 30 19:00:10 2015
@author Azzam Haidar
@author Tingxing Dong
*/
#include "common_magma.h"
#include "batched_kernel_param.h"
#define BLK_SIZE 256
// SWP_WIDTH is number of threads in a block
// 64 and 256 are better on Kepler;
extern __shared__ float shared_data[];
//=================================================================================================
static __device__
void slaswp_rowparallel_devfunc(
int n, int width, int height,
float *dA, int lda,
float *dout, int ldo,
magma_int_t* pivinfo)
{
//int height = k2- k1;
//int height = blockDim.x;
unsigned int tid = threadIdx.x;
dA += SWP_WIDTH * blockIdx.x * lda;
dout += SWP_WIDTH * blockIdx.x * ldo;
float *sdata = shared_data;
if(blockIdx.x == gridDim.x -1)
{
width = n - blockIdx.x * SWP_WIDTH;
}
if(tid < height)
{
int mynewroworig = pivinfo[tid]-1; //-1 to get the index in C
int itsreplacement = pivinfo[mynewroworig] -1 ; //-1 to get the index in C
#pragma unroll
for(int i=0; i<width; i++)
{
sdata[ tid + i * height ] = dA[ mynewroworig + i * lda ];
dA[ mynewroworig + i * lda ] = dA[ itsreplacement + i * lda ];
}
}
__syncthreads();
if(tid < height)
{
// copy back the upper swapped portion of A to dout
#pragma unroll
for(int i=0; i<width; i++)
{
dout[tid + i * ldo] = sdata[tid + i * height];
}
}
}
//=================================================================================================
// parallel swap the swaped dA(1:nb,i:n) is stored in dout
//=================================================================================================
__global__
void slaswp_rowparallel_kernel(
int n, int width, int height,
float *dinput, int ldi,
float *doutput, int ldo,
magma_int_t* pivinfo)
{
slaswp_rowparallel_devfunc(n, width, height, dinput, ldi, doutput, ldo, pivinfo);
}
//=================================================================================================
__global__
void slaswp_rowparallel_kernel_batched(
int n, int width, int height,
float **input_array, int ldi,
float **output_array, int ldo,
magma_int_t** pivinfo_array)
{
int batchid = blockIdx.z;
slaswp_rowparallel_devfunc(n, width, height, input_array[batchid], ldi, output_array[batchid], ldo, pivinfo_array[batchid]);
}
//=================================================================================================
//=================================================================================================
extern "C" void
magma_slaswp_rowparallel_batched( magma_int_t n,
float** input_array, magma_int_t ldi,
float** output_array, magma_int_t ldo,
magma_int_t k1, magma_int_t k2,
magma_int_t **pivinfo_array,
magma_int_t batchCount, magma_queue_t queue)
{
if(n == 0 ) return ;
int height = k2-k1;
if( height > 1024)
{
printf(" n=%d > 1024, not supported \n", n);
}
int blocks = (n-1)/ SWP_WIDTH + 1;
dim3 grid(blocks, 1, batchCount);
if( n < SWP_WIDTH)
{
slaswp_rowparallel_kernel_batched<<<grid, height, sizeof(float) * height * n, queue >>>
( n, n, height, input_array, ldi, output_array, ldo, pivinfo_array );
}
else
{
slaswp_rowparallel_kernel_batched<<< grid, height, sizeof(float) * height * SWP_WIDTH , queue >>>
(n, SWP_WIDTH, height, input_array, ldi, output_array, ldo, pivinfo_array );
}
}
//=================================================================================================
//=================================================================================================
extern "C" void
magma_slaswp_rowparallel_q( magma_int_t n,
float* input, magma_int_t ldi,
float* output, magma_int_t ldo,
magma_int_t k1, magma_int_t k2,
magma_int_t *pivinfo,
magma_queue_t queue)
{
if(n == 0 ) return ;
int height = k2-k1;
if( height > MAX_NTHREADS)
{
printf(" height=%d > %d, magma_slaswp_rowparallel_q not supported \n", n,MAX_NTHREADS);
}
int blocks = (n-1)/ SWP_WIDTH + 1;
dim3 grid(blocks, 1, 1);
if( n < SWP_WIDTH)
{
slaswp_rowparallel_kernel<<<grid, height, sizeof(float) * height * n, queue >>>
( n, n, height, input, ldi, output, ldo, pivinfo );
}
else
{
slaswp_rowparallel_kernel<<< grid, height, sizeof(float) * height * SWP_WIDTH , queue >>>
(n, SWP_WIDTH, height, input, ldi, output, ldo, pivinfo );
}
}
//=================================================================================================
extern "C" void
magma_slaswp_rowparallel( magma_int_t n, float* input, magma_int_t ldi,
float* output, magma_int_t ldo,
magma_int_t k1, magma_int_t k2,
magma_int_t *pivinfo)
{
magma_slaswp_rowparallel_q(n, input, ldi, output, ldo, k1, k2, pivinfo, magma_stream);
}
//=================================================================================================
//=================================================================================================
// serial swap that does swapping one row by one row
//=================================================================================================
__global__ void slaswp_rowserial_kernel_batched( int n, float **dA_array, int lda, int k1, int k2, magma_int_t** ipiv_array )
{
float* dA = dA_array[blockIdx.z];
magma_int_t *d_ipiv = ipiv_array[blockIdx.z];
unsigned int tid = threadIdx.x + blockDim.x*blockIdx.x;
k1--;
k2--;
if( tid < n) {
float A1;
for( int i1 = k1; i1 < k2; i1++ )
{
int i2 = d_ipiv[i1] - 1; // Fortran index, switch i1 and i2
if( i2 != i1)
{
A1 = dA[i1 + tid * lda];
dA[i1 + tid * lda] = dA[i2 + tid * lda];
dA[i2 + tid * lda] = A1;
}
}
}
}
//=================================================================================================
// serial swap that does swapping one row by one row, similar to LAPACK
// K1, K2 are in Fortran indexing
//=================================================================================================
extern "C" void
magma_slaswp_rowserial_batched(magma_int_t n, float** dA_array, magma_int_t lda,
magma_int_t k1, magma_int_t k2,
magma_int_t **ipiv_array,
magma_int_t batchCount, magma_queue_t queue)
{
if(n == 0 ) return ;
int blocks = (n-1)/ BLK_SIZE + 1;
dim3 grid(blocks, 1, batchCount);
slaswp_rowserial_kernel_batched<<< grid, max(BLK_SIZE, n), 0, queue >>>(
n, dA_array, lda, k1, k2, ipiv_array);
}
//=================================================================================================
// serial swap that does swapping one column by one column
//=================================================================================================
__global__ void slaswp_columnserial_kernel_batched( int n, float **dA_array, int lda, int k1, int k2, magma_int_t** ipiv_array )
{
float* dA = dA_array[blockIdx.z];
magma_int_t *d_ipiv = ipiv_array[blockIdx.z];
unsigned int tid = threadIdx.x + blockDim.x*blockIdx.x;
k1--;
k2--;
if( k1 < 0 || k2 < 0 ) return;
if( tid < n) {
float A1;
if(k1 <= k2)
{
for( int i1 = k1; i1 <= k2; i1++ )
{
int i2 = d_ipiv[i1] - 1; // Fortran index, switch i1 and i2
if( i2 != i1)
{
A1 = dA[i1 * lda + tid];
dA[i1 * lda + tid] = dA[i2 * lda + tid];
dA[i2 * lda + tid] = A1;
}
}
}else
{
for( int i1 = k1; i1 >= k2; i1-- )
{
int i2 = d_ipiv[i1] - 1; // Fortran index, switch i1 and i2
if( i2 != i1)
{
A1 = dA[i1 * lda + tid];
dA[i1 * lda + tid] = dA[i2 * lda + tid];
dA[i2 * lda + tid] = A1;
}
}
}
}
}
//=================================================================================================
// serial swap that does swapping one column by one column
// K1, K2 are in Fortran indexing
//=================================================================================================
extern "C" void
magma_slaswp_columnserial_batched(magma_int_t n, float** dA_array, magma_int_t lda,
magma_int_t k1, magma_int_t k2,
magma_int_t **ipiv_array,
magma_int_t batchCount, magma_queue_t queue)
{
if(n == 0 ) return ;
int blocks = (n-1)/ BLK_SIZE + 1;
dim3 grid(blocks, 1, batchCount);
slaswp_columnserial_kernel_batched<<< grid, min(BLK_SIZE, n), 0, queue >>>(
n, dA_array, lda, k1, k2, ipiv_array);
}
|
cd5c19adb61c7c7ef85efcb9d68e5f89757845ce.hip | // !!! This is a file automatically generated by hipify!!!
#include "THHUNN.h"
#include "im2col.h"
void THNN_CudaSpatialFullConvolution_updateOutput(
THCState *state,
THCudaTensor *input,
THCudaTensor *output,
THCudaTensor *weight,
THCudaTensor *bias,
THCudaTensor *columns,
THCudaTensor *ones,
int kW, int kH,
int dW, int dH,
int padW, int padH,
int adjW, int adjH)
{
int nInputPlane = THCudaTensor_size(state, weight, 0);
int nOutputPlane = THCudaTensor_size(state, weight, 1);
THCUNN_assertSameGPU(state, 6, input, output, weight,
bias, columns, ones);
THArgCheck(input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D (batch mode) tensor is expected");
int batch = 1;
if (input->nDimension == 3) {
THArgCheck(input->size[0] == nInputPlane, 2, "input channels and nInputPlane dont match");
// Force batch
batch = 0;
THCudaTensor_resize4d(state, input, 1, input->size[0], input->size[1], input->size[2]);
} else {
THArgCheck(input->size[1] == nInputPlane, 2, "input channels and nInputPlane dont match");
}
long inputWidth = input->size[3];
long inputHeight = input->size[2];
long outputWidth = (inputWidth - 1) * dW - 2*padW + kW + adjW;
long outputHeight = (inputHeight - 1) * dH - 2*padH + kH + adjH;
// Batch size + input planes
long batchSize = input->size[0];
// Resize output
THCudaTensor_resize4d(state, output, batchSize, nOutputPlane, outputHeight, outputWidth);
// Resize temporary columns
THCudaTensor_resize2d(state, columns, nOutputPlane*kW*kH, inputHeight*inputWidth);
// Define a buffer of ones, for bias accumulation
// Note: this buffer can be shared with other modules, it only ever gets increased,
// and always contains ones.
if (ones->nDimension != 2 || ones->size[0]*ones->size[1] < outputHeight*outputWidth) {
// Resize plane and fill with ones...
THCudaTensor_resize2d(state, ones, outputHeight, outputWidth);
THCudaTensor_fill(state, ones, 1);
}
// Helpers
THCudaTensor *input_n = THCudaTensor_new(state);
THCudaTensor *output_n = THCudaTensor_new(state);
// For each elt in batch, do:
for (int elt = 0; elt < batchSize; elt ++) {
// Matrix mulitply per output:
THCudaTensor_select(state, input_n, input, 0, elt);
THCudaTensor_select(state, output_n, output, 0, elt);
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m = weight->size[1] * weight->size[2] * weight->size[3];
long n = columns->size[1];
long k = weight->size[0];
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
'n', 't',
n, m, k,
1,
THCudaTensor_data(state, input_n), n,
THCudaTensor_data(state, weight), m,
0,
THCudaTensor_data(state, columns), n
);
// Unpack columns back into input:
col2im(
THCState_getCurrentStream(state),
THCudaTensor_data(state, columns),
nOutputPlane, outputHeight, outputWidth, kH, kW, padH, padW, dH, dW,
1, 1, THCudaTensor_data(state, output_n)
);
// Do Bias after:
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m_ = nOutputPlane;
long n_ = outputHeight * outputWidth;
long k_ = 1;
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
't', 'n',
n_, m_, k_,
1,
THCudaTensor_data(state, ones), k_,
THCudaTensor_data(state, bias), k_,
1,
THCudaTensor_data(state, output_n), n_
);
}
// Free
THCudaTensor_free(state, input_n);
THCudaTensor_free(state, output_n);
// Resize output
if (batch == 0) {
THCudaTensor_resize3d(state, output, nOutputPlane, outputHeight, outputWidth);
THCudaTensor_resize3d(state, input, nInputPlane, inputHeight, inputWidth);
}
}
void THNN_CudaSpatialFullConvolution_updateGradInput(
THCState *state,
THCudaTensor *input,
THCudaTensor *gradOutput,
THCudaTensor *gradInput,
THCudaTensor *weight,
THCudaTensor *gradColumns,
int kW, int kH,
int dW, int dH,
int padW, int padH,
int adjW, int adjH)
{
int nInputPlane = THCudaTensor_size(state, weight, 0);
int nOutputPlane = THCudaTensor_size(state, weight, 1);
THCUNN_assertSameGPU(state, 5, input, gradOutput, weight,
gradColumns, gradInput);
THArgCheck(input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D (batch mode) tensor is expected");
int batch = 1;
if (input->nDimension == 3) {
// Force batch
batch = 0;
THCudaTensor_resize4d(state, input, 1, input->size[0], input->size[1], input->size[2]);
THCudaTensor_resize4d(state, gradOutput, 1, gradOutput->size[0], gradOutput->size[1], gradOutput->size[2]);
}
long inputWidth = input->size[3];
long inputHeight = input->size[2];
long outputWidth = (inputWidth - 1) * dW - 2*padW + kW + adjW;
long outputHeight = (inputHeight - 1) * dH - 2*padH + kH + adjH;
// Batch size + input planes
long batchSize = input->size[0];
// Resize output
THCudaTensor_resize4d(state, gradInput, batchSize, nInputPlane, inputHeight, inputWidth);
// Resize temporary columns
THCudaTensor_resize2d(state, gradColumns, nOutputPlane*kW*kH, inputHeight*inputWidth);
// Helpers
THCudaTensor *gradInput_n = THCudaTensor_new(state);
THCudaTensor *gradOutput_n = THCudaTensor_new(state);
// For each elt in batch, do:
for (int elt = 0; elt < batchSize; elt ++) {
// Matrix mulitply per sample:
THCudaTensor_select(state, gradInput_n, gradInput, 0, elt);
THCudaTensor_select(state, gradOutput_n, gradOutput, 0, elt);
// Extract columns:
im2col(
THCState_getCurrentStream(state),
THCudaTensor_data(state, gradOutput_n),
nOutputPlane, outputHeight, outputWidth, kH, kW, padH, padW, dH, dW,
1, 1, THCudaTensor_data(state, gradColumns)
);
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m = weight->size[0];
long n = gradColumns->size[1];
long k = weight->size[1] * weight->size[2] * weight->size[3];
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
'n', 'n',
n, m, k,
1,
THCudaTensor_data(state, gradColumns), n,
THCudaTensor_data(state, weight), k,
0,
THCudaTensor_data(state, gradInput_n), n
);
}
// Free
THCudaTensor_free(state, gradInput_n);
THCudaTensor_free(state, gradOutput_n);
// Resize output
if (batch == 0) {
THCudaTensor_resize3d(state, gradOutput, nOutputPlane, outputHeight, outputWidth);
THCudaTensor_resize3d(state, input, nInputPlane, inputHeight, inputWidth);
THCudaTensor_resize3d(state, gradInput, nInputPlane, inputHeight, inputWidth);
}
}
void THNN_CudaSpatialFullConvolution_accGradParameters(
THCState *state,
THCudaTensor *input,
THCudaTensor *gradOutput,
THCudaTensor *gradWeight,
THCudaTensor *gradBias,
THCudaTensor *columns,
THCudaTensor *ones,
int kW, int kH,
int dW, int dH,
int padW, int padH,
int adjW, int adjH,
float scale)
{
int nInputPlane = THCudaTensor_size(state, gradWeight, 0);
int nOutputPlane = THCudaTensor_size(state, gradWeight, 1);
THCUNN_assertSameGPU(state, 6, input, gradOutput, gradWeight,
gradBias, columns, ones);
THArgCheck(input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D (batch mode) tensor is expected");
int batch = 1;
if (input->nDimension == 3) {
// Force batch
batch = 0;
THCudaTensor_resize4d(state, input, 1, input->size[0], input->size[1], input->size[2]);
THCudaTensor_resize4d(state, gradOutput, 1, gradOutput->size[0], gradOutput->size[1], gradOutput->size[2]);
}
long inputWidth = input->size[3];
long inputHeight = input->size[2];
long outputWidth = (inputWidth - 1) * dW - 2*padW + kW + adjW;
long outputHeight = (inputHeight - 1) * dH - 2*padH + kH + adjH;
// Batch size + input planes
long batchSize = input->size[0];
// Define a buffer of ones, for bias accumulation
if (ones->nDimension != 2 || ones->size[0]*ones->size[1] < outputHeight*outputWidth) {
// Resize plane and fill with ones...
THCudaTensor_resize2d(state, ones, outputHeight, outputWidth);
THCudaTensor_fill(state, ones, 1);
}
// Resize temporary columns
THCudaTensor_resize2d(state, columns, nOutputPlane*kW*kH, inputHeight*inputWidth);
// Helpers
THCudaTensor *input_n = THCudaTensor_new(state);
THCudaTensor *gradOutput_n = THCudaTensor_new(state);
// For each elt in batch, do:
for (int elt = 0; elt < batchSize; elt ++) {
// Matrix mulitply per output:
THCudaTensor_select(state, input_n, input, 0, elt);
THCudaTensor_select(state, gradOutput_n, gradOutput, 0, elt);
// Extract columns:
im2col(
THCState_getCurrentStream(state),
THCudaTensor_data(state, gradOutput_n),
nOutputPlane, outputHeight, outputWidth, kH, kW, padH, padW, dH, dW,
1, 1, THCudaTensor_data(state, columns)
);
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long n = columns->size[0]; // nOutputPlane * kh * kw
long m = input_n->size[0]; // nInputPlane
long k = columns->size[1]; // inputHeight * inputWidth
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
't', 'n',
n, m, k,
scale,
THCudaTensor_data(state, columns), k,
THCudaTensor_data(state, input_n), k,
1,
THCudaTensor_data(state, gradWeight), n
);
// Do Bias:
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m_ = nOutputPlane;
long k_ = outputHeight * outputWidth;
// Do GEMV (note: this is a bit confusing because gemv assumes column-major matrices)
THCudaBlas_gemv(
state,
't',
k_, m_,
scale,
THCudaTensor_data(state, gradOutput_n), k_,
THCudaTensor_data(state, ones), 1,
1,
THCudaTensor_data(state, gradBias), 1
);
}
// Free
THCudaTensor_free(state, input_n);
THCudaTensor_free(state, gradOutput_n);
// Resize
if (batch == 0) {
THCudaTensor_resize3d(state, gradOutput, nOutputPlane, outputHeight, outputWidth);
THCudaTensor_resize3d(state, input, nInputPlane, inputHeight, inputWidth);
}
}
| cd5c19adb61c7c7ef85efcb9d68e5f89757845ce.cu | #include "THCUNN.h"
#include "im2col.h"
void THNN_CudaSpatialFullConvolution_updateOutput(
THCState *state,
THCudaTensor *input,
THCudaTensor *output,
THCudaTensor *weight,
THCudaTensor *bias,
THCudaTensor *columns,
THCudaTensor *ones,
int kW, int kH,
int dW, int dH,
int padW, int padH,
int adjW, int adjH)
{
int nInputPlane = THCudaTensor_size(state, weight, 0);
int nOutputPlane = THCudaTensor_size(state, weight, 1);
THCUNN_assertSameGPU(state, 6, input, output, weight,
bias, columns, ones);
THArgCheck(input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D (batch mode) tensor is expected");
int batch = 1;
if (input->nDimension == 3) {
THArgCheck(input->size[0] == nInputPlane, 2, "input channels and nInputPlane dont match");
// Force batch
batch = 0;
THCudaTensor_resize4d(state, input, 1, input->size[0], input->size[1], input->size[2]);
} else {
THArgCheck(input->size[1] == nInputPlane, 2, "input channels and nInputPlane dont match");
}
long inputWidth = input->size[3];
long inputHeight = input->size[2];
long outputWidth = (inputWidth - 1) * dW - 2*padW + kW + adjW;
long outputHeight = (inputHeight - 1) * dH - 2*padH + kH + adjH;
// Batch size + input planes
long batchSize = input->size[0];
// Resize output
THCudaTensor_resize4d(state, output, batchSize, nOutputPlane, outputHeight, outputWidth);
// Resize temporary columns
THCudaTensor_resize2d(state, columns, nOutputPlane*kW*kH, inputHeight*inputWidth);
// Define a buffer of ones, for bias accumulation
// Note: this buffer can be shared with other modules, it only ever gets increased,
// and always contains ones.
if (ones->nDimension != 2 || ones->size[0]*ones->size[1] < outputHeight*outputWidth) {
// Resize plane and fill with ones...
THCudaTensor_resize2d(state, ones, outputHeight, outputWidth);
THCudaTensor_fill(state, ones, 1);
}
// Helpers
THCudaTensor *input_n = THCudaTensor_new(state);
THCudaTensor *output_n = THCudaTensor_new(state);
// For each elt in batch, do:
for (int elt = 0; elt < batchSize; elt ++) {
// Matrix mulitply per output:
THCudaTensor_select(state, input_n, input, 0, elt);
THCudaTensor_select(state, output_n, output, 0, elt);
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m = weight->size[1] * weight->size[2] * weight->size[3];
long n = columns->size[1];
long k = weight->size[0];
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
'n', 't',
n, m, k,
1,
THCudaTensor_data(state, input_n), n,
THCudaTensor_data(state, weight), m,
0,
THCudaTensor_data(state, columns), n
);
// Unpack columns back into input:
col2im(
THCState_getCurrentStream(state),
THCudaTensor_data(state, columns),
nOutputPlane, outputHeight, outputWidth, kH, kW, padH, padW, dH, dW,
1, 1, THCudaTensor_data(state, output_n)
);
// Do Bias after:
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m_ = nOutputPlane;
long n_ = outputHeight * outputWidth;
long k_ = 1;
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
't', 'n',
n_, m_, k_,
1,
THCudaTensor_data(state, ones), k_,
THCudaTensor_data(state, bias), k_,
1,
THCudaTensor_data(state, output_n), n_
);
}
// Free
THCudaTensor_free(state, input_n);
THCudaTensor_free(state, output_n);
// Resize output
if (batch == 0) {
THCudaTensor_resize3d(state, output, nOutputPlane, outputHeight, outputWidth);
THCudaTensor_resize3d(state, input, nInputPlane, inputHeight, inputWidth);
}
}
void THNN_CudaSpatialFullConvolution_updateGradInput(
THCState *state,
THCudaTensor *input,
THCudaTensor *gradOutput,
THCudaTensor *gradInput,
THCudaTensor *weight,
THCudaTensor *gradColumns,
int kW, int kH,
int dW, int dH,
int padW, int padH,
int adjW, int adjH)
{
int nInputPlane = THCudaTensor_size(state, weight, 0);
int nOutputPlane = THCudaTensor_size(state, weight, 1);
THCUNN_assertSameGPU(state, 5, input, gradOutput, weight,
gradColumns, gradInput);
THArgCheck(input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D (batch mode) tensor is expected");
int batch = 1;
if (input->nDimension == 3) {
// Force batch
batch = 0;
THCudaTensor_resize4d(state, input, 1, input->size[0], input->size[1], input->size[2]);
THCudaTensor_resize4d(state, gradOutput, 1, gradOutput->size[0], gradOutput->size[1], gradOutput->size[2]);
}
long inputWidth = input->size[3];
long inputHeight = input->size[2];
long outputWidth = (inputWidth - 1) * dW - 2*padW + kW + adjW;
long outputHeight = (inputHeight - 1) * dH - 2*padH + kH + adjH;
// Batch size + input planes
long batchSize = input->size[0];
// Resize output
THCudaTensor_resize4d(state, gradInput, batchSize, nInputPlane, inputHeight, inputWidth);
// Resize temporary columns
THCudaTensor_resize2d(state, gradColumns, nOutputPlane*kW*kH, inputHeight*inputWidth);
// Helpers
THCudaTensor *gradInput_n = THCudaTensor_new(state);
THCudaTensor *gradOutput_n = THCudaTensor_new(state);
// For each elt in batch, do:
for (int elt = 0; elt < batchSize; elt ++) {
// Matrix mulitply per sample:
THCudaTensor_select(state, gradInput_n, gradInput, 0, elt);
THCudaTensor_select(state, gradOutput_n, gradOutput, 0, elt);
// Extract columns:
im2col(
THCState_getCurrentStream(state),
THCudaTensor_data(state, gradOutput_n),
nOutputPlane, outputHeight, outputWidth, kH, kW, padH, padW, dH, dW,
1, 1, THCudaTensor_data(state, gradColumns)
);
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m = weight->size[0];
long n = gradColumns->size[1];
long k = weight->size[1] * weight->size[2] * weight->size[3];
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
'n', 'n',
n, m, k,
1,
THCudaTensor_data(state, gradColumns), n,
THCudaTensor_data(state, weight), k,
0,
THCudaTensor_data(state, gradInput_n), n
);
}
// Free
THCudaTensor_free(state, gradInput_n);
THCudaTensor_free(state, gradOutput_n);
// Resize output
if (batch == 0) {
THCudaTensor_resize3d(state, gradOutput, nOutputPlane, outputHeight, outputWidth);
THCudaTensor_resize3d(state, input, nInputPlane, inputHeight, inputWidth);
THCudaTensor_resize3d(state, gradInput, nInputPlane, inputHeight, inputWidth);
}
}
void THNN_CudaSpatialFullConvolution_accGradParameters(
THCState *state,
THCudaTensor *input,
THCudaTensor *gradOutput,
THCudaTensor *gradWeight,
THCudaTensor *gradBias,
THCudaTensor *columns,
THCudaTensor *ones,
int kW, int kH,
int dW, int dH,
int padW, int padH,
int adjW, int adjH,
float scale)
{
int nInputPlane = THCudaTensor_size(state, gradWeight, 0);
int nOutputPlane = THCudaTensor_size(state, gradWeight, 1);
THCUNN_assertSameGPU(state, 6, input, gradOutput, gradWeight,
gradBias, columns, ones);
THArgCheck(input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D (batch mode) tensor is expected");
int batch = 1;
if (input->nDimension == 3) {
// Force batch
batch = 0;
THCudaTensor_resize4d(state, input, 1, input->size[0], input->size[1], input->size[2]);
THCudaTensor_resize4d(state, gradOutput, 1, gradOutput->size[0], gradOutput->size[1], gradOutput->size[2]);
}
long inputWidth = input->size[3];
long inputHeight = input->size[2];
long outputWidth = (inputWidth - 1) * dW - 2*padW + kW + adjW;
long outputHeight = (inputHeight - 1) * dH - 2*padH + kH + adjH;
// Batch size + input planes
long batchSize = input->size[0];
// Define a buffer of ones, for bias accumulation
if (ones->nDimension != 2 || ones->size[0]*ones->size[1] < outputHeight*outputWidth) {
// Resize plane and fill with ones...
THCudaTensor_resize2d(state, ones, outputHeight, outputWidth);
THCudaTensor_fill(state, ones, 1);
}
// Resize temporary columns
THCudaTensor_resize2d(state, columns, nOutputPlane*kW*kH, inputHeight*inputWidth);
// Helpers
THCudaTensor *input_n = THCudaTensor_new(state);
THCudaTensor *gradOutput_n = THCudaTensor_new(state);
// For each elt in batch, do:
for (int elt = 0; elt < batchSize; elt ++) {
// Matrix mulitply per output:
THCudaTensor_select(state, input_n, input, 0, elt);
THCudaTensor_select(state, gradOutput_n, gradOutput, 0, elt);
// Extract columns:
im2col(
THCState_getCurrentStream(state),
THCudaTensor_data(state, gradOutput_n),
nOutputPlane, outputHeight, outputWidth, kH, kW, padH, padW, dH, dW,
1, 1, THCudaTensor_data(state, columns)
);
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long n = columns->size[0]; // nOutputPlane * kh * kw
long m = input_n->size[0]; // nInputPlane
long k = columns->size[1]; // inputHeight * inputWidth
// Do GEMM (note: this is a bit confusing because gemm assumes column-major matrices)
THCudaBlas_gemm(
state,
't', 'n',
n, m, k,
scale,
THCudaTensor_data(state, columns), k,
THCudaTensor_data(state, input_n), k,
1,
THCudaTensor_data(state, gradWeight), n
);
// Do Bias:
// M,N,K are dims of matrix A and B
// (see http://docs.nvidia.com/cuda/cublas/#cublas-lt-t-gt-gemm)
long m_ = nOutputPlane;
long k_ = outputHeight * outputWidth;
// Do GEMV (note: this is a bit confusing because gemv assumes column-major matrices)
THCudaBlas_gemv(
state,
't',
k_, m_,
scale,
THCudaTensor_data(state, gradOutput_n), k_,
THCudaTensor_data(state, ones), 1,
1,
THCudaTensor_data(state, gradBias), 1
);
}
// Free
THCudaTensor_free(state, input_n);
THCudaTensor_free(state, gradOutput_n);
// Resize
if (batch == 0) {
THCudaTensor_resize3d(state, gradOutput, nOutputPlane, outputHeight, outputWidth);
THCudaTensor_resize3d(state, input, nInputPlane, inputHeight, inputWidth);
}
}
|
1dd1c78fc797b6c5a84283163716c24b74e0035f.hip | // !!! This is a file automatically generated by hipify!!!
#include "hip/hip_runtime.h"
#include <stdio.h>
#include <string.h>
#define THREADS_PER_BLOCK 64
__global__ void part_a_cuda(int* a, int* b, int len)
{
int a_index = threadIdx.x + blockIdx.x * THREADS_PER_BLOCK;
int b_index = 0;
if (a_index < len) {
b_index = a[a_index] / 100;
atomicAdd(&b[b_index], 1);
}
}
__global__ void part_b_cuda(int* a, int* b, int len)
{
int a_index = threadIdx.x + blockIdx.x * THREADS_PER_BLOCK;
int b_index = 0;
__shared__ int temp[10];
if (a_index < len) {
b_index = a[a_index] / 100;
atomicAdd(&temp[b_index], 1);
}
__syncthreads();
if (threadIdx.x == 0) {
for (int i = 0; i < 10; i++) {
atomicAdd(&b[i], temp[i]);
}
}
}
__global__ void part_c_cuda(int* a, int* b)
{
b[threadIdx.x] = 0;
for (int i = 0; i <= threadIdx.x; i++) {
b[threadIdx.x] += a[i];
}
}
void part_a() {
//gather input from files
char buff[50000];
int inp[10000];
buff[0] = ' ';
char* token;
FILE* fp = fopen("inp.txt", "r");
fgets(buff+1, sizeof(buff), fp);
token = strtok(buff, ",");
int len = 0;
while(token != NULL) {
inp[len] = atoi(token+1);
len++;
token = strtok(NULL, ",");
}
int* A = (int* )malloc(sizeof(int) * len);
int* B = (int* )malloc(sizeof(int) * 10);
for (int i = 0; i < len; i++) {
A[i] = inp[i];
}
fclose(fp);
//cuda stuff
int *d_a, *d_b;
hipMalloc(&d_a, sizeof(int) * len);
hipMalloc(&d_b, sizeof(int) * 10);
hipMemcpy(d_a, A, sizeof(int) * len, hipMemcpyHostToDevice);
hipLaunchKernelGGL(( part_a_cuda), dim3((len + THREADS_PER_BLOCK)/THREADS_PER_BLOCK), dim3(THREADS_PER_BLOCK), 0, 0, d_a, d_b, len);
hipDeviceSynchronize();
hipMemcpy(B, d_b, sizeof(int) * 10, hipMemcpyDeviceToHost);
FILE* fp_end = fopen("q2a.txt", "w");
for (int i = 0; i < 10; i++) {
fprintf(fp_end, "%d", B[i]);
if (i != 9) {
fprintf(fp_end, "%s", ", ");
}
}
fclose(fp_end);
hipFree(d_a);
hipFree(d_b);
free(A);
free(B);
}
void part_b() {
//gather input from files
char buff[50000];
int inp[10000];
buff[0] = ' ';
char* token;
FILE* fp = fopen("inp.txt", "r");
fgets(buff+1, sizeof(buff), fp);
token = strtok(buff, ",");
int len = 0;
while(token != NULL) {
inp[len] = atoi(token+1);
len++;
token = strtok(NULL, ",");
}
int* A = (int* )malloc(sizeof(int) * len);
int* B = (int* )malloc(sizeof(int) * 10);
for (int i = 0; i < len; i++) {
A[i] = inp[i];
}
fclose(fp);
//cuda stuff
int *d_a, *d_b;
hipMalloc(&d_a, sizeof(int) * len);
hipMalloc(&d_b, sizeof(int) * 10);
hipMemcpy(d_a, A, sizeof(int) * len, hipMemcpyHostToDevice);
hipLaunchKernelGGL(( part_b_cuda), dim3((len + THREADS_PER_BLOCK)/THREADS_PER_BLOCK), dim3(THREADS_PER_BLOCK), 0, 0, d_a, d_b, len);
hipDeviceSynchronize();
hipMemcpy(B, d_b, sizeof(int) * 10, hipMemcpyDeviceToHost);
FILE* fp_end = fopen("q2b.txt", "w");
for (int i = 0; i < 10; i++) {
fprintf(fp_end, "%d", B[i]);
if (i != 9) {
fprintf(fp_end, "%s", ", ");
}
}
fclose(fp_end);
hipFree(d_a);
hipFree(d_b);
free(A);
free(B);
}
void part_c() {
//gather input from files
char buff[50000];
int inp[10000];
buff[0] = ' ';
char* token;
FILE* fp = fopen("inp.txt", "r");
fgets(buff+1, sizeof(buff), fp);
token = strtok(buff, ",");
int len = 0;
while(token != NULL) {
inp[len] = atoi(token+1);
len++;
token = strtok(NULL, ",");
}
int* A = (int* )malloc(sizeof(int) * len);
int* B = (int* )malloc(sizeof(int) * 10);
for (int i = 0; i < len; i++) {
A[i] = inp[i];
}
fclose(fp);
//cuda stuff
int *d_a, *d_b;
hipMalloc(&d_a, sizeof(int) * len);
hipMalloc(&d_b, sizeof(int) * 10);
hipMemcpy(d_a, A, sizeof(int) * len, hipMemcpyHostToDevice);
hipLaunchKernelGGL(( part_b_cuda), dim3((len + THREADS_PER_BLOCK)/THREADS_PER_BLOCK), dim3(THREADS_PER_BLOCK), 0, 0, d_a, d_b, len);
hipDeviceSynchronize();
hipMemcpy(B, d_b, sizeof(int) * 10, hipMemcpyDeviceToHost);
hipFree(d_a);
hipFree(d_b);
int *d_c;
int* C = (int* )malloc(sizeof(int) * 10);
//now do prefix sum of 10 elements in b
hipMalloc(&d_c, sizeof(int) * 10);
hipMalloc(&d_b, sizeof(int) * 10);
hipMemcpy(d_b, B, sizeof(int) * 10, hipMemcpyHostToDevice);
hipLaunchKernelGGL(( part_c_cuda), dim3(1), dim3(10), 0, 0, d_b, d_c);
hipDeviceSynchronize();
hipMemcpy(C, d_c, sizeof(int) * 10, hipMemcpyDeviceToHost);
//copy stuff to file
FILE* fp_end = fopen("q2c.txt", "w");
for (int i = 0; i < 10; i++) {
fprintf(fp_end, "%d", C[i]);
if (i != 9) {
fprintf(fp_end, "%s", ", ");
}
}
fclose(fp_end);
hipFree(d_c);
hipFree(d_b);
free(C);
free(B);
free(A);
}
int main(int argc, char **argv)
{
part_a();
hipDeviceReset();
part_b();
hipDeviceReset();
part_c();
return 0;
} | 1dd1c78fc797b6c5a84283163716c24b74e0035f.cu | #include <stdio.h>
#include <string.h>
#define THREADS_PER_BLOCK 64
__global__ void part_a_cuda(int* a, int* b, int len)
{
int a_index = threadIdx.x + blockIdx.x * THREADS_PER_BLOCK;
int b_index = 0;
if (a_index < len) {
b_index = a[a_index] / 100;
atomicAdd(&b[b_index], 1);
}
}
__global__ void part_b_cuda(int* a, int* b, int len)
{
int a_index = threadIdx.x + blockIdx.x * THREADS_PER_BLOCK;
int b_index = 0;
__shared__ int temp[10];
if (a_index < len) {
b_index = a[a_index] / 100;
atomicAdd(&temp[b_index], 1);
}
__syncthreads();
if (threadIdx.x == 0) {
for (int i = 0; i < 10; i++) {
atomicAdd(&b[i], temp[i]);
}
}
}
__global__ void part_c_cuda(int* a, int* b)
{
b[threadIdx.x] = 0;
for (int i = 0; i <= threadIdx.x; i++) {
b[threadIdx.x] += a[i];
}
}
void part_a() {
//gather input from files
char buff[50000];
int inp[10000];
buff[0] = ' ';
char* token;
FILE* fp = fopen("inp.txt", "r");
fgets(buff+1, sizeof(buff), fp);
token = strtok(buff, ",");
int len = 0;
while(token != NULL) {
inp[len] = atoi(token+1);
len++;
token = strtok(NULL, ",");
}
int* A = (int* )malloc(sizeof(int) * len);
int* B = (int* )malloc(sizeof(int) * 10);
for (int i = 0; i < len; i++) {
A[i] = inp[i];
}
fclose(fp);
//cuda stuff
int *d_a, *d_b;
cudaMalloc(&d_a, sizeof(int) * len);
cudaMalloc(&d_b, sizeof(int) * 10);
cudaMemcpy(d_a, A, sizeof(int) * len, cudaMemcpyHostToDevice);
part_a_cuda<<<(len + THREADS_PER_BLOCK)/THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(d_a, d_b, len);
cudaDeviceSynchronize();
cudaMemcpy(B, d_b, sizeof(int) * 10, cudaMemcpyDeviceToHost);
FILE* fp_end = fopen("q2a.txt", "w");
for (int i = 0; i < 10; i++) {
fprintf(fp_end, "%d", B[i]);
if (i != 9) {
fprintf(fp_end, "%s", ", ");
}
}
fclose(fp_end);
cudaFree(d_a);
cudaFree(d_b);
free(A);
free(B);
}
void part_b() {
//gather input from files
char buff[50000];
int inp[10000];
buff[0] = ' ';
char* token;
FILE* fp = fopen("inp.txt", "r");
fgets(buff+1, sizeof(buff), fp);
token = strtok(buff, ",");
int len = 0;
while(token != NULL) {
inp[len] = atoi(token+1);
len++;
token = strtok(NULL, ",");
}
int* A = (int* )malloc(sizeof(int) * len);
int* B = (int* )malloc(sizeof(int) * 10);
for (int i = 0; i < len; i++) {
A[i] = inp[i];
}
fclose(fp);
//cuda stuff
int *d_a, *d_b;
cudaMalloc(&d_a, sizeof(int) * len);
cudaMalloc(&d_b, sizeof(int) * 10);
cudaMemcpy(d_a, A, sizeof(int) * len, cudaMemcpyHostToDevice);
part_b_cuda<<<(len + THREADS_PER_BLOCK)/THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(d_a, d_b, len);
cudaDeviceSynchronize();
cudaMemcpy(B, d_b, sizeof(int) * 10, cudaMemcpyDeviceToHost);
FILE* fp_end = fopen("q2b.txt", "w");
for (int i = 0; i < 10; i++) {
fprintf(fp_end, "%d", B[i]);
if (i != 9) {
fprintf(fp_end, "%s", ", ");
}
}
fclose(fp_end);
cudaFree(d_a);
cudaFree(d_b);
free(A);
free(B);
}
void part_c() {
//gather input from files
char buff[50000];
int inp[10000];
buff[0] = ' ';
char* token;
FILE* fp = fopen("inp.txt", "r");
fgets(buff+1, sizeof(buff), fp);
token = strtok(buff, ",");
int len = 0;
while(token != NULL) {
inp[len] = atoi(token+1);
len++;
token = strtok(NULL, ",");
}
int* A = (int* )malloc(sizeof(int) * len);
int* B = (int* )malloc(sizeof(int) * 10);
for (int i = 0; i < len; i++) {
A[i] = inp[i];
}
fclose(fp);
//cuda stuff
int *d_a, *d_b;
cudaMalloc(&d_a, sizeof(int) * len);
cudaMalloc(&d_b, sizeof(int) * 10);
cudaMemcpy(d_a, A, sizeof(int) * len, cudaMemcpyHostToDevice);
part_b_cuda<<<(len + THREADS_PER_BLOCK)/THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(d_a, d_b, len);
cudaDeviceSynchronize();
cudaMemcpy(B, d_b, sizeof(int) * 10, cudaMemcpyDeviceToHost);
cudaFree(d_a);
cudaFree(d_b);
int *d_c;
int* C = (int* )malloc(sizeof(int) * 10);
//now do prefix sum of 10 elements in b
cudaMalloc(&d_c, sizeof(int) * 10);
cudaMalloc(&d_b, sizeof(int) * 10);
cudaMemcpy(d_b, B, sizeof(int) * 10, cudaMemcpyHostToDevice);
part_c_cuda<<<1, 10>>>(d_b, d_c);
cudaDeviceSynchronize();
cudaMemcpy(C, d_c, sizeof(int) * 10, cudaMemcpyDeviceToHost);
//copy stuff to file
FILE* fp_end = fopen("q2c.txt", "w");
for (int i = 0; i < 10; i++) {
fprintf(fp_end, "%d", C[i]);
if (i != 9) {
fprintf(fp_end, "%s", ", ");
}
}
fclose(fp_end);
cudaFree(d_c);
cudaFree(d_b);
free(C);
free(B);
free(A);
}
int main(int argc, char **argv)
{
part_a();
cudaDeviceReset();
part_b();
cudaDeviceReset();
part_c();
return 0;
} |
ba0fd873df61a23e2864fe2083afd3922bd4c921.hip | // !!! This is a file automatically generated by hipify!!!
#include <stdio.h>
#include <stdlib.h>
#include "hip/hip_runtime_api.h"
#include <hip/hip_runtime.h>
#include <omp.h>
#include <time.h>
#include <sys/time.h>
const int INF = 10000000;
const int V = 10010;
void input(char *inFileName);
void output(char *outFileName);
void block_FW(int B,int numdevs);
int ceil(int a, int b);
void cal(int B, int Round, int block_start_x, int block_start_y, int block_width, int block_height);
int init_device();
int n, m; // Number of vertices, edges
static int Dist[V][V];
int *gpudist0;
int *gpudist1;
int *hostdist;
int *hostdist2;
//time
double comtime[2];
double cmitime=0;
double ccomtime[2];
double memcpy_t=0;
__global__ void calculat(int B, int n, int Round, int block_start_x, int block_start_y, int block_width, int block_height, int *gpudist){
//for (int b_i = block_start_x; b_i < block_end_x; ++b_i) {
// for (int b_j = block_start_y; b_j < block_end_y; ++b_j) {
// To calculate B*B elements in the block (b_i, b_j)
// For each block, it need to compute B times
// for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
// To calculate original index of elements in the block (b_i, b_j)
// For instance, original index of (0,0) in block (1,2) is (2,5) for V=6,B=2
int b_i = blockIdx.x+block_start_x;
int b_j = blockIdx.y+block_start_y;
int distij,distik,distkj;// register value
int block_internal_start_x = b_i * B;
int block_internal_start_y = b_j * B;
int j = block_internal_start_y + threadIdx.x; // set column
if(j > n-1) j=n-1;
for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
distkj = gpudist[k*n+j];
for (int blk_idx = 0;blk_idx<B;blk_idx++){
//int block_internal_start_x = b_i * B;
// int block_internal_end_x = (b_i +1) * B;
//int block_internal_start_y = b_j * B;
// int block_internal_end_y = (b_j +1) * B;
// if (block_internal_end_x > n) block_internal_end_x = n;
// if (block_internal_end_y > n) block_internal_end_y = n;
// for (int i = block_internal_start_x; i < block_internal_end_x; ++i) {
// for (int j = block_internal_start_y; j < block_internal_end_y; ++j) {
int i = block_internal_start_x + blk_idx;
//int j = block_internal_start_y + threadIdx.x; // set column
if(i > n-1) i=n-1;
distij = gpudist[i*n+j];
distik = gpudist[i*n+k];
if (distik + distkj < distij)
gpudist[i*n+j] = distik + distkj;
__syncthreads();
}
}
//}
//}
//}
}
static __global__ void calculat32(int B, int n, int Round, int block_start_x, int block_start_y, int block_width, int block_height, int *dist){
int b_i = blockIdx.x+block_start_x;
int b_j = blockIdx.y+block_start_y;
int distij,distik,distkj;// register value
int block_internal_start_x = b_i * B;
int block_internal_start_y = b_j * B;
int j = block_internal_start_y + threadIdx.y;
int i = block_internal_start_x + threadIdx.x;
if(i > n-1) i=n-1;
if(j > n-1) j=n-1;
distij = dist[i*n+j];
for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
distik = dist[i*n+k];
distkj = dist[k*n+j];
if (distik + distkj < distij){
distij = distik + distkj;
dist[i*n+j]=distij;
}
__syncthreads();
}
}
double timer(void)
{ struct timeval tv;
struct timezone tz;
double t;
gettimeofday(&tv, &tz);
t = (double)tv.tv_sec*1000;
t += ((double)tv.tv_usec)/1000.0;
return t/1000;
}
int main(int argc, char* argv[])
{
hipError_t err;
//time
double t_st,t_end;
struct timeval tv;
struct timezone tz;
clock_t t0,t1;
t_st = timer();
t0 = clock();
double memcpy_start_t = 0, memcpy_end_t = 0;
double IO_start_t = 0, IO_end_t = 0;
double IO_t=0;
//time
int numdevs; // get devices number
//printf("go~%d\n",argc);
IO_start_t = timer();
input(argv[1]);
IO_end_t = timer();
IO_t = IO_t + IO_end_t -IO_start_t;
int B = atoi(argv[3]);
//printf("%d",B);
//init gpu && openMP threads
numdevs = init_device();
omp_set_num_threads(numdevs);
//gpudist = (int *)malloc(sizeof(int)*2);
//allocate GPU memory
memcpy_start_t = timer();
err = hipMalloc((void**)&gpudist0,sizeof(int)*n*n);
//printf("cudaMallocgpudist0 %s\n",err);
if(numdevs>1){
hipSetDevice(1);
err = hipMalloc((void**)&gpudist1,sizeof(int)*n*n);
//printf("cudaMallocgpudist1 %s\n",err);
}
//copy DIST to Device(GPU)
hipSetDevice(0);
hipMemcpy(gpudist0,hostdist,sizeof(int)*n*n,hipMemcpyHostToDevice);
// copy to master GPU and copy form master to slave
memcpy_end_t = timer();
memcpy_t = memcpy_t +memcpy_end_t - memcpy_start_t;
block_FW(B,numdevs);
memcpy_start_t = timer();
hipMemcpy(hostdist,gpudist0,sizeof(int)*n*n,hipMemcpyDeviceToHost);
memcpy_end_t = timer();
memcpy_t = memcpy_t +memcpy_end_t - memcpy_start_t;
hipFree(gpudist0);
hipFree(gpudist1);
IO_start_t = timer();
output(argv[2]);
IO_end_t = timer();
IO_t = IO_t + IO_end_t -IO_start_t;
//free(gpudist);
free(hostdist);
free(hostdist2);
t_end = timer();
t1 = clock();
//printf("blocksize:%d Total time = %lf sec %f \n", B, (t_end - t_st),ccomtime[0]);
//printf("computation time0 = %f computation time1 = %f IO = %f communication = %f memcpy = %f\n", comtime[0],comtime[1], IO_t, cmitime, memcpy_t);
return 0;
}
void input(char *inFileName)
{
FILE *infile = fopen(inFileName, "r");
fscanf(infile, "%d %d", &n, &m);
//allocate nxn matrix
hostdist = (int *)malloc(sizeof(int)*n*n);
hostdist2 = (int *)malloc(sizeof(int)*n*n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j){
hostdist2[i*n+j] = 0;
hostdist[i*n+j]=0;
}
else{
hostdist2[i*n+j] = INF;
hostdist[i*n+j]=INF;
}
}
}
while (--m >= 0) {
int a, b, v;
fscanf(infile, "%d %d %d", &a, &b, &v);
--a, --b;
hostdist2[a*n+b] = v;
hostdist[a*n+b] = v;
}
}
void output(char *outFileName)
{
FILE *outfile = fopen(outFileName, "w");
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (hostdist[i*n+j] >= INF) fprintf(outfile, "INF ");
else fprintf(outfile, "%d ", hostdist[i*n+j]);
}
fprintf(outfile, "\n");
}
}
int ceil(int a, int b)
{
return (a + b -1)/b;
}
void block_FW(int B, int numdevs)
{ omp_set_num_threads(numdevs);
comtime[0]=0;
comtime[1]=0;
/*hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);*/
float time;
double str;
int round = ceil(n, B);//?n/B????
//printf("round %d\n",round);
for (int r = 0; r < round; ++r) {
/*Phase 1*/
//hipEventRecord(start);
str=timer();
cal(B, r, r, r, 1, 1);
// printf("phase1\n");
/*Phase 2*/
cal(B, r, r, 0, r, 1);
cal(B, r, r, r +1, round - r -1, 1);
cal(B, r, 0, r, 1, r);
cal(B, r, r +1, r, 1, round - r -1);
// printf("phase2\n");
/*hipDeviceSynchronize();
hipEventRecord(stop);
hipEventSynchronize(stop);
hipEventElapsedTime(&time, start, stop);*/
comtime[1] +=(timer()-str);
comtime[0] +=(timer()-str);
str = timer();
if(numdevs >1 ){
hipMemcpy(gpudist1,gpudist0,sizeof(int)*n*n,hipMemcpyDeviceToDevice);
// printf("D2D\n");
}
//hipMemcpy(hostdist,gpudist0,sizeof(int)*n*n,hipMemcpyDeviceToHost);
cmitime = cmitime +timer() - str;
/*Phase 3*/
#pragma omp parallel private(str)
{
//hipEventRecord(start);
str=timer();
if(omp_get_num_threads()==1){
cal(B, r, 0, 0, r, r);
cal(B, r, 0, r +1, round -r -1, r);
cal(B, r, r +1, 0, r, round - r -1);
cal(B, r, r +1, r +1, round -r -1, round - r -1);
}
else{
if(omp_get_thread_num()==0){
hipSetDevice(omp_get_thread_num());
cal(B, r, 0, 0, r, r);
cal(B, r, 0, r +1, round -r -1, r);
}
if(omp_get_thread_num()==1){
hipSetDevice(omp_get_thread_num());
cal(B, r, r +1, 0, r, round - r -1);
cal(B, r, r +1, r +1, round -r -1, round - r -1);
}
}
hipDeviceSynchronize();
comtime[omp_get_thread_num()] +=(timer()-str);
/*hipEventRecord(stop);
hipEventSynchronize(stop);
hipEventElapsedTime(&time, start, stop);
comtime[omp_get_thread_num()] +=time;*/
}
if(numdevs >1 ){
str = timer();
hipSetDevice(1);
hipMemcpy(hostdist2,gpudist1,sizeof(int)*n*n,hipMemcpyDeviceToHost);
hipSetDevice(0);
hipMemcpy(hostdist,gpudist0,sizeof(int)*n*n,hipMemcpyDeviceToHost);
cmitime = cmitime +timer() - str;
int j=0;
int i=0;
ccomtime[0]=0;
ccomtime[1]=0;
str=timer();
#pragma omp parallel private(j,str)
{
#pragma omp for schedule(dynamic)
for(i=0;i<n;i++)
for(j=0;j<n;j++){
if(hostdist[i*n+j]>hostdist2[i*n+j]){
hostdist[i*n+j]=hostdist2[i*n+j];
//printf("1dist[%d][%d]= %d ",i,j,hostdist[i*n+j]);
//printf("2dist[%d][%d]= %d ",i,j,hostdist2[i*n+j]);
}
//if(hostdist[i*n+j]==hostdist2[i*n+j])
//printf("fuck\n");
}
}
ccomtime[0] +=(timer()-str);
//printf(" comtime[1] %f ",comtime[1]);
str = timer();
hipMemcpy(gpudist0,hostdist,sizeof(int)*n*n,hipMemcpyHostToDevice);
memcpy_t = memcpy_t +timer() - str;
}
}
}
void cal(int B, int Round, int block_start_x, int block_start_y, int block_width, int block_height)
{
//int block_end_x = block_start_x + block_height;
//int block_end_y = block_start_y + block_width;
dim3 guid_size = dim3(block_height, block_width);
//int block_size = B;
dim3 block_size;
if(B<=32)
block_size = dim3(B,B);
else
block_size = dim3(B,1);
//for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
//printf("a=%d",k);
//printf("is = %d",omp_get_thread_num());
if(omp_get_thread_num()){
if(B<=32)
hipLaunchKernelGGL(( calculat32), dim3(guid_size),dim3(block_size), 0, 0, B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist1);
else
hipLaunchKernelGGL(( calculat), dim3(guid_size),dim3(block_size), 0, 0, B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist1);
//printf("no");
}else{
if(B<=32)
hipLaunchKernelGGL(( calculat32), dim3(guid_size),dim3(block_size), 0, 0, B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist0);
else
hipLaunchKernelGGL(( calculat), dim3(guid_size),dim3(block_size), 0, 0, B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist0);
//printf("yes");
}
//}
}
int init_device(){
hipError_t err;
int numdevs;
//printf("go");
hipGetDeviceCount(&numdevs);
if(numdevs > 0){
err = hipSetDevice(0);
//printf("suda set =%s\n",err);
}
//printf("numdevs=%d\n",numdevs);
return numdevs;
}
| ba0fd873df61a23e2864fe2083afd3922bd4c921.cu | #include <stdio.h>
#include <stdlib.h>
#include "cuda_runtime_api.h"
#include <cuda.h>
#include <omp.h>
#include <time.h>
#include <sys/time.h>
const int INF = 10000000;
const int V = 10010;
void input(char *inFileName);
void output(char *outFileName);
void block_FW(int B,int numdevs);
int ceil(int a, int b);
void cal(int B, int Round, int block_start_x, int block_start_y, int block_width, int block_height);
int init_device();
int n, m; // Number of vertices, edges
static int Dist[V][V];
int *gpudist0;
int *gpudist1;
int *hostdist;
int *hostdist2;
//time
double comtime[2];
double cmitime=0;
double ccomtime[2];
double memcpy_t=0;
__global__ void calculat(int B, int n, int Round, int block_start_x, int block_start_y, int block_width, int block_height, int *gpudist){
//for (int b_i = block_start_x; b_i < block_end_x; ++b_i) {
// for (int b_j = block_start_y; b_j < block_end_y; ++b_j) {
// To calculate B*B elements in the block (b_i, b_j)
// For each block, it need to compute B times
// for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
// To calculate original index of elements in the block (b_i, b_j)
// For instance, original index of (0,0) in block (1,2) is (2,5) for V=6,B=2
int b_i = blockIdx.x+block_start_x;
int b_j = blockIdx.y+block_start_y;
int distij,distik,distkj;// register value
int block_internal_start_x = b_i * B;
int block_internal_start_y = b_j * B;
int j = block_internal_start_y + threadIdx.x; // set column
if(j > n-1) j=n-1;
for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
distkj = gpudist[k*n+j];
for (int blk_idx = 0;blk_idx<B;blk_idx++){
//int block_internal_start_x = b_i * B;
// int block_internal_end_x = (b_i +1) * B;
//int block_internal_start_y = b_j * B;
// int block_internal_end_y = (b_j +1) * B;
// if (block_internal_end_x > n) block_internal_end_x = n;
// if (block_internal_end_y > n) block_internal_end_y = n;
// for (int i = block_internal_start_x; i < block_internal_end_x; ++i) {
// for (int j = block_internal_start_y; j < block_internal_end_y; ++j) {
int i = block_internal_start_x + blk_idx;
//int j = block_internal_start_y + threadIdx.x; // set column
if(i > n-1) i=n-1;
distij = gpudist[i*n+j];
distik = gpudist[i*n+k];
if (distik + distkj < distij)
gpudist[i*n+j] = distik + distkj;
__syncthreads();
}
}
//}
//}
//}
}
static __global__ void calculat32(int B, int n, int Round, int block_start_x, int block_start_y, int block_width, int block_height, int *dist){
int b_i = blockIdx.x+block_start_x;
int b_j = blockIdx.y+block_start_y;
int distij,distik,distkj;// register value
int block_internal_start_x = b_i * B;
int block_internal_start_y = b_j * B;
int j = block_internal_start_y + threadIdx.y;
int i = block_internal_start_x + threadIdx.x;
if(i > n-1) i=n-1;
if(j > n-1) j=n-1;
distij = dist[i*n+j];
for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
distik = dist[i*n+k];
distkj = dist[k*n+j];
if (distik + distkj < distij){
distij = distik + distkj;
dist[i*n+j]=distij;
}
__syncthreads();
}
}
double timer(void)
{ struct timeval tv;
struct timezone tz;
double t;
gettimeofday(&tv, &tz);
t = (double)tv.tv_sec*1000;
t += ((double)tv.tv_usec)/1000.0;
return t/1000;
}
int main(int argc, char* argv[])
{
cudaError_t err;
//time
double t_st,t_end;
struct timeval tv;
struct timezone tz;
clock_t t0,t1;
t_st = timer();
t0 = clock();
double memcpy_start_t = 0, memcpy_end_t = 0;
double IO_start_t = 0, IO_end_t = 0;
double IO_t=0;
//time
int numdevs; // get devices number
//printf("go~%d\n",argc);
IO_start_t = timer();
input(argv[1]);
IO_end_t = timer();
IO_t = IO_t + IO_end_t -IO_start_t;
int B = atoi(argv[3]);
//printf("%d",B);
//init gpu && openMP threads
numdevs = init_device();
omp_set_num_threads(numdevs);
//gpudist = (int *)malloc(sizeof(int)*2);
//allocate GPU memory
memcpy_start_t = timer();
err = cudaMalloc((void**)&gpudist0,sizeof(int)*n*n);
//printf("cudaMallocgpudist0 %s\n",err);
if(numdevs>1){
cudaSetDevice(1);
err = cudaMalloc((void**)&gpudist1,sizeof(int)*n*n);
//printf("cudaMallocgpudist1 %s\n",err);
}
//copy DIST to Device(GPU)
cudaSetDevice(0);
cudaMemcpy(gpudist0,hostdist,sizeof(int)*n*n,cudaMemcpyHostToDevice);
// copy to master GPU and copy form master to slave
memcpy_end_t = timer();
memcpy_t = memcpy_t +memcpy_end_t - memcpy_start_t;
block_FW(B,numdevs);
memcpy_start_t = timer();
cudaMemcpy(hostdist,gpudist0,sizeof(int)*n*n,cudaMemcpyDeviceToHost);
memcpy_end_t = timer();
memcpy_t = memcpy_t +memcpy_end_t - memcpy_start_t;
cudaFree(gpudist0);
cudaFree(gpudist1);
IO_start_t = timer();
output(argv[2]);
IO_end_t = timer();
IO_t = IO_t + IO_end_t -IO_start_t;
//free(gpudist);
free(hostdist);
free(hostdist2);
t_end = timer();
t1 = clock();
//printf("blocksize:%d Total time = %lf sec %f \n", B, (t_end - t_st),ccomtime[0]);
//printf("computation time0 = %f computation time1 = %f IO = %f communication = %f memcpy = %f\n", comtime[0],comtime[1], IO_t, cmitime, memcpy_t);
return 0;
}
void input(char *inFileName)
{
FILE *infile = fopen(inFileName, "r");
fscanf(infile, "%d %d", &n, &m);
//allocate nxn matrix
hostdist = (int *)malloc(sizeof(int)*n*n);
hostdist2 = (int *)malloc(sizeof(int)*n*n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j){
hostdist2[i*n+j] = 0;
hostdist[i*n+j]=0;
}
else{
hostdist2[i*n+j] = INF;
hostdist[i*n+j]=INF;
}
}
}
while (--m >= 0) {
int a, b, v;
fscanf(infile, "%d %d %d", &a, &b, &v);
--a, --b;
hostdist2[a*n+b] = v;
hostdist[a*n+b] = v;
}
}
void output(char *outFileName)
{
FILE *outfile = fopen(outFileName, "w");
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (hostdist[i*n+j] >= INF) fprintf(outfile, "INF ");
else fprintf(outfile, "%d ", hostdist[i*n+j]);
}
fprintf(outfile, "\n");
}
}
int ceil(int a, int b)
{
return (a + b -1)/b;
}
void block_FW(int B, int numdevs)
{ omp_set_num_threads(numdevs);
comtime[0]=0;
comtime[1]=0;
/*cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);*/
float time;
double str;
int round = ceil(n, B);//?–n/B?„ä???
//printf("round %d\n",round);
for (int r = 0; r < round; ++r) {
/*Phase 1*/
//cudaEventRecord(start);
str=timer();
cal(B, r, r, r, 1, 1);
// printf("phase1\n");
/*Phase 2*/
cal(B, r, r, 0, r, 1);
cal(B, r, r, r +1, round - r -1, 1);
cal(B, r, 0, r, 1, r);
cal(B, r, r +1, r, 1, round - r -1);
// printf("phase2\n");
/*cudaDeviceSynchronize();
cudaEventRecord(stop);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);*/
comtime[1] +=(timer()-str);
comtime[0] +=(timer()-str);
str = timer();
if(numdevs >1 ){
cudaMemcpy(gpudist1,gpudist0,sizeof(int)*n*n,cudaMemcpyDeviceToDevice);
// printf("D2D\n");
}
//cudaMemcpy(hostdist,gpudist0,sizeof(int)*n*n,cudaMemcpyDeviceToHost);
cmitime = cmitime +timer() - str;
/*Phase 3*/
#pragma omp parallel private(str)
{
//cudaEventRecord(start);
str=timer();
if(omp_get_num_threads()==1){
cal(B, r, 0, 0, r, r);
cal(B, r, 0, r +1, round -r -1, r);
cal(B, r, r +1, 0, r, round - r -1);
cal(B, r, r +1, r +1, round -r -1, round - r -1);
}
else{
if(omp_get_thread_num()==0){
cudaSetDevice(omp_get_thread_num());
cal(B, r, 0, 0, r, r);
cal(B, r, 0, r +1, round -r -1, r);
}
if(omp_get_thread_num()==1){
cudaSetDevice(omp_get_thread_num());
cal(B, r, r +1, 0, r, round - r -1);
cal(B, r, r +1, r +1, round -r -1, round - r -1);
}
}
cudaDeviceSynchronize();
comtime[omp_get_thread_num()] +=(timer()-str);
/*cudaEventRecord(stop);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
comtime[omp_get_thread_num()] +=time;*/
}
if(numdevs >1 ){
str = timer();
cudaSetDevice(1);
cudaMemcpy(hostdist2,gpudist1,sizeof(int)*n*n,cudaMemcpyDeviceToHost);
cudaSetDevice(0);
cudaMemcpy(hostdist,gpudist0,sizeof(int)*n*n,cudaMemcpyDeviceToHost);
cmitime = cmitime +timer() - str;
int j=0;
int i=0;
ccomtime[0]=0;
ccomtime[1]=0;
str=timer();
#pragma omp parallel private(j,str)
{
#pragma omp for schedule(dynamic)
for(i=0;i<n;i++)
for(j=0;j<n;j++){
if(hostdist[i*n+j]>hostdist2[i*n+j]){
hostdist[i*n+j]=hostdist2[i*n+j];
//printf("1dist[%d][%d]= %d ",i,j,hostdist[i*n+j]);
//printf("2dist[%d][%d]= %d ",i,j,hostdist2[i*n+j]);
}
//if(hostdist[i*n+j]==hostdist2[i*n+j])
//printf("fuck\n");
}
}
ccomtime[0] +=(timer()-str);
//printf(" comtime[1] %f ",comtime[1]);
str = timer();
cudaMemcpy(gpudist0,hostdist,sizeof(int)*n*n,cudaMemcpyHostToDevice);
memcpy_t = memcpy_t +timer() - str;
}
}
}
void cal(int B, int Round, int block_start_x, int block_start_y, int block_width, int block_height)
{
//int block_end_x = block_start_x + block_height;
//int block_end_y = block_start_y + block_width;
dim3 guid_size = dim3(block_height, block_width);
//int block_size = B;
dim3 block_size;
if(B<=32)
block_size = dim3(B,B);
else
block_size = dim3(B,1);
//for (int k = Round * B; k < (Round +1) * B && k < n; ++k) {
//printf("a=%d",k);
//printf("is = %d",omp_get_thread_num());
if(omp_get_thread_num()){
if(B<=32)
calculat32<<<guid_size,block_size>>>(B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist1);
else
calculat<<<guid_size,block_size>>>(B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist1);
//printf("no");
}else{
if(B<=32)
calculat32<<<guid_size,block_size>>>(B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist0);
else
calculat<<<guid_size,block_size>>>(B,n,Round,block_start_x,block_start_y,block_width,block_height,gpudist0);
//printf("yes");
}
//}
}
int init_device(){
cudaError_t err;
int numdevs;
//printf("go");
cudaGetDeviceCount(&numdevs);
if(numdevs > 0){
err = cudaSetDevice(0);
//printf("suda set =%s\n",err);
}
//printf("numdevs=%d\n",numdevs);
return numdevs;
}
|
e5e7daec1eb4726af02ff61f6acf0f39fa37bf1d.hip | // !!! This is a file automatically generated by hipify!!!
#include <hip/hip_runtime.h>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#define DIM 4
#define MAX_THREADS 32
#define SHARED_MEM_CAPACITY (48 * 1024)
#define TILE_WIDTH 32
__global__ void matrix_multiplication
(float *A, float *B, float *C, int dim) {
// init the block index, thread index etc.
int bx = blockIdx.x; int by = blockIdx.y;
int tx = threadIdx.x; int ty = threadIdx.y;
// fixed row and col for a specific thread in a specific block
int row = by * TILE_WIDTH + ty;
int col = bx * TILE_WIDTH + tx;
// Allocate the TILE on the shared memory.
__shared__ float A_sub[TILE_WIDTH][TILE_WIDTH];
__shared__ float B_sub[TILE_WIDTH][TILE_WIDTH];
// If condition to eliminate extra or dim which dim % 32 (or 2^n) != 0
if (by * blockDim.y + ty < dim && bx * blockDim.y + tx < dim) {
// partial sum
float sum = 0;
for (int k = 0; k < dim / TILE_WIDTH + 1; k++) {
// in case that k * TILE_WIDTH + thread > dim,
// we assign those values to be 0.
// Even doing the dot product everything will be 0.
A_sub[ty][tx] =
(k * TILE_WIDTH + tx) < dim ?
A[row * dim + (k * TILE_WIDTH + tx)] : 0;
B_sub[ty][tx] =
(k * TILE_WIDTH + ty) < dim ?
B[(k * TILE_WIDTH + ty) * dim + col] : 0;
// Wait until all the threads finish doing that
__syncthreads();
// At this point, all of the TILES need for the
// target tile are loaded to shared mem.
// The sum will be the cumulated sum for the
// specific thread it's computing
for (int m = 0; m < TILE_WIDTH; m++) {
sum += A_sub[ty][m] * B_sub[m][tx];
}
// Wait until all the threads finish so that
// the shared mem can be flashed
__syncthreads();
}
// classic [][]
C[row * dim + col] = sum;
}
}
int main(int argc, char **argv) {
int dim;
if (argc == 2) {
dim = atoi(argv[1]);
} else {
dim = DIM;
}
int memSize = dim * dim * sizeof(float);
float *host_A, *host_B, *host_C;
float *dev_A, *dev_B, *dev_C;
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);
float milliseconds = 0;
host_A = (float *) malloc(memSize);
host_B = (float *) malloc(memSize);
host_C = (float *) malloc(memSize);
hipMalloc(&dev_A, memSize);
hipMalloc(&dev_B, memSize);
hipMalloc(&dev_C, memSize);
for (int i = 0; i < dim * dim; i++) {
host_A[i] = 0.9;
host_B[i] = 0.9;
}
hipMemcpy(dev_A, host_A, memSize, hipMemcpyHostToDevice);
hipMemcpy(dev_B, host_B, memSize, hipMemcpyHostToDevice);
hipEventRecord(start);
// If dim < MAX_THREADS, then the threads we using can be
// the dim itself. Otherwise, threads should be max threads
// in order to use 1024 threads per block.
int threads = dim < MAX_THREADS ? dim : MAX_THREADS;
// Calculate the number of blocks that is necessary for
// the calculation
int blocks = dim * dim / threads / threads + 1;
// Figure out the square-like block geometry
// (which shouldn't be matter too much, but for simplicity)
int block_x = (int) sqrt(blocks);
int block_y = blocks / block_x;
if (block_x * block_y < blocks) {
block_x++;
}
dim3 dimGrid(block_x, block_y);
dim3 dimBlock(threads, threads);
hipLaunchKernelGGL(( matrix_multiplication), dim3(dimGrid), dim3(dimBlock), 0, 0,
dev_A, dev_B, dev_C, dim);
hipMemcpy(host_C, dev_C, memSize, hipMemcpyDeviceToHost);
hipEventRecord(stop);
hipEventElapsedTime(&milliseconds, start, stop);
printf("Cuda version\n");
printf("The execution time is %f milliseconds\n", milliseconds);
printf("\n");
printf("Result - for sanity check\n");
for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
printf("%08f\t", host_C[i * dim + j]);
}
printf("\n");
}
hipEventDestroy(start);
hipEventDestroy(stop);
free(host_A);
free(host_B);
free(host_C);
hipFree(dev_A);
hipFree(dev_B);
hipFree(dev_C);
return 0;
}
| e5e7daec1eb4726af02ff61f6acf0f39fa37bf1d.cu | #include <cuda.h>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#define DIM 4
#define MAX_THREADS 32
#define SHARED_MEM_CAPACITY (48 * 1024)
#define TILE_WIDTH 32
__global__ void matrix_multiplication
(float *A, float *B, float *C, int dim) {
// init the block index, thread index etc.
int bx = blockIdx.x; int by = blockIdx.y;
int tx = threadIdx.x; int ty = threadIdx.y;
// fixed row and col for a specific thread in a specific block
int row = by * TILE_WIDTH + ty;
int col = bx * TILE_WIDTH + tx;
// Allocate the TILE on the shared memory.
__shared__ float A_sub[TILE_WIDTH][TILE_WIDTH];
__shared__ float B_sub[TILE_WIDTH][TILE_WIDTH];
// If condition to eliminate extra or dim which dim % 32 (or 2^n) != 0
if (by * blockDim.y + ty < dim && bx * blockDim.y + tx < dim) {
// partial sum
float sum = 0;
for (int k = 0; k < dim / TILE_WIDTH + 1; k++) {
// in case that k * TILE_WIDTH + thread > dim,
// we assign those values to be 0.
// Even doing the dot product everything will be 0.
A_sub[ty][tx] =
(k * TILE_WIDTH + tx) < dim ?
A[row * dim + (k * TILE_WIDTH + tx)] : 0;
B_sub[ty][tx] =
(k * TILE_WIDTH + ty) < dim ?
B[(k * TILE_WIDTH + ty) * dim + col] : 0;
// Wait until all the threads finish doing that
__syncthreads();
// At this point, all of the TILES need for the
// target tile are loaded to shared mem.
// The sum will be the cumulated sum for the
// specific thread it's computing
for (int m = 0; m < TILE_WIDTH; m++) {
sum += A_sub[ty][m] * B_sub[m][tx];
}
// Wait until all the threads finish so that
// the shared mem can be flashed
__syncthreads();
}
// classic [][]
C[row * dim + col] = sum;
}
}
int main(int argc, char **argv) {
int dim;
if (argc == 2) {
dim = atoi(argv[1]);
} else {
dim = DIM;
}
int memSize = dim * dim * sizeof(float);
float *host_A, *host_B, *host_C;
float *dev_A, *dev_B, *dev_C;
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
float milliseconds = 0;
host_A = (float *) malloc(memSize);
host_B = (float *) malloc(memSize);
host_C = (float *) malloc(memSize);
cudaMalloc(&dev_A, memSize);
cudaMalloc(&dev_B, memSize);
cudaMalloc(&dev_C, memSize);
for (int i = 0; i < dim * dim; i++) {
host_A[i] = 0.9;
host_B[i] = 0.9;
}
cudaMemcpy(dev_A, host_A, memSize, cudaMemcpyHostToDevice);
cudaMemcpy(dev_B, host_B, memSize, cudaMemcpyHostToDevice);
cudaEventRecord(start);
// If dim < MAX_THREADS, then the threads we using can be
// the dim itself. Otherwise, threads should be max threads
// in order to use 1024 threads per block.
int threads = dim < MAX_THREADS ? dim : MAX_THREADS;
// Calculate the number of blocks that is necessary for
// the calculation
int blocks = dim * dim / threads / threads + 1;
// Figure out the square-like block geometry
// (which shouldn't be matter too much, but for simplicity)
int block_x = (int) sqrt(blocks);
int block_y = blocks / block_x;
if (block_x * block_y < blocks) {
block_x++;
}
dim3 dimGrid(block_x, block_y);
dim3 dimBlock(threads, threads);
matrix_multiplication<<<dimGrid, dimBlock>>>
(dev_A, dev_B, dev_C, dim);
cudaMemcpy(host_C, dev_C, memSize, cudaMemcpyDeviceToHost);
cudaEventRecord(stop);
cudaEventElapsedTime(&milliseconds, start, stop);
printf("Cuda version\n");
printf("The execution time is %f milliseconds\n", milliseconds);
printf("\n");
printf("Result - for sanity check\n");
for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
printf("%08f\t", host_C[i * dim + j]);
}
printf("\n");
}
cudaEventDestroy(start);
cudaEventDestroy(stop);
free(host_A);
free(host_B);
free(host_C);
cudaFree(dev_A);
cudaFree(dev_B);
cudaFree(dev_C);
return 0;
}
|
e06c60ebb45cbd3db99cc6fdc581b4b755509f96.hip | // !!! This is a file automatically generated by hipify!!!
/*
* Proj 3-2 SKELETON
*/
#include <float.h>
#include <stdlib.h>
#include <stdio.h>
#include <hip/hip_runtime.h>
#include <cutil.h>
#include "utils.h"
/* Transposes the square array ARR. */
__global__ void transposeKernel(float *out, float *arr, int width) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < width && j < width)
out[(i * width) + j] = arr[(j * width) + i];
}
/* Rotates the square array ARR by 90 degrees counterclockwise. */
__global__ void rotateKernel(float *out, float *arr, int width) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < width && j < width)
out[(i * width) + j] = arr[(j * width) + width - i - 1];
}
__global__ void calc_min_dist_kernel(float *scratch, float *image, int i_width, float *temp, int t_width, int k, int l) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < t_width && j < t_width) {
float x = temp[(i * t_width) + j] - image[(i + k) * i_width + j + l];
scratch[(i * t_width) + j] = x * x;
}
}
__global__ void reduceKernel(float *arr, unsigned int len, unsigned int level) {
unsigned int threadIndex = (level * 2) * (blockIdx.x * blockDim.x + threadIdx.x);
if (threadIndex + level < len)
arr[threadIndex] += arr[threadIndex + level];
}
/* Returns the squared Euclidean distance between TEMPLATE and IMAGE. The size of IMAGE
* is I_WIDTH * I_HEIGHT, while TEMPLATE is square with side length T_WIDTH. The template
* image should be flipped, rotated, and translated across IMAGE.
*/
float calc_min_dist(float *image, int i_width, int i_height, float *temp, int t_width) {
// float* image and float* temp are pointers to GPU addressible memory
// You MAY NOT copy this data back to CPU addressible memory and you MAY
// NOT perform any computation using values from image or temp on the CPU.
// The only computation you may perform on the CPU directly derived from distance
// values is selecting the minimum distance value given a calculated distance and a
// "min so far"
float *scratch;
float seq = FLT_MAX;
float min_dist = FLT_MAX;
unsigned int len = t_width * t_width;
size_t size = t_width * t_width * sizeof(float);
CUDA_SAFE_CALL(hipMalloc(&scratch, size));
int threads_per_block = 512;
int gridx = t_width / 256;
int gridy = t_width / 2;
if (t_width < threads_per_block) {
gridx = 2;
gridy = 256;
}
dim3 dim_blocks_per_grid(gridx, gridy);
dim3 dim_threads_per_block(256, 2, 1);
for (int i = 0; i < 8; i++) {
if (i == 4) {
hipLaunchKernelGGL(( transposeKernel), dim3(dim_blocks_per_grid), dim3(dim_threads_per_block), 0, 0, scratch, temp, t_width);
hipDeviceSynchronize();
CUT_CHECK_ERROR("");
CUDA_SAFE_CALL(hipMemcpy(temp, scratch, size, hipMemcpyDeviceToDevice));
} else if (i > 0) {
hipLaunchKernelGGL(( rotateKernel), dim3(dim_blocks_per_grid), dim3(dim_threads_per_block), 0, 0, scratch, temp, t_width);
hipDeviceSynchronize();
CUT_CHECK_ERROR("");
CUDA_SAFE_CALL(hipMemcpy(temp, scratch, size, hipMemcpyDeviceToDevice));
}
for (int j = 0; j <= i_width - t_width; j++) {
for (int k = 0; k <= i_height - t_width; k++) {
hipLaunchKernelGGL(( calc_min_dist_kernel), dim3(dim_blocks_per_grid), dim3(dim_threads_per_block), 0, 0, scratch, image, i_width, temp, t_width, j, k);
hipDeviceSynchronize();
CUT_CHECK_ERROR("");
int blocks_per_grid = (len/threads_per_block)/2;
unsigned int level = 1;
while (level != len) {
dim3 dim_blocks_per_grid(blocks_per_grid, 1);
dim3 dim_threads_per_block(threads_per_block, 1, 1);
hipLaunchKernelGGL(( reduceKernel), dim3(dim_blocks_per_grid), dim3(dim_threads_per_block), 0, 0, scratch, len, level);
hipDeviceSynchronize();
CUT_CHECK_ERROR("");
level *= 2;
blocks_per_grid = blocks_per_grid / 2;
if (blocks_per_grid == 0) blocks_per_grid = 1;
}
CUDA_SAFE_CALL(hipMemcpy(&seq, scratch, sizeof(float), hipMemcpyDeviceToHost));
if (min_dist > seq) min_dist = seq;
}
}
}
CUDA_SAFE_CALL(hipFree(scratch));
return min_dist;
}
| e06c60ebb45cbd3db99cc6fdc581b4b755509f96.cu | /*
* Proj 3-2 SKELETON
*/
#include <float.h>
#include <stdlib.h>
#include <stdio.h>
#include <cuda_runtime.h>
#include <cutil.h>
#include "utils.h"
/* Transposes the square array ARR. */
__global__ void transposeKernel(float *out, float *arr, int width) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < width && j < width)
out[(i * width) + j] = arr[(j * width) + i];
}
/* Rotates the square array ARR by 90 degrees counterclockwise. */
__global__ void rotateKernel(float *out, float *arr, int width) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < width && j < width)
out[(i * width) + j] = arr[(j * width) + width - i - 1];
}
__global__ void calc_min_dist_kernel(float *scratch, float *image, int i_width, float *temp, int t_width, int k, int l) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if (i < t_width && j < t_width) {
float x = temp[(i * t_width) + j] - image[(i + k) * i_width + j + l];
scratch[(i * t_width) + j] = x * x;
}
}
__global__ void reduceKernel(float *arr, unsigned int len, unsigned int level) {
unsigned int threadIndex = (level * 2) * (blockIdx.x * blockDim.x + threadIdx.x);
if (threadIndex + level < len)
arr[threadIndex] += arr[threadIndex + level];
}
/* Returns the squared Euclidean distance between TEMPLATE and IMAGE. The size of IMAGE
* is I_WIDTH * I_HEIGHT, while TEMPLATE is square with side length T_WIDTH. The template
* image should be flipped, rotated, and translated across IMAGE.
*/
float calc_min_dist(float *image, int i_width, int i_height, float *temp, int t_width) {
// float* image and float* temp are pointers to GPU addressible memory
// You MAY NOT copy this data back to CPU addressible memory and you MAY
// NOT perform any computation using values from image or temp on the CPU.
// The only computation you may perform on the CPU directly derived from distance
// values is selecting the minimum distance value given a calculated distance and a
// "min so far"
float *scratch;
float seq = FLT_MAX;
float min_dist = FLT_MAX;
unsigned int len = t_width * t_width;
size_t size = t_width * t_width * sizeof(float);
CUDA_SAFE_CALL(cudaMalloc(&scratch, size));
int threads_per_block = 512;
int gridx = t_width / 256;
int gridy = t_width / 2;
if (t_width < threads_per_block) {
gridx = 2;
gridy = 256;
}
dim3 dim_blocks_per_grid(gridx, gridy);
dim3 dim_threads_per_block(256, 2, 1);
for (int i = 0; i < 8; i++) {
if (i == 4) {
transposeKernel<<<dim_blocks_per_grid, dim_threads_per_block>>>(scratch, temp, t_width);
cudaThreadSynchronize();
CUT_CHECK_ERROR("");
CUDA_SAFE_CALL(cudaMemcpy(temp, scratch, size, cudaMemcpyDeviceToDevice));
} else if (i > 0) {
rotateKernel<<<dim_blocks_per_grid, dim_threads_per_block>>>(scratch, temp, t_width);
cudaThreadSynchronize();
CUT_CHECK_ERROR("");
CUDA_SAFE_CALL(cudaMemcpy(temp, scratch, size, cudaMemcpyDeviceToDevice));
}
for (int j = 0; j <= i_width - t_width; j++) {
for (int k = 0; k <= i_height - t_width; k++) {
calc_min_dist_kernel<<<dim_blocks_per_grid, dim_threads_per_block>>>(scratch, image, i_width, temp, t_width, j, k);
cudaThreadSynchronize();
CUT_CHECK_ERROR("");
int blocks_per_grid = (len/threads_per_block)/2;
unsigned int level = 1;
while (level != len) {
dim3 dim_blocks_per_grid(blocks_per_grid, 1);
dim3 dim_threads_per_block(threads_per_block, 1, 1);
reduceKernel<<<dim_blocks_per_grid, dim_threads_per_block>>>(scratch, len, level);
cudaThreadSynchronize();
CUT_CHECK_ERROR("");
level *= 2;
blocks_per_grid = blocks_per_grid / 2;
if (blocks_per_grid == 0) blocks_per_grid = 1;
}
CUDA_SAFE_CALL(cudaMemcpy(&seq, scratch, sizeof(float), cudaMemcpyDeviceToHost));
if (min_dist > seq) min_dist = seq;
}
}
}
CUDA_SAFE_CALL(cudaFree(scratch));
return min_dist;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.