@@ -653,5 +653,352 @@ BENCHMARK_TEMPLATE_DEFINE_F(CoordinatesBench, DihedralsMDATriclinicOutBoxDouble,
653653BENCHMARK_REGISTER_F (CoordinatesBench, DihedralsMDATriclinicOutBoxDouble)->RangeMultiplier(10 )->Ranges({{10 , 10000000 }, {0 , 0 }, {0 , 0 }});
654654
655655
656+ template <typename T>
657+ class DistanceArrayCoordinatesBench : public benchmark ::Fixture {
658+ public:
659+ int ncoordsA;
660+ int ncoordsB;
661+ int nresults;
662+ T* coordsA = nullptr ;
663+ T* coordsB = nullptr ;
664+ T* ref = nullptr ;
665+ T* results = nullptr ;
666+ T box[3 ];
667+ T triclinic_box[9 ];
668+
669+ void SetUp (benchmark::State &state) override {
670+ ncoordsA = static_cast <std::size_t >(state.range (0 ));
671+ ncoordsB = static_cast <std::size_t >(state.range (1 ));
672+
673+ InitCoords (state.range (0 ), state.range (1 ), BOXSIZE, state.range (2 ));
674+ }
675+
676+ void InitCoords (int nA, int nB, const double boxsize, const double delta) {
677+ ncoordsA = nA;
678+ ncoordsB = nB;
679+ nresults = nA * nB;
680+
681+ coordsA = new T[nA * 3 ];
682+ coordsB = new T[nB * 3 ];
683+ ref = new T[nresults];
684+ results = new T[nresults];
685+
686+ RandomFloatingPoint<T>(coordsA, nA * 3 , 0 - delta, boxsize + delta);
687+ RandomFloatingPoint<T>(coordsB, nB * 3 , 0 - delta, boxsize + delta);
688+
689+ box[0 ] = boxsize;
690+ box[1 ] = boxsize;
691+ box[2 ] = boxsize;
692+
693+ triclinic_box[0 ] = boxsize; // lx
694+ triclinic_box[1 ] = 0.0 ; // must be 0
695+ triclinic_box[2 ] = 0.0 ; // "
696+ triclinic_box[3 ] = 0.0 ; // xy
697+ triclinic_box[4 ] = boxsize; // ly
698+ triclinic_box[5 ] = 0.0 ; // must be zero
699+ triclinic_box[6 ] = 0.0 ; // xz
700+ triclinic_box[7 ] = 0.0 ; // yz
701+ triclinic_box[8 ] = boxsize; // lz
702+ }
703+
704+ void TearDown (const ::benchmark::State &state) override {
705+ delete[] coordsA;
706+ delete[] coordsB;
707+ delete[] ref;
708+ delete[] results;
709+ }
710+
711+ void BM_distance_array_MDA (benchmark::State &state) {
712+ using ctype = ScalarToCoordinateT<T>;
713+
714+ for (auto _ : state) {
715+ _distance_array ((ctype*)coordsA, ncoordsA, (ctype*)coordsB, ncoordsB, ref);
716+ }
717+ state.SetItemsProcessed (nresults * state.iterations ());
718+ state.counters [" Per Result" ] = benchmark::Counter (
719+ nresults * state.iterations (),
720+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
721+ }
722+
723+ void BM_distance_array (benchmark::State &state) {
724+ for (auto _ : state) {
725+ distopia::DistanceArrayNoBox (coordsA, coordsB, ncoordsA, ncoordsB, results);
726+ }
727+ state.SetItemsProcessed (nresults * state.iterations ());
728+ state.counters [" Per Result" ] = benchmark::Counter (
729+ nresults * state.iterations (),
730+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
731+ }
732+
733+ void BM_distance_array_ortho_MDA (benchmark::State &state) {
734+ using ctype = ScalarToCoordinateT<T>;
735+
736+ for (auto _ : state) {
737+ _distance_array_ortho ((ctype *)coordsA, ncoordsA,
738+ (ctype *)coordsB, ncoordsB,
739+ box, ref);
740+ }
741+ state.SetItemsProcessed (nresults * state.iterations ());
742+ state.counters [" Per Result" ] = benchmark::Counter (
743+ nresults * state.iterations (),
744+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
745+ }
746+
747+ void BM_distance_array_ortho (benchmark::State &state) {
748+ for (auto _ : state) {
749+ distopia::DistanceArrayOrtho (coordsA, coordsB, ncoordsA, ncoordsB, box, results);
750+ }
751+ state.SetItemsProcessed (nresults * state.iterations ());
752+ state.counters [" Per Result" ] = benchmark::Counter (
753+ nresults * state.iterations (),
754+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
755+ }
756+
757+ void BM_distance_array_triclinic_MDA (benchmark::State &state) {
758+ using ctype = ScalarToCoordinateT<T>;
759+
760+ for (auto _ : state) {
761+ _distance_array_triclinic ((ctype*)coordsA, ncoordsA, (ctype*)coordsB, ncoordsB, triclinic_box, ref);
762+ }
763+ state.SetItemsProcessed (nresults * state.iterations ());
764+ state.counters [" Per Result" ] = benchmark::Counter (
765+ nresults * state.iterations (),
766+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
767+ }
768+
769+ void BM_distance_array_triclinic (benchmark::State &state) {
770+ for (auto _ : state) {
771+ distopia::DistanceArrayTriclinic (coordsA, coordsB, ncoordsA, ncoordsB, triclinic_box, results);
772+ }
773+ state.SetItemsProcessed (nresults * state.iterations ());
774+ state.counters [" Per Result" ] = benchmark::Counter (
775+ nresults * state.iterations (),
776+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
777+ }
778+ };
779+
780+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxMDAFloat, float )
781+ (benchmark::State &state) { BM_distance_array_MDA (state); }
782+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxMDAFloat)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
783+
784+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxMDADouble, double )
785+ (benchmark::State &state) { BM_distance_array_MDA (state); }
786+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxMDADouble)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
787+
788+
789+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxFloat, float )
790+ (benchmark::State &state) { BM_distance_array (state); }
791+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxFloat)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
792+
793+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxDouble, double )
794+ (benchmark::State &state) { BM_distance_array (state); }
795+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayNoBoxDouble)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
796+
797+
798+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoMDAFloat, float )
799+ (benchmark::State &state) { BM_distance_array_ortho_MDA (state); }
800+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoMDAFloat)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
801+
802+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoMDADouble, double )
803+ (benchmark::State &state) { BM_distance_array_ortho_MDA (state); }
804+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoMDADouble)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
805+
806+
807+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoFloat, float )
808+ (benchmark::State &state) { BM_distance_array_ortho (state); }
809+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoFloat)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
810+
811+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoDouble, double )
812+ (benchmark::State &state) { BM_distance_array_ortho (state); }
813+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayOrthoDouble)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
814+
815+
816+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicMDAFloat, float )
817+ (benchmark::State &state) { BM_distance_array_triclinic_MDA (state); }
818+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicMDAFloat)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
819+
820+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicMDADouble, double )
821+ (benchmark::State &state) { BM_distance_array_triclinic_MDA (state); }
822+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicMDADouble)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
823+
824+
825+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicFloat, float )
826+ (benchmark::State &state) { BM_distance_array_triclinic (state); }
827+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicFloat)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
828+
829+ BENCHMARK_TEMPLATE_DEFINE_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicDouble, double )
830+ (benchmark::State &state) { BM_distance_array_triclinic (state); }
831+ BENCHMARK_REGISTER_F (DistanceArrayCoordinatesBench, DistanceArrayTriclinicDouble)->RangeMultiplier(100 )->Ranges({{100 , 10000 }, {100 , 10000 }, {0 , 0 }});
832+
833+
834+ template <typename T>
835+ class SelfDistanceArrayCoordinatesBench : public benchmark ::Fixture {
836+ public:
837+ int ncoords;
838+ int nresults;
839+ T* coords = nullptr ;
840+ T* ref = nullptr ;
841+ T* results = nullptr ;
842+ T box[3 ];
843+ T triclinic_box[9 ];
844+
845+ void SetUp (benchmark::State &state) override {
846+ ncoords = static_cast <std::size_t >(state.range (0 ));
847+
848+ InitCoords (state.range (0 ), BOXSIZE, state.range (1 ));
849+ }
850+
851+ void InitCoords (int n, const double boxsize, const double delta) {
852+ ncoords = n;
853+ nresults = n * n;
854+
855+ coords = new T[n * 3 ];
856+ ref = new T[nresults];
857+ results = new T[nresults];
858+
859+ RandomFloatingPoint<T>(coords, n * 3 , 0 - delta, boxsize + delta);
860+
861+ box[0 ] = boxsize;
862+ box[1 ] = boxsize;
863+ box[2 ] = boxsize;
864+
865+ triclinic_box[0 ] = boxsize; // lx
866+ triclinic_box[1 ] = 0.0 ; // must be 0
867+ triclinic_box[2 ] = 0.0 ; // "
868+ triclinic_box[3 ] = 0.0 ; // xy
869+ triclinic_box[4 ] = boxsize; // ly
870+ triclinic_box[5 ] = 0.0 ; // must be zero
871+ triclinic_box[6 ] = 0.0 ; // xz
872+ triclinic_box[7 ] = 0.0 ; // yz
873+ triclinic_box[8 ] = boxsize; // lz
874+ }
875+
876+ void TearDown (const ::benchmark::State &state) override {
877+ delete[] coords;
878+ delete[] ref;
879+ delete[] results;
880+ }
881+
882+ void BM_self_distance_array_MDA (benchmark::State &state) {
883+ using ctype = ScalarToCoordinateT<T>;
884+
885+ for (auto _ : state) {
886+ _self_distance_array ((ctype*)coords, ncoords, ref);
887+ }
888+ state.SetItemsProcessed (nresults * state.iterations ());
889+ state.counters [" Per Result" ] = benchmark::Counter (
890+ nresults * state.iterations (),
891+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
892+ }
893+
894+ void BM_self_distance_array (benchmark::State &state) {
895+ for (auto _ : state) {
896+ distopia::SelfDistanceArrayNoBox (coords, ncoords, results);
897+ }
898+ state.SetItemsProcessed (nresults * state.iterations ());
899+ state.counters [" Per Result" ] = benchmark::Counter (
900+ nresults * state.iterations (),
901+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
902+ }
903+
904+ void BM_self_distance_array_ortho_MDA (benchmark::State &state) {
905+ using ctype = ScalarToCoordinateT<T>;
906+
907+ for (auto _ : state) {
908+ _self_distance_array_ortho ((ctype *)coords, ncoords,
909+ box, ref);
910+ }
911+ state.SetItemsProcessed (nresults * state.iterations ());
912+ state.counters [" Per Result" ] = benchmark::Counter (
913+ nresults * state.iterations (),
914+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
915+ }
916+
917+ void BM_self_distance_array_ortho (benchmark::State &state) {
918+ for (auto _ : state) {
919+ distopia::SelfDistanceArrayOrtho (coords, ncoords, box, results);
920+ }
921+ state.SetItemsProcessed (nresults * state.iterations ());
922+ state.counters [" Per Result" ] = benchmark::Counter (
923+ nresults * state.iterations (),
924+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
925+ }
926+
927+ void BM_self_distance_array_triclinic_MDA (benchmark::State &state) {
928+ using ctype = ScalarToCoordinateT<T>;
929+
930+ for (auto _ : state) {
931+ _self_distance_array_triclinic ((ctype*)coords, ncoords, triclinic_box, ref);
932+ }
933+ state.SetItemsProcessed (nresults * state.iterations ());
934+ state.counters [" Per Result" ] = benchmark::Counter (
935+ nresults * state.iterations (),
936+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
937+ }
938+
939+ void BM_self_distance_array_triclinic (benchmark::State &state) {
940+ for (auto _ : state) {
941+ distopia::SelfDistanceArrayTriclinic (coords, ncoords, triclinic_box, results);
942+ }
943+ state.SetItemsProcessed (nresults * state.iterations ());
944+ state.counters [" Per Result" ] = benchmark::Counter (
945+ nresults * state.iterations (),
946+ benchmark::Counter::kIsRate | benchmark::Counter::kInvert );
947+ }
948+ };
949+
950+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxMDAFloat, float )
951+ (benchmark::State &state) { BM_self_distance_array_MDA (state); }
952+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxMDAFloat)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
953+
954+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxMDADouble, double )
955+ (benchmark::State &state) { BM_self_distance_array_MDA (state); }
956+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxMDADouble)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
957+
958+
959+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxFloat, float )
960+ (benchmark::State &state) { BM_self_distance_array (state); }
961+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxFloat)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
962+
963+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxDouble, double )
964+ (benchmark::State &state) { BM_self_distance_array (state); }
965+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayNoBoxDouble)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
966+
967+
968+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoMDAFloat, float )
969+ (benchmark::State &state) { BM_self_distance_array_ortho_MDA (state); }
970+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoMDAFloat)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
971+
972+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoMDADouble, double )
973+ (benchmark::State &state) { BM_self_distance_array_ortho_MDA (state); }
974+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoMDADouble)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
975+
976+
977+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoFloat, float )
978+ (benchmark::State &state) { BM_self_distance_array_ortho (state); }
979+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoFloat)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
980+
981+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoDouble, double )
982+ (benchmark::State &state) { BM_self_distance_array_ortho (state); }
983+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayOrthoDouble)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
984+
985+
986+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicMDAFloat, float )
987+ (benchmark::State &state) { BM_self_distance_array_triclinic_MDA (state); }
988+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicMDAFloat)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
989+
990+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicMDADouble, double )
991+ (benchmark::State &state) { BM_self_distance_array_triclinic_MDA (state); }
992+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicMDADouble)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
993+
994+
995+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicFloat, float )
996+ (benchmark::State &state) { BM_self_distance_array_triclinic (state); }
997+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicFloat)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
998+
999+ BENCHMARK_TEMPLATE_DEFINE_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicDouble, double )
1000+ (benchmark::State &state) { BM_self_distance_array_triclinic (state); }
1001+ BENCHMARK_REGISTER_F (SelfDistanceArrayCoordinatesBench, SelfDistanceArrayTriclinicDouble)->RangeMultiplier(10 )->Ranges({{10 , 10000 }, {0 , 0 }, {0 , 0 }});
1002+
6561003
6571004BENCHMARK_MAIN ();
0 commit comments