39 #include "Utils/clusterspecifier.h" 69 for(
int i = 0; i < sites; i++)
70 lattice[i] = other.lattice[i];
73 lattice(std::move(other.lattice)),
74 sites(std::move(other.sites)),
75 size(std::move(other.size)) { }
78 Lattice(std::array<int, 4> sizeArray);
79 void allocate(std::array<int, 4> sizeArray);
82 std::vector<T> lattice;
83 std::array<int,4> size;
87 inline T& at(
int x,
int y,
int z,
int t) {
88 return lattice[x + size[0]*(y + size[1]*(z + size[2]*t))];
91 inline T& at(
const std::vector<int>& site){
92 return lattice[site[0] + size[0]*(site[1] + size[1]*(site[2] + size[2]*site[3]))];
94 inline T& at(
const std::array<int, 4>& site){
95 return lattice[site[0] + size[0]*(site[1] + size[1]*(site[2] + size[2]*site[3]))];
100 inline const T& at(
int x,
int y,
int z,
int t)
const {
101 return lattice[x + size[0]*(y + size[1]*(z + size[2]*t))];
104 inline const T& at(
const std::vector<int>& site)
const {
105 return lattice[site[0] + size[0]*(site[1] + size[1]*(site[2] + size[2]*site[3]))];
107 inline const T& at(
const std::array<int, 4>& site)
const {
108 return lattice[site[0] + size[0]*(site[1] + size[1]*(site[2] + size[2]*site[3]))];
110 inline const T& at(
int i)
const {
116 lattice = other.lattice;
122 std::swap(lattice, other.lattice);
123 std::swap(sites, other.sites);
124 std::swap(size, other.size);
131 for(
int i = 0; i < sites; i++)
132 lattice[i] += other.lattice[i];
136 for(
int i = 0; i < sites; i++)
137 lattice[i] += other.lattice[i];
153 for(
int i = 0; i < sites; i++)
154 lattice[i] -= other.lattice[i];
158 for(
int i = 0; i < sites; i++)
159 lattice[i] -= other.lattice[i];
175 for(
int i = 0; i < sites; i++)
176 lattice[i] *= other.lattice[i];
180 for(
int i = 0; i < sites; i++)
181 lattice[i] *= other.lattice[i];
198 inline Lattice& operator+=(
double scalar ) noexcept {
199 for(
int i = 0; i < sites; i++)
200 lattice[i] += scalar;
209 inline Lattice& operator-=(
double scalar ) noexcept {
210 for(
int i = 0; i < sites; i++)
211 lattice[i] -= scalar;
220 inline Lattice& operator*=(
double scalar ) noexcept {
221 for(
int i = 0; i < sites; i++)
222 lattice[i] *= scalar;
231 template <
typename T>
234 for(
int i = 0; i < result.sites; i++)
235 result.at(i) = ~base.at(i);
236 return std::move(result);
239 template <
typename T>
242 for(
int i = 0; i < result.sites; i++)
243 result.at(i) = ~base.at(i);
244 return std::move(result);
247 template <
typename T>
250 for(
int i = 0; i < result.sites; i++)
251 result.at(i) =
exp(base.at(i));
252 return std::move(result);
255 template <
typename T>
258 for(
int i = 0; i < result.sites; i++)
259 result.at(i) =
exp(base.at(i));
260 return std::move(result);
264 template <
typename T>
267 for(
int i = 0; i < base.sites; i++)
268 result += base.at(i);
276 for(
int i = 0; i < base.sites; i++)
277 result += base.at(i);
281 template <
typename T>
284 for(
int i = 0; i < base.sites; i++)
285 result += base.at(i);
293 for(
int i = 0; i < base.sites; i++)
294 result += base.at(i);
295 return std::move(result);
300 for(
int i = 0; i < base.sites; i++)
301 result.at(i) = base.at(i).realTrace();
302 return std::move(result);
307 for(
int i = 0; i < base.sites; i++)
308 result.at(i) = base.at(i).imagTrace();
309 return std::move(result);
314 for(
int i = 0; i < base.sites; i++)
315 result.at(i) = base.at(i).realTrace();
316 return std::move(result);
321 for(
int i = 0; i < base.sites; i++)
322 result.at(i) = base.at(i).imagTrace();
323 return std::move(result);
327 template <
typename T>
333 template <
typename T>
338 template <
typename T>
342 sites = size[0] * size[1] * size[2] * size[3];
343 lattice.resize(sites);
364 shifted.allocate(lat.size);
367 std::array<int,4> bufferSize;
369 for(
int i = 0; i < 4; i++)
370 i != shiftDir ? bufferSize[i] = shifted.size[i] : bufferSize[i] = 1;
371 sendBuffer.allocate(bufferSize);
372 recvBuffer.allocate(bufferSize);
376 if(shiftDir == 0 && shiftStep == 1){
377 for(
int y = 0; y < lat.size[1]; y++){
378 for(
int z = 0; z < lat.size[2]; z++){
379 for(
int t = 0; t < lat.size[3]; t++){
380 sendBuffer.at(0,y,z,t) = lat.at(0,y,z,t);
383 else if(shiftDir == 0 && shiftStep == -1){
384 for(
int y = 0; y < lat.size[1]; y++){
385 for(
int z = 0; z < lat.size[2]; z++){
386 for(
int t = 0; t < lat.size[3]; t++){
387 sendBuffer.at(0,y,z,t) = lat.at(lat.size[0] - 1,y,z,t);
392 else if(shiftDir == 1 && shiftStep == 1){
393 for(
int x = 0; x < lat.size[0]; x++){
394 for(
int z = 0; z < lat.size[2]; z++){
395 for(
int t = 0; t < lat.size[3]; t++){
396 sendBuffer.at(x,0,z,t) = lat.at(x,0,z,t);
399 else if(shiftDir == 1 && shiftStep == -1){
400 for(
int x = 0; x < lat.size[0]; x++){
401 for(
int z = 0; z < lat.size[2]; z++){
402 for(
int t = 0; t < lat.size[3]; t++){
403 sendBuffer.at(x,0,z,t) = lat.at(x,lat.size[1] - 1,z,t);
408 else if(shiftDir == 2 && shiftStep == 1){
409 for(
int x = 0; x < lat.size[0]; x++){
410 for(
int y = 0; y < lat.size[1]; y++){
411 for(
int t = 0; t < lat.size[3]; t++){
412 sendBuffer.at(x,y,0,t) = lat.at(x,y,0,t);
415 else if(shiftDir == 2 && shiftStep == -1){
416 for(
int x = 0; x < lat.size[0]; x++){
417 for(
int y = 0; y < lat.size[1]; y++){
418 for(
int t = 0; t < lat.size[3]; t++){
419 sendBuffer.at(x,y,0,t) = lat.at(x,y,lat.size[2] - 1,t);
422 else if(shiftDir == 3 && shiftStep == 1){
423 for(
int x = 0; x < lat.size[0]; x++){
424 for(
int y = 0; y < lat.size[1]; y++){
425 for(
int z = 0; z < lat.size[2]; z++){
426 sendBuffer.at(x,y,z,0) = lat.at(x,y,z,0);
429 else if(shiftDir == 3 && shiftStep == -1){
430 for(
int x = 0; x < lat.size[0]; x++){
431 for(
int y = 0; y < lat.size[1]; y++){
432 for(
int z = 0; z < lat.size[2]; z++){
433 sendBuffer.at(x,y,z,0) = lat.at(x,y,z,lat.size[3] - 1);
438 MPI_Request sendRequest, recvRequest;
440 int bufferCount = 18*bufferSize[0]*bufferSize[1]*bufferSize[2]*bufferSize[3];
442 shiftStep == -1 ? shiftRank = 0 : shiftRank = 1;
444 MPI_Isend(sendBuffer.lattice.data(), bufferCount, MPI_DOUBLE,
446 MPI_COMM_WORLD, &sendRequest);
447 MPI_Irecv(recvBuffer.lattice.data(), bufferCount, MPI_DOUBLE,
449 MPI_COMM_WORLD, &recvRequest);
454 if(shiftDir == 0 && shiftStep == 1){
455 for(
int x = 0; x < lat.size[0]-1; x++){
456 for(
int y = 0; y < lat.size[1]; y++){
457 for(
int z = 0; z < lat.size[2]; z++){
458 for(
int t = 0; t < lat.size[3]; t++){
459 shifted.at(x,y,z,t) = lat.at(x+1,y,z,t);
462 else if(shiftDir == 0 && shiftStep == -1){
463 for(
int x = 1; x < lat.size[0]; x++){
464 for(
int y = 0; y < lat.size[1]; y++){
465 for(
int z = 0; z < lat.size[2]; z++){
466 for(
int t = 0; t < lat.size[3]; t++){
467 shifted.at(x,y,z,t) = lat.at(x-1,y,z,t);
471 else if(shiftDir == 1 && shiftStep == 1){
472 for(
int x = 0; x < lat.size[0]; x++){
473 for(
int y = 0; y < lat.size[1]-1; y++){
474 for(
int z = 0; z < lat.size[2]; z++){
475 for(
int t = 0; t < lat.size[3]; t++){
476 shifted.at(x,y,z,t) = lat.at(x,y+1,z,t);
479 else if(shiftDir == 1 && shiftStep == -1){
480 for(
int x = 0; x < lat.size[0]; x++){
481 for(
int y = 1; y < lat.size[1]; y++){
482 for(
int z = 0; z < lat.size[2]; z++){
483 for(
int t = 0; t < lat.size[3]; t++){
484 shifted.at(x,y,z,t) = lat.at(x,y-1,z,t);
488 else if(shiftDir == 2 && shiftStep == 1){
489 for(
int x = 0; x < lat.size[0]; x++){
490 for(
int y = 0; y < lat.size[1]; y++){
491 for(
int z = 0; z < lat.size[2]-1; z++){
492 for(
int t = 0; t < lat.size[3]; t++){
493 shifted.at(x,y,z,t) = lat.at(x,y,z+1,t);
496 else if(shiftDir == 2 && shiftStep == -1){
497 for(
int x = 0; x < lat.size[0]; x++){
498 for(
int y = 0; y < lat.size[1]; y++){
499 for(
int z = 1; z < lat.size[2]; z++){
500 for(
int t = 0; t < lat.size[3]; t++){
501 shifted.at(x,y,z,t) = lat.at(x,y,z-1,t);
505 else if(shiftDir == 3 && shiftStep == 1){
506 for(
int x = 0; x < lat.size[0]; x++){
507 for(
int y = 0; y < lat.size[1]; y++){
508 for(
int z = 0; z < lat.size[2]; z++){
509 for(
int t = 0; t < lat.size[3]-1; t++){
510 shifted.at(x,y,z,t) = lat.at(x,y,z,t+1);
513 else if(shiftDir == 3 && shiftStep == -1){
514 for(
int x = 0; x < lat.size[0]; x++){
515 for(
int y = 0; y < lat.size[1]; y++){
516 for(
int z = 0; z < lat.size[2]; z++){
517 for(
int t = 1; t < lat.size[3]; t++){
518 shifted.at(x,y,z,t) = lat.at(x,y,z,t-1);
525 MPI_Wait(&sendRequest, &status);
526 MPI_Wait(&recvRequest, &status);
531 if(shiftDir == 0 && shiftStep == 1){
532 for(
int y = 0; y < lat.size[1]; y++){
533 for(
int z = 0; z < lat.size[2]; z++){
534 for(
int t = 0; t < lat.size[3]; t++){
535 shifted.at(lat.size[0] - 1,y,z,t) = recvBuffer.at(0,y,z,t);
538 else if(shiftDir == 0 && shiftStep == -1){
539 for(
int y = 0; y < lat.size[1]; y++){
540 for(
int z = 0; z < lat.size[2]; z++){
541 for(
int t = 0; t < lat.size[3]; t++){
542 shifted.at(0,y,z,t) = recvBuffer.at(0,y,z,t);
547 else if(shiftDir == 1 && shiftStep == 1){
548 for(
int x = 0; x < lat.size[0]; x++){
549 for(
int z = 0; z < lat.size[2]; z++){
550 for(
int t = 0; t < lat.size[3]; t++){
551 shifted.at(x,lat.size[1] - 1,z,t) = recvBuffer.at(x,0,z,t);
554 else if(shiftDir == 1 && shiftStep == -1){
555 for(
int x = 0; x < lat.size[0]; x++){
556 for(
int z = 0; z < lat.size[2]; z++){
557 for(
int t = 0; t < lat.size[3]; t++){
558 shifted.at(x,0,z,t) = recvBuffer.at(x,0,z,t);
563 else if(shiftDir == 2 && shiftStep == 1){
564 for(
int x = 0; x < lat.size[0]; x++){
565 for(
int y = 0; y < lat.size[1]; y++){
566 for(
int t = 0; t < lat.size[3]; t++){
567 shifted.at(x,y,lat.size[2] - 1,t) = recvBuffer.at(x,y,0,t);
570 else if(shiftDir == 2 && shiftStep == -1){
571 for(
int x = 0; x < lat.size[0]; x++){
572 for(
int y = 0; y < lat.size[1]; y++){
573 for(
int t = 0; t < lat.size[3]; t++){
574 shifted.at(x,y,0,t) = recvBuffer.at(x,y,0,t);
577 else if(shiftDir == 3 && shiftStep == 1){
578 for(
int x = 0; x < lat.size[0]; x++){
579 for(
int y = 0; y < lat.size[1]; y++){
580 for(
int z = 0; z < lat.size[2]; z++){
581 shifted.at(x,y,z,lat.size[3] - 1) = recvBuffer.at(x,y,z,0);
584 else if(shiftDir == 3 && shiftStep == -1){
585 for(
int x = 0; x < lat.size[0]; x++){
586 for(
int y = 0; y < lat.size[1]; y++){
587 for(
int z = 0; z < lat.size[2]; z++){
588 shifted.at(x,y,z,0) = recvBuffer.at(x,y,z,0);
601 shifted.allocate(lat.size);
604 std::array<int,4> bufferSize;
606 for(
int i = 0; i < 4; i++)
607 i != shiftDir ? bufferSize[i] = shifted.size[i] : bufferSize[i] = 1;
608 sendBuffer.allocate(bufferSize);
609 recvBuffer.allocate(bufferSize);
613 if(shiftDir == 0 && shiftStep == 1){
614 for(
int y = 0; y < lat.size[1]; y++){
615 for(
int z = 0; z < lat.size[2]; z++){
616 for(
int t = 0; t < lat.size[3]; t++){
617 sendBuffer.at(0,y,z,t) = lat.at(0,y,z,t);
620 else if(shiftDir == 0 && shiftStep == -1){
621 for(
int y = 0; y < lat.size[1]; y++){
622 for(
int z = 0; z < lat.size[2]; z++){
623 for(
int t = 0; t < lat.size[3]; t++){
624 sendBuffer.at(0,y,z,t) = lat.at(lat.size[0] - 1,y,z,t);
629 else if(shiftDir == 1 && shiftStep == 1){
630 for(
int x = 0; x < lat.size[0]; x++){
631 for(
int z = 0; z < lat.size[2]; z++){
632 for(
int t = 0; t < lat.size[3]; t++){
633 sendBuffer.at(x,0,z,t) = lat.at(x,0,z,t);
636 else if(shiftDir == 1 && shiftStep == -1){
637 for(
int x = 0; x < lat.size[0]; x++){
638 for(
int z = 0; z < lat.size[2]; z++){
639 for(
int t = 0; t < lat.size[3]; t++){
640 sendBuffer.at(x,0,z,t) = lat.at(x,lat.size[1] - 1,z,t);
645 else if(shiftDir == 2 && shiftStep == 1){
646 for(
int x = 0; x < lat.size[0]; x++){
647 for(
int y = 0; y < lat.size[1]; y++){
648 for(
int t = 0; t < lat.size[3]; t++){
649 sendBuffer.at(x,y,0,t) = lat.at(x,y,0,t);
652 else if(shiftDir == 2 && shiftStep == -1){
653 for(
int x = 0; x < lat.size[0]; x++){
654 for(
int y = 0; y < lat.size[1]; y++){
655 for(
int t = 0; t < lat.size[3]; t++){
656 sendBuffer.at(x,y,0,t) = lat.at(x,y,lat.size[2] - 1,t);
659 else if(shiftDir == 3 && shiftStep == 1){
660 for(
int x = 0; x < lat.size[0]; x++){
661 for(
int y = 0; y < lat.size[1]; y++){
662 for(
int z = 0; z < lat.size[2]; z++){
663 sendBuffer.at(x,y,z,0) = lat.at(x,y,z,0);
666 else if(shiftDir == 3 && shiftStep == -1){
667 for(
int x = 0; x < lat.size[0]; x++){
668 for(
int y = 0; y < lat.size[1]; y++){
669 for(
int z = 0; z < lat.size[2]; z++){
670 sendBuffer.at(x,y,z,0) = lat.at(x,y,z,lat.size[3] - 1);
675 MPI_Request sendRequest, recvRequest;
677 int bufferCount = 18*bufferSize[0]*bufferSize[1]*bufferSize[2]*bufferSize[3];
679 shiftStep == -1 ? shiftRank = 0 : shiftRank = 1;
681 MPI_Isend(sendBuffer.lattice.data(), bufferCount, MPI_DOUBLE,
683 MPI_COMM_WORLD, &sendRequest);
684 MPI_Irecv(recvBuffer.lattice.data(), bufferCount, MPI_DOUBLE,
686 MPI_COMM_WORLD, &recvRequest);
691 if(shiftDir == 0 && shiftStep == 1){
692 for(
int x = 0; x < lat.size[0]-1; x++){
693 for(
int y = 0; y < lat.size[1]; y++){
694 for(
int z = 0; z < lat.size[2]; z++){
695 for(
int t = 0; t < lat.size[3]; t++){
696 shifted.at(x,y,z,t) = lat.at(x+1,y,z,t);
699 else if(shiftDir == 0 && shiftStep == -1){
700 for(
int x = 1; x < lat.size[0]; x++){
701 for(
int y = 0; y < lat.size[1]; y++){
702 for(
int z = 0; z < lat.size[2]; z++){
703 for(
int t = 0; t < lat.size[3]; t++){
704 shifted.at(x,y,z,t) = lat.at(x-1,y,z,t);
708 else if(shiftDir == 1 && shiftStep == 1){
709 for(
int x = 0; x < lat.size[0]; x++){
710 for(
int y = 0; y < lat.size[1]-1; y++){
711 for(
int z = 0; z < lat.size[2]; z++){
712 for(
int t = 0; t < lat.size[3]; t++){
713 shifted.at(x,y,z,t) = lat.at(x,y+1,z,t);
716 else if(shiftDir == 1 && shiftStep == -1){
717 for(
int x = 0; x < lat.size[0]; x++){
718 for(
int y = 1; y < lat.size[1]; y++){
719 for(
int z = 0; z < lat.size[2]; z++){
720 for(
int t = 0; t < lat.size[3]; t++){
721 shifted.at(x,y,z,t) = lat.at(x,y-1,z,t);
725 else if(shiftDir == 2 && shiftStep == 1){
726 for(
int x = 0; x < lat.size[0]; x++){
727 for(
int y = 0; y < lat.size[1]; y++){
728 for(
int z = 0; z < lat.size[2]-1; z++){
729 for(
int t = 0; t < lat.size[3]; t++){
730 shifted.at(x,y,z,t) = lat.at(x,y,z+1,t);
733 else if(shiftDir == 2 && shiftStep == -1){
734 for(
int x = 0; x < lat.size[0]; x++){
735 for(
int y = 0; y < lat.size[1]; y++){
736 for(
int z = 1; z < lat.size[2]; z++){
737 for(
int t = 0; t < lat.size[3]; t++){
738 shifted.at(x,y,z,t) = lat.at(x,y,z-1,t);
742 else if(shiftDir == 3 && shiftStep == 1){
743 for(
int x = 0; x < lat.size[0]; x++){
744 for(
int y = 0; y < lat.size[1]; y++){
745 for(
int z = 0; z < lat.size[2]; z++){
746 for(
int t = 0; t < lat.size[3]-1; t++){
747 shifted.at(x,y,z,t) = lat.at(x,y,z,t+1);
750 else if(shiftDir == 3 && shiftStep == -1){
751 for(
int x = 0; x < lat.size[0]; x++){
752 for(
int y = 0; y < lat.size[1]; y++){
753 for(
int z = 0; z < lat.size[2]; z++){
754 for(
int t = 1; t < lat.size[3]; t++){
755 shifted.at(x,y,z,t) = lat.at(x,y,z,t-1);
762 MPI_Wait(&sendRequest, &status);
763 MPI_Wait(&recvRequest, &status);
768 if(shiftDir == 0 && shiftStep == 1){
769 for(
int y = 0; y < lat.size[1]; y++){
770 for(
int z = 0; z < lat.size[2]; z++){
771 for(
int t = 0; t < lat.size[3]; t++){
772 shifted.at(lat.size[0] - 1,y,z,t) = recvBuffer.at(0,y,z,t);
775 else if(shiftDir == 0 && shiftStep == -1){
776 for(
int y = 0; y < lat.size[1]; y++){
777 for(
int z = 0; z < lat.size[2]; z++){
778 for(
int t = 0; t < lat.size[3]; t++){
779 shifted.at(0,y,z,t) = recvBuffer.at(0,y,z,t);
784 else if(shiftDir == 1 && shiftStep == 1){
785 for(
int x = 0; x < lat.size[0]; x++){
786 for(
int z = 0; z < lat.size[2]; z++){
787 for(
int t = 0; t < lat.size[3]; t++){
788 shifted.at(x,lat.size[1] - 1,z,t) = recvBuffer.at(x,0,z,t);
791 else if(shiftDir == 1 && shiftStep == -1){
792 for(
int x = 0; x < lat.size[0]; x++){
793 for(
int z = 0; z < lat.size[2]; z++){
794 for(
int t = 0; t < lat.size[3]; t++){
795 shifted.at(x,0,z,t) = recvBuffer.at(x,0,z,t);
800 else if(shiftDir == 2 && shiftStep == 1){
801 for(
int x = 0; x < lat.size[0]; x++){
802 for(
int y = 0; y < lat.size[1]; y++){
803 for(
int t = 0; t < lat.size[3]; t++){
804 shifted.at(x,y,lat.size[2] - 1,t) = recvBuffer.at(x,y,0,t);
807 else if(shiftDir == 2 && shiftStep == -1){
808 for(
int x = 0; x < lat.size[0]; x++){
809 for(
int y = 0; y < lat.size[1]; y++){
810 for(
int t = 0; t < lat.size[3]; t++){
811 shifted.at(x,y,0,t) = recvBuffer.at(x,y,0,t);
814 else if(shiftDir == 3 && shiftStep == 1){
815 for(
int x = 0; x < lat.size[0]; x++){
816 for(
int y = 0; y < lat.size[1]; y++){
817 for(
int z = 0; z < lat.size[2]; z++){
818 shifted.at(x,y,z,lat.size[3] - 1) = recvBuffer.at(x,y,z,0);
821 else if(shiftDir == 3 && shiftStep == -1){
822 for(
int x = 0; x < lat.size[0]; x++){
823 for(
int y = 0; y < lat.size[1]; y++){
824 for(
int z = 0; z < lat.size[2]; z++){
825 shifted.at(x,y,z,0) = recvBuffer.at(x,y,z,0);
Implementation of a class to perform arithmetics between links.
void setLatticeImagIdentityValue(Lattice< SU3 > &su3lat, const Lattice< double > &lat)
sets a lattice object to only diagonal matrices with complex values
void setToIdentity(Lattice< SU3 > &su3lat)
sets a lattice object to all identity matrices
void setToZero(Lattice< SU3 > &su3lat)
sets a lattice object to all zero matrices
Utilities for parallelization.
Basic library to implement SU3 matrix arithmetics and functions.
SU3 exp(const SU3 &Q)
exponential of a SU3 algebra matrix
static int getNeighbor(int direction, int sign)
return the rank of the neighbor along the given direction and sign
Template class to store an array with 4 dimensional indices of a given datatype. Includes functionali...