diff --git a/src/kernels.cpp b/src/kernels.cpp index d1f14b3..e6cef3c 100644 --- a/src/kernels.cpp +++ b/src/kernels.cpp @@ -83,5 +83,39 @@ void initialize_registry(KernelRegistry* registry, std::string strategy_name) { return Kernel("daxpy", execute, prepare); }); + // SIMPLIFIED COULOMB POTENTIAL + registry->register_kernel("coulomb", [&]() { + auto potential = std::make_shared>(); + auto charge1 = std::make_shared>(); + auto charge2 = std::make_shared>(); + auto rx = std::make_shared>(); + auto ry = std::make_shared>(); + auto rz = std::make_shared>(); + + 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); + }); + + }