Added simplified Coulomb kernel

This commit is contained in:
Patrick Lipka 2024-12-13 11:48:18 +01:00
parent b5beb5d2cd
commit 8dd3de290b
1 changed files with 34 additions and 0 deletions

View File

@ -83,5 +83,39 @@ void initialize_registry(KernelRegistry* registry, std::string strategy_name) {
return Kernel("daxpy", execute, prepare); return Kernel("daxpy", execute, prepare);
}); });
// SIMPLIFIED COULOMB POTENTIAL
registry->register_kernel("coulomb", [&]() {
auto potential = std::make_shared<std::vector<float>>();
auto charge1 = std::make_shared<std::vector<float>>();
auto charge2 = std::make_shared<std::vector<float>>();
auto rx = std::make_shared<std::vector<float>>();
auto ry = std::make_shared<std::vector<float>>();
auto rz = std::make_shared<std::vector<float>>();
auto prepare = [=]() {
potential->resize(VECTOR_SIZE);
charge1->resize(VECTOR_SIZE);
charge2->resize(VECTOR_SIZE);
rx->resize(VECTOR_SIZE);
ry->resize(VECTOR_SIZE);
rz->resize(VECTOR_SIZE);
initialize_vector(*charge1);
initialize_vector(*charge2);
initialize_vector(*rx);
initialize_vector(*ry);
initialize_vector(*rz);
};
auto execute = [=](int kernel_start_idx, int kernel_end_idx, int num_threads_or_tasks) {
strategy::execute_strategy(strategy_name, kernel_start_idx, kernel_end_idx, num_threads_or_tasks, [&](int i) {
(*potential)[i] = (*charge1)[i] * (*charge2)[i] / std::sqrt((*rx)[i] * (*rx)[i] + (*ry)[i] * (*ry)[i] + (*rz)[i] * (*rz)[i]);
});
};
return Kernel("coulomb", execute, prepare);
});
} }