mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-10-21 16:34:44 +01:00 
			
		
		
		
	Compare commits
	
		
			621 Commits
		
	
	
		
			dirac-ITT-
			...
			feature/La
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | dc5b909f99 | ||
|  | 855b249f57 | ||
|  | 95d4b46446 | ||
|  | 5dfd216a34 | ||
|  | c2e8d0aa88 | ||
|  | bf96a4bdbf | ||
|  | 84685c9bc3 | ||
|  | 013ea4e8d1 | ||
|  | 7fbbb31a50 | ||
|  | 0e127b1fc7 | ||
|  | 68c028b0a6 | ||
|  | 7836cc2d74 | ||
| a61e0df54b | |||
| f871fb0c6d | |||
|  | 25d1cadd3b | ||
|  | c24d53bbd1 | ||
| 3c7a4106ed | |||
|  | 6eed167f0c | ||
|  | 4ad0df6fde | ||
|  | 68a5079f33 | ||
|  | 8634e19f1b | ||
|  | 9ada378e38 | ||
| bfbf2f1fa0 | |||
|  | 587bfcc0f4 | ||
|  | 8c658de179 | ||
|  | ba37d51ee9 | ||
|  | 4f4181c54a | ||
|  | 4d4ac2517b | ||
|  | e568c24d1d | ||
|  | b458326744 | ||
|  | 6e7d5e2243 | ||
|  | b35169f1dd | ||
|  | 441ad7498d | ||
|  | 6f6c5c549a | ||
|  | 1584e17b54 | ||
|  | 12982a4455 | ||
|  | 172f412102 | ||
|  | a64497265d | ||
|  | c45f24a1b5 | ||
|  | aaf37ee4d7 | ||
|  | 1dddd17e3c | ||
|  | 661f1d3e8e | ||
|  | edcf9b9293 | ||
|  | fe6860b4dd | ||
|  | d6406b13e1 | ||
|  | e369d7306d | ||
|  | 9f8d63e104 | ||
|  | 9b0240d101 | ||
|  | b27f0e5a53 | ||
|  | 75e4483407 | ||
|  | 0734e9ddd4 | ||
|  | 809b1cdd58 | ||
|  | 1be8089604 | ||
|  | 3e0eff6468 | ||
|  | 7ecc47ac89 | ||
|  | e9f1ac09de | ||
|  | fa0d8feff4 | ||
|  | 05b44aef6b | ||
|  | 03e9832efa | ||
|  | 28a375d35d | ||
|  | 3b06381745 | ||
|  | 91a0a3f820 | ||
|  | 8f44c799a6 | ||
|  | 96272f3841 | ||
|  | 5c936d88a0 | ||
|  | 1c64ee926e | ||
|  | 2cbb72a81c | ||
|  | 31d83ee046 | ||
|  | a9e8758a01 | ||
|  | 3e125c5b61 | ||
|  | eac6ec4b5e | ||
|  | 213f8db6a2 | ||
|  | 6358f35b7e | ||
|  | 43f5a0df50 | ||
|  | c897878776 | ||
|  | 2baf193031 | ||
|  | 362ba0443a | ||
|  | 276a2353df | ||
|  | c5b9147b53 | ||
|  | 64ac815fd9 | ||
|  | a1be533329 | ||
| 141da3ae71 | |||
| 94edf9cf8b | |||
| c11a3ca0a7 | |||
|  | 870b1a85ae | ||
|  | b5510427f9 | ||
|  | 26ed65c8f8 | ||
|  | f7f043d8cf | ||
|  | ddcaa6ad29 | ||
| c8d4d184ee | |||
| 1569a374a9 | |||
| eddf023b8a | |||
|  | f089bf5629 | ||
|  | 276f113f28 | ||
| a13c109111 | |||
|  | ab6afd18ac | ||
|  | 5bde64d48b | ||
|  | 2f5add4d5f | ||
| c5a885dcd6 | |||
|  | c9c073eee4 | ||
|  | f290b2e908 | ||
|  | 5f8225461b | ||
| 20e186a1e0 | |||
|  | 6ef4af989b | ||
|  | ccde8b817f | ||
|  | 68168bf72d | ||
|  | e93d0feaa7 | ||
|  | 8f601d9b39 | ||
|  | 5436308e4a | ||
|  | 07fe7d0cbe | ||
|  | 60b57706c4 | ||
|  | 954e38bebe | ||
|  | b1a38bde7a | ||
|  | 2581875edc | ||
|  | 6c6d43eb4e | ||
|  | e1dcfd3553 | ||
|  | 888838473a | ||
|  | 01568b0e62 | ||
|  | d5ce66f6ab | ||
|  | d86936a3de | ||
|  | 0fb84fa34b | ||
|  | 0880747edb | ||
|  | b801e1fcd6 | ||
|  | 8bb11e5039 | ||
|  | 3686827df5 | ||
|  | 60589a93a3 | ||
|  | bc1f5be265 | ||
| 360cface33 | |||
|  | 80302e95a8 | ||
| caf2f6b274 | |||
| c49be8988b | |||
| 971c2379bd | |||
|  | 94b0d66e4c | ||
|  | 1c430ec71c | ||
|  | 0b63e2e9cd | ||
|  | 5e8af396fd | ||
| a7d19dbb64 | |||
| 90dbe03e17 | |||
| 8b14096990 | |||
|  | b938202081 | ||
| 485c5db0fe | |||
|  | 386b4fcb04 | ||
|  | 11219a8f7a | ||
|  | c399c2b44d | ||
|  | af7de7a294 | ||
|  | 1dc86efd26 | ||
| 30391cb2eb | |||
|  | 2e88408f5c | ||
|  | 0f468e2179 | ||
|  | 4790e99817 | ||
|  | 2dd63aa7a4 | ||
|  | 559a501140 | ||
|  | 945684c470 | ||
|  | e30a80a234 | ||
|  | c96483e3bd | ||
|  | ae31a6a760 | ||
|  | dd8f2a64fe | ||
|  | 7b8b2731e7 | ||
|  | 237a8ec918 | ||
|  | 3caf0e8b09 | ||
|  | 896f3a8002 | ||
|  | bc5ba39278 | ||
|  | fbe1209f7e | ||
|  | f0fcdf75b5 | ||
|  | 53bffb83d4 | ||
|  | cd44e851f1 | ||
|  | fb24e3a7d2 | ||
|  | 655a69259a | ||
|  | ebb1bebf24 | ||
|  | 53a9260a94 | ||
|  | dc6f637e70 | ||
|  | 507c4e9efc | ||
|  | f8a5194c70 | ||
|  | cff3bae155 | ||
| 6e3ce7423e | |||
| 15f15a7cfd | |||
| 0e5f626226 | |||
|  | 97b9c6f03d | ||
|  | 63982819c6 | ||
|  | b00d2d2c39 | ||
|  | f1b3e21830 | ||
|  | b7f8c5b823 | ||
|  | 3923683e9b | ||
|  | e199fda9dc | ||
| 7bb405e790 | |||
| ec16eacc6a | |||
|  | cf858deb16 | ||
|  | a3affac963 | ||
| d9d1f43ba2 | |||
| b7cd721308 | |||
| 29f026c375 | |||
| 58c7a13d54 | |||
|  | 24162c9ead | ||
|  | e564d11687 | ||
|  | 0b2162f375 | ||
|  | 5610570182 | ||
|  | 44f65526e0 | ||
|  | 43e48542ab | ||
|  | 0b85f1bfc8 | ||
|  | 9947cfbf14 | ||
|  | 357badce5e | ||
|  | 0091eec23a | ||
|  | 9e9c2962df | ||
|  | bda97212a9 | ||
|  | b91282ad46 | ||
|  | 0a68470f9a | ||
|  | 6ecf280723 | ||
|  | 7eeab7f995 | ||
|  | 9b32d51cd1 | ||
|  | 7b3ed160aa | ||
|  | 1a0163f45c | ||
|  | 9028e278e4 | ||
|  | 44b218a595 | ||
| dd62f2f371 | |||
| 0d612039ed | |||
|  | bfc0306a43 | ||
|  | 4c0ae75ac5 | ||
| e8ac75055c | |||
| 8b30c5956c | |||
| 185da83454 | |||
| 6718fa8c4f | |||
|  | 3cb8cb7282 | ||
|  | 4ce63af7d5 | ||
|  | 89c4e9b168 | ||
| 67c3fa0f5f | |||
| 65d4f17976 | |||
| e2fe97277b | |||
|  | 84f9c37ed4 | ||
|  | fe406e230d | ||
| bcf6f3890c | |||
| 591a38c487 | |||
| 842754bea9 | |||
| 0887566134 | |||
| 61fc50d616 | |||
| a9c8d7dad0 | |||
|  | 3dbc8586fa | ||
|  | 7305910c95 | ||
| 259d504ef0 | |||
| f3a77f4b7f | |||
| 26d7b829a0 | |||
| 64161a8743 | |||
| 2401360784 | |||
|  | 2cfb50cbe5 | ||
| f9aa39e1c4 | |||
| 0fbf445edd | |||
| e78794688a | |||
| 9e31307963 | |||
| 29e2eddea8 | |||
| 0a038ea15a | |||
| 62eb1f0e59 | |||
| 5422251959 | |||
|  | 9579c9c327 | ||
|  | 3729c7a7a6 | ||
|  | c24d4c8d0e | ||
|  | a14038051f | ||
|  | 3e560b9462 | ||
|  | d93c6760ec | ||
|  | ae3b7713a9 | ||
|  | 5139eaf491 | ||
| cbd8fbe771 | |||
| d391f05cb7 | |||
| 3127b52c90 | |||
| 01f00385a4 | |||
| 59aae5f5ec | |||
| 624246409c | |||
| 2a9ebddad5 | |||
| ff7afe6e17 | |||
| 33cb509d4b | |||
| 456c78c233 | |||
| 2fd4989029 | |||
| 2427a21428 | |||
| 514993ed17 | |||
|  | 2c35c89b92 | ||
|  | 28ceacec45 | ||
|  | e6a3e375cf | ||
|  | 4987edbd44 | ||
|  | ad140bb6e7 | ||
|  | 1f04e56038 | ||
|  | 4bfc8c85c3 | ||
|  | e55397bc13 | ||
| a3fe874a5b | |||
| f403ab0133 | |||
|  | 94b8fb5686 | ||
|  | 1f1d77b01a | ||
|  | 6a15e2e8ef | ||
| 074d17429f | |||
|  | 25f73018f4 | ||
|  | 1d7ccc6b2c | ||
|  | 59d9ccf70c | ||
|  | 1860b1698c | ||
|  | 9b8d1cc3da | ||
|  | 149c3f9e9c | ||
|  | c519aab19d | ||
|  | 69929f20bb | ||
|  | 91cc33e907 | ||
|  | a493429218 | ||
|  | 915f610da0 | ||
|  | c79606a5dc | ||
|  | 360efd0088 | ||
|  | 7b42ac9982 | ||
|  | c5c647e35e | ||
| a4e5fd1000 | |||
| 682e7d7839 | |||
|  | 8e057721a9 | ||
|  | fa5e4add47 | ||
|  | 5d44346be3 | ||
|  | 27ea2afe86 | ||
|  | 78e8704eac | ||
|  | 67131d82f2 | ||
|  | 615a9448b9 | ||
|  | 00164f5ce5 | ||
|  | a7f72eb994 | ||
|  | 501fa1614a | ||
|  | 5bf42e1e15 | ||
|  | fe4d9b003c | ||
|  | 4a699b4da3 | ||
|  | 689323f4ee | ||
|  | 749189fd72 | ||
|  | f941c4ee18 | ||
|  | 3a754fcd51 | ||
|  | 84b441800f | ||
|  | 1ef424b139 | ||
|  | aa66f41c69 | ||
|  | f96c800d25 | ||
|  | 32a52d7583 | ||
|  | fa04b6d3c2 | ||
|  | 7fab183c0e | ||
|  | 9ec9850bdb | ||
|  | 0c4ddaea0b | ||
|  | 00ebc150ad | ||
|  | 0f3e9ae57d | ||
|  | 034de160bf | ||
|  | 76bcf6cd8c | ||
|  | 91b8bf0613 | ||
|  | 14507fd6e4 | ||
|  | 2db05ac214 | ||
|  | 31f99574fa | ||
|  | a34c8a2961 | ||
|  | ccd20df827 | ||
|  | e9be293444 | ||
|  | d577211cc3 | ||
|  | f4336e480a | ||
|  | e4d461cb03 | ||
|  | 3d63b4894e | ||
|  | 08583afaff | ||
|  | b395a312af | ||
|  | 66295b99aa | ||
|  | b8654be0ef | ||
|  | a479325349 | ||
|  | f6c3f6bf2d | ||
|  | d83868fdbb | ||
|  | 303e0b927d | ||
|  | 28ba8a0f48 | ||
|  | f9e28577f3 | ||
|  | e0cae833da | ||
|  | 8a3aae98f6 | ||
|  | 8309f2364b | ||
|  | cac1750078 | ||
|  | e17cd35151 | ||
|  | ccdec7a7ab | ||
|  | 93642d813d | ||
|  | 0bc381f982 | ||
|  | 2986aa76f8 | ||
|  | 657779374b | ||
|  | ec8cd11c1f | ||
|  | cbda4f66e0 | ||
|  | 6579dd30ff | ||
|  | 031c94e02e | ||
|  | 6391b2a1d0 | ||
|  | 2e50b55ae4 | ||
|  | 137886c316 | ||
|  | 27936900e6 | ||
|  | cd3e810d25 | ||
|  | 317ddfedee | ||
|  | e325929851 | ||
|  | 47af3565f4 | ||
|  | 4b4d187935 | ||
|  | 9aff354ab5 | ||
|  | cb9ff20249 | ||
|  | 9fe6ac71ea | ||
|  | ef61b549e6 | ||
| 5c392a6ecc | |||
|  | f1fa00b71b | ||
|  | bf58557fb1 | ||
|  | 10cb37f504 | ||
|  | 1374c943d4 | ||
|  | a1d80282ec | ||
|  | 4eb8bbbebe | ||
|  | d1c6288c5f | ||
|  | dd949bc428 | ||
|  | bb7378cfc3 | ||
|  | f0e084a88c | ||
|  | 153672d8ec | ||
|  | 08ca338875 | ||
|  | f7cbf82c04 | ||
|  | 07009c569a | ||
|  | 15d690e9b9 | ||
| 63b2bc1936 | |||
|  | d810e8c8fb | ||
|  | 09f4cdb11e | ||
|  | 1e54882f71 | ||
|  | 27caff92c6 | ||
| d38cee73bf | |||
| 8784f2a88d | |||
| c497864b5d | |||
| 05c1c88440 | |||
|  | d54807b8c0 | ||
|  | f6ba2b95ce | ||
|  | 5625b47c7d | ||
|  | 1edcf902b7 | ||
|  | e5c19e1fd7 | ||
|  | a11d0a33d1 | ||
|  | 4f8b6f26b4 | ||
|  | 073525c5b3 | ||
|  | eb6153080a | ||
|  | f7072d1ac2 | ||
| a021933002 | |||
|  | 56478d63a5 | ||
| df21668f2c | |||
|  | 482368e9de | ||
|  | fddeb29d6b | ||
|  | a9ec5cf564 | ||
|  | 946a8671b9 | ||
|  | a6eeea777b | ||
|  | 771a1b8e79 | ||
|  | bfb68e6f02 | ||
|  | 77f7737ccc | ||
|  | 9a827d0242 | ||
|  | 999c623590 | ||
|  | 18c335198a | ||
|  | f9df685cde | ||
|  | 17c5b0f152 | ||
|  | 5918769f97 | ||
|  | b542d349b8 | ||
|  | 91eaace19d | ||
|  | bbaf1ada91 | ||
|  | 1950ac9294 | ||
|  | 13fa70ac1a | ||
|  | 7cb2b11f26 | ||
|  | 1184ed29ae | ||
|  | 203c7bf6fa | ||
|  | d856327250 | ||
|  | a5fe07c077 | ||
|  | b83b2b1415 | ||
|  | 3006663b9c | ||
|  | 59bd1fe21b | ||
| a56e3b40c4 | |||
|  | 4e907fef2c | ||
|  | 67888b657f | ||
|  | 74af885d4e | ||
|  | d36d2fb40d | ||
|  | 4b4c2a715b | ||
|  | 54a5e6c1d0 | ||
|  | f365a83fae | ||
|  | 34a9aeb331 | ||
| 5846566728 | |||
| 21b02760c3 | |||
|  | 2bcb704af2 | ||
|  | edabb3577f | ||
|  | ce5df177ee | ||
|  | a0bb8e5b46 | ||
|  | 46f88e6d72 | ||
|  | dd8f1ea189 | ||
|  | b61835c1a5 | ||
|  | 459f70e8d4 | ||
|  | 061e48fd73 | ||
|  | ab50145001 | ||
|  | 0145685f96 | ||
|  | 9d45fca8bc | ||
|  | ac9e6b63c0 | ||
|  | e140b3f802 | ||
|  | d9d3d30cc7 | ||
|  | 47a12ec7b5 | ||
|  | ec1e2f7a40 | ||
|  | 41f73ec083 | ||
|  | 6d0786ff9d | ||
|  | b7f93aeb4d | ||
|  | 202a7fe900 | ||
|  | 8d168ded4a | ||
|  | e73e4b4002 | ||
|  | caa6605b43 | ||
|  | 522c9248ae | ||
|  | 75ee6cfc86 | ||
|  | fde71c3c52 | ||
|  | 7d867a8134 | ||
|  | 9939b267d2 | ||
|  | 323e9c439a | ||
|  | 28396f1048 | ||
|  | 67b34e5789 | ||
|  | 191fbf85fc | ||
|  | 8f4b3049cd | ||
|  | 2a6e673a91 | ||
|  | 9b6cde173f | ||
|  | 9f280b82c4 | ||
|  | 93650f3a61 | ||
|  | cab4b4d063 | ||
|  | cf4b30b2dd | ||
|  | c51d0b4078 | ||
|  | 7a53dc3715 | ||
|  | 875e1a841f | ||
|  | 0366288b1c | ||
|  | 6293d438cd | ||
|  | 852ade029a | ||
|  | 9fa07eecde | ||
|  | f64fb7bd77 | ||
|  | 2a35449b91 | ||
|  | 184af5bd05 | ||
|  | 097c9637ee | ||
|  | d9593c4b81 | ||
|  | ac740f73ce | ||
|  | 75dc7794b9 | ||
|  | dee68fc728 | ||
|  | a2d3643634 | ||
|  | 57002924bc | ||
|  | 7d2d5e8d3d | ||
|  | 4a29ab0d0a | ||
|  | 0165bcb58e | ||
|  | deca1ecc50 | ||
|  | 349d75e483 | ||
|  | e51475703a | ||
|  | 1feddf4ba6 | ||
|  | 600d7ddc2e | ||
|  | e504260f3d | ||
|  | 08b0e472aa | ||
|  | c11d69787e | ||
|  | dc6b2d30d2 | ||
|  | 7a3bd5c66c | ||
|  | 18211eb5b1 | ||
|  | 863bb2ad10 | ||
|  | 5e4bea8f20 | ||
|  | 6ebf9f15b7 | ||
|  | 1d7aa673a4 | ||
|  | b9104f3072 | ||
| b672717096 | |||
| 284ee194b1 | |||
|  | 1bd311ba9c | ||
|  | 41af8c12d7 | ||
|  | 2f4cbeb4d5 | ||
|  | 5633a2db20 | ||
|  | 2d433ba307 | ||
|  | b8e45ae490 | ||
|  | b35fc4e7f9 | ||
|  | 60f11bfd72 | ||
|  | fb7c4fb815 | ||
|  | 00bb71e5af | ||
|  | cfed2c1ea0 | ||
|  | 8d442b502d | ||
|  | e5c8b7369e | ||
|  | b1b15f0b70 | ||
|  | c504b4dbad | ||
|  | 622a21bec6 | ||
|  | eec79e0a1e | ||
|  | 23135aa58a | ||
|  | 927c7ae3ed | ||
|  | 05d04ceff8 | ||
|  | 8313367a50 | ||
|  | 5c479ce663 | ||
|  | 4bf9d65bf8 | ||
|  | 3a056c4dff | ||
|  | b0ba651654 | ||
|  | 25d4c175c3 | ||
|  | 08b314fd0f | ||
|  | 34332fe393 | ||
|  | c2010f21ab | ||
|  | 98f610ce53 | ||
|  | d44cc204d1 | ||
|  | a8d7986e1c | ||
|  | 77e0af9c2e | ||
|  | 92ec509bfa | ||
|  | e80a87ff7f | ||
|  | ca1077c560 | ||
|  | 867fe93018 | ||
|  | 09651c3326 | ||
|  | f87f2a3f8b | ||
|  | 62a64d9108 | ||
|  | 49331a3e72 | ||
|  | 51d84ec057 | ||
|  | db14fb30df | ||
|  | b9356d3866 | ||
|  | 99a73f4287 | ||
|  | f302eea91e | ||
|  | 5553b8d2b8 | ||
|  | a6ccbbe108 | ||
|  | d2003f24f4 | ||
|  | 6299dd35f5 | ||
|  | a39daecb62 | ||
|  | 159770e21b | ||
|  | dc5a6404ea | ||
|  | 44260643f6 | ||
|  | 1425afc72f | ||
|  | 752048f410 | ||
|  | a07556dd5f | ||
|  | b694996302 | ||
|  | c382c351a5 | ||
|  | af2d6ce2e0 | ||
|  | ac1253bb76 | ||
|  | f80a847aef | ||
|  | 93cb5d4e97 | ||
|  | 9e48b7dfda | ||
|  | 363611ae21 | ||
|  | 3b8a791e28 | ||
|  | 6fd82228bf | ||
|  | d0c2c9c71f | ||
|  | c8cafa77ca | ||
|  | ca6efc685e | ||
|  | a3bcad3804 | ||
|  | 5a5b66292b | ||
|  | b8ae787b5e | ||
|  | fbe2c3b5f9 | ||
|  | 1ed69816b9 | ||
|  | e63be32ad2 | ||
|  | 6aa106d906 | ||
|  | 33d59c8869 | ||
|  | a833fd8dbf | ||
|  | 3750b9ffee | ||
|  | 5e549ebd8b | ||
|  | fff484eca5 | ||
|  | 5fdc05782b | ||
|  | a04eb7df5d | ||
|  | e9712bc7fb | ||
|  | 0cd6b1858c | 
							
								
								
									
										13
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -88,11 +88,18 @@ Thumbs.db | |||||||
| ################### | ################### | ||||||
| build*/* | build*/* | ||||||
|  |  | ||||||
|  | # bootstrap # | ||||||
|  | ############# | ||||||
|  | *.tar.bz2* | ||||||
|  |  | ||||||
| # IDE related files # | # IDE related files # | ||||||
| ##################### | ##################### | ||||||
| *.xcodeproj/* | *.xcodeproj/* | ||||||
| build.sh | build.sh | ||||||
| .vscode | .vscode | ||||||
|  | *.code-workspace | ||||||
|  | .ctags | ||||||
|  | tags | ||||||
|  |  | ||||||
| # Eigen source # | # Eigen source # | ||||||
| ################ | ################ | ||||||
| @@ -122,4 +129,10 @@ make-bin-BUCK.sh | |||||||
| ##################### | ##################### | ||||||
| lib/qcd/spin/gamma-gen/*.h | lib/qcd/spin/gamma-gen/*.h | ||||||
| lib/qcd/spin/gamma-gen/*.cc | lib/qcd/spin/gamma-gen/*.cc | ||||||
|  | lib/version.h | ||||||
|  |  | ||||||
|  | # vs code editor files # | ||||||
|  | ######################## | ||||||
|  | .vscode/ | ||||||
|  | .vscode/settings.json | ||||||
|  | settings.json | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								.travis.yml
									
									
									
									
									
								
							| @@ -19,6 +19,8 @@ before_install: | |||||||
|     - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install libmpc; fi |     - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install libmpc; fi | ||||||
|      |      | ||||||
| install: | install: | ||||||
|  |     - export CWD=`pwd` | ||||||
|  |     - echo $CWD | ||||||
|     - export CC=$CC$VERSION |     - export CC=$CC$VERSION | ||||||
|     - export CXX=$CXX$VERSION |     - export CXX=$CXX$VERSION | ||||||
|     - echo $PATH |     - echo $PATH | ||||||
| @@ -36,11 +38,23 @@ script: | |||||||
|     - ./bootstrap.sh |     - ./bootstrap.sh | ||||||
|     - mkdir build |     - mkdir build | ||||||
|     - cd build |     - cd build | ||||||
|     - ../configure --enable-precision=single --enable-simd=SSE4 --enable-comms=none |     - mkdir lime | ||||||
|  |     - cd lime | ||||||
|  |     - mkdir build | ||||||
|  |     - cd build | ||||||
|  |     - wget http://usqcd-software.github.io/downloads/c-lime/lime-1.3.2.tar.gz | ||||||
|  |     - tar xf lime-1.3.2.tar.gz | ||||||
|  |     - cd lime-1.3.2 | ||||||
|  |     - ./configure --prefix=$CWD/build/lime/install | ||||||
|  |     - make -j4 | ||||||
|  |     - make install | ||||||
|  |     - cd $CWD/build | ||||||
|  |     - ../configure --enable-precision=single --enable-simd=SSE4 --enable-comms=none --with-lime=$CWD/build/lime/install | ||||||
|     - make -j4  |     - make -j4  | ||||||
|     - ./benchmarks/Benchmark_dwf --threads 1 --debug-signals |     - ./benchmarks/Benchmark_dwf --threads 1 --debug-signals | ||||||
|     - echo make clean |     - echo make clean | ||||||
|     - ../configure --enable-precision=double --enable-simd=SSE4 --enable-comms=none |     - ../configure --enable-precision=double --enable-simd=SSE4 --enable-comms=none --with-lime=$CWD/build/lime/install | ||||||
|     - make -j4 |     - make -j4 | ||||||
|     - ./benchmarks/Benchmark_dwf --threads 1 --debug-signals |     - ./benchmarks/Benchmark_dwf --threads 1 --debug-signals | ||||||
|     - make check |     - make check | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,6 +5,10 @@ include $(top_srcdir)/doxygen.inc | |||||||
|  |  | ||||||
| bin_SCRIPTS=grid-config | bin_SCRIPTS=grid-config | ||||||
|  |  | ||||||
|  | BUILT_SOURCES = version.h | ||||||
|  |  | ||||||
|  | version.h: | ||||||
|  | 	echo "`git log -n 1 --format=format:"#define GITHASH \\"%H:%d\\"%n" HEAD`" > $(srcdir)/lib/version.h | ||||||
|  |  | ||||||
| .PHONY: bench check tests doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL) | .PHONY: bench check tests doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -187,10 +187,11 @@ Alternatively, some CPU codenames can be directly used: | |||||||
| | `<code>`    | Description                            | | | `<code>`    | Description                            | | ||||||
| | ----------- | -------------------------------------- | | | ----------- | -------------------------------------- | | ||||||
| | `KNL`       | [Intel Xeon Phi codename Knights Landing](http://ark.intel.com/products/codename/48999/Knights-Landing) | | | `KNL`       | [Intel Xeon Phi codename Knights Landing](http://ark.intel.com/products/codename/48999/Knights-Landing) | | ||||||
|  | | `SKL`       | [Intel Skylake with AVX512 extensions](https://ark.intel.com/products/codename/37572/Skylake#@server) | | ||||||
| | `BGQ`       | Blue Gene/Q                            | | | `BGQ`       | Blue Gene/Q                            | | ||||||
|  |  | ||||||
| #### Notes: | #### Notes: | ||||||
| - We currently support AVX512 only for the Intel compiler. Support for GCC and clang will appear in future versions of Grid when the AVX512 support within GCC and clang will be more advanced. | - We currently support AVX512 for the Intel compiler and GCC (KNL and SKL target). Support for clang will appear in future versions of Grid when the AVX512 support in the compiler will be more advanced. | ||||||
| - For BG/Q only [bgclang](http://trac.alcf.anl.gov/projects/llvm-bgq) is supported. We do not presently plan to support more compilers for this platform. | - For BG/Q only [bgclang](http://trac.alcf.anl.gov/projects/llvm-bgq) is supported. We do not presently plan to support more compilers for this platform. | ||||||
| - BG/Q performances are currently rather poor. This is being investigated for future versions. | - BG/Q performances are currently rather poor. This is being investigated for future versions. | ||||||
| - The vector size for the `GEN` target can be specified with the `configure` script option `--enable-gen-simd-width`. | - The vector size for the `GEN` target can be specified with the `configure` script option `--enable-gen-simd-width`. | ||||||
|   | |||||||
							
								
								
									
										38
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								TODO
									
									
									
									
									
								
							| @@ -1,21 +1,37 @@ | |||||||
| TODO: | TODO: | ||||||
| --------------- | --------------- | ||||||
|  |  | ||||||
| Large item work list: | Code item work list | ||||||
|  |  | ||||||
| 1)- BG/Q port and check | a) namespaces & indentation | ||||||
| 2)- Christoph's local basis expansion Lanczos |  GRID_BEGIN_NAMESPACE(); | ||||||
| 3)- Precision conversion and sort out localConvert      <-- partial |  GRID_END_NAMESPACE(); | ||||||
|  | -- delete QCD namespace | ||||||
|  |  | ||||||
|   - Consistent linear solver flop count/rate -- PARTIAL, time but no flop/s yet | b) GPU branch | ||||||
| 4)- Physical propagator interface | - start branch | ||||||
| 5)- Conserved currents | - Increase Macro use in core library support; prepare for change | ||||||
| 6)- Multigrid Wilson and DWF, compare to other Multigrid implementations | - Audit volume of "device" code | ||||||
| 7)- HDCR resume | - Virtual function audit | ||||||
|  | - Start port once Nvidia box is up | ||||||
|  | - Cut down volume of code for first port? How? | ||||||
|  |  | ||||||
|  | Physics item work list: | ||||||
|  |  | ||||||
|  | 1)- BG/Q port and check ; Andrew says ok. | ||||||
|  | 2)- Consistent linear solver flop count/rate -- PARTIAL, time but no flop/s yet | ||||||
|  | 3)- Physical propagator interface | ||||||
|  | 4)- Multigrid Wilson and DWF, compare to other Multigrid implementations | ||||||
|  | 5)- HDCR resume | ||||||
|  |  | ||||||
|  | ---------------------------- | ||||||
| Recent DONE  | Recent DONE  | ||||||
|  | -- RNG I/O in ILDG/SciDAC (minor)  | ||||||
| -- MultiRHS with spread out extra dim -- Go through filesystem with SciDAC I/O.  <--- DONE | -- Precision conversion and sort out localConvert      <-- partial/easy | ||||||
|  | -- Conserved currents (Andrew) | ||||||
|  | -- Split grid | ||||||
|  | -- Christoph's local basis expansion Lanczos | ||||||
|  | -- MultiRHS with spread out extra dim -- Go through filesystem with SciDAC I/O ; <-- DONE ; bmark cori | ||||||
| -- Lanczos Remove DenseVector, DenseMatrix; Use Eigen instead. <-- DONE | -- Lanczos Remove DenseVector, DenseMatrix; Use Eigen instead. <-- DONE | ||||||
| -- GaugeFix into central location                      <-- DONE | -- GaugeFix into central location                      <-- DONE | ||||||
| -- Scidac and Ildg metadata handling                   <-- DONE | -- Scidac and Ildg metadata handling                   <-- DONE | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								VERSION
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								VERSION
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| Version : 0.7.0 | Version : 0.8.0 | ||||||
|  |  | ||||||
| - Clang 3.5 and above, ICPC v16 and above, GCC 6.3 and above recommended | - Clang 3.5 and above, ICPC v16 and above, GCC 6.3 and above recommended | ||||||
| - MPI and MPI3 comms optimisations for KNL and OPA finished | - MPI and MPI3 comms optimisations for KNL and OPA finished | ||||||
|   | |||||||
							
								
								
									
										108
									
								
								benchmarks/Benchmark_IO.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								benchmarks/Benchmark_IO.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,108 @@ | |||||||
|  | #include <Grid/Grid.h> | ||||||
|  | #ifdef HAVE_LIME | ||||||
|  |  | ||||||
|  | using namespace std; | ||||||
|  | using namespace Grid; | ||||||
|  | using namespace Grid::QCD; | ||||||
|  |  | ||||||
|  | #define MSG cout << GridLogMessage | ||||||
|  | #define SEP \ | ||||||
|  | "=============================================================================" | ||||||
|  | #ifndef BENCH_IO_LMAX | ||||||
|  | #define BENCH_IO_LMAX 40 | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | typedef function<void(const string, LatticeFermion &)> WriterFn; | ||||||
|  | typedef function<void(LatticeFermion &, const string)> ReaderFn; | ||||||
|  |  | ||||||
|  | string filestem(const int l) | ||||||
|  | { | ||||||
|  |   return "iobench_l" + to_string(l); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void limeWrite(const string filestem, LatticeFermion &vec) | ||||||
|  | { | ||||||
|  |   emptyUserRecord record; | ||||||
|  |   ScidacWriter    binWriter(vec._grid->IsBoss()); | ||||||
|  |  | ||||||
|  |   binWriter.open(filestem + ".bin"); | ||||||
|  |   binWriter.writeScidacFieldRecord(vec, record); | ||||||
|  |   binWriter.close(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void limeRead(LatticeFermion &vec, const string filestem) | ||||||
|  | { | ||||||
|  |   emptyUserRecord record; | ||||||
|  |   ScidacReader    binReader; | ||||||
|  |  | ||||||
|  |   binReader.open(filestem + ".bin"); | ||||||
|  |   binReader.readScidacFieldRecord(vec, record); | ||||||
|  |   binReader.close(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void writeBenchmark(const int l, const WriterFn &write) | ||||||
|  | { | ||||||
|  |   auto                      mpi  = GridDefaultMpi(); | ||||||
|  |   auto                      simd = GridDefaultSimd(Nd, vComplex::Nsimd()); | ||||||
|  |   vector<int>               latt = {l*mpi[0], l*mpi[1], l*mpi[2], l*mpi[3]}; | ||||||
|  |   unique_ptr<GridCartesian> gPt(SpaceTimeGrid::makeFourDimGrid(latt, simd, mpi)); | ||||||
|  |   GridCartesian             *g = gPt.get(); | ||||||
|  |   GridParallelRNG           rng(g); | ||||||
|  |   LatticeFermion            vec(g); | ||||||
|  |   emptyUserRecord           record; | ||||||
|  |   ScidacWriter              binWriter(g->IsBoss()); | ||||||
|  |  | ||||||
|  |   cout << "-- Local volume " << l << "^4" << endl; | ||||||
|  |   random(rng, vec); | ||||||
|  |   write(filestem(l), vec); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void readBenchmark(const int l, const ReaderFn &read) | ||||||
|  | { | ||||||
|  |   auto                      mpi  = GridDefaultMpi(); | ||||||
|  |   auto                      simd = GridDefaultSimd(Nd, vComplex::Nsimd()); | ||||||
|  |   vector<int>               latt = {l*mpi[0], l*mpi[1], l*mpi[2], l*mpi[3]}; | ||||||
|  |   unique_ptr<GridCartesian> gPt(SpaceTimeGrid::makeFourDimGrid(latt, simd, mpi)); | ||||||
|  |   GridCartesian             *g = gPt.get(); | ||||||
|  |   LatticeFermion            vec(g); | ||||||
|  |   emptyUserRecord           record; | ||||||
|  |   ScidacReader              binReader; | ||||||
|  |  | ||||||
|  |   cout << "-- Local volume " << l << "^4" << endl; | ||||||
|  |   read(vec, filestem(l)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int main (int argc, char ** argv) | ||||||
|  | { | ||||||
|  |   Grid_init(&argc,&argv); | ||||||
|  |  | ||||||
|  |   auto simd = GridDefaultSimd(Nd,vComplex::Nsimd()); | ||||||
|  |   auto mpi  = GridDefaultMpi(); | ||||||
|  |  | ||||||
|  |   int64_t threads = GridThread::GetThreads(); | ||||||
|  |   MSG << "Grid is setup to use " << threads << " threads" << endl; | ||||||
|  |   MSG << SEP << endl; | ||||||
|  |   MSG << "Benchmark Lime write" << endl; | ||||||
|  |   MSG << SEP << endl; | ||||||
|  |   for (int l = 4; l <= BENCH_IO_LMAX; l += 2) | ||||||
|  |   { | ||||||
|  |     writeBenchmark(l, limeWrite); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   MSG << "Benchmark Lime read" << endl; | ||||||
|  |   MSG << SEP << endl; | ||||||
|  |   for (int l = 4; l <= BENCH_IO_LMAX; l += 2) | ||||||
|  |   { | ||||||
|  |     readBenchmark(l, limeRead); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   Grid_finalize(); | ||||||
|  |  | ||||||
|  |   return EXIT_SUCCESS; | ||||||
|  | } | ||||||
|  | #else | ||||||
|  | int main (int argc, char ** argv) | ||||||
|  | { | ||||||
|  |   return EXIT_SUCCESS; | ||||||
|  | } | ||||||
|  | #endif | ||||||
| @@ -158,8 +158,10 @@ public: | |||||||
|  |  | ||||||
| 	  dbytes=0; | 	  dbytes=0; | ||||||
| 	  ncomm=0; | 	  ncomm=0; | ||||||
|  | #ifdef GRID_OMP | ||||||
| 	  parallel_for(int dir=0;dir<8;dir++){ | #pragma omp parallel for num_threads(Grid::CartesianCommunicator::nCommThreads) | ||||||
|  | #endif | ||||||
|  | 	  for(int dir=0;dir<8;dir++){ | ||||||
|  |  | ||||||
| 	    double tbytes; | 	    double tbytes; | ||||||
| 	    int mu =dir % 4; | 	    int mu =dir % 4; | ||||||
| @@ -175,9 +177,14 @@ public: | |||||||
| 		int comm_proc = mpi_layout[mu]-1; | 		int comm_proc = mpi_layout[mu]-1; | ||||||
| 		Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | 		Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | ||||||
| 	      } | 	      } | ||||||
|  | #ifdef GRID_OMP | ||||||
|  | 	int tid = omp_get_thread_num();  | ||||||
|  | #else  | ||||||
|  |         int tid = dir; | ||||||
|  | #endif | ||||||
| 	      tbytes= Grid.StencilSendToRecvFrom((void *)&xbuf[dir][0], xmit_to_rank, | 	      tbytes= Grid.StencilSendToRecvFrom((void *)&xbuf[dir][0], xmit_to_rank, | ||||||
| 						 (void *)&rbuf[dir][0], recv_from_rank, | 						 (void *)&rbuf[dir][0], recv_from_rank, | ||||||
| 						 bytes,dir); | 						 bytes,tid); | ||||||
| 	   | 	   | ||||||
| #ifdef GRID_OMP | #ifdef GRID_OMP | ||||||
| #pragma omp atomic | #pragma omp atomic | ||||||
| @@ -701,12 +708,14 @@ int main (int argc, char ** argv) | |||||||
|   if ( do_su3 ) { |   if ( do_su3 ) { | ||||||
|     // empty for now |     // empty for now | ||||||
|   } |   } | ||||||
|  | #if 1 | ||||||
|   int sel=2; |   int sel=2; | ||||||
|   std::vector<int> L_list({8,12,16,24}); |   std::vector<int> L_list({8,12,16,24}); | ||||||
|  | #else | ||||||
|   //int sel=1; |   int sel=1; | ||||||
|   //  std::vector<int> L_list({8,12}); |   std::vector<int> L_list({8,12}); | ||||||
|  | #endif | ||||||
|  |   int selm1=sel-1; | ||||||
|   std::vector<double> robust_list; |   std::vector<double> robust_list; | ||||||
|  |  | ||||||
|   std::vector<double> wilson; |   std::vector<double> wilson; | ||||||
| @@ -785,7 +794,8 @@ int main (int argc, char ** argv) | |||||||
|   std::cout<<GridLogMessage << "=================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "=================================================================================="<<std::endl; | ||||||
|  |  | ||||||
|   std::cout<<GridLogMessage << "=================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "=================================================================================="<<std::endl; | ||||||
|   std::cout<<GridLogMessage << " Comparison point     result: "  << dwf4[sel]/NN << " Mflop/s per node"<<std::endl; |   std::cout<<GridLogMessage << " Comparison point     result: "  << 0.5*(dwf4[sel]+dwf4[selm1])/NN << " Mflop/s per node"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << " Comparison point is 0.5*("<<dwf4[sel]/NN<<"+"<<dwf4[selm1]/NN << ") "<<std::endl; | ||||||
|   std::cout<<std::setprecision(3); |   std::cout<<std::setprecision(3); | ||||||
|   std::cout<<GridLogMessage << " Comparison point robustness: "  << robust_list[sel] <<std::endl; |   std::cout<<GridLogMessage << " Comparison point robustness: "  << robust_list[sel] <<std::endl; | ||||||
|   std::cout<<GridLogMessage << "=================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "=================================================================================="<<std::endl; | ||||||
|   | |||||||
| @@ -106,7 +106,7 @@ int main (int argc, char ** argv) | |||||||
|       for(int i=0;i<Nloop;i++){ |       for(int i=0;i<Nloop;i++){ | ||||||
|       double start=usecond(); |       double start=usecond(); | ||||||
|  |  | ||||||
| 	std::vector<CartesianCommunicator::CommsRequest_t> requests; | 	std::vector<CommsRequest_t> requests; | ||||||
|  |  | ||||||
| 	ncomm=0; | 	ncomm=0; | ||||||
| 	for(int mu=0;mu<4;mu++){ | 	for(int mu=0;mu<4;mu++){ | ||||||
| @@ -169,7 +169,11 @@ int main (int argc, char ** argv) | |||||||
|   for(int lat=4;lat<=maxlat;lat+=4){ |   for(int lat=4;lat<=maxlat;lat+=4){ | ||||||
|     for(int Ls=8;Ls<=8;Ls*=2){ |     for(int Ls=8;Ls<=8;Ls*=2){ | ||||||
|  |  | ||||||
|       std::vector<int> latt_size  ({lat,lat,lat,lat}); |       std::vector<int> latt_size  ({lat*mpi_layout[0], | ||||||
|  |                                     lat*mpi_layout[1], | ||||||
|  |                                     lat*mpi_layout[2], | ||||||
|  |                                     lat*mpi_layout[3]}); | ||||||
|  |  | ||||||
|  |  | ||||||
|       GridCartesian     Grid(latt_size,simd_layout,mpi_layout); |       GridCartesian     Grid(latt_size,simd_layout,mpi_layout); | ||||||
|       RealD Nrank = Grid._Nprocessors; |       RealD Nrank = Grid._Nprocessors; | ||||||
| @@ -202,7 +206,7 @@ int main (int argc, char ** argv) | |||||||
| 	    int recv_from_rank; | 	    int recv_from_rank; | ||||||
| 	     | 	     | ||||||
| 	    { | 	    { | ||||||
| 	      std::vector<CartesianCommunicator::CommsRequest_t> requests; | 	      std::vector<CommsRequest_t> requests; | ||||||
| 	      Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | 	      Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | ||||||
| 	      Grid.SendToRecvFromBegin(requests, | 	      Grid.SendToRecvFromBegin(requests, | ||||||
| 				       (void *)&xbuf[mu][0], | 				       (void *)&xbuf[mu][0], | ||||||
| @@ -215,7 +219,7 @@ int main (int argc, char ** argv) | |||||||
|  |  | ||||||
| 	    comm_proc = mpi_layout[mu]-1; | 	    comm_proc = mpi_layout[mu]-1; | ||||||
| 	    { | 	    { | ||||||
| 	      std::vector<CartesianCommunicator::CommsRequest_t> requests; | 	      std::vector<CommsRequest_t> requests; | ||||||
| 	      Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | 	      Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | ||||||
| 	      Grid.SendToRecvFromBegin(requests, | 	      Grid.SendToRecvFromBegin(requests, | ||||||
| 				       (void *)&xbuf[mu+4][0], | 				       (void *)&xbuf[mu+4][0], | ||||||
| @@ -290,7 +294,7 @@ int main (int argc, char ** argv) | |||||||
| 	dbytes=0; | 	dbytes=0; | ||||||
| 	ncomm=0; | 	ncomm=0; | ||||||
|  |  | ||||||
| 	std::vector<CartesianCommunicator::CommsRequest_t> requests; | 	std::vector<CommsRequest_t> requests; | ||||||
|  |  | ||||||
| 	for(int mu=0;mu<4;mu++){ | 	for(int mu=0;mu<4;mu++){ | ||||||
| 	 | 	 | ||||||
| @@ -383,7 +387,7 @@ int main (int argc, char ** argv) | |||||||
|       for(int i=0;i<Nloop;i++){ |       for(int i=0;i<Nloop;i++){ | ||||||
| 	double start=usecond(); | 	double start=usecond(); | ||||||
|  |  | ||||||
| 	std::vector<CartesianCommunicator::CommsRequest_t> requests; | 	std::vector<CommsRequest_t> requests; | ||||||
| 	dbytes=0; | 	dbytes=0; | ||||||
| 	ncomm=0; | 	ncomm=0; | ||||||
| 	for(int mu=0;mu<4;mu++){ | 	for(int mu=0;mu<4;mu++){ | ||||||
| @@ -446,7 +450,7 @@ int main (int argc, char ** argv) | |||||||
|   }     |   }     | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #ifdef GRID_OMP | ||||||
|   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "= Benchmarking threaded STENCIL halo exchange in "<<nmu<<" dimensions"<<std::endl; |   std::cout<<GridLogMessage << "= Benchmarking threaded STENCIL halo exchange in "<<nmu<<" dimensions"<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
| @@ -481,11 +485,12 @@ int main (int argc, char ** argv) | |||||||
|       for(int i=0;i<Nloop;i++){ |       for(int i=0;i<Nloop;i++){ | ||||||
| 	double start=usecond(); | 	double start=usecond(); | ||||||
|  |  | ||||||
| 	std::vector<CartesianCommunicator::CommsRequest_t> requests; | 	std::vector<CommsRequest_t> requests; | ||||||
| 	dbytes=0; | 	dbytes=0; | ||||||
| 	ncomm=0; | 	ncomm=0; | ||||||
|  |  | ||||||
| 	parallel_for(int dir=0;dir<8;dir++){ | #pragma omp parallel for num_threads(Grid::CartesianCommunicator::nCommThreads) | ||||||
|  | 	for(int dir=0;dir<8;dir++){ | ||||||
|  |  | ||||||
| 	  double tbytes; | 	  double tbytes; | ||||||
| 	  int mu =dir % 4; | 	  int mu =dir % 4; | ||||||
| @@ -502,9 +507,9 @@ int main (int argc, char ** argv) | |||||||
| 	      int comm_proc = mpi_layout[mu]-1; | 	      int comm_proc = mpi_layout[mu]-1; | ||||||
| 	      Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | 	      Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); | ||||||
| 	    } | 	    } | ||||||
|  |             int tid = omp_get_thread_num(); | ||||||
| 	    tbytes= Grid.StencilSendToRecvFrom((void *)&xbuf[dir][0], xmit_to_rank, | 	    tbytes= Grid.StencilSendToRecvFrom((void *)&xbuf[dir][0], xmit_to_rank, | ||||||
| 					       (void *)&rbuf[dir][0], recv_from_rank, bytes,dir); | 					       (void *)&rbuf[dir][0], recv_from_rank, bytes,tid); | ||||||
|  |  | ||||||
| #pragma omp atomic | #pragma omp atomic | ||||||
| 	    dbytes+=tbytes; | 	    dbytes+=tbytes; | ||||||
| @@ -532,7 +537,7 @@ int main (int argc, char ** argv) | |||||||
|   |   | ||||||
|     } |     } | ||||||
|   }     |   }     | ||||||
|  | #endif | ||||||
|   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "= All done; Bye Bye"<<std::endl; |   std::cout<<GridLogMessage << "= All done; Bye Bye"<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|   | |||||||
| @@ -48,10 +48,19 @@ int main (int argc, char ** argv) | |||||||
|  |  | ||||||
|  |  | ||||||
|   int threads = GridThread::GetThreads(); |   int threads = GridThread::GetThreads(); | ||||||
|   std::cout<<GridLogMessage << "Grid is setup to use "<<threads<<" threads"<<std::endl; |  | ||||||
|  |  | ||||||
|   std::vector<int> latt4 = GridDefaultLatt(); |   std::vector<int> latt4 = GridDefaultLatt(); | ||||||
|   const int Ls=16; |   int Ls=16; | ||||||
|  |   for(int i=0;i<argc;i++) | ||||||
|  |     if(std::string(argv[i]) == "-Ls"){ | ||||||
|  |       std::stringstream ss(argv[i+1]); ss >> Ls; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   GridLogLayout(); | ||||||
|  |  | ||||||
|  |   long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); | ||||||
|  |  | ||||||
|  |  | ||||||
|   GridCartesian         * UGrid   = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); |   GridCartesian         * UGrid   = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); | ||||||
|   GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); |   GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); | ||||||
|   GridCartesian         * FGrid   = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); |   GridCartesian         * FGrid   = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); | ||||||
| @@ -181,7 +190,7 @@ int main (int argc, char ** argv) | |||||||
|     FGrid->Barrier(); |     FGrid->Barrier(); | ||||||
|      |      | ||||||
|     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|     double flops=1344*volume*ncall; |     double flops=single_site_flops*volume*ncall; | ||||||
|  |  | ||||||
|     std::cout<<GridLogMessage << "Called Dw "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; |     std::cout<<GridLogMessage << "Called Dw "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; | ||||||
|     //    std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl; |     //    std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl; | ||||||
| @@ -220,7 +229,7 @@ int main (int argc, char ** argv) | |||||||
|     FGrid->Barrier(); |     FGrid->Barrier(); | ||||||
|      |      | ||||||
|     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|     double flops=1344*volume*ncall; |     double flops=single_site_flops*volume*ncall; | ||||||
|  |  | ||||||
|     std::cout<<GridLogMessage << "Called half prec comms Dw "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; |     std::cout<<GridLogMessage << "Called half prec comms Dw "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; | ||||||
|     std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; |     std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
| @@ -271,7 +280,7 @@ int main (int argc, char ** argv) | |||||||
|     double t1=usecond(); |     double t1=usecond(); | ||||||
|     FGrid->Barrier(); |     FGrid->Barrier(); | ||||||
|     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|     double flops=1344*volume*ncall; |     double flops=single_site_flops*volume*ncall; | ||||||
|  |  | ||||||
|     std::cout<<GridLogMessage << "Called Dw s_inner "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; |     std::cout<<GridLogMessage << "Called Dw s_inner "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; | ||||||
|     std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; |     std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
| @@ -349,7 +358,7 @@ int main (int argc, char ** argv) | |||||||
|       //      sDw.stat.print(); |       //      sDw.stat.print(); | ||||||
|  |  | ||||||
|       double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |       double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|       double flops=(1344.0*volume*ncall)/2; |       double flops=(single_site_flops*volume*ncall)/2.0; | ||||||
|  |  | ||||||
|       std::cout<<GridLogMessage << "sDeo mflop/s =   "<< flops/(t1-t0)<<std::endl; |       std::cout<<GridLogMessage << "sDeo mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
|       std::cout<<GridLogMessage << "sDeo mflop/s per rank   "<< flops/(t1-t0)/NP<<std::endl; |       std::cout<<GridLogMessage << "sDeo mflop/s per rank   "<< flops/(t1-t0)/NP<<std::endl; | ||||||
| @@ -472,7 +481,7 @@ int main (int argc, char ** argv) | |||||||
|     FGrid->Barrier(); |     FGrid->Barrier(); | ||||||
|      |      | ||||||
|     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|     double flops=(1344.0*volume*ncall)/2; |     double flops=(single_site_flops*volume*ncall)/2.0; | ||||||
|  |  | ||||||
|     std::cout<<GridLogMessage << "Deo mflop/s =   "<< flops/(t1-t0)<<std::endl; |     std::cout<<GridLogMessage << "Deo mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
|     std::cout<<GridLogMessage << "Deo mflop/s per rank   "<< flops/(t1-t0)/NP<<std::endl; |     std::cout<<GridLogMessage << "Deo mflop/s per rank   "<< flops/(t1-t0)/NP<<std::endl; | ||||||
|   | |||||||
| @@ -51,6 +51,7 @@ int main (int argc, char ** argv) | |||||||
| { | { | ||||||
|   Grid_init(&argc,&argv); |   Grid_init(&argc,&argv); | ||||||
|  |  | ||||||
|  |  | ||||||
|   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|   std::cout << GridLogMessage<< "* Kernel options --dslash-generic, --dslash-unroll, --dslash-asm" <<std::endl; |   std::cout << GridLogMessage<< "* Kernel options --dslash-generic, --dslash-unroll, --dslash-asm" <<std::endl; | ||||||
|   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
| @@ -107,6 +108,7 @@ void benchDw(std::vector<int> & latt4, int Ls, int threads,int report ) | |||||||
|   GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); |   GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); | ||||||
|   GridCartesian         * FGrid   = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); |   GridCartesian         * FGrid   = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); | ||||||
|   GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); |   GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); | ||||||
|  |   long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); | ||||||
|  |  | ||||||
|   std::vector<int> seeds4({1,2,3,4}); |   std::vector<int> seeds4({1,2,3,4}); | ||||||
|   std::vector<int> seeds5({5,6,7,8}); |   std::vector<int> seeds5({5,6,7,8}); | ||||||
| @@ -196,7 +198,7 @@ void benchDw(std::vector<int> & latt4, int Ls, int threads,int report ) | |||||||
|    |    | ||||||
|   if ( ! report ) { |   if ( ! report ) { | ||||||
|     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|     double flops=1344*volume*ncall; |     double flops=single_site_flops*volume*ncall; | ||||||
|     std::cout <<"\t"<<NP<< "\t"<<flops/(t1-t0)<< "\t"; |     std::cout <<"\t"<<NP<< "\t"<<flops/(t1-t0)<< "\t"; | ||||||
|   } |   } | ||||||
|    |    | ||||||
| @@ -228,7 +230,7 @@ void benchDw(std::vector<int> & latt4, int Ls, int threads,int report ) | |||||||
|      |      | ||||||
|     if(!report){ |     if(!report){ | ||||||
|       double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |       double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|       double flops=(1344.0*volume*ncall)/2; |       double flops=(single_site_flops*volume*ncall)/2.0; | ||||||
|       std::cout<< flops/(t1-t0); |       std::cout<< flops/(t1-t0); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @@ -237,6 +239,7 @@ void benchDw(std::vector<int> & latt4, int Ls, int threads,int report ) | |||||||
| #define CHECK_SDW | #define CHECK_SDW | ||||||
| void benchsDw(std::vector<int> & latt4, int Ls, int threads, int report ) | void benchsDw(std::vector<int> & latt4, int Ls, int threads, int report ) | ||||||
| { | { | ||||||
|  |   long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); | ||||||
|  |  | ||||||
|   GridCartesian         * UGrid   = SpaceTimeGrid::makeFourDimGrid(latt4, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); |   GridCartesian         * UGrid   = SpaceTimeGrid::makeFourDimGrid(latt4, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); | ||||||
|   GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); |   GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); | ||||||
| @@ -321,7 +324,7 @@ void benchsDw(std::vector<int> & latt4, int Ls, int threads, int report ) | |||||||
|     Counter.Report(); |     Counter.Report(); | ||||||
|   } else {  |   } else {  | ||||||
|     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|     double flops=1344*volume*ncall; |     double flops=single_site_flops*volume*ncall; | ||||||
|     std::cout<<"\t"<< flops/(t1-t0); |     std::cout<<"\t"<< flops/(t1-t0); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -358,7 +361,7 @@ void benchsDw(std::vector<int> & latt4, int Ls, int threads, int report ) | |||||||
|     CounterSdw.Report(); |     CounterSdw.Report(); | ||||||
|   } else { |   } else { | ||||||
|     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|     double flops=(1344.0*volume*ncall)/2; |     double flops=(single_site_flops*volume*ncall)/2.0; | ||||||
|     std::cout<<"\t"<< flops/(t1-t0); |     std::cout<<"\t"<< flops/(t1-t0); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										190
									
								
								benchmarks/Benchmark_gparity.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										190
									
								
								benchmarks/Benchmark_gparity.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,190 @@ | |||||||
|  | #include <Grid/Grid.h> | ||||||
|  | #include <sstream> | ||||||
|  | using namespace std; | ||||||
|  | using namespace Grid; | ||||||
|  | using namespace Grid::QCD; | ||||||
|  |  | ||||||
|  | template<class d> | ||||||
|  | struct scal { | ||||||
|  |   d internal; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  |   Gamma::Algebra Gmu [] = { | ||||||
|  |     Gamma::Algebra::GammaX, | ||||||
|  |     Gamma::Algebra::GammaY, | ||||||
|  |     Gamma::Algebra::GammaZ, | ||||||
|  |     Gamma::Algebra::GammaT | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  | typedef typename GparityDomainWallFermionF::FermionField GparityLatticeFermionF; | ||||||
|  | typedef typename GparityDomainWallFermionD::FermionField GparityLatticeFermionD; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | int main (int argc, char ** argv) | ||||||
|  | { | ||||||
|  |   Grid_init(&argc,&argv); | ||||||
|  |  | ||||||
|  |   int Ls=16; | ||||||
|  |   for(int i=0;i<argc;i++) | ||||||
|  |     if(std::string(argv[i]) == "-Ls"){ | ||||||
|  |       std::stringstream ss(argv[i+1]); ss >> Ls; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   int threads = GridThread::GetThreads(); | ||||||
|  |   std::cout<<GridLogMessage << "Grid is setup to use "<<threads<<" threads"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "Ls = " << Ls << std::endl; | ||||||
|  |  | ||||||
|  |   std::vector<int> latt4 = GridDefaultLatt(); | ||||||
|  |  | ||||||
|  |   GridCartesian         * UGrid   = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplexF::Nsimd()),GridDefaultMpi()); | ||||||
|  |   GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); | ||||||
|  |   GridCartesian         * FGrid   = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); | ||||||
|  |   GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); | ||||||
|  |  | ||||||
|  |   std::vector<int> seeds4({1,2,3,4}); | ||||||
|  |   std::vector<int> seeds5({5,6,7,8}); | ||||||
|  |    | ||||||
|  |   std::cout << GridLogMessage << "Initialising 4d RNG" << std::endl; | ||||||
|  |   GridParallelRNG          RNG4(UGrid);  RNG4.SeedFixedIntegers(seeds4); | ||||||
|  |   std::cout << GridLogMessage << "Initialising 5d RNG" << std::endl; | ||||||
|  |   GridParallelRNG          RNG5(FGrid);  RNG5.SeedFixedIntegers(seeds5); | ||||||
|  |   std::cout << GridLogMessage << "Initialised RNGs" << std::endl; | ||||||
|  |  | ||||||
|  |   GparityLatticeFermionF src   (FGrid); random(RNG5,src); | ||||||
|  |   RealD N2 = 1.0/::sqrt(norm2(src)); | ||||||
|  |   src = src*N2; | ||||||
|  |  | ||||||
|  |   GparityLatticeFermionF result(FGrid); result=zero; | ||||||
|  |   GparityLatticeFermionF    ref(FGrid);    ref=zero; | ||||||
|  |   GparityLatticeFermionF    tmp(FGrid); | ||||||
|  |   GparityLatticeFermionF    err(FGrid); | ||||||
|  |  | ||||||
|  |   std::cout << GridLogMessage << "Drawing gauge field" << std::endl; | ||||||
|  |   LatticeGaugeFieldF Umu(UGrid);  | ||||||
|  |   SU3::HotConfiguration(RNG4,Umu);  | ||||||
|  |   std::cout << GridLogMessage << "Random gauge initialised " << std::endl; | ||||||
|  |  | ||||||
|  |   RealD mass=0.1; | ||||||
|  |   RealD M5  =1.8; | ||||||
|  |  | ||||||
|  |   RealD NP = UGrid->_Nprocessors; | ||||||
|  |   RealD NN = UGrid->NodeCount(); | ||||||
|  |  | ||||||
|  |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|  |   std::cout << GridLogMessage<< "* Kernel options --dslash-generic, --dslash-unroll, --dslash-asm" <<std::endl; | ||||||
|  |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|  |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|  |   std::cout << GridLogMessage<< "* Benchmarking DomainWallFermion::Dhop                  "<<std::endl; | ||||||
|  |   std::cout << GridLogMessage<< "* Vectorising space-time by "<<vComplexF::Nsimd()<<std::endl; | ||||||
|  | #ifdef GRID_OMP | ||||||
|  |   if ( WilsonKernelsStatic::Comms == WilsonKernelsStatic::CommsAndCompute ) std::cout << GridLogMessage<< "* Using Overlapped Comms/Compute" <<std::endl; | ||||||
|  |   if ( WilsonKernelsStatic::Comms == WilsonKernelsStatic::CommsThenCompute) std::cout << GridLogMessage<< "* Using sequential comms compute" <<std::endl; | ||||||
|  | #endif | ||||||
|  |   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptGeneric   ) std::cout << GridLogMessage<< "* Using GENERIC Nc WilsonKernels" <<std::endl; | ||||||
|  |   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptHandUnroll) std::cout << GridLogMessage<< "* Using Nc=3       WilsonKernels" <<std::endl; | ||||||
|  |   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptInlineAsm ) std::cout << GridLogMessage<< "* Using Asm Nc=3   WilsonKernels" <<std::endl; | ||||||
|  |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   std::cout << GridLogMessage<< "* SINGLE/SINGLE"<<std::endl; | ||||||
|  |   GparityDomainWallFermionF Dw(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5); | ||||||
|  |   int ncall =1000; | ||||||
|  |   if (1) { | ||||||
|  |     FGrid->Barrier(); | ||||||
|  |     Dw.ZeroCounters(); | ||||||
|  |     Dw.Dhop(src,result,0); | ||||||
|  |     std::cout<<GridLogMessage<<"Called warmup"<<std::endl; | ||||||
|  |     double t0=usecond(); | ||||||
|  |     for(int i=0;i<ncall;i++){ | ||||||
|  |       __SSC_START; | ||||||
|  |       Dw.Dhop(src,result,0); | ||||||
|  |       __SSC_STOP; | ||||||
|  |     } | ||||||
|  |     double t1=usecond(); | ||||||
|  |     FGrid->Barrier(); | ||||||
|  |      | ||||||
|  |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|  |     double flops=2*1320*volume*ncall; | ||||||
|  |  | ||||||
|  |     std::cout<<GridLogMessage << "Called Dw "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; | ||||||
|  |     //    std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl; | ||||||
|  |     //    std::cout<<GridLogMessage << "norm ref    "<< norm2(ref)<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s per rank =  "<< flops/(t1-t0)/NP<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s per node =  "<< flops/(t1-t0)/NN<<std::endl; | ||||||
|  |     Dw.Report(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   std::cout << GridLogMessage<< "* SINGLE/HALF"<<std::endl; | ||||||
|  |   GparityDomainWallFermionFH DwH(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5); | ||||||
|  |   if (1) { | ||||||
|  |     FGrid->Barrier(); | ||||||
|  |     DwH.ZeroCounters(); | ||||||
|  |     DwH.Dhop(src,result,0); | ||||||
|  |     double t0=usecond(); | ||||||
|  |     for(int i=0;i<ncall;i++){ | ||||||
|  |       __SSC_START; | ||||||
|  |       DwH.Dhop(src,result,0); | ||||||
|  |       __SSC_STOP; | ||||||
|  |     } | ||||||
|  |     double t1=usecond(); | ||||||
|  |     FGrid->Barrier(); | ||||||
|  |      | ||||||
|  |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|  |     double flops=2*1320*volume*ncall; | ||||||
|  |  | ||||||
|  |     std::cout<<GridLogMessage << "Called half prec comms Dw "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s per rank =  "<< flops/(t1-t0)/NP<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s per node =  "<< flops/(t1-t0)/NN<<std::endl; | ||||||
|  |     DwH.Report(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   GridCartesian         * UGrid_d   = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplexD::Nsimd()),GridDefaultMpi()); | ||||||
|  |   GridRedBlackCartesian * UrbGrid_d = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid_d); | ||||||
|  |   GridCartesian         * FGrid_d   = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid_d); | ||||||
|  |   GridRedBlackCartesian * FrbGrid_d = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid_d); | ||||||
|  |  | ||||||
|  |    | ||||||
|  |   std::cout << GridLogMessage<< "* DOUBLE/DOUBLE"<<std::endl; | ||||||
|  |   GparityLatticeFermionD src_d(FGrid_d); | ||||||
|  |   precisionChange(src_d,src); | ||||||
|  |  | ||||||
|  |   LatticeGaugeFieldD Umu_d(UGrid_d);  | ||||||
|  |   precisionChange(Umu_d,Umu); | ||||||
|  |  | ||||||
|  |   GparityLatticeFermionD result_d(FGrid_d); | ||||||
|  |  | ||||||
|  |   GparityDomainWallFermionD DwD(Umu_d,*FGrid_d,*FrbGrid_d,*UGrid_d,*UrbGrid_d,mass,M5); | ||||||
|  |   if (1) { | ||||||
|  |     FGrid_d->Barrier(); | ||||||
|  |     DwD.ZeroCounters(); | ||||||
|  |     DwD.Dhop(src_d,result_d,0); | ||||||
|  |     std::cout<<GridLogMessage<<"Called warmup"<<std::endl; | ||||||
|  |     double t0=usecond(); | ||||||
|  |     for(int i=0;i<ncall;i++){ | ||||||
|  |       __SSC_START; | ||||||
|  |       DwD.Dhop(src_d,result_d,0); | ||||||
|  |       __SSC_STOP; | ||||||
|  |     } | ||||||
|  |     double t1=usecond(); | ||||||
|  |     FGrid_d->Barrier(); | ||||||
|  |      | ||||||
|  |     double volume=Ls;  for(int mu=0;mu<Nd;mu++) volume=volume*latt4[mu]; | ||||||
|  |     double flops=2*1320*volume*ncall; | ||||||
|  |  | ||||||
|  |     std::cout<<GridLogMessage << "Called Dw "<<ncall<<" times in "<<t1-t0<<" us"<<std::endl; | ||||||
|  |     //    std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl; | ||||||
|  |     //    std::cout<<GridLogMessage << "norm ref    "<< norm2(ref)<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s per rank =  "<< flops/(t1-t0)/NP<<std::endl; | ||||||
|  |     std::cout<<GridLogMessage << "mflop/s per node =  "<< flops/(t1-t0)/NN<<std::endl; | ||||||
|  |     DwD.Report(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   Grid_finalize(); | ||||||
|  | } | ||||||
|  |  | ||||||
| @@ -55,7 +55,7 @@ int main (int argc, char ** argv) | |||||||
|   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s"<<"\t\t"<<"Gflop/s"<<"\t\t seconds"<<std::endl; |   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s"<<"\t\t"<<"Gflop/s"<<"\t\t seconds"<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; |   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; | ||||||
|   uint64_t lmax=96; |   uint64_t lmax=64; | ||||||
| #define NLOOP (10*lmax*lmax*lmax*lmax/vol) | #define NLOOP (10*lmax*lmax*lmax*lmax/vol) | ||||||
|   for(int lat=8;lat<=lmax;lat+=8){ |   for(int lat=8;lat<=lmax;lat+=8){ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ int main (int argc, char ** argv) | |||||||
|   std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); |   std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); | ||||||
|   std::vector<int> mpi_layout  = GridDefaultMpi(); |   std::vector<int> mpi_layout  = GridDefaultMpi(); | ||||||
|   GridCartesian               Grid(latt_size,simd_layout,mpi_layout); |   GridCartesian               Grid(latt_size,simd_layout,mpi_layout); | ||||||
|   GridRedBlackCartesian     RBGrid(latt_size,simd_layout,mpi_layout); |   GridRedBlackCartesian     RBGrid(&Grid); | ||||||
|  |  | ||||||
|   int threads = GridThread::GetThreads(); |   int threads = GridThread::GetThreads(); | ||||||
|   std::cout<<GridLogMessage << "Grid is setup to use "<<threads<<" threads"<<std::endl; |   std::cout<<GridLogMessage << "Grid is setup to use "<<threads<<" threads"<<std::endl; | ||||||
|   | |||||||
| @@ -35,9 +35,11 @@ using namespace Grid::QCD; | |||||||
| int main (int argc, char ** argv) | int main (int argc, char ** argv) | ||||||
| { | { | ||||||
|   Grid_init(&argc,&argv); |   Grid_init(&argc,&argv); | ||||||
| #define LMAX (64) | #define LMAX (32) | ||||||
|  | #define LMIN (16) | ||||||
|  | #define LINC (4) | ||||||
|  |  | ||||||
|   int64_t Nloop=20; |   int64_t Nloop=2000; | ||||||
|  |  | ||||||
|   std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); |   std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); | ||||||
|   std::vector<int> mpi_layout  = GridDefaultMpi(); |   std::vector<int> mpi_layout  = GridDefaultMpi(); | ||||||
| @@ -51,7 +53,7 @@ int main (int argc, char ** argv) | |||||||
|   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; |   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; |   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; | ||||||
|  |  | ||||||
|   for(int lat=2;lat<=LMAX;lat+=2){ |   for(int lat=LMIN;lat<=LMAX;lat+=LINC){ | ||||||
|  |  | ||||||
|       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); |       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); | ||||||
|       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; |       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; | ||||||
| @@ -83,7 +85,7 @@ int main (int argc, char ** argv) | |||||||
|   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; |   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; |   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; | ||||||
|  |  | ||||||
|   for(int lat=2;lat<=LMAX;lat+=2){ |   for(int lat=LMIN;lat<=LMAX;lat+=LINC){ | ||||||
|  |  | ||||||
|       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); |       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); | ||||||
|       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; |       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; | ||||||
| @@ -114,7 +116,7 @@ int main (int argc, char ** argv) | |||||||
|   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; |   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; |   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; | ||||||
|  |  | ||||||
|   for(int lat=2;lat<=LMAX;lat+=2){ |   for(int lat=LMIN;lat<=LMAX;lat+=LINC){ | ||||||
|  |  | ||||||
|       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); |       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); | ||||||
|       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; |       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; | ||||||
| @@ -145,7 +147,7 @@ int main (int argc, char ** argv) | |||||||
|   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; |   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; |   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; | ||||||
|  |  | ||||||
|   for(int lat=2;lat<=LMAX;lat+=2){ |   for(int lat=LMIN;lat<=LMAX;lat+=LINC){ | ||||||
|      |      | ||||||
|     std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); |     std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); | ||||||
|     int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; |     int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; | ||||||
| @@ -165,10 +167,87 @@ int main (int argc, char ** argv) | |||||||
|     double time = (stop-start)/Nloop*1000.0; |     double time = (stop-start)/Nloop*1000.0; | ||||||
|      |      | ||||||
|     double bytes=3*vol*Nc*Nc*sizeof(Complex); |     double bytes=3*vol*Nc*Nc*sizeof(Complex); | ||||||
|       double flops=Nc*Nc*(8+8+8)*vol; |     double flops=Nc*Nc*(6+8+8)*vol; | ||||||
|     std::cout<<GridLogMessage<<std::setprecision(3) << lat<<"\t\t"<<bytes<<"   \t\t"<<bytes/time<<"\t\t" << flops/time<<std::endl; |     std::cout<<GridLogMessage<<std::setprecision(3) << lat<<"\t\t"<<bytes<<"   \t\t"<<bytes/time<<"\t\t" << flops/time<<std::endl; | ||||||
|      |      | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "= Benchmarking SU3xSU3  CovShiftForward(z,x,y)"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; | ||||||
|  |  | ||||||
|  |   for(int lat=LMIN;lat<=LMAX;lat+=LINC){ | ||||||
|  |  | ||||||
|  |       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); | ||||||
|  |       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; | ||||||
|  |  | ||||||
|  |       GridCartesian     Grid(latt_size,simd_layout,mpi_layout); | ||||||
|  |       GridParallelRNG          pRNG(&Grid);      pRNG.SeedFixedIntegers(std::vector<int>({45,12,81,9})); | ||||||
|  |  | ||||||
|  |       LatticeColourMatrix z(&Grid); random(pRNG,z); | ||||||
|  |       LatticeColourMatrix x(&Grid); random(pRNG,x); | ||||||
|  |       LatticeColourMatrix y(&Grid); random(pRNG,y); | ||||||
|  |  | ||||||
|  |       for(int mu=0;mu<4;mu++){ | ||||||
|  | 	      double start=usecond(); | ||||||
|  | 	      for(int64_t i=0;i<Nloop;i++){ | ||||||
|  | 	        z = PeriodicBC::CovShiftForward(x,mu,y); | ||||||
|  | 	    } | ||||||
|  | 	    double stop=usecond(); | ||||||
|  | 	    double time = (stop-start)/Nloop*1000.0; | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	    double bytes=3*vol*Nc*Nc*sizeof(Complex); | ||||||
|  | 	    double flops=Nc*Nc*(6+8+8)*vol; | ||||||
|  | 	    std::cout<<GridLogMessage<<std::setprecision(3) << lat<<"\t\t"<<bytes<<"   \t\t"<<bytes/time<<"\t\t" << flops/time<<std::endl; | ||||||
|  |       } | ||||||
|  |   } | ||||||
|  | #if 1 | ||||||
|  |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "= Benchmarking SU3xSU3  z= x * Cshift(y)"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "===================================================================================================="<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "  L  "<<"\t\t"<<"bytes"<<"\t\t\t"<<"GB/s\t\t GFlop/s"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "----------------------------------------------------------"<<std::endl; | ||||||
|  |  | ||||||
|  |   for(int lat=LMIN;lat<=LMAX;lat+=LINC){ | ||||||
|  |       std::vector<int> latt_size  ({lat*mpi_layout[0],lat*mpi_layout[1],lat*mpi_layout[2],lat*mpi_layout[3]}); | ||||||
|  |       int64_t vol = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; | ||||||
|  |  | ||||||
|  |       GridCartesian     Grid(latt_size,simd_layout,mpi_layout); | ||||||
|  |       GridParallelRNG          pRNG(&Grid);      pRNG.SeedFixedIntegers(std::vector<int>({45,12,81,9})); | ||||||
|  |  | ||||||
|  |       LatticeColourMatrix z(&Grid); random(pRNG,z); | ||||||
|  |       LatticeColourMatrix x(&Grid); random(pRNG,x); | ||||||
|  |       LatticeColourMatrix y(&Grid); random(pRNG,y); | ||||||
|  |       LatticeColourMatrix tmp(&Grid); | ||||||
|  |  | ||||||
|  |       for(int mu=0;mu<4;mu++){ | ||||||
|  | 	double tshift=0; | ||||||
|  | 	double tmult =0; | ||||||
|  |  | ||||||
|  | 	double start=usecond(); | ||||||
|  | 	for(int64_t i=0;i<Nloop;i++){ | ||||||
|  | 	  tshift-=usecond(); | ||||||
|  | 	  tmp = Cshift(y,mu,-1); | ||||||
|  | 	  tshift+=usecond(); | ||||||
|  | 	  tmult-=usecond(); | ||||||
|  | 	  z   = x*tmp; | ||||||
|  | 	  tmult+=usecond(); | ||||||
|  | 	} | ||||||
|  | 	double stop=usecond(); | ||||||
|  | 	double time = (stop-start)/Nloop; | ||||||
|  | 	tshift = tshift/Nloop; | ||||||
|  | 	tmult  = tmult /Nloop; | ||||||
|  | 	 | ||||||
|  | 	double bytes=3*vol*Nc*Nc*sizeof(Complex); | ||||||
|  | 	double flops=Nc*Nc*(6+8+8)*vol; | ||||||
|  | 	std::cout<<GridLogMessage<<std::setprecision(3) << "total us "<<time<<" shift "<<tshift <<" mult "<<tmult<<std::endl; | ||||||
|  | 	time = time * 1000; // convert to NS for GB/s | ||||||
|  | 	std::cout<<GridLogMessage<<std::setprecision(3) << lat<<"\t\t"<<bytes<<"   \t\t"<<bytes/time<<"\t\t" << flops/time<<std::endl; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | #endif | ||||||
|   Grid_finalize(); |   Grid_finalize(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|  |  | ||||||
|     Source file: ./benchmarks/Benchmark_wilson.cc |     Source file: ./benchmarks/Benchmark_wilson.cc | ||||||
|  |  | ||||||
|     Copyright (C) 2015 |     Copyright (C) 2018 | ||||||
|  |  | ||||||
| Author: Peter Boyle <paboyle@ph.ed.ac.uk> | Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||||
| Author: paboyle <paboyle@ph.ed.ac.uk> | Author: paboyle <paboyle@ph.ed.ac.uk> | ||||||
| @@ -32,6 +32,9 @@ using namespace std; | |||||||
| using namespace Grid; | using namespace Grid; | ||||||
| using namespace Grid::QCD; | using namespace Grid::QCD; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #include "Grid/util/Profiling.h" | ||||||
|  |  | ||||||
| template<class d> | template<class d> | ||||||
| struct scal { | struct scal { | ||||||
|   d internal; |   d internal; | ||||||
| @@ -45,6 +48,7 @@ struct scal { | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
| bool overlapComms = false; | bool overlapComms = false; | ||||||
|  | bool perfProfiling = false; | ||||||
|  |  | ||||||
| int main (int argc, char ** argv) | int main (int argc, char ** argv) | ||||||
| { | { | ||||||
| @@ -53,18 +57,29 @@ int main (int argc, char ** argv) | |||||||
|   if( GridCmdOptionExists(argv,argv+argc,"--asynch") ){ |   if( GridCmdOptionExists(argv,argv+argc,"--asynch") ){ | ||||||
|     overlapComms = true; |     overlapComms = true; | ||||||
|   } |   } | ||||||
|  |   if( GridCmdOptionExists(argv,argv+argc,"--perf") ){ | ||||||
|  |     perfProfiling = true; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); | ||||||
|  |  | ||||||
|  |  | ||||||
|   std::vector<int> latt_size   = GridDefaultLatt(); |   std::vector<int> latt_size   = GridDefaultLatt(); | ||||||
|   std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); |   std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); | ||||||
|   std::vector<int> mpi_layout  = GridDefaultMpi(); |   std::vector<int> mpi_layout  = GridDefaultMpi(); | ||||||
|   GridCartesian               Grid(latt_size,simd_layout,mpi_layout); |   GridCartesian               Grid(latt_size,simd_layout,mpi_layout); | ||||||
|   GridRedBlackCartesian     RBGrid(latt_size,simd_layout,mpi_layout); |   GridRedBlackCartesian     RBGrid(&Grid); | ||||||
|  |  | ||||||
|   int threads = GridThread::GetThreads(); |   int threads = GridThread::GetThreads(); | ||||||
|   std::cout<<GridLogMessage << "Grid is setup to use "<<threads<<" threads"<<std::endl; |  | ||||||
|  |   GridLogLayout(); | ||||||
|  |  | ||||||
|   std::cout<<GridLogMessage << "Grid floating point word size is REALF"<< sizeof(RealF)<<std::endl; |   std::cout<<GridLogMessage << "Grid floating point word size is REALF"<< sizeof(RealF)<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "Grid floating point word size is REALD"<< sizeof(RealD)<<std::endl; |   std::cout<<GridLogMessage << "Grid floating point word size is REALD"<< sizeof(RealD)<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "Grid floating point word size is REAL"<< sizeof(Real)<<std::endl; |   std::cout<<GridLogMessage << "Grid floating point word size is REAL"<< sizeof(Real)<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "Grid number of colours : "<< QCD::Nc <<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "Benchmarking Wilson operator in the fundamental representation" << std::endl; | ||||||
|  |  | ||||||
|  |  | ||||||
|   std::vector<int> seeds({1,2,3,4}); |   std::vector<int> seeds({1,2,3,4}); | ||||||
|   GridParallelRNG          pRNG(&Grid); |   GridParallelRNG          pRNG(&Grid); | ||||||
| @@ -134,9 +149,25 @@ int main (int argc, char ** argv) | |||||||
|     Dw.Dhop(src,result,0); |     Dw.Dhop(src,result,0); | ||||||
|   } |   } | ||||||
|   double t1=usecond(); |   double t1=usecond(); | ||||||
|   double flops=1344*volume*ncall; |   double flops=single_site_flops*volume*ncall; | ||||||
|  |    | ||||||
|  |   if (perfProfiling){ | ||||||
|  |   std::cout<<GridLogMessage << "Profiling Dw with perf"<<std::endl; | ||||||
|  |      | ||||||
|  |   System::profile("kernel", [&]() { | ||||||
|  |     for(int i=0;i<ncall;i++){ | ||||||
|  |       Dw.Dhop(src,result,0); | ||||||
|  |     } | ||||||
|  |   }); | ||||||
|  |  | ||||||
|  |   std::cout<<GridLogMessage << "Generated kernel.data"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "Use with: perf report -i kernel.data"<<std::endl; | ||||||
|  |  | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   std::cout<<GridLogMessage << "Called Dw"<<std::endl; |   std::cout<<GridLogMessage << "Called Dw"<<std::endl; | ||||||
|  |   std::cout<<GridLogMessage << "flops per site " << single_site_flops << std::endl; | ||||||
|   std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl; |   std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "norm ref    "<< norm2(ref)<<std::endl; |   std::cout<<GridLogMessage << "norm ref    "<< norm2(ref)<<std::endl; | ||||||
|   std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; |   std::cout<<GridLogMessage << "mflop/s =   "<< flops/(t1-t0)<<std::endl; | ||||||
|   | |||||||
| @@ -62,6 +62,7 @@ int main (int argc, char ** argv) | |||||||
|   std::cout << GridLogMessage<< "* Kernel options --dslash-generic, --dslash-unroll, --dslash-asm" <<std::endl; |   std::cout << GridLogMessage<< "* Kernel options --dslash-generic, --dslash-unroll, --dslash-asm" <<std::endl; | ||||||
|   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|  |   std::cout << GridLogMessage<< "* Number of colours "<< QCD::Nc <<std::endl; | ||||||
|   std::cout << GridLogMessage<< "* Benchmarking WilsonFermionR::Dhop                  "<<std::endl; |   std::cout << GridLogMessage<< "* Benchmarking WilsonFermionR::Dhop                  "<<std::endl; | ||||||
|   std::cout << GridLogMessage<< "* Vectorising space-time by "<<vComplex::Nsimd()<<std::endl; |   std::cout << GridLogMessage<< "* Vectorising space-time by "<<vComplex::Nsimd()<<std::endl; | ||||||
|   if ( sizeof(Real)==4 )   std::cout << GridLogMessage<< "* SINGLE precision "<<std::endl; |   if ( sizeof(Real)==4 )   std::cout << GridLogMessage<< "* SINGLE precision "<<std::endl; | ||||||
| @@ -69,13 +70,15 @@ int main (int argc, char ** argv) | |||||||
|   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptGeneric   ) std::cout << GridLogMessage<< "* Using GENERIC Nc WilsonKernels" <<std::endl; |   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptGeneric   ) std::cout << GridLogMessage<< "* Using GENERIC Nc WilsonKernels" <<std::endl; | ||||||
|   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptHandUnroll) std::cout << GridLogMessage<< "* Using Nc=3       WilsonKernels" <<std::endl; |   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptHandUnroll) std::cout << GridLogMessage<< "* Using Nc=3       WilsonKernels" <<std::endl; | ||||||
|   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptInlineAsm ) std::cout << GridLogMessage<< "* Using Asm Nc=3   WilsonKernels" <<std::endl; |   if ( WilsonKernelsStatic::Opt == WilsonKernelsStatic::OptInlineAsm ) std::cout << GridLogMessage<< "* Using Asm Nc=3   WilsonKernels" <<std::endl; | ||||||
|  |   std::cout << GridLogMessage << "* OpenMP threads       : "<< GridThread::GetThreads() <<std::endl; | ||||||
|  |   std::cout << GridLogMessage << "* MPI tasks            : "<< GridCmdVectorIntToString(mpi_layout) << std::endl; | ||||||
|   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; |   std::cout << GridLogMessage<< "*****************************************************************" <<std::endl; | ||||||
|  |  | ||||||
|   std::cout<<GridLogMessage << "============================================================================="<< std::endl; |   std::cout<<GridLogMessage << "================================================================================================="<< std::endl; | ||||||
|   std::cout<<GridLogMessage << "= Benchmarking Wilson" << std::endl; |   std::cout<<GridLogMessage << "= Benchmarking Wilson operator in the fundamental representation" << std::endl; | ||||||
|   std::cout<<GridLogMessage << "============================================================================="<< std::endl; |   std::cout<<GridLogMessage << "================================================================================================="<< std::endl; | ||||||
|   std::cout<<GridLogMessage << "Volume\t\t\tWilson/MFLOPs\tWilsonDag/MFLOPs" << std::endl; |   std::cout<<GridLogMessage << "Volume\t\t\tWilson/MFLOPs\tWilsonDag/MFLOPs\tWilsonEO/MFLOPs\tWilsonDagEO/MFLOPs" << std::endl; | ||||||
|   std::cout<<GridLogMessage << "============================================================================="<< std::endl; |   std::cout<<GridLogMessage << "================================================================================================="<< std::endl; | ||||||
|  |  | ||||||
|   int Lmax = 32; |   int Lmax = 32; | ||||||
|   int dmin = 0; |   int dmin = 0; | ||||||
| @@ -93,17 +96,24 @@ int main (int argc, char ** argv) | |||||||
| 	  std::cout << latt_size.back() << "\t\t"; | 	  std::cout << latt_size.back() << "\t\t"; | ||||||
|  |  | ||||||
| 	  GridCartesian           Grid(latt_size,simd_layout,mpi_layout); | 	  GridCartesian           Grid(latt_size,simd_layout,mpi_layout); | ||||||
| 	  GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout); | 	  GridRedBlackCartesian RBGrid(&Grid); | ||||||
|  |  | ||||||
| 	  GridParallelRNG  pRNG(&Grid); pRNG.SeedFixedIntegers(seeds); | 	  GridParallelRNG  pRNG(&Grid); pRNG.SeedFixedIntegers(seeds); | ||||||
| 	  LatticeGaugeField Umu(&Grid); random(pRNG,Umu); | 	  LatticeGaugeField Umu(&Grid); random(pRNG,Umu); | ||||||
| 	  LatticeFermion        src(&Grid); random(pRNG,src); | 	  LatticeFermion        src(&Grid); random(pRNG,src); | ||||||
|  | 	  LatticeFermion    src_o(&RBGrid); pickCheckerboard(Odd,src_o,src); | ||||||
| 	  LatticeFermion     result(&Grid); result=zero; | 	  LatticeFermion     result(&Grid); result=zero; | ||||||
|  | 	  LatticeFermion result_e(&RBGrid); result_e=zero; | ||||||
|  |  | ||||||
| 	  double volume = std::accumulate(latt_size.begin(),latt_size.end(),1,std::multiplies<int>()); | 	  double volume = std::accumulate(latt_size.begin(),latt_size.end(),1,std::multiplies<int>()); | ||||||
|  |  | ||||||
| 	  WilsonFermionR Dw(Umu,Grid,RBGrid,mass,params); | 	  WilsonFermionR Dw(Umu,Grid,RBGrid,mass,params); | ||||||
|  |  | ||||||
|  |     // Full operator       | ||||||
|  | 	  bench_wilson(src,result,Dw,volume,DaggerNo); | ||||||
|  | 	  bench_wilson(src,result,Dw,volume,DaggerYes); | ||||||
|  |     std::cout << "\t"; | ||||||
|  |     // EO | ||||||
| 	  bench_wilson(src,result,Dw,volume,DaggerNo); | 	  bench_wilson(src,result,Dw,volume,DaggerNo); | ||||||
| 	  bench_wilson(src,result,Dw,volume,DaggerYes); | 	  bench_wilson(src,result,Dw,volume,DaggerYes); | ||||||
| 	  std::cout << std::endl; | 	  std::cout << std::endl; | ||||||
| @@ -122,9 +132,26 @@ void bench_wilson ( | |||||||
| 		   int const           dag ) | 		   int const           dag ) | ||||||
| { | { | ||||||
|   int ncall    = 1000; |   int ncall    = 1000; | ||||||
|  |   long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); | ||||||
|   double t0    = usecond(); |   double t0    = usecond(); | ||||||
|   for(int i=0; i<ncall; i++) { Dw.Dhop(src,result,dag); } |   for(int i=0; i<ncall; i++) { Dw.Dhop(src,result,dag); } | ||||||
|   double t1    = usecond(); |   double t1    = usecond(); | ||||||
|   double flops = 1344 * volume * ncall; |   double flops = single_site_flops * volume * ncall; | ||||||
|  |   std::cout << flops/(t1-t0) << "\t\t"; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void bench_wilson_eo ( | ||||||
|  | 		   LatticeFermion &    src, | ||||||
|  | 		   LatticeFermion & result, | ||||||
|  | 		   WilsonFermionR &     Dw, | ||||||
|  | 		   double const     volume, | ||||||
|  | 		   int const           dag ) | ||||||
|  | { | ||||||
|  |   int ncall    = 1000; | ||||||
|  |   long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); | ||||||
|  |   double t0    = usecond(); | ||||||
|  |   for(int i=0; i<ncall; i++) { Dw.DhopEO(src,result,dag); } | ||||||
|  |   double t1    = usecond(); | ||||||
|  |   double flops = (single_site_flops * volume * ncall)/2.0; | ||||||
|   std::cout << flops/(t1-t0) << "\t\t"; |   std::cout << flops/(t1-t0) << "\t\t"; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,11 +1,16 @@ | |||||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||||
|  |  | ||||||
| EIGEN_URL='http://bitbucket.org/eigen/eigen/get/3.3.3.tar.bz2' | EIGEN_SRC='3.3.3.tar.bz2' | ||||||
|  | EIGEN_URL="http://bitbucket.org/eigen/eigen/get/${EIGEN_SRC}" | ||||||
|  |  | ||||||
|  | if [ -f ${EIGEN_SRC} ]; then | ||||||
|  |   echo "-- skip deploying Eigen source..." | ||||||
|  | else | ||||||
|   echo "-- deploying Eigen source..." |   echo "-- deploying Eigen source..." | ||||||
|   wget ${EIGEN_URL} --no-check-certificate |   wget ${EIGEN_URL} --no-check-certificate | ||||||
|   ./scripts/update_eigen.sh `basename ${EIGEN_URL}` |   ./scripts/update_eigen.sh `basename ${EIGEN_URL}` | ||||||
| rm `basename ${EIGEN_URL}` |   #rm `basename ${EIGEN_URL}` | ||||||
|  | fi | ||||||
|  |  | ||||||
| echo '-- generating Make.inc files...' | echo '-- generating Make.inc files...' | ||||||
| ./scripts/filelist | ./scripts/filelist | ||||||
|   | |||||||
							
								
								
									
										32
									
								
								configure.ac
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								configure.ac
									
									
									
									
									
								
							| @@ -249,6 +249,9 @@ case ${ax_cv_cxx_compiler_vendor} in | |||||||
|       AVX512) |       AVX512) | ||||||
|         AC_DEFINE([AVX512],[1],[AVX512 intrinsics]) |         AC_DEFINE([AVX512],[1],[AVX512 intrinsics]) | ||||||
|         SIMD_FLAGS='-mavx512f -mavx512pf -mavx512er -mavx512cd';; |         SIMD_FLAGS='-mavx512f -mavx512pf -mavx512er -mavx512cd';; | ||||||
|  |       SKL) | ||||||
|  |         AC_DEFINE([AVX512],[1],[AVX512 intrinsics for SkyLake Xeon]) | ||||||
|  |         SIMD_FLAGS='-march=skylake-avx512';; | ||||||
|       KNC) |       KNC) | ||||||
|         AC_DEFINE([IMCI],[1],[IMCI intrinsics for Knights Corner]) |         AC_DEFINE([IMCI],[1],[IMCI intrinsics for Knights Corner]) | ||||||
|         SIMD_FLAGS='';; |         SIMD_FLAGS='';; | ||||||
| @@ -337,17 +340,21 @@ case ${ac_PRECISION} in | |||||||
| esac | esac | ||||||
|  |  | ||||||
| ######################  Shared memory allocation technique under MPI3 | ######################  Shared memory allocation technique under MPI3 | ||||||
| AC_ARG_ENABLE([shm],[AC_HELP_STRING([--enable-shm=shmget|shmopen|hugetlbfs], | AC_ARG_ENABLE([shm],[AC_HELP_STRING([--enable-shm=shmopen|shmget|hugetlbfs|shmnone], | ||||||
|               [Select SHM allocation technique])],[ac_SHM=${enable_shm}],[ac_SHM=shmopen]) |               [Select SHM allocation technique])],[ac_SHM=${enable_shm}],[ac_SHM=shmopen]) | ||||||
|  |  | ||||||
| case ${ac_SHM} in | case ${ac_SHM} in | ||||||
|  |  | ||||||
|  |      shmopen) | ||||||
|  |      AC_DEFINE([GRID_MPI3_SHMOPEN],[1],[GRID_MPI3_SHMOPEN] ) | ||||||
|  |      ;; | ||||||
|  |  | ||||||
|      shmget) |      shmget) | ||||||
|      AC_DEFINE([GRID_MPI3_SHMGET],[1],[GRID_MPI3_SHMGET] ) |      AC_DEFINE([GRID_MPI3_SHMGET],[1],[GRID_MPI3_SHMGET] ) | ||||||
|      ;; |      ;; | ||||||
|  |  | ||||||
|      shmopen) |      shmnone) | ||||||
|      AC_DEFINE([GRID_MPI3_SHMOPEN],[1],[GRID_MPI3_SHMOPEN] ) |      AC_DEFINE([GRID_MPI3_SHM_NONE],[1],[GRID_MPI3_SHM_NONE] ) | ||||||
|      ;; |      ;; | ||||||
|  |  | ||||||
|      hugetlbfs) |      hugetlbfs) | ||||||
| @@ -363,11 +370,11 @@ esac | |||||||
| AC_ARG_ENABLE([shmpath],[AC_HELP_STRING([--enable-shmpath=path], | AC_ARG_ENABLE([shmpath],[AC_HELP_STRING([--enable-shmpath=path], | ||||||
|               [Select SHM mmap base path for hugetlbfs])], |               [Select SHM mmap base path for hugetlbfs])], | ||||||
| 	      [ac_SHMPATH=${enable_shmpath}], | 	      [ac_SHMPATH=${enable_shmpath}], | ||||||
| 	      [ac_SHMPATH=/var/lib/hugetlbfs/pagesize-2MB/]) | 	      [ac_SHMPATH=/var/lib/hugetlbfs/global/pagesize-2MB/]) | ||||||
| AC_DEFINE_UNQUOTED([GRID_SHM_PATH],["$ac_SHMPATH"],[Path to a hugetlbfs filesystem for MMAPing]) | AC_DEFINE_UNQUOTED([GRID_SHM_PATH],["$ac_SHMPATH"],[Path to a hugetlbfs filesystem for MMAPing]) | ||||||
|  |  | ||||||
| ############### communication type selection | ############### communication type selection | ||||||
| AC_ARG_ENABLE([comms],[AC_HELP_STRING([--enable-comms=none|mpi|mpi-auto|mpi3|mpi3-auto|shmem], | AC_ARG_ENABLE([comms],[AC_HELP_STRING([--enable-comms=none|mpi|mpi-auto], | ||||||
|               [Select communications])],[ac_COMMS=${enable_comms}],[ac_COMMS=none]) |               [Select communications])],[ac_COMMS=${enable_comms}],[ac_COMMS=none]) | ||||||
|  |  | ||||||
| case ${ac_COMMS} in | case ${ac_COMMS} in | ||||||
| @@ -375,22 +382,10 @@ case ${ac_COMMS} in | |||||||
|         AC_DEFINE([GRID_COMMS_NONE],[1],[GRID_COMMS_NONE] ) |         AC_DEFINE([GRID_COMMS_NONE],[1],[GRID_COMMS_NONE] ) | ||||||
|         comms_type='none' |         comms_type='none' | ||||||
|      ;; |      ;; | ||||||
|      mpi3*) |      mpi*) | ||||||
|         AC_DEFINE([GRID_COMMS_MPI3],[1],[GRID_COMMS_MPI3] ) |         AC_DEFINE([GRID_COMMS_MPI3],[1],[GRID_COMMS_MPI3] ) | ||||||
|         comms_type='mpi3' |         comms_type='mpi3' | ||||||
|      ;; |      ;; | ||||||
|      mpit) |  | ||||||
|         AC_DEFINE([GRID_COMMS_MPIT],[1],[GRID_COMMS_MPIT] ) |  | ||||||
|         comms_type='mpit' |  | ||||||
|      ;; |  | ||||||
|      mpi*) |  | ||||||
|         AC_DEFINE([GRID_COMMS_MPI],[1],[GRID_COMMS_MPI] ) |  | ||||||
|         comms_type='mpi' |  | ||||||
|      ;; |  | ||||||
|      shmem) |  | ||||||
|         AC_DEFINE([GRID_COMMS_SHMEM],[1],[GRID_COMMS_SHMEM] ) |  | ||||||
|         comms_type='shmem' |  | ||||||
|      ;; |  | ||||||
|      *) |      *) | ||||||
|         AC_MSG_ERROR([${ac_COMMS} unsupported --enable-comms option]); |         AC_MSG_ERROR([${ac_COMMS} unsupported --enable-comms option]); | ||||||
|      ;; |      ;; | ||||||
| @@ -550,6 +545,7 @@ AC_CONFIG_FILES(tests/forces/Makefile) | |||||||
| AC_CONFIG_FILES(tests/hadrons/Makefile) | AC_CONFIG_FILES(tests/hadrons/Makefile) | ||||||
| AC_CONFIG_FILES(tests/hmc/Makefile) | AC_CONFIG_FILES(tests/hmc/Makefile) | ||||||
| AC_CONFIG_FILES(tests/solver/Makefile) | AC_CONFIG_FILES(tests/solver/Makefile) | ||||||
|  | AC_CONFIG_FILES(tests/lanczos/Makefile) | ||||||
| AC_CONFIG_FILES(tests/smearing/Makefile) | AC_CONFIG_FILES(tests/smearing/Makefile) | ||||||
| AC_CONFIG_FILES(tests/qdpxx/Makefile) | AC_CONFIG_FILES(tests/qdpxx/Makefile) | ||||||
| AC_CONFIG_FILES(tests/testu01/Makefile) | AC_CONFIG_FILES(tests/testu01/Makefile) | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Application.cc | Source file: extras/Hadrons/Application.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -43,12 +42,7 @@ using namespace Hadrons; | |||||||
| // constructors //////////////////////////////////////////////////////////////// | // constructors //////////////////////////////////////////////////////////////// | ||||||
| Application::Application(void) | Application::Application(void) | ||||||
| { | { | ||||||
|     LOG(Message) << "Modules available:" << std::endl; |     initLogger(); | ||||||
|     auto list = ModuleFactory::getInstance().getBuilderList(); |  | ||||||
|     for (auto &m: list) |  | ||||||
|     { |  | ||||||
|         LOG(Message) << "  " << m << std::endl; |  | ||||||
|     } |  | ||||||
|     auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim); |     auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim); | ||||||
|     locVol_ = 1; |     locVol_ = 1; | ||||||
|     for (unsigned int d = 0; d < dim.size(); ++d) |     for (unsigned int d = 0; d < dim.size(); ++d) | ||||||
| @@ -73,12 +67,6 @@ Application::Application(const std::string parameterFileName) | |||||||
|     parameterFileName_ = parameterFileName; |     parameterFileName_ = parameterFileName; | ||||||
| } | } | ||||||
|  |  | ||||||
| // environment shortcut //////////////////////////////////////////////////////// |  | ||||||
| Environment & Application::env(void) const |  | ||||||
| { |  | ||||||
|     return Environment::getInstance(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // access ////////////////////////////////////////////////////////////////////// | // access ////////////////////////////////////////////////////////////////////// | ||||||
| void Application::setPar(const Application::GlobalPar &par) | void Application::setPar(const Application::GlobalPar &par) | ||||||
| { | { | ||||||
| @@ -94,14 +82,13 @@ const Application::GlobalPar & Application::getPar(void) | |||||||
| // execute ///////////////////////////////////////////////////////////////////// | // execute ///////////////////////////////////////////////////////////////////// | ||||||
| void Application::run(void) | void Application::run(void) | ||||||
| { | { | ||||||
|     if (!parameterFileName_.empty() and (env().getNModule() == 0)) |     if (!parameterFileName_.empty() and (vm().getNModule() == 0)) | ||||||
|     { |     { | ||||||
|         parseParameterFile(parameterFileName_); |         parseParameterFile(parameterFileName_); | ||||||
|     } |     } | ||||||
|     if (!scheduled_) |     vm().printContent(); | ||||||
|     { |     env().printContent(); | ||||||
|     schedule(); |     schedule(); | ||||||
|     } |  | ||||||
|     printSchedule(); |     printSchedule(); | ||||||
|     configLoop(); |     configLoop(); | ||||||
| } | } | ||||||
| @@ -124,12 +111,20 @@ void Application::parseParameterFile(const std::string parameterFileName) | |||||||
|     LOG(Message) << "Building application from '" << parameterFileName << "'..." << std::endl; |     LOG(Message) << "Building application from '" << parameterFileName << "'..." << std::endl; | ||||||
|     read(reader, "parameters", par); |     read(reader, "parameters", par); | ||||||
|     setPar(par); |     setPar(par); | ||||||
|     push(reader, "modules"); |     if (!push(reader, "modules")) | ||||||
|     push(reader, "module"); |     { | ||||||
|  |         HADRON_ERROR(Parsing, "Cannot open node 'modules' in parameter file '"  | ||||||
|  |                               + parameterFileName + "'"); | ||||||
|  |     } | ||||||
|  |     if (!push(reader, "module")) | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '"  | ||||||
|  |                               + parameterFileName + "'"); | ||||||
|  |     } | ||||||
|     do |     do | ||||||
|     { |     { | ||||||
|         read(reader, "id", id); |         read(reader, "id", id); | ||||||
|         env().createModule(id.name, id.type, reader); |         vm().createModule(id.name, id.type, reader); | ||||||
|     } while (reader.nextElement("module")); |     } while (reader.nextElement("module")); | ||||||
|     pop(reader); |     pop(reader); | ||||||
|     pop(reader); |     pop(reader); | ||||||
| @@ -139,7 +134,7 @@ void Application::saveParameterFile(const std::string parameterFileName) | |||||||
| { | { | ||||||
|     XmlWriter          writer(parameterFileName); |     XmlWriter          writer(parameterFileName); | ||||||
|     ObjectId           id; |     ObjectId           id; | ||||||
|     const unsigned int nMod = env().getNModule(); |     const unsigned int nMod = vm().getNModule(); | ||||||
|      |      | ||||||
|     LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl; |     LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl; | ||||||
|     write(writer, "parameters", getPar()); |     write(writer, "parameters", getPar()); | ||||||
| @@ -147,10 +142,10 @@ void Application::saveParameterFile(const std::string parameterFileName) | |||||||
|     for (unsigned int i = 0; i < nMod; ++i) |     for (unsigned int i = 0; i < nMod; ++i) | ||||||
|     { |     { | ||||||
|         push(writer, "module"); |         push(writer, "module"); | ||||||
|         id.name = env().getModuleName(i); |         id.name = vm().getModuleName(i); | ||||||
|         id.type = env().getModule(i)->getRegisteredName(); |         id.type = vm().getModule(i)->getRegisteredName(); | ||||||
|         write(writer, "id", id); |         write(writer, "id", id); | ||||||
|         env().getModule(i)->saveParameters(writer, "options"); |         vm().getModule(i)->saveParameters(writer, "options"); | ||||||
|         pop(writer); |         pop(writer); | ||||||
|     } |     } | ||||||
|     pop(writer); |     pop(writer); | ||||||
| @@ -158,96 +153,14 @@ void Application::saveParameterFile(const std::string parameterFileName) | |||||||
| } | } | ||||||
|  |  | ||||||
| // schedule computation //////////////////////////////////////////////////////// | // schedule computation //////////////////////////////////////////////////////// | ||||||
| #define MEM_MSG(size)\ |  | ||||||
| sizeString((size)*locVol_) << " (" << sizeString(size)  << "/site)" |  | ||||||
|  |  | ||||||
| #define DEFINE_MEMPEAK \ |  | ||||||
| GeneticScheduler<unsigned int>::ObjFunc memPeak = \ |  | ||||||
| [this](const std::vector<unsigned int> &program)\ |  | ||||||
| {\ |  | ||||||
|     unsigned int memPeak;\ |  | ||||||
|     bool         msg;\ |  | ||||||
|     \ |  | ||||||
|     msg = HadronsLogMessage.isActive();\ |  | ||||||
|     HadronsLogMessage.Active(false);\ |  | ||||||
|     env().dryRun(true);\ |  | ||||||
|     memPeak = env().executeProgram(program);\ |  | ||||||
|     env().dryRun(false);\ |  | ||||||
|     env().freeAll();\ |  | ||||||
|     HadronsLogMessage.Active(true);\ |  | ||||||
|     \ |  | ||||||
|     return memPeak;\ |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void Application::schedule(void) | void Application::schedule(void) | ||||||
| { | { | ||||||
|     DEFINE_MEMPEAK; |     if (!scheduled_ and !loadedSchedule_) | ||||||
|      |  | ||||||
|     // build module dependency graph |  | ||||||
|     LOG(Message) << "Building module graph..." << std::endl; |  | ||||||
|     auto graph = env().makeModuleGraph(); |  | ||||||
|     auto con = graph.getConnectedComponents(); |  | ||||||
|      |  | ||||||
|     // constrained topological sort using a genetic algorithm |  | ||||||
|     LOG(Message) << "Scheduling computation..." << std::endl; |  | ||||||
|     LOG(Message) << "               #module= " << graph.size() << std::endl; |  | ||||||
|     LOG(Message) << "       population size= " << par_.genetic.popSize << std::endl; |  | ||||||
|     LOG(Message) << "       max. generation= " << par_.genetic.maxGen << std::endl; |  | ||||||
|     LOG(Message) << "  max. cst. generation= " << par_.genetic.maxCstGen << std::endl; |  | ||||||
|     LOG(Message) << "         mutation rate= " << par_.genetic.mutationRate << std::endl; |  | ||||||
|      |  | ||||||
|     unsigned int                               k = 0, gen, prevPeak, nCstPeak = 0; |  | ||||||
|     std::random_device                         rd; |  | ||||||
|     GeneticScheduler<unsigned int>::Parameters par; |  | ||||||
|      |  | ||||||
|     par.popSize      = par_.genetic.popSize; |  | ||||||
|     par.mutationRate = par_.genetic.mutationRate; |  | ||||||
|     par.seed         = rd(); |  | ||||||
|     memPeak_         = 0; |  | ||||||
|     CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); |  | ||||||
|     for (unsigned int i = 0; i < con.size(); ++i) |  | ||||||
|     { |     { | ||||||
|         GeneticScheduler<unsigned int> scheduler(con[i], memPeak, par); |         program_   = vm().schedule(par_.genetic); | ||||||
|          |  | ||||||
|         gen = 0; |  | ||||||
|         do |  | ||||||
|         { |  | ||||||
|             LOG(Debug) << "Generation " << gen << ":" << std::endl; |  | ||||||
|             scheduler.nextGeneration(); |  | ||||||
|             if (gen != 0) |  | ||||||
|             { |  | ||||||
|                 if (prevPeak == scheduler.getMinValue()) |  | ||||||
|                 { |  | ||||||
|                     nCstPeak++; |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     nCstPeak = 0; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             prevPeak = scheduler.getMinValue(); |  | ||||||
|             if (gen % 10 == 0) |  | ||||||
|             { |  | ||||||
|                 LOG(Iterative) << "Generation " << gen << ": " |  | ||||||
|                                << MEM_MSG(scheduler.getMinValue()) << std::endl; |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             gen++; |  | ||||||
|         } while ((gen < par_.genetic.maxGen) |  | ||||||
|                  and (nCstPeak < par_.genetic.maxCstGen)); |  | ||||||
|         auto &t = scheduler.getMinSchedule(); |  | ||||||
|         if (scheduler.getMinValue() > memPeak_) |  | ||||||
|         { |  | ||||||
|             memPeak_ = scheduler.getMinValue(); |  | ||||||
|         } |  | ||||||
|         for (unsigned int j = 0; j < t.size(); ++j) |  | ||||||
|         { |  | ||||||
|             program_.push_back(t[j]); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|         scheduled_ = true; |         scheduled_ = true; | ||||||
|     } |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| void Application::saveSchedule(const std::string filename) | void Application::saveSchedule(const std::string filename) | ||||||
| { | { | ||||||
| @@ -256,21 +169,19 @@ void Application::saveSchedule(const std::string filename) | |||||||
|      |      | ||||||
|     if (!scheduled_) |     if (!scheduled_) | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("Computation not scheduled"); |         HADRON_ERROR(Definition, "Computation not scheduled"); | ||||||
|     } |     } | ||||||
|     LOG(Message) << "Saving current schedule to '" << filename << "'..." |     LOG(Message) << "Saving current schedule to '" << filename << "'..." | ||||||
|                  << std::endl; |                  << std::endl; | ||||||
|     for (auto address: program_) |     for (auto address: program_) | ||||||
|     { |     { | ||||||
|         program.push_back(env().getModuleName(address)); |         program.push_back(vm().getModuleName(address)); | ||||||
|     } |     } | ||||||
|     write(writer, "schedule", program); |     write(writer, "schedule", program); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Application::loadSchedule(const std::string filename) | void Application::loadSchedule(const std::string filename) | ||||||
| { | { | ||||||
|     DEFINE_MEMPEAK; |  | ||||||
|      |  | ||||||
|     TextReader               reader(filename); |     TextReader               reader(filename); | ||||||
|     std::vector<std::string> program; |     std::vector<std::string> program; | ||||||
|      |      | ||||||
| @@ -280,24 +191,24 @@ void Application::loadSchedule(const std::string filename) | |||||||
|     program_.clear(); |     program_.clear(); | ||||||
|     for (auto &name: program) |     for (auto &name: program) | ||||||
|     { |     { | ||||||
|         program_.push_back(env().getModuleAddress(name)); |         program_.push_back(vm().getModuleAddress(name)); | ||||||
|     } |     } | ||||||
|     scheduled_ = true; |     loadedSchedule_ = true; | ||||||
|     memPeak_   = memPeak(program_); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void Application::printSchedule(void) | void Application::printSchedule(void) | ||||||
| { | { | ||||||
|     if (!scheduled_) |     if (!scheduled_) | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("Computation not scheduled"); |         HADRON_ERROR(Definition, "Computation not scheduled"); | ||||||
|     } |     } | ||||||
|     LOG(Message) << "Schedule (memory peak: " << MEM_MSG(memPeak_) << "):" |     auto peak = vm().memoryNeeded(program_); | ||||||
|  |     LOG(Message) << "Schedule (memory needed: " << sizeString(peak) << "):" | ||||||
|                  << std::endl; |                  << std::endl; | ||||||
|     for (unsigned int i = 0; i < program_.size(); ++i) |     for (unsigned int i = 0; i < program_.size(); ++i) | ||||||
|     { |     { | ||||||
|         LOG(Message) << std::setw(4) << i + 1 << ": " |         LOG(Message) << std::setw(4) << i + 1 << ": " | ||||||
|                      << env().getModuleName(program_[i]) << std::endl; |                      << vm().getModuleName(program_[i]) << std::endl; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -310,8 +221,8 @@ void Application::configLoop(void) | |||||||
|     { |     { | ||||||
|         LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t |         LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t | ||||||
|                      << " " << BIG_SEP << std::endl; |                      << " " << BIG_SEP << std::endl; | ||||||
|         env().setTrajectory(t); |         vm().setTrajectory(t); | ||||||
|         env().executeProgram(program_); |         vm().executeProgram(program_); | ||||||
|     } |     } | ||||||
|     LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; |     LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; | ||||||
|     env().freeAll(); |     env().freeAll(); | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Application.hpp | Source file: extras/Hadrons/Application.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -31,8 +30,7 @@ See the full license in the file "LICENSE" in the top level distribution directo | |||||||
| #define Hadrons_Application_hpp_ | #define Hadrons_Application_hpp_ | ||||||
|  |  | ||||||
| #include <Grid/Hadrons/Global.hpp> | #include <Grid/Hadrons/Global.hpp> | ||||||
| #include <Grid/Hadrons/Environment.hpp> | #include <Grid/Hadrons/VirtualMachine.hpp> | ||||||
| #include <Grid/Hadrons/ModuleFactory.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules.hpp> | #include <Grid/Hadrons/Modules.hpp> | ||||||
|  |  | ||||||
| BEGIN_HADRONS_NAMESPACE | BEGIN_HADRONS_NAMESPACE | ||||||
| @@ -51,24 +49,12 @@ public: | |||||||
|                                         unsigned int, end, |                                         unsigned int, end, | ||||||
|                                         unsigned int, step); |                                         unsigned int, step); | ||||||
|     }; |     }; | ||||||
|     class GeneticPar: Serializable |  | ||||||
|     { |  | ||||||
|     public: |  | ||||||
|         GeneticPar(void): |  | ||||||
|             popSize{20}, maxGen{1000}, maxCstGen{100}, mutationRate{.1} {}; |  | ||||||
|     public: |  | ||||||
|         GRID_SERIALIZABLE_CLASS_MEMBERS(GeneticPar, |  | ||||||
|                                         unsigned int, popSize, |  | ||||||
|                                         unsigned int, maxGen, |  | ||||||
|                                         unsigned int, maxCstGen, |  | ||||||
|                                         double      , mutationRate); |  | ||||||
|     }; |  | ||||||
|     class GlobalPar: Serializable |     class GlobalPar: Serializable | ||||||
|     { |     { | ||||||
|     public: |     public: | ||||||
|         GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, |         GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, | ||||||
|                                         TrajRange,                  trajCounter, |                                         TrajRange,                  trajCounter, | ||||||
|                                         GeneticPar,  genetic, |                                         VirtualMachine::GeneticPar, genetic, | ||||||
|                                         std::string,                seed); |                                         std::string,                seed); | ||||||
|     }; |     }; | ||||||
| public: | public: | ||||||
| @@ -100,14 +86,15 @@ public: | |||||||
|     void configLoop(void); |     void configLoop(void); | ||||||
| private: | private: | ||||||
|     // environment shortcut |     // environment shortcut | ||||||
|     Environment & env(void) const; |     DEFINE_ENV_ALIAS; | ||||||
|  |     // virtual machine shortcut | ||||||
|  |     DEFINE_VM_ALIAS; | ||||||
| private: | private: | ||||||
|     long unsigned int       locVol_; |     long unsigned int       locVol_; | ||||||
|     std::string             parameterFileName_{""}; |     std::string             parameterFileName_{""}; | ||||||
|     GlobalPar               par_; |     GlobalPar               par_; | ||||||
|     std::vector<unsigned int> program_; |     VirtualMachine::Program program_; | ||||||
|     Environment::Size         memPeak_; |     bool                    scheduled_{false}, loadedSchedule_{false}; | ||||||
|     bool                      scheduled_{false}; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
| @@ -117,14 +104,16 @@ private: | |||||||
| template <typename M> | template <typename M> | ||||||
| void Application::createModule(const std::string name) | void Application::createModule(const std::string name) | ||||||
| { | { | ||||||
|     env().createModule<M>(name); |     vm().createModule<M>(name); | ||||||
|  |     scheduled_ = false; | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename M> | template <typename M> | ||||||
| void Application::createModule(const std::string name, | void Application::createModule(const std::string name, | ||||||
|                                const typename M::Par &par) |                                const typename M::Par &par) | ||||||
| { | { | ||||||
|     env().createModule<M>(name, par); |     vm().createModule<M>(name, par); | ||||||
|  |     scheduled_ = false; | ||||||
| } | } | ||||||
|  |  | ||||||
| END_HADRONS_NAMESPACE | END_HADRONS_NAMESPACE | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Environment.cc | Source file: extras/Hadrons/Environment.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -35,6 +34,9 @@ using namespace Grid; | |||||||
| using namespace QCD; | using namespace QCD; | ||||||
| using namespace Hadrons; | using namespace Hadrons; | ||||||
|  |  | ||||||
|  | #define ERROR_NO_ADDRESS(address)\ | ||||||
|  | HADRON_ERROR(Definition, "no object with address " + std::to_string(address)); | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                       Environment implementation                           * |  *                       Environment implementation                           * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| @@ -56,28 +58,6 @@ Environment::Environment(void) | |||||||
|     rng4d_.reset(new GridParallelRNG(grid4d_.get())); |     rng4d_.reset(new GridParallelRNG(grid4d_.get())); | ||||||
| } | } | ||||||
|  |  | ||||||
| // dry run ///////////////////////////////////////////////////////////////////// |  | ||||||
| void Environment::dryRun(const bool isDry) |  | ||||||
| { |  | ||||||
|     dryRun_ = isDry; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::isDryRun(void) const |  | ||||||
| { |  | ||||||
|     return dryRun_; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // trajectory number /////////////////////////////////////////////////////////// |  | ||||||
| void Environment::setTrajectory(const unsigned int traj) |  | ||||||
| { |  | ||||||
|     traj_ = traj; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| unsigned int Environment::getTrajectory(void) const |  | ||||||
| { |  | ||||||
|     return traj_; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // grids /////////////////////////////////////////////////////////////////////// | // grids /////////////////////////////////////////////////////////////////////// | ||||||
| void Environment::createGrid(const unsigned int Ls) | void Environment::createGrid(const unsigned int Ls) | ||||||
| { | { | ||||||
| @@ -105,7 +85,7 @@ GridCartesian * Environment::getGrid(const unsigned int Ls) const | |||||||
|     } |     } | ||||||
|     catch(std::out_of_range &) |     catch(std::out_of_range &) | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no grid with Ls= " << Ls); |         HADRON_ERROR(Definition, "no grid with Ls= " + std::to_string(Ls)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -124,7 +104,7 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const | |||||||
|     } |     } | ||||||
|     catch(std::out_of_range &) |     catch(std::out_of_range &) | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no red-black 5D grid with Ls= " << Ls); |         HADRON_ERROR(Definition, "no red-black 5D grid with Ls= " + std::to_string(Ls)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -143,6 +123,11 @@ int Environment::getDim(const unsigned int mu) const | |||||||
|     return dim_[mu]; |     return dim_[mu]; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | unsigned long int Environment::getLocalVolume(void) const | ||||||
|  | { | ||||||
|  |     return locVol_; | ||||||
|  | } | ||||||
|  |  | ||||||
| // random number generator ///////////////////////////////////////////////////// | // random number generator ///////////////////////////////////////////////////// | ||||||
| void Environment::setSeed(const std::vector<int> &seed) | void Environment::setSeed(const std::vector<int> &seed) | ||||||
| { | { | ||||||
| @@ -154,291 +139,6 @@ GridParallelRNG * Environment::get4dRng(void) const | |||||||
|     return rng4d_.get(); |     return rng4d_.get(); | ||||||
| } | } | ||||||
|  |  | ||||||
| // module management /////////////////////////////////////////////////////////// |  | ||||||
| void Environment::pushModule(Environment::ModPt &pt) |  | ||||||
| { |  | ||||||
|     std::string name = pt->getName(); |  | ||||||
|      |  | ||||||
|     if (!hasModule(name)) |  | ||||||
|     { |  | ||||||
|         std::vector<unsigned int> inputAddress; |  | ||||||
|         unsigned int              address; |  | ||||||
|         ModuleInfo                m; |  | ||||||
|          |  | ||||||
|         m.data = std::move(pt); |  | ||||||
|         m.type = typeIdPt(*m.data.get()); |  | ||||||
|         m.name = name; |  | ||||||
|         auto input  = m.data->getInput(); |  | ||||||
|         for (auto &in: input) |  | ||||||
|         { |  | ||||||
|             if (!hasObject(in)) |  | ||||||
|             { |  | ||||||
|                 addObject(in , -1); |  | ||||||
|             } |  | ||||||
|             m.input.push_back(objectAddress_[in]); |  | ||||||
|         } |  | ||||||
|         auto output = m.data->getOutput(); |  | ||||||
|         module_.push_back(std::move(m)); |  | ||||||
|         address              = static_cast<unsigned int>(module_.size() - 1); |  | ||||||
|         moduleAddress_[name] = address; |  | ||||||
|         for (auto &out: output) |  | ||||||
|         { |  | ||||||
|             if (!hasObject(out)) |  | ||||||
|             { |  | ||||||
|                 addObject(out, address); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 if (object_[objectAddress_[out]].module < 0) |  | ||||||
|                 { |  | ||||||
|                     object_[objectAddress_[out]].module = address; |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     HADRON_ERROR("object '" + out |  | ||||||
|                                  + "' is already produced by module '" |  | ||||||
|                                  + module_[object_[getObjectAddress(out)].module].name |  | ||||||
|                                  + "' (while pushing module '" + name + "')"); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("module '" + name + "' already exists"); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| unsigned int Environment::getNModule(void) const |  | ||||||
| { |  | ||||||
|     return module_.size(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void Environment::createModule(const std::string name, const std::string type, |  | ||||||
|                                XmlReader &reader) |  | ||||||
| { |  | ||||||
|     auto &factory = ModuleFactory::getInstance(); |  | ||||||
|     auto pt       = factory.create(type, name); |  | ||||||
|      |  | ||||||
|     pt->parseParameters(reader, "options"); |  | ||||||
|     pushModule(pt); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| ModuleBase * Environment::getModule(const unsigned int address) const |  | ||||||
| { |  | ||||||
|     if (hasModule(address)) |  | ||||||
|     { |  | ||||||
|         return module_[address].data.get(); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("no module with address " + std::to_string(address)); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| ModuleBase * Environment::getModule(const std::string name) const |  | ||||||
| { |  | ||||||
|     return getModule(getModuleAddress(name)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| unsigned int Environment::getModuleAddress(const std::string name) const |  | ||||||
| { |  | ||||||
|     if (hasModule(name)) |  | ||||||
|     { |  | ||||||
|         return moduleAddress_.at(name); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("no module with name '" + name + "'"); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| std::string Environment::getModuleName(const unsigned int address) const |  | ||||||
| { |  | ||||||
|     if (hasModule(address)) |  | ||||||
|     { |  | ||||||
|         return module_[address].name; |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("no module with address " + std::to_string(address)); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| std::string Environment::getModuleType(const unsigned int address) const |  | ||||||
| { |  | ||||||
|     if (hasModule(address)) |  | ||||||
|     { |  | ||||||
|         return typeName(module_[address].type); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("no module with address " + std::to_string(address)); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| std::string Environment::getModuleType(const std::string name) const |  | ||||||
| { |  | ||||||
|     return getModuleType(getModuleAddress(name)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| std::string Environment::getModuleNamespace(const unsigned int address) const |  | ||||||
| { |  | ||||||
|     std::string type = getModuleType(address), ns; |  | ||||||
|      |  | ||||||
|     auto pos2 = type.rfind("::"); |  | ||||||
|     auto pos1 = type.rfind("::", pos2 - 2); |  | ||||||
|      |  | ||||||
|     return type.substr(pos1 + 2, pos2 - pos1 - 2); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| std::string Environment::getModuleNamespace(const std::string name) const |  | ||||||
| { |  | ||||||
|     return getModuleNamespace(getModuleAddress(name)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::hasModule(const unsigned int address) const |  | ||||||
| { |  | ||||||
|     return (address < module_.size()); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::hasModule(const std::string name) const |  | ||||||
| { |  | ||||||
|     return (moduleAddress_.find(name) != moduleAddress_.end()); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| Graph<unsigned int> Environment::makeModuleGraph(void) const |  | ||||||
| { |  | ||||||
|     Graph<unsigned int> moduleGraph; |  | ||||||
|      |  | ||||||
|     for (unsigned int i = 0; i < module_.size(); ++i) |  | ||||||
|     { |  | ||||||
|         moduleGraph.addVertex(i); |  | ||||||
|         for (auto &j: module_[i].input) |  | ||||||
|         { |  | ||||||
|             moduleGraph.addEdge(object_[j].module, i); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     return moduleGraph; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #define BIG_SEP "===============" |  | ||||||
| #define SEP     "---------------" |  | ||||||
| #define MEM_MSG(size)\ |  | ||||||
| sizeString((size)*locVol_) << " (" << sizeString(size)  << "/site)" |  | ||||||
|  |  | ||||||
| Environment::Size |  | ||||||
| Environment::executeProgram(const std::vector<unsigned int> &p) |  | ||||||
| { |  | ||||||
|     Size                                memPeak = 0, sizeBefore, sizeAfter; |  | ||||||
|     std::vector<std::set<unsigned int>> freeProg; |  | ||||||
|     bool                                continueCollect, nothingFreed; |  | ||||||
|      |  | ||||||
|     // build garbage collection schedule |  | ||||||
|     freeProg.resize(p.size()); |  | ||||||
|     for (unsigned int i = 0; i < object_.size(); ++i) |  | ||||||
|     { |  | ||||||
|         auto pred = [i, this](const unsigned int j) |  | ||||||
|         { |  | ||||||
|             auto &in = module_[j].input; |  | ||||||
|             auto it  = std::find(in.begin(), in.end(), i); |  | ||||||
|              |  | ||||||
|             return (it != in.end()) or (j == object_[i].module); |  | ||||||
|         }; |  | ||||||
|         auto it = std::find_if(p.rbegin(), p.rend(), pred); |  | ||||||
|         if (it != p.rend()) |  | ||||||
|         { |  | ||||||
|             freeProg[p.rend() - it - 1].insert(i); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     // program execution |  | ||||||
|     for (unsigned int i = 0; i < p.size(); ++i) |  | ||||||
|     { |  | ||||||
|         // execute module |  | ||||||
|         if (!isDryRun()) |  | ||||||
|         { |  | ||||||
|             LOG(Message) << SEP << " Measurement step " << i+1 << "/" |  | ||||||
|                          << p.size() << " (module '" << module_[p[i]].name |  | ||||||
|                          << "') " << SEP << std::endl; |  | ||||||
|         } |  | ||||||
|         (*module_[p[i]].data)(); |  | ||||||
|         sizeBefore = getTotalSize(); |  | ||||||
|         // print used memory after execution |  | ||||||
|         if (!isDryRun()) |  | ||||||
|         { |  | ||||||
|             LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) |  | ||||||
|                          << std::endl; |  | ||||||
|         } |  | ||||||
|         if (sizeBefore > memPeak) |  | ||||||
|         { |  | ||||||
|             memPeak = sizeBefore; |  | ||||||
|         } |  | ||||||
|         // garbage collection for step i |  | ||||||
|         if (!isDryRun()) |  | ||||||
|         { |  | ||||||
|             LOG(Message) << "Garbage collection..." << std::endl; |  | ||||||
|         } |  | ||||||
|         nothingFreed = true; |  | ||||||
|         do |  | ||||||
|         { |  | ||||||
|             continueCollect = false; |  | ||||||
|             auto toFree = freeProg[i]; |  | ||||||
|             for (auto &j: toFree) |  | ||||||
|             { |  | ||||||
|                 // continue garbage collection while there are still |  | ||||||
|                 // objects without owners |  | ||||||
|                 continueCollect = continueCollect or !hasOwners(j); |  | ||||||
|                 if(freeObject(j)) |  | ||||||
|                 { |  | ||||||
|                     // if an object has been freed, remove it from |  | ||||||
|                     // the garbage collection schedule |  | ||||||
|                     freeProg[i].erase(j); |  | ||||||
|                     nothingFreed = false; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } while (continueCollect); |  | ||||||
|         // any remaining objects in step i garbage collection schedule |  | ||||||
|         // is scheduled for step i + 1 |  | ||||||
|         if (i + 1 < p.size()) |  | ||||||
|         { |  | ||||||
|             for (auto &j: freeProg[i]) |  | ||||||
|             { |  | ||||||
|                 freeProg[i + 1].insert(j); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         // print used memory after garbage collection if necessary |  | ||||||
|         if (!isDryRun()) |  | ||||||
|         { |  | ||||||
|             sizeAfter = getTotalSize(); |  | ||||||
|             if (sizeBefore != sizeAfter) |  | ||||||
|             { |  | ||||||
|                 LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) |  | ||||||
|                              << std::endl; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 LOG(Message) << "Nothing to free" << std::endl; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     return memPeak; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| Environment::Size Environment::executeProgram(const std::vector<std::string> &p) |  | ||||||
| { |  | ||||||
|     std::vector<unsigned int> pAddress; |  | ||||||
|      |  | ||||||
|     for (auto &n: p) |  | ||||||
|     { |  | ||||||
|         pAddress.push_back(getModuleAddress(n)); |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     return executeProgram(pAddress); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // general memory management /////////////////////////////////////////////////// | // general memory management /////////////////////////////////////////////////// | ||||||
| void Environment::addObject(const std::string name, const int moduleAddress) | void Environment::addObject(const std::string name, const int moduleAddress) | ||||||
| { | { | ||||||
| @@ -448,46 +148,25 @@ void Environment::addObject(const std::string name, const int moduleAddress) | |||||||
|          |          | ||||||
|         info.name   = name; |         info.name   = name; | ||||||
|         info.module = moduleAddress; |         info.module = moduleAddress; | ||||||
|  |         info.data   = nullptr; | ||||||
|         object_.push_back(std::move(info)); |         object_.push_back(std::move(info)); | ||||||
|         objectAddress_[name] = static_cast<unsigned int>(object_.size() - 1); |         objectAddress_[name] = static_cast<unsigned int>(object_.size() - 1); | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("object '" + name + "' already exists"); |         HADRON_ERROR(Definition, "object '" + name + "' already exists"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| void Environment::registerObject(const unsigned int address, | void Environment::setObjectModule(const unsigned int objAddress, | ||||||
|                                  const unsigned int size, const unsigned int Ls) |                                   const int modAddress) | ||||||
| { | { | ||||||
|     if (!hasRegisteredObject(address)) |     object_[objAddress].module = modAddress; | ||||||
|     { |  | ||||||
|         if (hasObject(address)) |  | ||||||
|         { |  | ||||||
|             object_[address].size         = size; |  | ||||||
|             object_[address].Ls           = Ls; |  | ||||||
|             object_[address].isRegistered = true; |  | ||||||
|         } |  | ||||||
|         else |  | ||||||
|         { |  | ||||||
|             HADRON_ERROR("no object with address " + std::to_string(address)); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("object with address " + std::to_string(address) |  | ||||||
|                      + " already registered"); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void Environment::registerObject(const std::string name, | unsigned int Environment::getMaxAddress(void) const | ||||||
|                                  const unsigned int size, const unsigned int Ls) |  | ||||||
| { | { | ||||||
|     if (!hasObject(name)) |     return object_.size(); | ||||||
|     { |  | ||||||
|         addObject(name); |  | ||||||
|     } |  | ||||||
|     registerObject(getObjectAddress(name), size, Ls); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| unsigned int Environment::getObjectAddress(const std::string name) const | unsigned int Environment::getObjectAddress(const std::string name) const | ||||||
| @@ -498,7 +177,7 @@ unsigned int Environment::getObjectAddress(const std::string name) const | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with name '" + name + "'"); |         HADRON_ERROR(Definition, "no object with name '" + name + "'"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -510,13 +189,13 @@ std::string Environment::getObjectName(const unsigned int address) const | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         ERROR_NO_ADDRESS(address); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| std::string Environment::getObjectType(const unsigned int address) const | std::string Environment::getObjectType(const unsigned int address) const | ||||||
| { | { | ||||||
|     if (hasRegisteredObject(address)) |     if (hasObject(address)) | ||||||
|     { |     { | ||||||
|         if (object_[address].type) |         if (object_[address].type) | ||||||
|         { |         { | ||||||
| @@ -527,14 +206,9 @@ std::string Environment::getObjectType(const unsigned int address) const | |||||||
|             return "<no type>"; |             return "<no type>"; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     else if (hasObject(address)) |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("object with address " + std::to_string(address) |  | ||||||
|                      + " exists but is not registered"); |  | ||||||
|     } |  | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         ERROR_NO_ADDRESS(address); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -545,18 +219,13 @@ std::string Environment::getObjectType(const std::string name) const | |||||||
|  |  | ||||||
| Environment::Size Environment::getObjectSize(const unsigned int address) const | Environment::Size Environment::getObjectSize(const unsigned int address) const | ||||||
| { | { | ||||||
|     if (hasRegisteredObject(address)) |     if (hasObject(address)) | ||||||
|     { |     { | ||||||
|         return object_[address].size; |         return object_[address].size; | ||||||
|     } |     } | ||||||
|     else if (hasObject(address)) |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("object with address " + std::to_string(address) |  | ||||||
|                      + " exists but is not registered"); |  | ||||||
|     } |  | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         ERROR_NO_ADDRESS(address); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -565,7 +234,24 @@ Environment::Size Environment::getObjectSize(const std::string name) const | |||||||
|     return getObjectSize(getObjectAddress(name)); |     return getObjectSize(getObjectAddress(name)); | ||||||
| } | } | ||||||
|  |  | ||||||
| unsigned int Environment::getObjectModule(const unsigned int address) const | Environment::Storage Environment::getObjectStorage(const unsigned int address) const | ||||||
|  | { | ||||||
|  |     if (hasObject(address)) | ||||||
|  |     { | ||||||
|  |         return object_[address].storage; | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         ERROR_NO_ADDRESS(address); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Environment::Storage Environment::getObjectStorage(const std::string name) const | ||||||
|  | { | ||||||
|  |     return getObjectStorage(getObjectAddress(name)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int Environment::getObjectModule(const unsigned int address) const | ||||||
| { | { | ||||||
|     if (hasObject(address)) |     if (hasObject(address)) | ||||||
|     { |     { | ||||||
| @@ -573,29 +259,24 @@ unsigned int Environment::getObjectModule(const unsigned int address) const | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         ERROR_NO_ADDRESS(address); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| unsigned int Environment::getObjectModule(const std::string name) const | int Environment::getObjectModule(const std::string name) const | ||||||
| { | { | ||||||
|     return getObjectModule(getObjectAddress(name)); |     return getObjectModule(getObjectAddress(name)); | ||||||
| } | } | ||||||
|  |  | ||||||
| unsigned int Environment::getObjectLs(const unsigned int address) const | unsigned int Environment::getObjectLs(const unsigned int address) const | ||||||
| { | { | ||||||
|     if (hasRegisteredObject(address)) |     if (hasObject(address)) | ||||||
|     { |     { | ||||||
|         return object_[address].Ls; |         return object_[address].Ls; | ||||||
|     } |     } | ||||||
|     else if (hasObject(address)) |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("object with address " + std::to_string(address) |  | ||||||
|                      + " exists but is not registered"); |  | ||||||
|     } |  | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         ERROR_NO_ADDRESS(address); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -616,30 +297,6 @@ bool Environment::hasObject(const std::string name) const | |||||||
|     return ((it != objectAddress_.end()) and hasObject(it->second)); |     return ((it != objectAddress_.end()) and hasObject(it->second)); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Environment::hasRegisteredObject(const unsigned int address) const |  | ||||||
| { |  | ||||||
|     if (hasObject(address)) |  | ||||||
|     { |  | ||||||
|         return object_[address].isRegistered; |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::hasRegisteredObject(const std::string name) const |  | ||||||
| { |  | ||||||
|     if (hasObject(name)) |  | ||||||
|     { |  | ||||||
|         return hasRegisteredObject(getObjectAddress(name)); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::hasCreatedObject(const unsigned int address) const | bool Environment::hasCreatedObject(const unsigned int address) const | ||||||
| { | { | ||||||
|     if (hasObject(address)) |     if (hasObject(address)) | ||||||
| @@ -679,93 +336,28 @@ Environment::Size Environment::getTotalSize(void) const | |||||||
|     Environment::Size size = 0; |     Environment::Size size = 0; | ||||||
|      |      | ||||||
|     for (auto &o: object_) |     for (auto &o: object_) | ||||||
|     { |  | ||||||
|         if (o.isRegistered) |  | ||||||
|     { |     { | ||||||
|         size += o.size; |         size += o.size; | ||||||
|     } |     } | ||||||
|     } |  | ||||||
|      |      | ||||||
|     return size; |     return size; | ||||||
| } | } | ||||||
|  |  | ||||||
| void Environment::addOwnership(const unsigned int owner, | void Environment::freeObject(const unsigned int address) | ||||||
|                                const unsigned int property) |  | ||||||
| { | { | ||||||
|     if (hasObject(property)) |     if (hasCreatedObject(address)) | ||||||
|     { |  | ||||||
|         object_[property].owners.insert(owner); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(property)); |  | ||||||
|     } |  | ||||||
|     if (hasObject(owner)) |  | ||||||
|     { |  | ||||||
|         object_[owner].properties.insert(property); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(owner)); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void Environment::addOwnership(const std::string owner, |  | ||||||
|                                const std::string property) |  | ||||||
| { |  | ||||||
|     addOwnership(getObjectAddress(owner), getObjectAddress(property)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::hasOwners(const unsigned int address) const |  | ||||||
| { |  | ||||||
|      |  | ||||||
|     if (hasObject(address)) |  | ||||||
|     { |  | ||||||
|         return (!object_[address].owners.empty()); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::hasOwners(const std::string name) const |  | ||||||
| { |  | ||||||
|     return hasOwners(getObjectAddress(name)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Environment::freeObject(const unsigned int address) |  | ||||||
| { |  | ||||||
|     if (!hasOwners(address)) |  | ||||||
|     { |  | ||||||
|         if (!isDryRun() and object_[address].isRegistered) |  | ||||||
|     { |     { | ||||||
|         LOG(Message) << "Destroying object '" << object_[address].name |         LOG(Message) << "Destroying object '" << object_[address].name | ||||||
|                      << "'" << std::endl; |                      << "'" << std::endl; | ||||||
|     } |     } | ||||||
|         for (auto &p: object_[address].properties) |  | ||||||
|         { |  | ||||||
|             object_[p].owners.erase(address); |  | ||||||
|         } |  | ||||||
|     object_[address].size = 0; |     object_[address].size = 0; | ||||||
|         object_[address].Ls           = 0; |  | ||||||
|         object_[address].isRegistered = false; |  | ||||||
|     object_[address].type = nullptr; |     object_[address].type = nullptr; | ||||||
|         object_[address].owners.clear(); |  | ||||||
|         object_[address].properties.clear(); |  | ||||||
|     object_[address].data.reset(nullptr); |     object_[address].data.reset(nullptr); | ||||||
|          |  | ||||||
|         return true; |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Environment::freeObject(const std::string name) | void Environment::freeObject(const std::string name) | ||||||
| { | { | ||||||
|     return freeObject(getObjectAddress(name)); |     freeObject(getObjectAddress(name)); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Environment::freeAll(void) | void Environment::freeAll(void) | ||||||
| @@ -776,18 +368,24 @@ void Environment::freeAll(void) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| void Environment::printContent(void) | void Environment::protectObjects(const bool protect) | ||||||
| { | { | ||||||
|     LOG(Message) << "Modules: " << std::endl; |     protect_ = protect; | ||||||
|     for (unsigned int i = 0; i < module_.size(); ++i) |  | ||||||
|     { |  | ||||||
|         LOG(Message) << std::setw(4) << i << ": " |  | ||||||
|                      << getModuleName(i) << std::endl; |  | ||||||
| } | } | ||||||
|     LOG(Message) << "Objects: " << std::endl; |  | ||||||
|  | bool Environment::objectsProtected(void) const | ||||||
|  | { | ||||||
|  |     return protect_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // print environment content /////////////////////////////////////////////////// | ||||||
|  | void Environment::printContent(void) const | ||||||
|  | { | ||||||
|  |     LOG(Debug) << "Objects: " << std::endl; | ||||||
|     for (unsigned int i = 0; i < object_.size(); ++i) |     for (unsigned int i = 0; i < object_.size(); ++i) | ||||||
|     { |     { | ||||||
|         LOG(Message) << std::setw(4) << i << ": " |         LOG(Debug) << std::setw(4) << i << ": " | ||||||
|                      << getObjectName(i) << std::endl; |                    << getObjectName(i) << " (" | ||||||
|  |                    << sizeString(getObjectSize(i)) << ")" << std::endl; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Environment.hpp | Source file: extras/Hadrons/Environment.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -31,20 +30,12 @@ See the full license in the file "LICENSE" in the top level distribution directo | |||||||
| #define Hadrons_Environment_hpp_ | #define Hadrons_Environment_hpp_ | ||||||
|  |  | ||||||
| #include <Grid/Hadrons/Global.hpp> | #include <Grid/Hadrons/Global.hpp> | ||||||
| #include <Grid/Hadrons/Graph.hpp> |  | ||||||
|  |  | ||||||
| #ifndef SITE_SIZE_TYPE |  | ||||||
| #define SITE_SIZE_TYPE unsigned int |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| BEGIN_HADRONS_NAMESPACE | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                         Global environment                                 * |  *                         Global environment                                 * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| // forward declaration of Module |  | ||||||
| class ModuleBase; |  | ||||||
|  |  | ||||||
| class Object | class Object | ||||||
| { | { | ||||||
| public: | public: | ||||||
| @@ -66,123 +57,78 @@ private: | |||||||
|     std::unique_ptr<T> objPt_{nullptr}; |     std::unique_ptr<T> objPt_{nullptr}; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | #define DEFINE_ENV_ALIAS \ | ||||||
|  | inline Environment & env(void) const\ | ||||||
|  | {\ | ||||||
|  |     return Environment::getInstance();\ | ||||||
|  | } | ||||||
|  |  | ||||||
| class Environment | class Environment | ||||||
| { | { | ||||||
|     SINGLETON(Environment); |     SINGLETON(Environment); | ||||||
| public: | public: | ||||||
|     typedef SITE_SIZE_TYPE                         Size; |     typedef SITE_SIZE_TYPE                         Size; | ||||||
|     typedef std::unique_ptr<ModuleBase>            ModPt; |  | ||||||
|     typedef std::unique_ptr<GridCartesian>         GridPt; |     typedef std::unique_ptr<GridCartesian>         GridPt; | ||||||
|     typedef std::unique_ptr<GridRedBlackCartesian> GridRbPt; |     typedef std::unique_ptr<GridRedBlackCartesian> GridRbPt; | ||||||
|     typedef std::unique_ptr<GridParallelRNG>       RngPt; |     typedef std::unique_ptr<GridParallelRNG>       RngPt; | ||||||
|     typedef std::unique_ptr<LatticeBase>           LatticePt; |     enum class Storage {object, cache, temporary}; | ||||||
| private: | private: | ||||||
|     struct ModuleInfo |  | ||||||
|     { |  | ||||||
|         const std::type_info      *type{nullptr}; |  | ||||||
|         std::string               name; |  | ||||||
|         ModPt                     data{nullptr}; |  | ||||||
|         std::vector<unsigned int> input; |  | ||||||
|     }; |  | ||||||
|     struct ObjInfo |     struct ObjInfo | ||||||
|     { |     { | ||||||
|         Size                    size{0}; |         Size                    size{0}; | ||||||
|  |         Storage                 storage{Storage::object}; | ||||||
|         unsigned int            Ls{0}; |         unsigned int            Ls{0}; | ||||||
|         bool                    isRegistered{false}; |  | ||||||
|         const std::type_info    *type{nullptr}; |         const std::type_info    *type{nullptr}; | ||||||
|         std::string             name; |         std::string             name; | ||||||
|         int                     module{-1}; |         int                     module{-1}; | ||||||
|         std::set<unsigned int>  owners, properties; |  | ||||||
|         std::unique_ptr<Object> data{nullptr}; |         std::unique_ptr<Object> data{nullptr}; | ||||||
|     }; |     }; | ||||||
| public: | public: | ||||||
|     // dry run |  | ||||||
|     void                    dryRun(const bool isDry); |  | ||||||
|     bool                    isDryRun(void) const; |  | ||||||
|     // trajectory number |  | ||||||
|     void                    setTrajectory(const unsigned int traj); |  | ||||||
|     unsigned int            getTrajectory(void) const; |  | ||||||
|     // grids |     // grids | ||||||
|     void                    createGrid(const unsigned int Ls); |     void                    createGrid(const unsigned int Ls); | ||||||
|     GridCartesian *         getGrid(const unsigned int Ls = 1) const; |     GridCartesian *         getGrid(const unsigned int Ls = 1) const; | ||||||
|     GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; |     GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; | ||||||
|     std::vector<int>        getDim(void) const; |     std::vector<int>        getDim(void) const; | ||||||
|     int                     getDim(const unsigned int mu) const; |     int                     getDim(const unsigned int mu) const; | ||||||
|  |     unsigned long int       getLocalVolume(void) const; | ||||||
|     unsigned int            getNd(void) const; |     unsigned int            getNd(void) const; | ||||||
|     // random number generator |     // random number generator | ||||||
|     void                    setSeed(const std::vector<int> &seed); |     void                    setSeed(const std::vector<int> &seed); | ||||||
|     GridParallelRNG *       get4dRng(void) const; |     GridParallelRNG *       get4dRng(void) const; | ||||||
|     // module management |  | ||||||
|     void                    pushModule(ModPt &pt); |  | ||||||
|     template <typename M> |  | ||||||
|     void                    createModule(const std::string name); |  | ||||||
|     template <typename M> |  | ||||||
|     void                    createModule(const std::string name, |  | ||||||
|                                          const typename M::Par &par); |  | ||||||
|     void                    createModule(const std::string name, |  | ||||||
|                                          const std::string type, |  | ||||||
|                                          XmlReader &reader); |  | ||||||
|     unsigned int            getNModule(void) const; |  | ||||||
|     ModuleBase *            getModule(const unsigned int address) const; |  | ||||||
|     ModuleBase *            getModule(const std::string name) const; |  | ||||||
|     template <typename M> |  | ||||||
|     M *                     getModule(const unsigned int address) const; |  | ||||||
|     template <typename M> |  | ||||||
|     M *                     getModule(const std::string name) const; |  | ||||||
|     unsigned int            getModuleAddress(const std::string name) const; |  | ||||||
|     std::string             getModuleName(const unsigned int address) const; |  | ||||||
|     std::string             getModuleType(const unsigned int address) const; |  | ||||||
|     std::string             getModuleType(const std::string name) const; |  | ||||||
|     std::string             getModuleNamespace(const unsigned int address) const; |  | ||||||
|     std::string             getModuleNamespace(const std::string name) const; |  | ||||||
|     bool                    hasModule(const unsigned int address) const; |  | ||||||
|     bool                    hasModule(const std::string name) const; |  | ||||||
|     Graph<unsigned int>     makeModuleGraph(void) const; |  | ||||||
|     Size                    executeProgram(const std::vector<unsigned int> &p); |  | ||||||
|     Size                    executeProgram(const std::vector<std::string> &p); |  | ||||||
|     // general memory management |     // general memory management | ||||||
|     void                    addObject(const std::string name, |     void                    addObject(const std::string name, | ||||||
|                                       const int moduleAddress = -1); |                                       const int moduleAddress = -1); | ||||||
|     void                    registerObject(const unsigned int address, |     template <typename B, typename T, typename ... Ts> | ||||||
|                                            const unsigned int size, |     void                    createDerivedObject(const std::string name, | ||||||
|                                            const unsigned int Ls = 1); |                                                 const Environment::Storage storage, | ||||||
|     void                    registerObject(const std::string name, |                                                 const unsigned int Ls, | ||||||
|                                            const unsigned int size, |                                                 Ts && ... args); | ||||||
|                                            const unsigned int Ls = 1); |     template <typename T, typename ... Ts> | ||||||
|     template <typename T> |     void                    createObject(const std::string name, | ||||||
|     unsigned int            lattice4dSize(void) const; |                                          const Environment::Storage storage, | ||||||
|     template <typename T> |                                          const unsigned int Ls, | ||||||
|     void                    registerLattice(const unsigned int address, |                                          Ts && ... args); | ||||||
|                                             const unsigned int Ls = 1); |     void                    setObjectModule(const unsigned int objAddress, | ||||||
|     template <typename T> |                                             const int modAddress); | ||||||
|     void                    registerLattice(const std::string name, |  | ||||||
|                                             const unsigned int Ls = 1); |  | ||||||
|     template <typename T> |  | ||||||
|     void                    setObject(const unsigned int address, T *object); |  | ||||||
|     template <typename T> |  | ||||||
|     void                    setObject(const std::string name, T *object); |  | ||||||
|     template <typename T> |     template <typename T> | ||||||
|     T *                     getObject(const unsigned int address) const; |     T *                     getObject(const unsigned int address) const; | ||||||
|     template <typename T> |     template <typename T> | ||||||
|     T *                     getObject(const std::string name) const; |     T *                     getObject(const std::string name) const; | ||||||
|     template <typename T> |     unsigned int            getMaxAddress(void) const; | ||||||
|     T *                     createLattice(const unsigned int address); |  | ||||||
|     template <typename T> |  | ||||||
|     T *                     createLattice(const std::string name); |  | ||||||
|     unsigned int            getObjectAddress(const std::string name) const; |     unsigned int            getObjectAddress(const std::string name) const; | ||||||
|     std::string             getObjectName(const unsigned int address) const; |     std::string             getObjectName(const unsigned int address) const; | ||||||
|     std::string             getObjectType(const unsigned int address) const; |     std::string             getObjectType(const unsigned int address) const; | ||||||
|     std::string             getObjectType(const std::string name) const; |     std::string             getObjectType(const std::string name) const; | ||||||
|     Size                    getObjectSize(const unsigned int address) const; |     Size                    getObjectSize(const unsigned int address) const; | ||||||
|     Size                    getObjectSize(const std::string name) const; |     Size                    getObjectSize(const std::string name) const; | ||||||
|     unsigned int            getObjectModule(const unsigned int address) const; |     Storage                 getObjectStorage(const unsigned int address) const; | ||||||
|     unsigned int            getObjectModule(const std::string name) const; |     Storage                 getObjectStorage(const std::string name) const; | ||||||
|  |     int                     getObjectModule(const unsigned int address) const; | ||||||
|  |     int                     getObjectModule(const std::string name) const; | ||||||
|     unsigned int            getObjectLs(const unsigned int address) const; |     unsigned int            getObjectLs(const unsigned int address) const; | ||||||
|     unsigned int            getObjectLs(const std::string name) const; |     unsigned int            getObjectLs(const std::string name) const; | ||||||
|     bool                    hasObject(const unsigned int address) const; |     bool                    hasObject(const unsigned int address) const; | ||||||
|     bool                    hasObject(const std::string name) const; |     bool                    hasObject(const std::string name) const; | ||||||
|     bool                    hasRegisteredObject(const unsigned int address) const; |  | ||||||
|     bool                    hasRegisteredObject(const std::string name) const; |  | ||||||
|     bool                    hasCreatedObject(const unsigned int address) const; |     bool                    hasCreatedObject(const unsigned int address) const; | ||||||
|     bool                    hasCreatedObject(const std::string name) const; |     bool                    hasCreatedObject(const std::string name) const; | ||||||
|     bool                    isObject5d(const unsigned int address) const; |     bool                    isObject5d(const unsigned int address) const; | ||||||
| @@ -192,20 +138,17 @@ public: | |||||||
|     template <typename T> |     template <typename T> | ||||||
|     bool                    isObjectOfType(const std::string name) const; |     bool                    isObjectOfType(const std::string name) const; | ||||||
|     Environment::Size       getTotalSize(void) const; |     Environment::Size       getTotalSize(void) const; | ||||||
|     void                    addOwnership(const unsigned int owner, |     void                    freeObject(const unsigned int address); | ||||||
|                                          const unsigned int property); |     void                    freeObject(const std::string name); | ||||||
|     void                    addOwnership(const std::string owner, |  | ||||||
|                                          const std::string property); |  | ||||||
|     bool                    hasOwners(const unsigned int address) const; |  | ||||||
|     bool                    hasOwners(const std::string name) const; |  | ||||||
|     bool                    freeObject(const unsigned int address); |  | ||||||
|     bool                    freeObject(const std::string name); |  | ||||||
|     void                    freeAll(void); |     void                    freeAll(void); | ||||||
|     void                    printContent(void); |     void                    protectObjects(const bool protect); | ||||||
|  |     bool                    objectsProtected(void) const; | ||||||
|  |     // print environment content | ||||||
|  |     void                    printContent(void) const; | ||||||
| private: | private: | ||||||
|     // general |     // general | ||||||
|     bool                                   dryRun_{false}; |     unsigned long int                      locVol_; | ||||||
|     unsigned int                           traj_, locVol_; |     bool                                   protect_{true}; | ||||||
|     // grids |     // grids | ||||||
|     std::vector<int>                       dim_; |     std::vector<int>                       dim_; | ||||||
|     GridPt                                 grid4d_; |     GridPt                                 grid4d_; | ||||||
| @@ -215,11 +158,6 @@ private: | |||||||
|     unsigned int                           nd_; |     unsigned int                           nd_; | ||||||
|     // random number generator |     // random number generator | ||||||
|     RngPt                                  rng4d_; |     RngPt                                  rng4d_; | ||||||
|     // module and related maps |  | ||||||
|     std::vector<ModuleInfo>                module_; |  | ||||||
|     std::map<std::string, unsigned int>    moduleAddress_; |  | ||||||
|     // lattice store |  | ||||||
|     std::map<unsigned int, LatticePt>      lattice_; |  | ||||||
|     // object store |     // object store | ||||||
|     std::vector<ObjInfo>                   object_; |     std::vector<ObjInfo>                   object_; | ||||||
|     std::map<std::string, unsigned int>    objectAddress_; |     std::map<std::string, unsigned int>    objectAddress_; | ||||||
| @@ -256,96 +194,64 @@ void Holder<T>::reset(T *pt) | |||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                     Environment template implementation                    * |  *                     Environment template implementation                    * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| // module management /////////////////////////////////////////////////////////// | // general memory management /////////////////////////////////////////////////// | ||||||
| template <typename M> | template <typename B, typename T, typename ... Ts> | ||||||
| void Environment::createModule(const std::string name) | void Environment::createDerivedObject(const std::string name, | ||||||
|  |                                       const Environment::Storage storage, | ||||||
|  |                                       const unsigned int Ls, | ||||||
|  |                                       Ts && ... args) | ||||||
| { | { | ||||||
|     ModPt pt(new M(name)); |     if (!hasObject(name)) | ||||||
|      |     { | ||||||
|     pushModule(pt); |         addObject(name); | ||||||
|     } |     } | ||||||
|      |      | ||||||
| template <typename M> |     unsigned int address = getObjectAddress(name); | ||||||
| void Environment::createModule(const std::string name, |  | ||||||
|                                const typename M::Par &par) |  | ||||||
| { |  | ||||||
|     ModPt pt(new M(name)); |  | ||||||
|      |      | ||||||
|     static_cast<M *>(pt.get())->setPar(par); |     if (!object_[address].data or !objectsProtected()) | ||||||
|     pushModule(pt); |     { | ||||||
| } |         MemoryStats memStats; | ||||||
|      |      | ||||||
| template <typename M> |         if (!MemoryProfiler::stats) | ||||||
| M * Environment::getModule(const unsigned int address) const |  | ||||||
|         { |         { | ||||||
|     if (auto *pt = dynamic_cast<M *>(getModule(address))) |             MemoryProfiler::stats = &memStats; | ||||||
|     { |  | ||||||
|         return pt; |  | ||||||
|         } |         } | ||||||
|     else |         size_t initMem           = MemoryProfiler::stats->currentlyAllocated; | ||||||
|     { |         object_[address].storage = storage; | ||||||
|         HADRON_ERROR("module '" + module_[address].name |         object_[address].Ls      = Ls; | ||||||
|                      + "' does not have type " + typeid(M).name() |         object_[address].data.reset(new Holder<B>(new T(std::forward<Ts>(args)...))); | ||||||
|                      + "(object type: " + getModuleType(address) + ")"); |         object_[address].size    = MemoryProfiler::stats->maxAllocated - initMem; | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename M> |  | ||||||
| M * Environment::getModule(const std::string name) const |  | ||||||
| { |  | ||||||
|     return getModule<M>(getModuleAddress(name)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| unsigned int Environment::lattice4dSize(void) const |  | ||||||
| { |  | ||||||
|     return sizeof(typename T::vector_object)/getGrid()->Nsimd(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| void Environment::registerLattice(const unsigned int address, |  | ||||||
|                                   const unsigned int Ls) |  | ||||||
| { |  | ||||||
|     createGrid(Ls); |  | ||||||
|     registerObject(address, Ls*lattice4dSize<T>(), Ls); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| void Environment::registerLattice(const std::string name, const unsigned int Ls) |  | ||||||
| { |  | ||||||
|     createGrid(Ls); |  | ||||||
|     registerObject(name, Ls*lattice4dSize<T>(), Ls); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| void Environment::setObject(const unsigned int address, T *object) |  | ||||||
| { |  | ||||||
|     if (hasRegisteredObject(address)) |  | ||||||
|     { |  | ||||||
|         object_[address].data.reset(new Holder<T>(object)); |  | ||||||
|         object_[address].type    = &typeid(T); |         object_[address].type    = &typeid(T); | ||||||
|     } |         if (MemoryProfiler::stats == &memStats) | ||||||
|     else if (hasObject(address)) |  | ||||||
|         { |         { | ||||||
|         HADRON_ERROR("object with address " + std::to_string(address) + |             MemoryProfiler::stats = nullptr; | ||||||
|                      " exists but is not registered"); |  | ||||||
|         } |         } | ||||||
|     else |     } | ||||||
|  |     // object already exists, no error if it is a cache, error otherwise | ||||||
|  |     else if ((object_[address].storage != Storage::cache) or  | ||||||
|  |              (object_[address].storage != storage)        or | ||||||
|  |              (object_[address].name    != name)           or | ||||||
|  |              (object_[address].type    != &typeid(T))) | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         HADRON_ERROR(Definition, "object '" + name + "' already allocated"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename T, typename ... Ts> | ||||||
| void Environment::setObject(const std::string name, T *object) | void Environment::createObject(const std::string name,  | ||||||
|  |                                const Environment::Storage storage, | ||||||
|  |                                const unsigned int Ls, | ||||||
|  |                                Ts && ... args) | ||||||
| { | { | ||||||
|     setObject(getObjectAddress(name), object); |     createDerivedObject<T, T>(name, storage, Ls, std::forward<Ts>(args)...); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename T> | ||||||
| T * Environment::getObject(const unsigned int address) const | T * Environment::getObject(const unsigned int address) const | ||||||
| { | { | ||||||
|     if (hasRegisteredObject(address)) |     if (hasObject(address)) | ||||||
|  |     { | ||||||
|  |         if (hasCreatedObject(address)) | ||||||
|         { |         { | ||||||
|             if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get())) |             if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get())) | ||||||
|             { |             { | ||||||
| @@ -353,19 +259,20 @@ T * Environment::getObject(const unsigned int address) const | |||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|             HADRON_ERROR("object with address " + std::to_string(address) + |                 HADRON_ERROR(Definition, "object with address " + std::to_string(address) + | ||||||
|                             " does not have type '" + typeName(&typeid(T)) + |                             " does not have type '" + typeName(&typeid(T)) + | ||||||
|                             "' (has type '" + getObjectType(address) + "')"); |                             "' (has type '" + getObjectType(address) + "')"); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     else if (hasObject(address)) |         else | ||||||
|         { |         { | ||||||
|         HADRON_ERROR("object with address " + std::to_string(address) + |             HADRON_ERROR(Definition, "object with address " + std::to_string(address) + | ||||||
|                      " exists but is not registered"); |                          " is empty"); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         HADRON_ERROR(Definition, "no object with address " + std::to_string(address)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -375,26 +282,10 @@ T * Environment::getObject(const std::string name) const | |||||||
|     return getObject<T>(getObjectAddress(name)); |     return getObject<T>(getObjectAddress(name)); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| T * Environment::createLattice(const unsigned int address) |  | ||||||
| { |  | ||||||
|     GridCartesian *g = getGrid(getObjectLs(address)); |  | ||||||
|      |  | ||||||
|     setObject(address, new T(g)); |  | ||||||
|      |  | ||||||
|     return getObject<T>(address); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| T * Environment::createLattice(const std::string name) |  | ||||||
| { |  | ||||||
|     return createLattice<T>(getObjectAddress(name)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename T> | template <typename T> | ||||||
| bool Environment::isObjectOfType(const unsigned int address) const | bool Environment::isObjectOfType(const unsigned int address) const | ||||||
| { | { | ||||||
|     if (hasRegisteredObject(address)) |     if (hasObject(address)) | ||||||
|     { |     { | ||||||
|         if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get())) |         if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get())) | ||||||
|         { |         { | ||||||
| @@ -405,14 +296,9 @@ bool Environment::isObjectOfType(const unsigned int address) const | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     else if (hasObject(address)) |  | ||||||
|     { |  | ||||||
|         HADRON_ERROR("object with address " + std::to_string(address) + |  | ||||||
|                      " exists but is not registered"); |  | ||||||
|     } |  | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("no object with address " + std::to_string(address)); |         HADRON_ERROR(Definition, "no object with address " + std::to_string(address)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										57
									
								
								extras/Hadrons/Exceptions.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								extras/Hadrons/Exceptions.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Exceptions.cc | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Exceptions.hpp> | ||||||
|  |  | ||||||
|  | #ifndef ERR_SUFF | ||||||
|  | #define ERR_SUFF " (" + loc + ")" | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #define CONST_EXC(name, init) \ | ||||||
|  | name::name(std::string msg, std::string loc)\ | ||||||
|  | :init\ | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | using namespace Grid; | ||||||
|  | using namespace Hadrons; | ||||||
|  | using namespace Exceptions; | ||||||
|  |  | ||||||
|  | // logic errors | ||||||
|  | CONST_EXC(Logic, logic_error(msg + ERR_SUFF)) | ||||||
|  | CONST_EXC(Definition, Logic("definition error: " + msg, loc)) | ||||||
|  | CONST_EXC(Implementation, Logic("implementation error: " + msg, loc)) | ||||||
|  | CONST_EXC(Range, Logic("range error: " + msg, loc)) | ||||||
|  | CONST_EXC(Size, Logic("size error: " + msg, loc)) | ||||||
|  | // runtime errors | ||||||
|  | CONST_EXC(Runtime, runtime_error(msg + ERR_SUFF)) | ||||||
|  | CONST_EXC(Argument, Runtime("argument error: " + msg, loc)) | ||||||
|  | CONST_EXC(Io, Runtime("IO error: " + msg, loc)) | ||||||
|  | CONST_EXC(Memory, Runtime("memory error: " + msg, loc)) | ||||||
|  | CONST_EXC(Parsing, Runtime("parsing error: " + msg, loc)) | ||||||
|  | CONST_EXC(Program, Runtime("program error: " + msg, loc)) | ||||||
|  | CONST_EXC(System, Runtime("system error: " + msg, loc)) | ||||||
							
								
								
									
										72
									
								
								extras/Hadrons/Exceptions.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								extras/Hadrons/Exceptions.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Exceptions.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_Exceptions_hpp_ | ||||||
|  | #define Hadrons_Exceptions_hpp_ | ||||||
|  |  | ||||||
|  | #include <stdexcept> | ||||||
|  | #ifndef Hadrons_Global_hpp_ | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #define SRC_LOC std::string(__FUNCTION__) + " at " + std::string(__FILE__) + ":"\ | ||||||
|  |                 + std::to_string(__LINE__) | ||||||
|  | #define HADRON_ERROR(exc, msg)\ | ||||||
|  | LOG(Error) << msg << std::endl;\ | ||||||
|  | throw(Exceptions::exc(msg, SRC_LOC)); | ||||||
|  |  | ||||||
|  | #define DECL_EXC(name, base) \ | ||||||
|  | class name: public base\ | ||||||
|  | {\ | ||||||
|  | public:\ | ||||||
|  |     name(std::string msg, std::string loc);\ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | namespace Exceptions | ||||||
|  | { | ||||||
|  |     // logic errors | ||||||
|  |     DECL_EXC(Logic, std::logic_error); | ||||||
|  |     DECL_EXC(Definition, Logic); | ||||||
|  |     DECL_EXC(Implementation, Logic); | ||||||
|  |     DECL_EXC(Range, Logic); | ||||||
|  |     DECL_EXC(Size, Logic); | ||||||
|  |     // runtime errors | ||||||
|  |     DECL_EXC(Runtime, std::runtime_error); | ||||||
|  |     DECL_EXC(Argument, Runtime); | ||||||
|  |     DECL_EXC(Io, Runtime); | ||||||
|  |     DECL_EXC(Memory, Runtime); | ||||||
|  |     DECL_EXC(Parsing, Runtime); | ||||||
|  |     DECL_EXC(Program, Runtime); | ||||||
|  |     DECL_EXC(System, Runtime); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_Exceptions_hpp_ | ||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Factory.hpp | Source file: extras/Hadrons/Factory.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -95,7 +94,7 @@ std::unique_ptr<T> Factory<T>::create(const std::string type, | |||||||
|     } |     } | ||||||
|     catch (std::out_of_range &) |     catch (std::out_of_range &) | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("object of type '" + type + "' unknown"); |         HADRON_ERROR(Argument, "object of type '" + type + "' unknown"); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return func(name); |     return func(name); | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/GeneticScheduler.hpp | Source file: extras/Hadrons/GeneticScheduler.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -38,13 +37,13 @@ BEGIN_HADRONS_NAMESPACE | |||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                   Scheduler based on a genetic algorithm                   * |  *                   Scheduler based on a genetic algorithm                   * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| class GeneticScheduler | class GeneticScheduler | ||||||
| { | { | ||||||
| public: | public: | ||||||
|     typedef std::vector<T>                 Gene; |     typedef std::vector<T>                 Gene; | ||||||
|     typedef std::pair<Gene *, Gene *>      GenePair; |     typedef std::pair<Gene *, Gene *>      GenePair; | ||||||
|     typedef std::function<int(const Gene &)> ObjFunc; |     typedef std::function<V(const Gene &)> ObjFunc; | ||||||
|     struct Parameters |     struct Parameters | ||||||
|     { |     { | ||||||
|         double       mutationRate; |         double       mutationRate; | ||||||
| @@ -65,7 +64,7 @@ public: | |||||||
|     void benchmarkCrossover(const unsigned int nIt); |     void benchmarkCrossover(const unsigned int nIt); | ||||||
|     // print population |     // print population | ||||||
|     friend std::ostream & operator<<(std::ostream &out, |     friend std::ostream & operator<<(std::ostream &out, | ||||||
|                                      const GeneticScheduler<T> &s) |                                      const GeneticScheduler<V, T> &s) | ||||||
|     { |     { | ||||||
|         out << "["; |         out << "["; | ||||||
|         for (auto &p: s.population_) |         for (auto &p: s.population_) | ||||||
| @@ -90,7 +89,7 @@ private: | |||||||
|     Graph<T>               &graph_; |     Graph<T>               &graph_; | ||||||
|     const ObjFunc          &func_; |     const ObjFunc          &func_; | ||||||
|     const Parameters       par_; |     const Parameters       par_; | ||||||
|     std::multimap<int, Gene> population_; |     std::multimap<V, Gene> population_; | ||||||
|     std::mt19937           gen_; |     std::mt19937           gen_; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -98,8 +97,8 @@ private: | |||||||
|  *                       template implementation                              * |  *                       template implementation                              * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| // constructor ///////////////////////////////////////////////////////////////// | // constructor ///////////////////////////////////////////////////////////////// | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| GeneticScheduler<T>::GeneticScheduler(Graph<T> &graph, const ObjFunc &func, | GeneticScheduler<V, T>::GeneticScheduler(Graph<T> &graph, const ObjFunc &func, | ||||||
|                                       const Parameters &par) |                                       const Parameters &par) | ||||||
| : graph_(graph) | : graph_(graph) | ||||||
| , func_(func) | , func_(func) | ||||||
| @@ -109,22 +108,22 @@ GeneticScheduler<T>::GeneticScheduler(Graph<T> &graph, const ObjFunc &func, | |||||||
| } | } | ||||||
|  |  | ||||||
| // access ////////////////////////////////////////////////////////////////////// | // access ////////////////////////////////////////////////////////////////////// | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| const typename GeneticScheduler<T>::Gene & | const typename GeneticScheduler<V, T>::Gene & | ||||||
| GeneticScheduler<T>::getMinSchedule(void) | GeneticScheduler<V, T>::getMinSchedule(void) | ||||||
| { | { | ||||||
|     return population_.begin()->second; |     return population_.begin()->second; | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| int GeneticScheduler<T>::getMinValue(void) | int GeneticScheduler<V, T>::getMinValue(void) | ||||||
| { | { | ||||||
|     return population_.begin()->first; |     return population_.begin()->first; | ||||||
| } | } | ||||||
|  |  | ||||||
| // breed a new generation ////////////////////////////////////////////////////// | // breed a new generation ////////////////////////////////////////////////////// | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| void GeneticScheduler<T>::nextGeneration(void) | void GeneticScheduler<V, T>::nextGeneration(void) | ||||||
| { | { | ||||||
|     // random initialization of the population if necessary |     // random initialization of the population if necessary | ||||||
|     if (population_.size() != par_.popSize) |     if (population_.size() != par_.popSize) | ||||||
| @@ -158,8 +157,8 @@ void GeneticScheduler<T>::nextGeneration(void) | |||||||
| } | } | ||||||
|  |  | ||||||
| // evolution steps ///////////////////////////////////////////////////////////// | // evolution steps ///////////////////////////////////////////////////////////// | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| void GeneticScheduler<T>::initPopulation(void) | void GeneticScheduler<V, T>::initPopulation(void) | ||||||
| { | { | ||||||
|     population_.clear(); |     population_.clear(); | ||||||
|     for (unsigned int i = 0; i < par_.popSize; ++i) |     for (unsigned int i = 0; i < par_.popSize; ++i) | ||||||
| @@ -170,8 +169,8 @@ void GeneticScheduler<T>::initPopulation(void) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| void GeneticScheduler<T>::doCrossover(void) | void GeneticScheduler<V, T>::doCrossover(void) | ||||||
| { | { | ||||||
|     auto p = selectPair(); |     auto p = selectPair(); | ||||||
|     Gene &p1 = *(p.first), &p2 = *(p.second); |     Gene &p1 = *(p.first), &p2 = *(p.second); | ||||||
| @@ -185,8 +184,8 @@ void GeneticScheduler<T>::doCrossover(void) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| void GeneticScheduler<T>::doMutation(void) | void GeneticScheduler<V, T>::doMutation(void) | ||||||
| { | { | ||||||
|     std::uniform_real_distribution<double>      mdis(0., 1.); |     std::uniform_real_distribution<double>      mdis(0., 1.); | ||||||
|     std::uniform_int_distribution<unsigned int> pdis(0, population_.size() - 1); |     std::uniform_int_distribution<unsigned int> pdis(0, population_.size() - 1); | ||||||
| @@ -206,40 +205,35 @@ void GeneticScheduler<T>::doMutation(void) | |||||||
| } | } | ||||||
|  |  | ||||||
| // genetic operators /////////////////////////////////////////////////////////// | // genetic operators /////////////////////////////////////////////////////////// | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| typename GeneticScheduler<T>::GenePair GeneticScheduler<T>::selectPair(void) | typename GeneticScheduler<V, T>::GenePair GeneticScheduler<V, T>::selectPair(void) | ||||||
| { | { | ||||||
|     std::vector<double> prob; |     std::vector<double> prob; | ||||||
|     unsigned int        ind; |     unsigned int        ind; | ||||||
|     Gene                *p1, *p2; |     Gene                *p1, *p2; | ||||||
|  |     const double        max = population_.rbegin()->first; | ||||||
|  |      | ||||||
|  |  | ||||||
|     for (auto &c: population_) |     for (auto &c: population_) | ||||||
|     { |     { | ||||||
|         prob.push_back(1./c.first); |         prob.push_back(std::exp((c.first-1.)/max)); | ||||||
|     }         |     }         | ||||||
|     do |  | ||||||
|     { |  | ||||||
|         double probCpy; |  | ||||||
|          |  | ||||||
|     std::discrete_distribution<unsigned int> dis1(prob.begin(), prob.end()); |     std::discrete_distribution<unsigned int> dis1(prob.begin(), prob.end()); | ||||||
|     auto rIt = population_.begin(); |     auto rIt = population_.begin(); | ||||||
|     ind = dis1(gen_); |     ind = dis1(gen_); | ||||||
|     std::advance(rIt, ind); |     std::advance(rIt, ind); | ||||||
|     p1 = &(rIt->second); |     p1 = &(rIt->second); | ||||||
|         probCpy   = prob[ind]; |  | ||||||
|     prob[ind] = 0.; |     prob[ind] = 0.; | ||||||
|     std::discrete_distribution<unsigned int> dis2(prob.begin(), prob.end()); |     std::discrete_distribution<unsigned int> dis2(prob.begin(), prob.end()); | ||||||
|     rIt = population_.begin(); |     rIt = population_.begin(); | ||||||
|     std::advance(rIt, dis2(gen_)); |     std::advance(rIt, dis2(gen_)); | ||||||
|     p2 = &(rIt->second); |     p2 = &(rIt->second); | ||||||
|         prob[ind] = probCpy; |  | ||||||
|     } while (p1 == p2); |  | ||||||
|      |      | ||||||
|     return std::make_pair(p1, p2); |     return std::make_pair(p1, p2); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| void GeneticScheduler<T>::crossover(Gene &c1, Gene &c2, const Gene &p1, | void GeneticScheduler<V, T>::crossover(Gene &c1, Gene &c2, const Gene &p1, | ||||||
|                                     const Gene &p2) |                                     const Gene &p2) | ||||||
| { | { | ||||||
|     Gene                                        buf; |     Gene                                        buf; | ||||||
| @@ -273,8 +267,8 @@ void GeneticScheduler<T>::crossover(Gene &c1, Gene &c2, const Gene &p1, | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| void GeneticScheduler<T>::mutation(Gene &m, const Gene &c) | void GeneticScheduler<V, T>::mutation(Gene &m, const Gene &c) | ||||||
| { | { | ||||||
|     Gene                                        buf; |     Gene                                        buf; | ||||||
|     std::uniform_int_distribution<unsigned int> dis(0, c.size() - 1); |     std::uniform_int_distribution<unsigned int> dis(0, c.size() - 1); | ||||||
| @@ -303,8 +297,8 @@ void GeneticScheduler<T>::mutation(Gene &m, const Gene &c) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename V, typename T> | ||||||
| void GeneticScheduler<T>::benchmarkCrossover(const unsigned int nIt) | void GeneticScheduler<V, T>::benchmarkCrossover(const unsigned int nIt) | ||||||
| { | { | ||||||
|     Gene   p1, p2, c1, c2; |     Gene   p1, p2, c1, c2; | ||||||
|     double neg = 0., eq = 0., pos = 0., total; |     double neg = 0., eq = 0., pos = 0., total; | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Global.cc | Source file: extras/Hadrons/Global.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -39,31 +38,19 @@ HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); | |||||||
| HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); | HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); | ||||||
| HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); | HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); | ||||||
|  |  | ||||||
| // pretty size formatting ////////////////////////////////////////////////////// | void Hadrons::initLogger(void) | ||||||
| std::string Hadrons::sizeString(long unsigned int bytes) |  | ||||||
|  |  | ||||||
| { | { | ||||||
|     constexpr unsigned int bufSize = 256; |     auto w = std::string("Hadrons").length(); | ||||||
|     const char             *suffixes[7] = {"", "K", "M", "G", "T", "P", "E"}; |     GridLogError.setTopWidth(w); | ||||||
|     char                   buf[256]; |     GridLogWarning.setTopWidth(w); | ||||||
|     long unsigned int      s     = 0; |     GridLogMessage.setTopWidth(w); | ||||||
|     double                 count = bytes; |     GridLogIterative.setTopWidth(w); | ||||||
|      |     GridLogDebug.setTopWidth(w); | ||||||
|     while (count >= 1024 && s < 7) |     HadronsLogError.Active(GridLogError.isActive()); | ||||||
|     { |     HadronsLogWarning.Active(GridLogWarning.isActive()); | ||||||
|         s++; |     HadronsLogMessage.Active(GridLogMessage.isActive()); | ||||||
|         count /= 1024; |     HadronsLogIterative.Active(GridLogIterative.isActive()); | ||||||
|     } |     HadronsLogDebug.Active(GridLogDebug.isActive()); | ||||||
|     if (count - floor(count) == 0.0) |  | ||||||
|     { |  | ||||||
|         snprintf(buf, bufSize, "%d %sB", (int)count, suffixes[s]); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         snprintf(buf, bufSize, "%.1f %sB", count, suffixes[s]); |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     return std::string(buf); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // type utilities ////////////////////////////////////////////////////////////// | // type utilities ////////////////////////////////////////////////////////////// | ||||||
| @@ -80,3 +67,10 @@ std::string Hadrons::typeName(const std::type_info *info) | |||||||
|      |      | ||||||
|     return name; |     return name; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // default writers/readers ///////////////////////////////////////////////////// | ||||||
|  | #ifdef HAVE_HDF5 | ||||||
|  | const std::string Hadrons::resultFileExt = "h5"; | ||||||
|  | #else | ||||||
|  | const std::string Hadrons::resultFileExt = "xml"; | ||||||
|  | #endif | ||||||
|   | |||||||
| @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Global.hpp | Source file: extras/Hadrons/Global.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -35,6 +35,10 @@ See the full license in the file "LICENSE" in the top level distribution directo | |||||||
| #include <Grid/Grid.h> | #include <Grid/Grid.h> | ||||||
| #include <cxxabi.h> | #include <cxxabi.h> | ||||||
|  |  | ||||||
|  | #ifndef SITE_SIZE_TYPE | ||||||
|  | #define SITE_SIZE_TYPE size_t | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #define BEGIN_HADRONS_NAMESPACE \ | #define BEGIN_HADRONS_NAMESPACE \ | ||||||
| namespace Grid {\ | namespace Grid {\ | ||||||
| using namespace QCD;\ | using namespace QCD;\ | ||||||
| @@ -57,6 +61,9 @@ using Grid::operator<<; | |||||||
| #ifndef SIMPL | #ifndef SIMPL | ||||||
| #define SIMPL ScalarImplCR | #define SIMPL ScalarImplCR | ||||||
| #endif | #endif | ||||||
|  | #ifndef GIMPL | ||||||
|  | #define GIMPL GimplTypesR | ||||||
|  | #endif | ||||||
|  |  | ||||||
| BEGIN_HADRONS_NAMESPACE | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
| @@ -65,9 +72,8 @@ BEGIN_HADRONS_NAMESPACE | |||||||
| typedef FermionOperator<FImpl>                        FMat##suffix;            \ | typedef FermionOperator<FImpl>                        FMat##suffix;            \ | ||||||
| typedef typename FImpl::FermionField                  FermionField##suffix;    \ | typedef typename FImpl::FermionField                  FermionField##suffix;    \ | ||||||
| typedef typename FImpl::PropagatorField               PropagatorField##suffix; \ | typedef typename FImpl::PropagatorField               PropagatorField##suffix; \ | ||||||
| typedef typename FImpl::SitePropagator               SitePropagator##suffix;   \ | typedef typename FImpl::SitePropagator::scalar_object SitePropagator##suffix;  \ | ||||||
| typedef std::vector<typename FImpl::SitePropagator::scalar_object>             \ | typedef std::vector<SitePropagator##suffix>           SlicedPropagator##suffix; | ||||||
|                                                      SlicedPropagator##suffix; |  | ||||||
|  |  | ||||||
| #define GAUGE_TYPE_ALIASES(FImpl, suffix)\ | #define GAUGE_TYPE_ALIASES(FImpl, suffix)\ | ||||||
| typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix; | typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix; | ||||||
| @@ -81,7 +87,8 @@ typedef std::function<void(FermionField##suffix &,\ | |||||||
|                       const FermionField##suffix &)> SolverFn##suffix; |                       const FermionField##suffix &)> SolverFn##suffix; | ||||||
|  |  | ||||||
| #define SINK_TYPE_ALIASES(suffix)\ | #define SINK_TYPE_ALIASES(suffix)\ | ||||||
| typedef std::function<SlicedPropagator##suffix(const PropagatorField##suffix &)> SinkFn##suffix; | typedef std::function<SlicedPropagator##suffix\ | ||||||
|  |                       (const PropagatorField##suffix &)> SinkFn##suffix; | ||||||
|  |  | ||||||
| #define FGS_TYPE_ALIASES(FImpl, suffix)\ | #define FGS_TYPE_ALIASES(FImpl, suffix)\ | ||||||
| FERM_TYPE_ALIASES(FImpl, suffix)\ | FERM_TYPE_ALIASES(FImpl, suffix)\ | ||||||
| @@ -97,11 +104,6 @@ public: | |||||||
| }; | }; | ||||||
|  |  | ||||||
| #define LOG(channel) std::cout << HadronsLog##channel | #define LOG(channel) std::cout << HadronsLog##channel | ||||||
| #define HADRON_ERROR(msg)\ |  | ||||||
| LOG(Error) << msg << " (" << __FUNCTION__ << " at " << __FILE__ << ":"\ |  | ||||||
|            << __LINE__ << ")" << std::endl;\ |  | ||||||
| abort(); |  | ||||||
|  |  | ||||||
| #define DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl; | #define DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl; | ||||||
|  |  | ||||||
| extern HadronsLogger HadronsLogError; | extern HadronsLogger HadronsLogError; | ||||||
| @@ -110,6 +112,8 @@ extern HadronsLogger HadronsLogMessage; | |||||||
| extern HadronsLogger HadronsLogIterative; | extern HadronsLogger HadronsLogIterative; | ||||||
| extern HadronsLogger HadronsLogDebug; | extern HadronsLogger HadronsLogDebug; | ||||||
|  |  | ||||||
|  | void initLogger(void); | ||||||
|  |  | ||||||
| // singleton pattern | // singleton pattern | ||||||
| #define SINGLETON(name)\ | #define SINGLETON(name)\ | ||||||
| public:\ | public:\ | ||||||
| @@ -135,9 +139,6 @@ public:\ | |||||||
| private:\ | private:\ | ||||||
|     name(void) = default; |     name(void) = default; | ||||||
|  |  | ||||||
| // pretty size formating |  | ||||||
| std::string sizeString(long unsigned int bytes); |  | ||||||
|  |  | ||||||
| // type utilities | // type utilities | ||||||
| template <typename T> | template <typename T> | ||||||
| const std::type_info * typeIdPt(const T &x) | const std::type_info * typeIdPt(const T &x) | ||||||
| @@ -166,14 +167,21 @@ std::string typeName(void) | |||||||
| } | } | ||||||
|  |  | ||||||
| // default writers/readers | // default writers/readers | ||||||
|  | extern const std::string resultFileExt; | ||||||
|  |  | ||||||
| #ifdef HAVE_HDF5 | #ifdef HAVE_HDF5 | ||||||
| typedef Hdf5Reader CorrReader; | typedef Hdf5Reader ResultReader; | ||||||
| typedef Hdf5Writer CorrWriter; | typedef Hdf5Writer ResultWriter; | ||||||
| #else | #else | ||||||
| typedef XmlReader CorrReader; | typedef XmlReader ResultReader; | ||||||
| typedef XmlWriter CorrWriter; | typedef XmlWriter ResultWriter; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #define RESULT_FILE_NAME(name) \ | ||||||
|  | name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt | ||||||
|  |  | ||||||
| END_HADRONS_NAMESPACE | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Exceptions.hpp> | ||||||
|  |  | ||||||
| #endif // Hadrons_Global_hpp_ | #endif // Hadrons_Global_hpp_ | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Graph.hpp | Source file: extras/Hadrons/Graph.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -185,7 +184,7 @@ void Graph<T>::removeVertex(const T &value) | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("vertex " << value << " does not exists"); |         HADRON_ERROR(Range, "vertex does not exists"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // remove all edges containing the vertex |     // remove all edges containing the vertex | ||||||
| @@ -214,7 +213,7 @@ void Graph<T>::removeEdge(const Edge &e) | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("edge "  << e << " does not exists"); |         HADRON_ERROR(Range, "edge does not exists"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -260,7 +259,7 @@ void Graph<T>::mark(const T &value, const bool doMark) | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("vertex " << value << " does not exists"); |         HADRON_ERROR(Range, "vertex does not exists"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -298,7 +297,7 @@ bool Graph<T>::isMarked(const T &value) const | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         HADRON_ERROR("vertex " << value << " does not exists"); |         HADRON_ERROR(Range, "vertex does not exists"); | ||||||
|          |          | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
| @@ -430,7 +429,7 @@ std::vector<T> Graph<T>::getAdjacentVertices(const T &value) const | |||||||
|     { |     { | ||||||
|         return ((e.first == value) or (e.second == value)); |         return ((e.first == value) or (e.second == value)); | ||||||
|     }; |     }; | ||||||
|     auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); |     auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred); | ||||||
|      |      | ||||||
|     while (eIt != edgeSet_.end()) |     while (eIt != edgeSet_.end()) | ||||||
|     { |     { | ||||||
| @@ -442,7 +441,7 @@ std::vector<T> Graph<T>::getAdjacentVertices(const T &value) const | |||||||
|         { |         { | ||||||
|             adjacentVertex.push_back((*eIt).first); |             adjacentVertex.push_back((*eIt).first); | ||||||
|         } |         } | ||||||
|         eIt = find_if(++eIt, edgeSet_.end(), pred); |         eIt = std::find_if(++eIt, edgeSet_.end(), pred); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return adjacentVertex; |     return adjacentVertex; | ||||||
| @@ -458,12 +457,12 @@ std::vector<T> Graph<T>::getChildren(const T &value) const | |||||||
|     { |     { | ||||||
|         return (e.first == value); |         return (e.first == value); | ||||||
|     }; |     }; | ||||||
|     auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); |     auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred); | ||||||
|      |      | ||||||
|     while (eIt != edgeSet_.end()) |     while (eIt != edgeSet_.end()) | ||||||
|     { |     { | ||||||
|         child.push_back((*eIt).second); |         child.push_back((*eIt).second); | ||||||
|         eIt = find_if(++eIt, edgeSet_.end(), pred); |         eIt = std::find_if(++eIt, edgeSet_.end(), pred); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return child; |     return child; | ||||||
| @@ -479,12 +478,12 @@ std::vector<T> Graph<T>::getParents(const T &value) const | |||||||
|     { |     { | ||||||
|         return (e.second == value); |         return (e.second == value); | ||||||
|     }; |     }; | ||||||
|     auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); |     auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred); | ||||||
|      |      | ||||||
|     while (eIt != edgeSet_.end()) |     while (eIt != edgeSet_.end()) | ||||||
|     { |     { | ||||||
|         parent.push_back((*eIt).first); |         parent.push_back((*eIt).first); | ||||||
|         eIt = find_if(++eIt, edgeSet_.end(), pred); |         eIt = std::find_if(++eIt, edgeSet_.end(), pred); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return parent; |     return parent; | ||||||
| @@ -544,7 +543,7 @@ std::vector<T> Graph<T>::topoSort(void) | |||||||
|     { |     { | ||||||
|         if (tmpMarked.at(v)) |         if (tmpMarked.at(v)) | ||||||
|         { |         { | ||||||
|             HADRON_ERROR("cannot topologically sort a cyclic graph"); |             HADRON_ERROR(Range, "cannot topologically sort a cyclic graph"); | ||||||
|         } |         } | ||||||
|         if (!isMarked(v)) |         if (!isMarked(v)) | ||||||
|         { |         { | ||||||
| @@ -603,7 +602,7 @@ std::vector<T> Graph<T>::topoSort(Gen &gen) | |||||||
|     { |     { | ||||||
|         if (tmpMarked.at(v)) |         if (tmpMarked.at(v)) | ||||||
|         { |         { | ||||||
|             HADRON_ERROR("cannot topologically sort a cyclic graph"); |             HADRON_ERROR(Range, "cannot topologically sort a cyclic graph"); | ||||||
|         } |         } | ||||||
|         if (!isMarked(v)) |         if (!isMarked(v)) | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/HadronsXmlRun.cc | Source file: extras/Hadrons/HadronsXmlRun.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -55,12 +54,6 @@ int main(int argc, char *argv[]) | |||||||
|      |      | ||||||
|     // initialization |     // initialization | ||||||
|     Grid_init(&argc, &argv); |     Grid_init(&argc, &argv); | ||||||
|     HadronsLogError.Active(GridLogError.isActive()); |  | ||||||
|     HadronsLogWarning.Active(GridLogWarning.isActive()); |  | ||||||
|     HadronsLogMessage.Active(GridLogMessage.isActive()); |  | ||||||
|     HadronsLogIterative.Active(GridLogIterative.isActive()); |  | ||||||
|     HadronsLogDebug.Active(GridLogDebug.isActive()); |  | ||||||
|     LOG(Message) << "Grid initialized" << std::endl; |  | ||||||
|      |      | ||||||
|     // execution |     // execution | ||||||
|     Application application(parameterFileName); |     Application application(parameterFileName); | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/HadronsXmlSchedule.cc | Source file: extras/Hadrons/HadronsXmlSchedule.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -49,12 +48,6 @@ int main(int argc, char *argv[]) | |||||||
|      |      | ||||||
|     // initialization |     // initialization | ||||||
|     Grid_init(&argc, &argv); |     Grid_init(&argc, &argv); | ||||||
|     HadronsLogError.Active(GridLogError.isActive()); |  | ||||||
|     HadronsLogWarning.Active(GridLogWarning.isActive()); |  | ||||||
|     HadronsLogMessage.Active(GridLogMessage.isActive()); |  | ||||||
|     HadronsLogIterative.Active(GridLogIterative.isActive()); |  | ||||||
|     HadronsLogDebug.Active(GridLogDebug.isActive()); |  | ||||||
|     LOG(Message) << "Grid initialized" << std::endl; |  | ||||||
|      |      | ||||||
|     // execution |     // execution | ||||||
|     Application application; |     Application application; | ||||||
|   | |||||||
| @@ -7,20 +7,24 @@ libHadrons_a_SOURCES = \ | |||||||
|     $(modules_cc)      \ |     $(modules_cc)      \ | ||||||
|     Application.cc     \ |     Application.cc     \ | ||||||
|     Environment.cc     \ |     Environment.cc     \ | ||||||
|  | 	Exceptions.cc      \ | ||||||
|     Global.cc          \ |     Global.cc          \ | ||||||
|     Module.cc |     Module.cc		   \ | ||||||
|  | 	VirtualMachine.cc | ||||||
| libHadrons_adir = $(pkgincludedir)/Hadrons | libHadrons_adir = $(pkgincludedir)/Hadrons | ||||||
| nobase_libHadrons_a_HEADERS = \ | nobase_libHadrons_a_HEADERS = \ | ||||||
| 	$(modules_hpp)            \ | 	$(modules_hpp)            \ | ||||||
| 	Application.hpp           \ | 	Application.hpp           \ | ||||||
| 	Environment.hpp           \ | 	Environment.hpp           \ | ||||||
|  | 	Exceptions.hpp            \ | ||||||
| 	Factory.hpp               \ | 	Factory.hpp               \ | ||||||
| 	GeneticScheduler.hpp      \ | 	GeneticScheduler.hpp      \ | ||||||
| 	Global.hpp                \ | 	Global.hpp                \ | ||||||
| 	Graph.hpp                 \ | 	Graph.hpp                 \ | ||||||
| 	Module.hpp                \ | 	Module.hpp                \ | ||||||
| 	Modules.hpp               \ | 	Modules.hpp               \ | ||||||
| 	ModuleFactory.hpp | 	ModuleFactory.hpp         \ | ||||||
|  | 	VirtualMachine.hpp | ||||||
|  |  | ||||||
| HadronsXmlRun_SOURCES = HadronsXmlRun.cc | HadronsXmlRun_SOURCES = HadronsXmlRun.cc | ||||||
| HadronsXmlRun_LDADD   = libHadrons.a -lGrid | HadronsXmlRun_LDADD   = libHadrons.a -lGrid | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Module.cc | Source file: extras/Hadrons/Module.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -39,7 +38,6 @@ using namespace Hadrons; | |||||||
| // constructor ///////////////////////////////////////////////////////////////// | // constructor ///////////////////////////////////////////////////////////////// | ||||||
| ModuleBase::ModuleBase(const std::string name) | ModuleBase::ModuleBase(const std::string name) | ||||||
| : name_(name) | : name_(name) | ||||||
| , env_(Environment::getInstance()) |  | ||||||
| {} | {} | ||||||
|  |  | ||||||
| // access ////////////////////////////////////////////////////////////////////// | // access ////////////////////////////////////////////////////////////////////// | ||||||
| @@ -48,15 +46,10 @@ std::string ModuleBase::getName(void) const | |||||||
|     return name_; |     return name_; | ||||||
| } | } | ||||||
|  |  | ||||||
| Environment & ModuleBase::env(void) const |  | ||||||
| { |  | ||||||
|     return env_; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // get factory registration name if available | // get factory registration name if available | ||||||
| std::string ModuleBase::getRegisteredName(void) | std::string ModuleBase::getRegisteredName(void) | ||||||
| { | { | ||||||
|     HADRON_ERROR("module '" + getName() + "' has a type not registered" |     HADRON_ERROR(Definition, "module '" + getName() + "' has no registered type" | ||||||
|                  + " in the factory"); |                  + " in the factory"); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -64,8 +57,5 @@ std::string ModuleBase::getRegisteredName(void) | |||||||
| void ModuleBase::operator()(void) | void ModuleBase::operator()(void) | ||||||
| { | { | ||||||
|     setup(); |     setup(); | ||||||
|     if (!env().isDryRun()) |  | ||||||
|     { |  | ||||||
|     execute(); |     execute(); | ||||||
| } | } | ||||||
| } |  | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Module.hpp | Source file: extras/Hadrons/Module.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -31,7 +30,7 @@ See the full license in the file "LICENSE" in the top level distribution directo | |||||||
| #define Hadrons_Module_hpp_ | #define Hadrons_Module_hpp_ | ||||||
|  |  | ||||||
| #include <Grid/Hadrons/Global.hpp> | #include <Grid/Hadrons/Global.hpp> | ||||||
| #include <Grid/Hadrons/Environment.hpp> | #include <Grid/Hadrons/VirtualMachine.hpp> | ||||||
|  |  | ||||||
| BEGIN_HADRONS_NAMESPACE | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
| @@ -87,6 +86,56 @@ public:\ | |||||||
| static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; | static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; | ||||||
|  |  | ||||||
| #define ARG(...) __VA_ARGS__ | #define ARG(...) __VA_ARGS__ | ||||||
|  | #define MACRO_REDIRECT(arg1, arg2, arg3, macro, ...) macro | ||||||
|  |  | ||||||
|  | #define envGet(type, name)\ | ||||||
|  | *env().template getObject<type>(name) | ||||||
|  |  | ||||||
|  | #define envGetTmp(type, var)\ | ||||||
|  | type &var = *env().template getObject<type>(getName() + "_tmp_" + #var) | ||||||
|  |  | ||||||
|  | #define envHasType(type, name)\ | ||||||
|  | env().template isObjectOfType<type>(name) | ||||||
|  |  | ||||||
|  | #define envCreate(type, name, Ls, ...)\ | ||||||
|  | env().template createObject<type>(name, Environment::Storage::object, Ls, __VA_ARGS__) | ||||||
|  |  | ||||||
|  | #define envCreateDerived(base, type, name, Ls, ...)\ | ||||||
|  | env().template createDerivedObject<base, type>(name, Environment::Storage::object, Ls, __VA_ARGS__) | ||||||
|  |  | ||||||
|  | #define envCreateLat4(type, name)\ | ||||||
|  | envCreate(type, name, 1, env().getGrid()) | ||||||
|  |  | ||||||
|  | #define envCreateLat5(type, name, Ls)\ | ||||||
|  | envCreate(type, name, Ls, env().getGrid(Ls)) | ||||||
|  |  | ||||||
|  | #define envCreateLat(...)\ | ||||||
|  | MACRO_REDIRECT(__VA_ARGS__, envCreateLat5, envCreateLat4)(__VA_ARGS__) | ||||||
|  |  | ||||||
|  | #define envCache(type, name, Ls, ...)\ | ||||||
|  | env().template createObject<type>(name, Environment::Storage::cache, Ls, __VA_ARGS__) | ||||||
|  |  | ||||||
|  | #define envCacheLat4(type, name)\ | ||||||
|  | envCache(type, name, 1, env().getGrid()) | ||||||
|  |  | ||||||
|  | #define envCacheLat5(type, name, Ls)\ | ||||||
|  | envCache(type, name, Ls, env().getGrid(Ls)) | ||||||
|  |  | ||||||
|  | #define envCacheLat(...)\ | ||||||
|  | MACRO_REDIRECT(__VA_ARGS__, envCacheLat5, envCacheLat4)(__VA_ARGS__) | ||||||
|  |  | ||||||
|  | #define envTmp(type, name, Ls, ...)\ | ||||||
|  | env().template createObject<type>(getName() + "_tmp_" + name,         \ | ||||||
|  |                                   Environment::Storage::temporary, Ls, __VA_ARGS__) | ||||||
|  |  | ||||||
|  | #define envTmpLat4(type, name)\ | ||||||
|  | envTmp(type, name, 1, env().getGrid()) | ||||||
|  |  | ||||||
|  | #define envTmpLat5(type, name, Ls)\ | ||||||
|  | envTmp(type, name, Ls, env().getGrid(Ls)) | ||||||
|  |  | ||||||
|  | #define envTmpLat(...)\ | ||||||
|  | MACRO_REDIRECT(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__) | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                            Module class                                    * |  *                            Module class                                    * | ||||||
| @@ -101,23 +150,30 @@ public: | |||||||
|     virtual ~ModuleBase(void) = default; |     virtual ~ModuleBase(void) = default; | ||||||
|     // access |     // access | ||||||
|     std::string getName(void) const; |     std::string getName(void) const; | ||||||
|     Environment &env(void) const; |  | ||||||
|     // get factory registration name if available |     // get factory registration name if available | ||||||
|     virtual std::string getRegisteredName(void); |     virtual std::string getRegisteredName(void); | ||||||
|     // dependencies/products |     // dependencies/products | ||||||
|     virtual std::vector<std::string> getInput(void) = 0; |     virtual std::vector<std::string> getInput(void) = 0; | ||||||
|  |     virtual std::vector<std::string> getReference(void) | ||||||
|  |     { | ||||||
|  |         return std::vector<std::string>(0); | ||||||
|  |     }; | ||||||
|     virtual std::vector<std::string> getOutput(void) = 0; |     virtual std::vector<std::string> getOutput(void) = 0; | ||||||
|     // parse parameters |     // parse parameters | ||||||
|     virtual void parseParameters(XmlReader &reader, const std::string name) = 0; |     virtual void parseParameters(XmlReader &reader, const std::string name) = 0; | ||||||
|     virtual void saveParameters(XmlWriter &writer, const std::string name) = 0; |     virtual void saveParameters(XmlWriter &writer, const std::string name) = 0; | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void) {}; |     virtual void setup(void) {}; | ||||||
|  |     virtual void execute(void) = 0; | ||||||
|     // execution |     // execution | ||||||
|     void operator()(void); |     void operator()(void); | ||||||
|     virtual void execute(void) = 0; | protected: | ||||||
|  |     // environment shortcut | ||||||
|  |     DEFINE_ENV_ALIAS; | ||||||
|  |     // virtual machine shortcut | ||||||
|  |     DEFINE_VM_ALIAS; | ||||||
| private: | private: | ||||||
|     std::string name_; |     std::string name_; | ||||||
|     Environment &env_; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // derived class, templating the parameter class | // derived class, templating the parameter class | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/ModuleFactory.hpp | Source file: extras/Hadrons/ModuleFactory.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,25 +1,65 @@ | |||||||
| #include <Grid/Hadrons/Modules/MAction/DWF.hpp> | /************************************************************************************* | ||||||
| #include <Grid/Hadrons/Modules/MAction/Wilson.hpp> |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
| #include <Grid/Hadrons/Modules/MContraction/Baryon.hpp> | #include <Grid/Hadrons/Modules/MContraction/Baryon.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MContraction/DiscLoop.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MContraction/Gamma3pt.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MContraction/Meson.hpp> | #include <Grid/Hadrons/Modules/MContraction/Meson.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MContraction/WeakHamiltonian.hpp> | #include <Grid/Hadrons/Modules/MContraction/WeakHamiltonian.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp> | #include <Grid/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MContraction/DiscLoop.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp> | #include <Grid/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MContraction/Gamma3pt.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MContraction/WardIdentity.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MFermion/GaugeProp.hpp> | #include <Grid/Hadrons/Modules/MFermion/GaugeProp.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MGauge/Load.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MGauge/Random.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MGauge/StochEm.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MGauge/Unit.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MLoop/NoiseLoop.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MScalar/ChargedProp.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MScalar/FreeProp.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MScalar/Scalar.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MSink/Point.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MSolver/RBPrecCG.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MSource/Point.hpp> |  | ||||||
| #include <Grid/Hadrons/Modules/MSource/SeqGamma.hpp> | #include <Grid/Hadrons/Modules/MSource/SeqGamma.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MSource/Point.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MSource/Wall.hpp> | #include <Grid/Hadrons/Modules/MSource/Wall.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MSource/Z2.hpp> | #include <Grid/Hadrons/Modules/MSource/Z2.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MSource/SeqConserved.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MSink/Smear.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MSink/Point.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MSolver/RBPrecCG.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MGauge/Unit.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MGauge/Random.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MGauge/StochEm.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MGauge/FundtoHirep.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MUtilities/TestSeqGamma.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MUtilities/TestSeqConserved.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MLoop/NoiseLoop.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MScalar/FreeProp.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MScalar/Scalar.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MScalar/ChargedProp.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MAction/DWF.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MAction/Wilson.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MAction/WilsonClover.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MScalarSUN/Div.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MScalarSUN/TrMag.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MScalarSUN/TwoPoint.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MScalarSUN/TrPhi.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MIO/LoadNersc.hpp> | ||||||
|  | #include <Grid/Hadrons/Modules/MIO/LoadBinary.hpp> | ||||||
|   | |||||||
| @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MAction/DWF.hpp | Source file: extras/Hadrons/Modules/MAction/DWF.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -65,6 +65,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -102,16 +103,6 @@ std::vector<std::string> TDWF<FImpl>::getOutput(void) | |||||||
| // setup /////////////////////////////////////////////////////////////////////// | // setup /////////////////////////////////////////////////////////////////////// | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TDWF<FImpl>::setup(void) | void TDWF<FImpl>::setup(void) | ||||||
| { |  | ||||||
|     unsigned int size; |  | ||||||
|      |  | ||||||
|     size = 2*env().template lattice4dSize<typename FImpl::DoubledGaugeField>(); |  | ||||||
|     env().registerObject(getName(), size, par().Ls); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// |  | ||||||
| template <typename FImpl> |  | ||||||
| void TDWF<FImpl>::execute(void) |  | ||||||
| { | { | ||||||
|     LOG(Message) << "Setting up domain wall fermion matrix with m= " |     LOG(Message) << "Setting up domain wall fermion matrix with m= " | ||||||
|                  << par().mass << ", M5= " << par().M5 << " and Ls= " |                  << par().mass << ", M5= " << par().M5 << " and Ls= " | ||||||
| @@ -119,20 +110,24 @@ void TDWF<FImpl>::execute(void) | |||||||
|                  << std::endl; |                  << std::endl; | ||||||
|     LOG(Message) << "Fermion boundary conditions: " << par().boundary |     LOG(Message) << "Fermion boundary conditions: " << par().boundary | ||||||
|                  << std::endl; |                  << std::endl; | ||||||
|  |                   | ||||||
|     env().createGrid(par().Ls); |     env().createGrid(par().Ls); | ||||||
|     auto &U      = *env().template getObject<LatticeGaugeField>(par().gauge); |     auto &U    = envGet(LatticeGaugeField, par().gauge); | ||||||
|     auto &g4   = *env().getGrid(); |     auto &g4   = *env().getGrid(); | ||||||
|     auto &grb4 = *env().getRbGrid(); |     auto &grb4 = *env().getRbGrid(); | ||||||
|     auto &g5   = *env().getGrid(par().Ls); |     auto &g5   = *env().getGrid(par().Ls); | ||||||
|     auto &grb5 = *env().getRbGrid(par().Ls); |     auto &grb5 = *env().getRbGrid(par().Ls); | ||||||
|     std::vector<Complex> boundary = strToVec<Complex>(par().boundary); |     std::vector<Complex> boundary = strToVec<Complex>(par().boundary); | ||||||
|     typename DomainWallFermion<FImpl>::ImplParams implParams(boundary); |     typename DomainWallFermion<FImpl>::ImplParams implParams(boundary); | ||||||
|     FMat *fMatPt = new DomainWallFermion<FImpl>(U, g5, grb5, g4, grb4, |     envCreateDerived(FMat, DomainWallFermion<FImpl>, getName(), par().Ls, U, g5, | ||||||
|                                                 par().mass, par().M5, |                      grb5, g4, grb4, par().mass, par().M5, implParams); | ||||||
|                                                 implParams); |  | ||||||
|     env().setObject(getName(), fMatPt); |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TDWF<FImpl>::execute(void) | ||||||
|  | {} | ||||||
|  |  | ||||||
| END_MODULE_NAMESPACE | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
| END_HADRONS_NAMESPACE | END_HADRONS_NAMESPACE | ||||||
|   | |||||||
| @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MAction/Wilson.hpp | Source file: extras/Hadrons/Modules/MAction/Wilson.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -63,6 +63,7 @@ public: | |||||||
|     // dependencies/products |     // dependencies/products | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -101,29 +102,24 @@ std::vector<std::string> TWilson<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TWilson<FImpl>::setup(void) | void TWilson<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     unsigned int size; |     LOG(Message) << "Setting up TWilson fermion matrix with m= " << par().mass | ||||||
|  |                  << " using gauge field '" << par().gauge << "'" << std::endl; | ||||||
|  |     LOG(Message) << "Fermion boundary conditions: " << par().boundary | ||||||
|  |                  << std::endl; | ||||||
|                   |                   | ||||||
|     size = 2*env().template lattice4dSize<typename FImpl::DoubledGaugeField>(); |     auto &U      = envGet(LatticeGaugeField, par().gauge); | ||||||
|     env().registerObject(getName(), size); |     auto &grid   = *env().getGrid(); | ||||||
|  |     auto &gridRb = *env().getRbGrid(); | ||||||
|  |     std::vector<Complex> boundary = strToVec<Complex>(par().boundary); | ||||||
|  |     typename WilsonFermion<FImpl>::ImplParams implParams(boundary); | ||||||
|  |     envCreateDerived(FMat, WilsonFermion<FImpl>, getName(), 1, U, grid, gridRb, | ||||||
|  |                      par().mass, implParams); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TWilson<FImpl>::execute() | void TWilson<FImpl>::execute() | ||||||
| { | {} | ||||||
|     LOG(Message) << "Setting up TWilson fermion matrix with m= " << par().mass |  | ||||||
|                  << " using gauge field '" << par().gauge << "'" << std::endl; |  | ||||||
|     LOG(Message) << "Fermion boundary conditions: " << par().boundary  |  | ||||||
|                  << std::endl; |  | ||||||
|     auto &U      = *env().template getObject<LatticeGaugeField>(par().gauge); |  | ||||||
|     auto &grid   = *env().getGrid(); |  | ||||||
|     auto &gridRb = *env().getRbGrid(); |  | ||||||
|     std::vector<Complex> boundary = strToVec<Complex>(par().boundary); |  | ||||||
|     typename WilsonFermion<FImpl>::ImplParams implParams(boundary); |  | ||||||
|     FMat *fMatPt = new WilsonFermion<FImpl>(U, grid, gridRb, par().mass, |  | ||||||
|                                             implParams); |  | ||||||
|     env().setObject(getName(), fMatPt); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| END_MODULE_NAMESPACE | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										153
									
								
								extras/Hadrons/Modules/MAction/WilsonClover.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								extras/Hadrons/Modules/MAction/WilsonClover.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,153 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MAction/Wilson.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015 | ||||||
|  | Copyright (C) 2016 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_MAction_WilsonClover_hpp_ | ||||||
|  | #define Hadrons_MAction_WilsonClover_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                            TWilson quark action                            * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MAction) | ||||||
|  |  | ||||||
|  | class WilsonCloverPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverPar, | ||||||
|  |                                     std::string, gauge, | ||||||
|  |                                     double     , mass, | ||||||
|  | 				                    double     , csw_r, | ||||||
|  | 				                    double     , csw_t, | ||||||
|  | 				                    WilsonAnisotropyCoefficients ,clover_anisotropy, | ||||||
|  |                                     std::string, boundary | ||||||
|  | 				    ); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | class TWilsonClover: public Module<WilsonCloverPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     FGS_TYPE_ALIASES(FImpl,); | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TWilsonClover(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TWilsonClover(void) = default; | ||||||
|  |     // dependencies/products | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(WilsonClover, TWilsonClover<FIMPL>, MAction); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                     TWilsonClover template implementation                        * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | TWilsonClover<FImpl>::TWilsonClover(const std::string name) | ||||||
|  | : Module<WilsonCloverPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TWilsonClover<FImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().gauge}; | ||||||
|  |  | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TWilsonClover<FImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |  | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TWilsonClover<FImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     //unsigned int size; | ||||||
|  |  | ||||||
|  |     // size = 2*env().template lattice4dSize<typename FImpl::DoubledGaugeField>(); | ||||||
|  |     // env().registerObject(getName(), size); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     LOG(Message) << "Setting up TWilsonClover fermion matrix with m= " << par().mass | ||||||
|  |                  << " using gauge field '" << par().gauge << "'" << std::endl; | ||||||
|  |     LOG(Message) << "Fermion boundary conditions: " << par().boundary  | ||||||
|  |                  << std::endl; | ||||||
|  |     LOG(Message) << "Clover term csw_r: " << par().csw_r | ||||||
|  |                  << " csw_t: " << par().csw_t | ||||||
|  |                  << std::endl; | ||||||
|  |     auto &U      = envGet(LatticeGaugeField, par().gauge); | ||||||
|  |     auto &grid   = *env().getGrid(); | ||||||
|  |     auto &gridRb = *env().getRbGrid(); | ||||||
|  |     std::vector<Complex> boundary = strToVec<Complex>(par().boundary); | ||||||
|  |     typename WilsonCloverFermion<FImpl>::ImplParams implParams(boundary); | ||||||
|  |     envCreateDerived(FMat, WilsonCloverFermion<FImpl>, getName(), 1, U, grid, gridRb, par().mass, | ||||||
|  | 						  par().csw_r, | ||||||
|  | 						  par().csw_t, | ||||||
|  | 					      par().clover_anisotropy, | ||||||
|  | 						  implParams);  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     //FMat *fMatPt = new WilsonCloverFermion<FImpl>(U, grid, gridRb, par().mass, | ||||||
|  | 	//					  par().csw_r, | ||||||
|  | 	//					  par().csw_t, | ||||||
|  | 	//				      par().clover_anisotropy, | ||||||
|  | 	//					  implParams); | ||||||
|  |     //env().setObject(getName(), fMatPt); | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TWilsonClover<FImpl>::execute() | ||||||
|  | { | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_WilsonClover_hpp_ | ||||||
| @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/Baryon.hpp | Source file: extras/Hadrons/Modules/MContraction/Baryon.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -72,6 +72,9 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
| }; | }; | ||||||
| @@ -99,11 +102,18 @@ std::vector<std::string> TBaryon<FImpl1, FImpl2, FImpl3>::getInput(void) | |||||||
| template <typename FImpl1, typename FImpl2, typename FImpl3> | template <typename FImpl1, typename FImpl2, typename FImpl3> | ||||||
| std::vector<std::string> TBaryon<FImpl1, FImpl2, FImpl3>::getOutput(void) | std::vector<std::string> TBaryon<FImpl1, FImpl2, FImpl3>::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> out = {getName()}; |     std::vector<std::string> out = {}; | ||||||
|      |      | ||||||
|     return out; |     return out; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl1, typename FImpl2, typename FImpl3> | ||||||
|  | void TBaryon<FImpl1, FImpl2, FImpl3>::setup(void) | ||||||
|  | { | ||||||
|  |     envTmpLat(LatticeComplex, "c"); | ||||||
|  | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| template <typename FImpl1, typename FImpl2, typename FImpl3> | template <typename FImpl1, typename FImpl2, typename FImpl3> | ||||||
| void TBaryon<FImpl1, FImpl2, FImpl3>::execute(void) | void TBaryon<FImpl1, FImpl2, FImpl3>::execute(void) | ||||||
| @@ -112,11 +122,11 @@ void TBaryon<FImpl1, FImpl2, FImpl3>::execute(void) | |||||||
|                  << " quarks '" << par().q1 << "', '" << par().q2 << "', and '" |                  << " quarks '" << par().q1 << "', '" << par().q2 << "', and '" | ||||||
|                  << par().q3 << "'" << std::endl; |                  << par().q3 << "'" << std::endl; | ||||||
|      |      | ||||||
|     CorrWriter             writer(par().output); |     ResultWriter writer(RESULT_FILE_NAME(par().output)); | ||||||
|     PropagatorField1      &q1 = *env().template getObject<PropagatorField1>(par().q1); |     auto       &q1 = envGet(PropagatorField1, par().q1); | ||||||
|     PropagatorField2      &q2 = *env().template getObject<PropagatorField2>(par().q2); |     auto       &q2 = envGet(PropagatorField2, par().q2); | ||||||
|     PropagatorField3      &q3 = *env().template getObject<PropagatorField3>(par().q2); |     auto       &q3 = envGet(PropagatorField3, par().q2); | ||||||
|     LatticeComplex        c(env().getGrid()); |     envGetTmp(LatticeComplex, c); | ||||||
|     Result     result; |     Result     result; | ||||||
|      |      | ||||||
|     // FIXME: do contractions |     // FIXME: do contractions | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/DiscLoop.hpp | Source file: extras/Hadrons/Modules/MContraction/DiscLoop.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -68,6 +69,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -97,7 +99,7 @@ std::vector<std::string> TDiscLoop<FImpl>::getInput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| std::vector<std::string> TDiscLoop<FImpl>::getOutput(void) | std::vector<std::string> TDiscLoop<FImpl>::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> out = {getName()}; |     std::vector<std::string> out = {}; | ||||||
|      |      | ||||||
|     return out; |     return out; | ||||||
| } | } | ||||||
| @@ -106,7 +108,7 @@ std::vector<std::string> TDiscLoop<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TDiscLoop<FImpl>::setup(void) | void TDiscLoop<FImpl>::setup(void) | ||||||
| { | { | ||||||
|      |     envTmpLat(LatticeComplex, "c"); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| @@ -117,13 +119,13 @@ void TDiscLoop<FImpl>::execute(void) | |||||||
|                  << "' using '" << par().q_loop << "' with " << par().gamma  |                  << "' using '" << par().q_loop << "' with " << par().gamma  | ||||||
|                  << " insertion." << std::endl; |                  << " insertion." << std::endl; | ||||||
|  |  | ||||||
|     CorrWriter            writer(par().output); |     ResultWriter          writer(RESULT_FILE_NAME(par().output)); | ||||||
|     PropagatorField       &q_loop = *env().template getObject<PropagatorField>(par().q_loop); |     auto                  &q_loop = envGet(PropagatorField, par().q_loop); | ||||||
|     LatticeComplex        c(env().getGrid()); |  | ||||||
|     Gamma                 gamma(par().gamma); |     Gamma                 gamma(par().gamma); | ||||||
|     std::vector<TComplex> buf; |     std::vector<TComplex> buf; | ||||||
|     Result                result; |     Result                result; | ||||||
|  |  | ||||||
|  |     envGetTmp(LatticeComplex, c); | ||||||
|     c = trace(gamma*q_loop); |     c = trace(gamma*q_loop); | ||||||
|     sliceSum(c, buf, Tp); |     sliceSum(c, buf, Tp); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/Gamma3pt.hpp | Source file: extras/Hadrons/Modules/MContraction/Gamma3pt.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -51,6 +52,14 @@ BEGIN_HADRONS_NAMESPACE | |||||||
|  *                   q1 |  *                   q1 | ||||||
|  * |  * | ||||||
|  *      trace(g5*q1*adj(q2)*g5*gamma*q3) |  *      trace(g5*q1*adj(q2)*g5*gamma*q3) | ||||||
|  |  *  | ||||||
|  |  *  options: | ||||||
|  |  *   - q1: sink smeared propagator, source at i | ||||||
|  |  *   - q2: propagator, source at i | ||||||
|  |  *   - q3: propagator, source at f | ||||||
|  |  *   - gamma: gamma matrix to insert | ||||||
|  |  *   - tSnk: sink position for propagator q1. | ||||||
|  |  * | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
| @@ -66,6 +75,7 @@ public: | |||||||
|                                     std::string,    q2, |                                     std::string,    q2, | ||||||
|                                     std::string,    q3, |                                     std::string,    q3, | ||||||
|                                     Gamma::Algebra, gamma, |                                     Gamma::Algebra, gamma, | ||||||
|  |                                     unsigned int,   tSnk, | ||||||
|                                     std::string,    output); |                                     std::string,    output); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -90,6 +100,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -119,7 +130,7 @@ std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getInput(void) | |||||||
| template <typename FImpl1, typename FImpl2, typename FImpl3> | template <typename FImpl1, typename FImpl2, typename FImpl3> | ||||||
| std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getOutput(void) | std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> out = {getName()}; |     std::vector<std::string> out = {}; | ||||||
|      |      | ||||||
|     return out; |     return out; | ||||||
| } | } | ||||||
| @@ -128,7 +139,7 @@ std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getOutput(void) | |||||||
| template <typename FImpl1, typename FImpl2, typename FImpl3> | template <typename FImpl1, typename FImpl2, typename FImpl3> | ||||||
| void TGamma3pt<FImpl1, FImpl2, FImpl3>::setup(void) | void TGamma3pt<FImpl1, FImpl2, FImpl3>::setup(void) | ||||||
| { | { | ||||||
|      |     envTmpLat(LatticeComplex, "c"); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| @@ -140,17 +151,22 @@ void TGamma3pt<FImpl1, FImpl2, FImpl3>::execute(void) | |||||||
|                  << par().q3 << "', with " << par().gamma << " insertion."  |                  << par().q3 << "', with " << par().gamma << " insertion."  | ||||||
|                  << std::endl; |                  << std::endl; | ||||||
|  |  | ||||||
|     CorrWriter            writer(par().output); |     // Initialise variables. q2 and q3 are normal propagators, q1 may be  | ||||||
|     PropagatorField1      &q1 = *env().template getObject<PropagatorField1>(par().q1); |     // sink smeared. | ||||||
|     PropagatorField2      &q2 = *env().template getObject<PropagatorField2>(par().q2); |     ResultWriter          writer(RESULT_FILE_NAME(par().output)); | ||||||
|     PropagatorField3      &q3 = *env().template getObject<PropagatorField3>(par().q3); |     auto                  &q1 = envGet(SlicedPropagator1, par().q1); | ||||||
|     LatticeComplex        c(env().getGrid()); |     auto                  &q2 = envGet(PropagatorField2, par().q2); | ||||||
|  |     auto                  &q3 = envGet(PropagatorField2, par().q3); | ||||||
|     Gamma                 g5(Gamma::Algebra::Gamma5); |     Gamma                 g5(Gamma::Algebra::Gamma5); | ||||||
|     Gamma                 gamma(par().gamma); |     Gamma                 gamma(par().gamma); | ||||||
|     std::vector<TComplex> buf; |     std::vector<TComplex> buf; | ||||||
|     Result                result; |     Result                result; | ||||||
|      |      | ||||||
|     c = trace(g5*q1*adj(q2)*(g5*gamma)*q3); |     // Extract relevant timeslice of sinked propagator q1, then contract & | ||||||
|  |     // sum over all spacial positions of gamma insertion. | ||||||
|  |     SitePropagator1 q1Snk = q1[par().tSnk]; | ||||||
|  |     envGetTmp(LatticeComplex, c); | ||||||
|  |     c = trace(g5*q1Snk*adj(q2)*(g5*gamma)*q3); | ||||||
|     sliceSum(c, buf, Tp); |     sliceSum(c, buf, Tp); | ||||||
|  |  | ||||||
|     result.gamma = par().gamma; |     result.gamma = par().gamma; | ||||||
|   | |||||||
| @@ -4,12 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/Meson.hpp | Source file: extras/Hadrons/Modules/MContraction/Meson.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
| Copyright (C) 2017 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|         Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -51,8 +49,7 @@ BEGIN_HADRONS_NAMESPACE | |||||||
|            in a sequence (e.g. "<Gamma5 Gamma5><Gamma5 GammaT>"). |            in a sequence (e.g. "<Gamma5 Gamma5><Gamma5 GammaT>"). | ||||||
|  |  | ||||||
|            Special values: "all" - perform all possible contractions. |            Special values: "all" - perform all possible contractions. | ||||||
|  - mom: momentum insertion, space-separated float sequence (e.g ".1 .2 1. 0."), |  - sink: module to compute the sink to use in contraction (string). | ||||||
|         given as multiples of (2*pi) / L. |  | ||||||
| */ | */ | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
| @@ -98,6 +95,9 @@ public: | |||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|     virtual void parseGammaString(std::vector<GammaPair> &gammaList); |     virtual void parseGammaString(std::vector<GammaPair> &gammaList); | ||||||
|  | protected: | ||||||
|  |     // execution | ||||||
|  |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
| }; | }; | ||||||
| @@ -125,7 +125,7 @@ std::vector<std::string> TMeson<FImpl1, FImpl2>::getInput(void) | |||||||
| template <typename FImpl1, typename FImpl2> | template <typename FImpl1, typename FImpl2> | ||||||
| std::vector<std::string> TMeson<FImpl1, FImpl2>::getOutput(void) | std::vector<std::string> TMeson<FImpl1, FImpl2>::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> output = {getName()}; |     std::vector<std::string> output = {}; | ||||||
|      |      | ||||||
|     return output; |     return output; | ||||||
| } | } | ||||||
| @@ -154,6 +154,12 @@ void TMeson<FImpl1, FImpl2>::parseGammaString(std::vector<GammaPair> &gammaList) | |||||||
|     }  |     }  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl1, typename FImpl2> | ||||||
|  | void TMeson<FImpl1, FImpl2>::setup(void) | ||||||
|  | { | ||||||
|  |     envTmpLat(LatticeComplex, "c"); | ||||||
|  | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| #define mesonConnected(q1, q2, gSnk, gSrc) \ | #define mesonConnected(q1, q2, gSnk, gSrc) \ | ||||||
| @@ -166,7 +172,7 @@ void TMeson<FImpl1, FImpl2>::execute(void) | |||||||
|                  << " quarks '" << par().q1 << "' and '" << par().q2 << "'" |                  << " quarks '" << par().q1 << "' and '" << par().q2 << "'" | ||||||
|                  << std::endl; |                  << std::endl; | ||||||
|      |      | ||||||
|     CorrWriter             writer(par().output); |     ResultWriter           writer(RESULT_FILE_NAME(par().output)); | ||||||
|     std::vector<TComplex>  buf; |     std::vector<TComplex>  buf; | ||||||
|     std::vector<Result>    result; |     std::vector<Result>    result; | ||||||
|     Gamma                  g5(Gamma::Algebra::Gamma5); |     Gamma                  g5(Gamma::Algebra::Gamma5); | ||||||
| @@ -181,11 +187,11 @@ void TMeson<FImpl1, FImpl2>::execute(void) | |||||||
|         result[i].gamma_src = gammaList[i].second; |         result[i].gamma_src = gammaList[i].second; | ||||||
|         result[i].corr.resize(nt); |         result[i].corr.resize(nt); | ||||||
|     } |     } | ||||||
|     if (env().template isObjectOfType<SlicedPropagator1>(par().q1) and |     if (envHasType(SlicedPropagator1, par().q1) and | ||||||
|         env().template isObjectOfType<SlicedPropagator2>(par().q2)) |         envHasType(SlicedPropagator2, par().q2)) | ||||||
|     { |     { | ||||||
|         SlicedPropagator1 &q1 = *env().template getObject<SlicedPropagator1>(par().q1); |         auto &q1 = envGet(SlicedPropagator1, par().q1); | ||||||
|         SlicedPropagator2 &q2 = *env().template getObject<SlicedPropagator2>(par().q2); |         auto &q2 = envGet(SlicedPropagator2, par().q2); | ||||||
|          |          | ||||||
|         LOG(Message) << "(propagator already sinked)" << std::endl; |         LOG(Message) << "(propagator already sinked)" << std::endl; | ||||||
|         for (unsigned int i = 0; i < result.size(); ++i) |         for (unsigned int i = 0; i < result.size(); ++i) | ||||||
| @@ -201,10 +207,10 @@ void TMeson<FImpl1, FImpl2>::execute(void) | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         PropagatorField1 &q1   = *env().template getObject<PropagatorField1>(par().q1); |         auto &q1 = envGet(PropagatorField1, par().q1); | ||||||
|         PropagatorField2 &q2   = *env().template getObject<PropagatorField2>(par().q2); |         auto &q2 = envGet(PropagatorField2, par().q2); | ||||||
|         LatticeComplex   c(env().getGrid()); |  | ||||||
|          |          | ||||||
|  |         envGetTmp(LatticeComplex, c); | ||||||
|         LOG(Message) << "(using sink '" << par().sink << "')" << std::endl; |         LOG(Message) << "(using sink '" << par().sink << "')" << std::endl; | ||||||
|         for (unsigned int i = 0; i < result.size(); ++i) |         for (unsigned int i = 0; i < result.size(); ++i) | ||||||
|         { |         { | ||||||
| @@ -212,18 +218,17 @@ void TMeson<FImpl1, FImpl2>::execute(void) | |||||||
|             Gamma       gSrc(gammaList[i].second); |             Gamma       gSrc(gammaList[i].second); | ||||||
|             std::string ns; |             std::string ns; | ||||||
|                  |                  | ||||||
|             ns = env().getModuleNamespace(env().getObjectModule(par().sink)); |             ns = vm().getModuleNamespace(env().getObjectModule(par().sink)); | ||||||
|             if (ns == "MSource") |             if (ns == "MSource") | ||||||
|             { |             { | ||||||
|                 PropagatorField1 &sink = |                 PropagatorField1 &sink = envGet(PropagatorField1, par().sink); | ||||||
|                     *env().template getObject<PropagatorField1>(par().sink); |  | ||||||
|                  |                  | ||||||
|                 c = trace(mesonConnected(q1, q2, gSnk, gSrc)*sink); |                 c = trace(mesonConnected(q1, q2, gSnk, gSrc)*sink); | ||||||
|                 sliceSum(c, buf, Tp); |                 sliceSum(c, buf, Tp); | ||||||
|             } |             } | ||||||
|             else if (ns == "MSink") |             else if (ns == "MSink") | ||||||
|             { |             { | ||||||
|                 SinkFnScalar &sink = *env().template getObject<SinkFnScalar>(par().sink); |                 SinkFnScalar &sink = envGet(SinkFnScalar, par().sink); | ||||||
|                  |                  | ||||||
|                 c   = trace(mesonConnected(q1, q2, gSnk, gSrc)); |                 c   = trace(mesonConnected(q1, q2, gSnk, gSrc)); | ||||||
|                 buf = sink(c); |                 buf = sink(c); | ||||||
|   | |||||||
							
								
								
									
										224
									
								
								extras/Hadrons/Modules/MContraction/WardIdentity.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								extras/Hadrons/Modules/MContraction/WardIdentity.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,224 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MContraction/WardIdentity.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_MContraction_WardIdentity_hpp_ | ||||||
|  | #define Hadrons_MContraction_WardIdentity_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |   Ward Identity contractions | ||||||
|  |  ----------------------------- | ||||||
|  |   | ||||||
|  |  * options: | ||||||
|  |  - q:          propagator, 5D if available (string) | ||||||
|  |  - action:     action module used for propagator solution (string) | ||||||
|  |  - mass:       mass of quark (double) | ||||||
|  |  - test_axial: whether or not to test PCAC relation. | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                              WardIdentity                                  * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MContraction) | ||||||
|  |  | ||||||
|  | class WardIdentityPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(WardIdentityPar, | ||||||
|  |                                     std::string, q, | ||||||
|  |                                     std::string, action, | ||||||
|  |                                     double,      mass, | ||||||
|  |                                     bool,        test_axial); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | class TWardIdentity: public Module<WardIdentityPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     FERM_TYPE_ALIASES(FImpl,); | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TWardIdentity(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TWardIdentity(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | private: | ||||||
|  |     unsigned int Ls_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(WardIdentity, TWardIdentity<FIMPL>, MContraction); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                     TWardIdentity implementation                           * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | TWardIdentity<FImpl>::TWardIdentity(const std::string name) | ||||||
|  | : Module<WardIdentityPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TWardIdentity<FImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().q, par().action}; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TWardIdentity<FImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {}; | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TWardIdentity<FImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     Ls_ = env().getObjectLs(par().q); | ||||||
|  |     if (Ls_ != env().getObjectLs(par().action)) | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Size, "Ls mismatch between quark action and propagator"); | ||||||
|  |     } | ||||||
|  |     envTmpLat(PropagatorField, "tmp"); | ||||||
|  |     envTmpLat(PropagatorField, "vector_WI"); | ||||||
|  |     if (par().test_axial) | ||||||
|  |     { | ||||||
|  |         envTmpLat(PropagatorField, "psi"); | ||||||
|  |         envTmpLat(LatticeComplex,  "PP"); | ||||||
|  |         envTmpLat(LatticeComplex,  "axial_defect"); | ||||||
|  |         envTmpLat(LatticeComplex,  "PJ5q"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TWardIdentity<FImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     LOG(Message) << "Performing Ward Identity checks for quark '" << par().q | ||||||
|  |                  << "'." << std::endl; | ||||||
|  |  | ||||||
|  |     auto  &q   = envGet(PropagatorField, par().q); | ||||||
|  |     auto  &act = envGet(FMat, par().action); | ||||||
|  |     Gamma g5(Gamma::Algebra::Gamma5); | ||||||
|  |  | ||||||
|  |     // Compute D_mu V_mu, D here is backward derivative. | ||||||
|  |     envGetTmp(PropagatorField, tmp); | ||||||
|  |     envGetTmp(PropagatorField, vector_WI); | ||||||
|  |     vector_WI    = zero; | ||||||
|  |     for (unsigned int mu = 0; mu < Nd; ++mu) | ||||||
|  |     { | ||||||
|  |         act.ContractConservedCurrent(q, q, tmp, Current::Vector, mu); | ||||||
|  |         tmp -= Cshift(tmp, mu, -1); | ||||||
|  |         vector_WI += tmp; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Test ward identity D_mu V_mu = 0; | ||||||
|  |     LOG(Message) << "Vector Ward Identity check Delta_mu V_mu = "  | ||||||
|  |                  << norm2(vector_WI) << std::endl; | ||||||
|  |  | ||||||
|  |     if (par().test_axial) | ||||||
|  |     { | ||||||
|  |         envGetTmp(PropagatorField, psi); | ||||||
|  |         envGetTmp(LatticeComplex, PP); | ||||||
|  |         envGetTmp(LatticeComplex, axial_defect); | ||||||
|  |         envGetTmp(LatticeComplex, PJ5q); | ||||||
|  |         std::vector<TComplex> axial_buf; | ||||||
|  |  | ||||||
|  |         // Compute <P|D_mu A_mu>, D is backwards derivative. | ||||||
|  |         axial_defect = zero; | ||||||
|  |         for (unsigned int mu = 0; mu < Nd; ++mu) | ||||||
|  |         { | ||||||
|  |             act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu); | ||||||
|  |             tmp -= Cshift(tmp, mu, -1); | ||||||
|  |             axial_defect += trace(g5*tmp); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Get <P|J5q> for 5D (zero for 4D) and <P|P>. | ||||||
|  |         PJ5q = zero; | ||||||
|  |         if (Ls_ > 1) | ||||||
|  |         { | ||||||
|  |             // <P|P> | ||||||
|  |             ExtractSlice(tmp, q, 0, 0); | ||||||
|  |             psi  = 0.5 * (tmp - g5*tmp); | ||||||
|  |             ExtractSlice(tmp, q, Ls_ - 1, 0); | ||||||
|  |             psi += 0.5 * (tmp + g5*tmp); | ||||||
|  |             PP = trace(adj(psi)*psi); | ||||||
|  |  | ||||||
|  |             // <P|5Jq> | ||||||
|  |             ExtractSlice(tmp, q, Ls_/2 - 1, 0); | ||||||
|  |             psi  = 0.5 * (tmp + g5*tmp); | ||||||
|  |             ExtractSlice(tmp, q, Ls_/2, 0); | ||||||
|  |             psi += 0.5 * (tmp - g5*tmp); | ||||||
|  |             PJ5q = trace(adj(psi)*psi); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             PP = trace(adj(q)*q); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Test ward identity <P|D_mu A_mu> = 2m<P|P> + 2<P|J5q> | ||||||
|  |         LOG(Message) << "|D_mu A_mu|^2 = " << norm2(axial_defect) << std::endl; | ||||||
|  |         LOG(Message) << "|PP|^2        = " << norm2(PP) << std::endl; | ||||||
|  |         LOG(Message) << "|PJ5q|^2      = " << norm2(PJ5q) << std::endl; | ||||||
|  |         LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = " | ||||||
|  |                      << norm2(axial_defect) << std::endl; | ||||||
|  |      | ||||||
|  |         // Axial defect by timeslice. | ||||||
|  |         axial_defect -= 2.*(par().mass*PP + PJ5q); | ||||||
|  |         LOG(Message) << "Check Axial defect by timeslice" << std::endl; | ||||||
|  |         sliceSum(axial_defect, axial_buf, Tp); | ||||||
|  |         for (int t = 0; t < axial_buf.size(); ++t) | ||||||
|  |         { | ||||||
|  |             LOG(Message) << "t = " << t << ": "  | ||||||
|  |                          << TensorRemove(axial_buf[t]) << std::endl; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_WardIdentity_hpp_ | ||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp | Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -76,6 +77,7 @@ public: | |||||||
|                                     std::string, q2, |                                     std::string, q2, | ||||||
|                                     std::string, q3, |                                     std::string, q3, | ||||||
|                                     std::string, q4, |                                     std::string, q4, | ||||||
|  |                                     unsigned int, tSnk, | ||||||
|                                     std::string, output); |                                     std::string, output); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -99,11 +101,13 @@ public:\ | |||||||
|     /* dependency relation */ \ |     /* dependency relation */ \ | ||||||
|     virtual std::vector<std::string> getInput(void);\ |     virtual std::vector<std::string> getInput(void);\ | ||||||
|     virtual std::vector<std::string> getOutput(void);\ |     virtual std::vector<std::string> getOutput(void);\ | ||||||
|  | public:\ | ||||||
|  |     std::vector<std::string> VA_label = {"V", "A"};\ | ||||||
|  | protected:\ | ||||||
|     /* setup */ \ |     /* setup */ \ | ||||||
|     virtual void setup(void);\ |     virtual void setup(void);\ | ||||||
|     /* execution */ \ |     /* execution */ \ | ||||||
|     virtual void execute(void);\ |     virtual void execute(void);\ | ||||||
|     std::vector<std::string> VA_label = {"V", "A"};\ |  | ||||||
| };\ | };\ | ||||||
| MODULE_REGISTER_NS(modname, T##modname, MContraction); | MODULE_REGISTER_NS(modname, T##modname, MContraction); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc | Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -54,6 +55,8 @@ using namespace MContraction; | |||||||
|  *  |  *  | ||||||
|  * S: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1]*q4*gL[mu][p_2]) |  * S: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1]*q4*gL[mu][p_2]) | ||||||
|  * E: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1])*trace(q4*gL[mu][p_2]) |  * E: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1])*trace(q4*gL[mu][p_2]) | ||||||
|  |  *  | ||||||
|  |  * Note q1 must be sink smeared. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
| @@ -74,7 +77,7 @@ std::vector<std::string> TWeakHamiltonianEye::getInput(void) | |||||||
|  |  | ||||||
| std::vector<std::string> TWeakHamiltonianEye::getOutput(void) | std::vector<std::string> TWeakHamiltonianEye::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> out = {getName()}; |     std::vector<std::string> out = {}; | ||||||
|      |      | ||||||
|     return out; |     return out; | ||||||
| } | } | ||||||
| @@ -82,7 +85,15 @@ std::vector<std::string> TWeakHamiltonianEye::getOutput(void) | |||||||
| // setup /////////////////////////////////////////////////////////////////////// | // setup /////////////////////////////////////////////////////////////////////// | ||||||
| void TWeakHamiltonianEye::setup(void) | void TWeakHamiltonianEye::setup(void) | ||||||
| { | { | ||||||
|  |     unsigned int ndim = env().getNd(); | ||||||
|  |  | ||||||
|  |     envTmpLat(LatticeComplex,  "expbuf"); | ||||||
|  |     envTmpLat(PropagatorField, "tmp1"); | ||||||
|  |     envTmpLat(LatticeComplex,  "tmp2"); | ||||||
|  |     envTmp(std::vector<PropagatorField>, "S_body", 1, ndim, PropagatorField(env().getGrid())); | ||||||
|  |     envTmp(std::vector<PropagatorField>, "S_loop", 1, ndim, PropagatorField(env().getGrid())); | ||||||
|  |     envTmp(std::vector<LatticeComplex>,  "E_body", 1, ndim, LatticeComplex(env().getGrid())); | ||||||
|  |     envTmp(std::vector<LatticeComplex>,  "E_loop", 1, ndim, LatticeComplex(env().getGrid())); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| @@ -93,28 +104,31 @@ void TWeakHamiltonianEye::execute(void) | |||||||
|                  << par().q2 << ", '" << par().q3 << "' and '" << par().q4  |                  << par().q2 << ", '" << par().q3 << "' and '" << par().q4  | ||||||
|                  << "'." << std::endl; |                  << "'." << std::endl; | ||||||
|  |  | ||||||
|     CorrWriter             writer(par().output); |     ResultWriter           writer(RESULT_FILE_NAME(par().output)); | ||||||
|     PropagatorField &q1 = *env().template getObject<PropagatorField>(par().q1); |     auto                   &q1 = envGet(SlicedPropagator, par().q1); | ||||||
|     PropagatorField &q2 = *env().template getObject<PropagatorField>(par().q2); |     auto                   &q2 = envGet(PropagatorField, par().q2); | ||||||
|     PropagatorField &q3 = *env().template getObject<PropagatorField>(par().q3); |     auto                   &q3 = envGet(PropagatorField, par().q3); | ||||||
|     PropagatorField &q4 = *env().template getObject<PropagatorField>(par().q4); |     auto                   &q4 = envGet(PropagatorField, par().q4); | ||||||
|     Gamma                  g5  = Gamma(Gamma::Algebra::Gamma5); |     Gamma                  g5  = Gamma(Gamma::Algebra::Gamma5); | ||||||
|     LatticeComplex        expbuf(env().getGrid()); |  | ||||||
|     std::vector<TComplex>  corrbuf; |     std::vector<TComplex>  corrbuf; | ||||||
|     std::vector<Result>    result(n_eye_diag); |     std::vector<Result>    result(n_eye_diag); | ||||||
|     unsigned int ndim    = env().getNd(); |     unsigned int ndim    = env().getNd(); | ||||||
|  |  | ||||||
|     PropagatorField              tmp1(env().getGrid()); |     envGetTmp(LatticeComplex,               expbuf);  | ||||||
|     LatticeComplex               tmp2(env().getGrid()); |     envGetTmp(PropagatorField,              tmp1); | ||||||
|     std::vector<PropagatorField> S_body(ndim, tmp1); |     envGetTmp(LatticeComplex,               tmp2); | ||||||
|     std::vector<PropagatorField> S_loop(ndim, tmp1); |     envGetTmp(std::vector<PropagatorField>, S_body); | ||||||
|     std::vector<LatticeComplex>  E_body(ndim, tmp2); |     envGetTmp(std::vector<PropagatorField>, S_loop); | ||||||
|     std::vector<LatticeComplex>  E_loop(ndim, tmp2); |     envGetTmp(std::vector<LatticeComplex>,  E_body); | ||||||
|  |     envGetTmp(std::vector<LatticeComplex>,  E_loop); | ||||||
|  |  | ||||||
|  |     // Get sink timeslice of q1. | ||||||
|  |     SitePropagator q1Snk = q1[par().tSnk]; | ||||||
|  |  | ||||||
|     // Setup for S-type contractions. |     // Setup for S-type contractions. | ||||||
|     for (int mu = 0; mu < ndim; ++mu) |     for (int mu = 0; mu < ndim; ++mu) | ||||||
|     { |     { | ||||||
|         S_body[mu] = MAKE_SE_BODY(q1, q2, q3, GammaL(Gamma::gmu[mu])); |         S_body[mu] = MAKE_SE_BODY(q1Snk, q2, q3, GammaL(Gamma::gmu[mu])); | ||||||
|         S_loop[mu] = MAKE_SE_LOOP(q4, GammaL(Gamma::gmu[mu])); |         S_loop[mu] = MAKE_SE_LOOP(q4, GammaL(Gamma::gmu[mu])); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp | Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc | Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -76,7 +77,7 @@ std::vector<std::string> TWeakHamiltonianNonEye::getInput(void) | |||||||
|  |  | ||||||
| std::vector<std::string> TWeakHamiltonianNonEye::getOutput(void) | std::vector<std::string> TWeakHamiltonianNonEye::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> out = {getName()}; |     std::vector<std::string> out = {}; | ||||||
|      |      | ||||||
|     return out; |     return out; | ||||||
| } | } | ||||||
| @@ -84,7 +85,15 @@ std::vector<std::string> TWeakHamiltonianNonEye::getOutput(void) | |||||||
| // setup /////////////////////////////////////////////////////////////////////// | // setup /////////////////////////////////////////////////////////////////////// | ||||||
| void TWeakHamiltonianNonEye::setup(void) | void TWeakHamiltonianNonEye::setup(void) | ||||||
| { | { | ||||||
|  |     unsigned int ndim = env().getNd(); | ||||||
|  |  | ||||||
|  |     envTmpLat(LatticeComplex,  "expbuf"); | ||||||
|  |     envTmpLat(PropagatorField, "tmp1"); | ||||||
|  |     envTmpLat(LatticeComplex,  "tmp2"); | ||||||
|  |     envTmp(std::vector<PropagatorField>, "C_i_side_loop", 1, ndim, PropagatorField(env().getGrid())); | ||||||
|  |     envTmp(std::vector<PropagatorField>, "C_f_side_loop", 1, ndim, PropagatorField(env().getGrid())); | ||||||
|  |     envTmp(std::vector<LatticeComplex>,  "W_i_side_loop", 1, ndim, LatticeComplex(env().getGrid())); | ||||||
|  |     envTmp(std::vector<LatticeComplex>,  "W_f_side_loop", 1, ndim, LatticeComplex(env().getGrid())); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| @@ -95,23 +104,23 @@ void TWeakHamiltonianNonEye::execute(void) | |||||||
|                  << par().q2 << ", '" << par().q3 << "' and '" << par().q4  |                  << par().q2 << ", '" << par().q3 << "' and '" << par().q4  | ||||||
|                  << "'." << std::endl; |                  << "'." << std::endl; | ||||||
|      |      | ||||||
|     CorrWriter             writer(par().output); |     ResultWriter          writer(RESULT_FILE_NAME(par().output)); | ||||||
|     PropagatorField &q1 = *env().template getObject<PropagatorField>(par().q1); |     auto                  &q1 = envGet(PropagatorField, par().q1); | ||||||
|     PropagatorField &q2 = *env().template getObject<PropagatorField>(par().q2); |     auto                  &q2 = envGet(PropagatorField, par().q2); | ||||||
|     PropagatorField &q3 = *env().template getObject<PropagatorField>(par().q3); |     auto                  &q3 = envGet(PropagatorField, par().q3); | ||||||
|     PropagatorField &q4 = *env().template getObject<PropagatorField>(par().q4); |     auto                  &q4 = envGet(PropagatorField, par().q4); | ||||||
|     Gamma                 g5  = Gamma(Gamma::Algebra::Gamma5); |     Gamma                 g5  = Gamma(Gamma::Algebra::Gamma5); | ||||||
|     LatticeComplex        expbuf(env().getGrid()); |  | ||||||
|     std::vector<TComplex> corrbuf; |     std::vector<TComplex> corrbuf; | ||||||
|     std::vector<Result>   result(n_noneye_diag);  |     std::vector<Result>   result(n_noneye_diag);  | ||||||
|     unsigned int          ndim = env().getNd(); |     unsigned int          ndim = env().getNd(); | ||||||
|  |  | ||||||
|     PropagatorField              tmp1(env().getGrid()); |     envGetTmp(LatticeComplex,               expbuf);  | ||||||
|     LatticeComplex               tmp2(env().getGrid()); |     envGetTmp(PropagatorField,              tmp1); | ||||||
|     std::vector<PropagatorField> C_i_side_loop(ndim, tmp1); |     envGetTmp(LatticeComplex,               tmp2); | ||||||
|     std::vector<PropagatorField> C_f_side_loop(ndim, tmp1); |     envGetTmp(std::vector<PropagatorField>, C_i_side_loop); | ||||||
|     std::vector<LatticeComplex>  W_i_side_loop(ndim, tmp2); |     envGetTmp(std::vector<PropagatorField>, C_f_side_loop); | ||||||
|     std::vector<LatticeComplex>  W_f_side_loop(ndim, tmp2); |     envGetTmp(std::vector<LatticeComplex>,  W_i_side_loop); | ||||||
|  |     envGetTmp(std::vector<LatticeComplex>,  W_f_side_loop); | ||||||
|  |  | ||||||
|     // Setup for C-type contractions. |     // Setup for C-type contractions. | ||||||
|     for (int mu = 0; mu < ndim; ++mu) |     for (int mu = 0; mu < ndim; ++mu) | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp | Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc | Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -78,7 +79,7 @@ std::vector<std::string> TWeakNeutral4ptDisc::getInput(void) | |||||||
|  |  | ||||||
| std::vector<std::string> TWeakNeutral4ptDisc::getOutput(void) | std::vector<std::string> TWeakNeutral4ptDisc::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> out = {getName()}; |     std::vector<std::string> out = {}; | ||||||
|      |      | ||||||
|     return out; |     return out; | ||||||
| } | } | ||||||
| @@ -86,7 +87,13 @@ std::vector<std::string> TWeakNeutral4ptDisc::getOutput(void) | |||||||
| // setup /////////////////////////////////////////////////////////////////////// | // setup /////////////////////////////////////////////////////////////////////// | ||||||
| void TWeakNeutral4ptDisc::setup(void) | void TWeakNeutral4ptDisc::setup(void) | ||||||
| { | { | ||||||
|  |     unsigned int ndim = env().getNd(); | ||||||
|  |  | ||||||
|  |     envTmpLat(LatticeComplex,  "expbuf"); | ||||||
|  |     envTmpLat(PropagatorField, "tmp"); | ||||||
|  |     envTmpLat(LatticeComplex,  "curr"); | ||||||
|  |     envTmp(std::vector<PropagatorField>, "meson", 1, ndim, PropagatorField(env().getGrid())); | ||||||
|  |     envTmp(std::vector<PropagatorField>, "loop", 1, ndim,  PropagatorField(env().getGrid())); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| @@ -97,21 +104,21 @@ void TWeakNeutral4ptDisc::execute(void) | |||||||
|                  << par().q2 << ", '" << par().q3 << "' and '" << par().q4  |                  << par().q2 << ", '" << par().q3 << "' and '" << par().q4  | ||||||
|                  << "'." << std::endl; |                  << "'." << std::endl; | ||||||
|  |  | ||||||
|     CorrWriter             writer(par().output); |     ResultWriter          writer(RESULT_FILE_NAME(par().output)); | ||||||
|     PropagatorField &q1 = *env().template getObject<PropagatorField>(par().q1); |     auto                  &q1 = envGet(PropagatorField, par().q1); | ||||||
|     PropagatorField &q2 = *env().template getObject<PropagatorField>(par().q2); |     auto                  &q2 = envGet(PropagatorField, par().q2); | ||||||
|     PropagatorField &q3 = *env().template getObject<PropagatorField>(par().q3); |     auto                  &q3 = envGet(PropagatorField, par().q3); | ||||||
|     PropagatorField &q4 = *env().template getObject<PropagatorField>(par().q4); |     auto                  &q4 = envGet(PropagatorField, par().q4); | ||||||
|     Gamma                 g5  = Gamma(Gamma::Algebra::Gamma5); |     Gamma                 g5  = Gamma(Gamma::Algebra::Gamma5); | ||||||
|     LatticeComplex        expbuf(env().getGrid()); |  | ||||||
|     std::vector<TComplex> corrbuf; |     std::vector<TComplex> corrbuf; | ||||||
|     std::vector<Result>   result(n_neut_disc_diag); |     std::vector<Result>   result(n_neut_disc_diag); | ||||||
|     unsigned int          ndim = env().getNd(); |     unsigned int          ndim = env().getNd(); | ||||||
|  |  | ||||||
|     PropagatorField              tmp(env().getGrid()); |     envGetTmp(LatticeComplex,               expbuf);  | ||||||
|     std::vector<PropagatorField> meson(ndim, tmp); |     envGetTmp(PropagatorField,              tmp); | ||||||
|     std::vector<PropagatorField> loop(ndim, tmp); |     envGetTmp(LatticeComplex,               curr); | ||||||
|     LatticeComplex               curr(env().getGrid()); |     envGetTmp(std::vector<PropagatorField>, meson); | ||||||
|  |     envGetTmp(std::vector<PropagatorField>, loop); | ||||||
|  |  | ||||||
|     // Setup for type 1 contractions. |     // Setup for type 1 contractions. | ||||||
|     for (int mu = 0; mu < ndim; ++mu) |     for (int mu = 0; mu < ndim; ++mu) | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp | Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson    <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
|   | |||||||
| @@ -1,3 +1,32 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MFermion/GaugeProp.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
| #ifndef Hadrons_MFermion_GaugeProp_hpp_ | #ifndef Hadrons_MFermion_GaugeProp_hpp_ | ||||||
| #define Hadrons_MFermion_GaugeProp_hpp_ | #define Hadrons_MFermion_GaugeProp_hpp_ | ||||||
|  |  | ||||||
| @@ -7,6 +36,27 @@ | |||||||
|  |  | ||||||
| BEGIN_HADRONS_NAMESPACE | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  * 5D -> 4D and 4D -> 5D conversions.                                         * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | template<class vobj> // Note that 5D object is modified. | ||||||
|  | inline void make_4D(Lattice<vobj> &in_5d, Lattice<vobj> &out_4d, int Ls) | ||||||
|  | { | ||||||
|  |     axpby_ssp_pminus(in_5d, 0., in_5d, 1., in_5d, 0, 0); | ||||||
|  |     axpby_ssp_pplus(in_5d, 1., in_5d, 1., in_5d, 0, Ls-1); | ||||||
|  |     ExtractSlice(out_4d, in_5d, 0, 0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template<class vobj> | ||||||
|  | inline void make_5D(Lattice<vobj> &in_4d, Lattice<vobj> &out_5d, int Ls) | ||||||
|  | { | ||||||
|  |     out_5d = zero; | ||||||
|  |     InsertSlice(in_4d, out_5d, 0, 0); | ||||||
|  |     InsertSlice(in_4d, out_5d, Ls-1, 0); | ||||||
|  |     axpby_ssp_pplus(out_5d, 0., out_5d, 1., out_5d, 0, 0); | ||||||
|  |     axpby_ssp_pminus(out_5d, 0., out_5d, 1., out_5d, Ls-1, Ls-1); | ||||||
|  | } | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                                GaugeProp                                   * |  *                                GaugeProp                                   * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| @@ -33,6 +83,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -43,7 +94,6 @@ private: | |||||||
| }; | }; | ||||||
|  |  | ||||||
| MODULE_REGISTER_NS(GaugeProp, TGaugeProp<FIMPL>, MFermion); | MODULE_REGISTER_NS(GaugeProp, TGaugeProp<FIMPL>, MFermion); | ||||||
|  |  | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                      TGaugeProp implementation                             * |  *                      TGaugeProp implementation                             * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| @@ -75,10 +125,13 @@ template <typename FImpl> | |||||||
| void TGaugeProp<FImpl>::setup(void) | void TGaugeProp<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     Ls_ = env().getObjectLs(par().solver); |     Ls_ = env().getObjectLs(par().solver); | ||||||
|     env().template registerLattice<PropagatorField>(getName()); |     envCreateLat(PropagatorField, getName()); | ||||||
|  |     envTmpLat(FermionField, "source", Ls_); | ||||||
|  |     envTmpLat(FermionField, "sol", Ls_); | ||||||
|  |     envTmpLat(FermionField, "tmp"); | ||||||
|     if (Ls_ > 1) |     if (Ls_ > 1) | ||||||
|     { |     { | ||||||
|         env().template registerLattice<PropagatorField>(getName() + "_5d", Ls_); |         envCreateLat(PropagatorField, getName() + "_5d", Ls_); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -89,21 +142,18 @@ void TGaugeProp<FImpl>::execute(void) | |||||||
|     LOG(Message) << "Computing quark propagator '" << getName() << "'" |     LOG(Message) << "Computing quark propagator '" << getName() << "'" | ||||||
|                  << std::endl; |                  << std::endl; | ||||||
|      |      | ||||||
|     FermionField    source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)), |  | ||||||
|     tmp(env().getGrid()); |  | ||||||
|     std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); |     std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); | ||||||
|     PropagatorField &prop    = *env().template createLattice<PropagatorField>(propName); |     auto        &prop    = envGet(PropagatorField, propName); | ||||||
|     PropagatorField &fullSrc = *env().template getObject<PropagatorField>(par().source); |     auto        &fullSrc = envGet(PropagatorField, par().source); | ||||||
|     SolverFn        &solver  = *env().template getObject<SolverFn>(par().solver); |     auto        &solver  = envGet(SolverFn, par().solver); | ||||||
|     if (Ls_ > 1) |  | ||||||
|     { |  | ||||||
|         env().template createLattice<PropagatorField>(getName()); |  | ||||||
|     } |  | ||||||
|      |      | ||||||
|  |     envGetTmp(FermionField, source); | ||||||
|  |     envGetTmp(FermionField, sol); | ||||||
|  |     envGetTmp(FermionField, tmp); | ||||||
|     LOG(Message) << "Inverting using solver '" << par().solver |     LOG(Message) << "Inverting using solver '" << par().solver | ||||||
|                  << "' on source '" << par().source << "'" << std::endl; |                  << "' on source '" << par().source << "'" << std::endl; | ||||||
|     for (unsigned int s = 0; s < Ns; ++s) |     for (unsigned int s = 0; s < Ns; ++s) | ||||||
|     for (unsigned int c = 0; c < Nc; ++c) |       for (unsigned int c = 0; c < FImpl::Dimension; ++c) | ||||||
|     { |     { | ||||||
|         LOG(Message) << "Inversion for spin= " << s << ", color= " << c |         LOG(Message) << "Inversion for spin= " << s << ", color= " << c | ||||||
|                      << std::endl; |                      << std::endl; | ||||||
| @@ -112,16 +162,12 @@ void TGaugeProp<FImpl>::execute(void) | |||||||
|         { |         { | ||||||
|             if (Ls_ == 1) |             if (Ls_ == 1) | ||||||
|             { |             { | ||||||
|                 PropToFerm(source, fullSrc, s, c); |                PropToFerm<FImpl>(source, fullSrc, s, c); | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 source = zero; |                 PropToFerm<FImpl>(tmp, fullSrc, s, c); | ||||||
|                 PropToFerm(tmp, fullSrc, s, c); |                 make_5D(tmp, source, Ls_); | ||||||
|                 InsertSlice(tmp, source, 0, 0); |  | ||||||
|                 InsertSlice(tmp, source, Ls_-1, 0); |  | ||||||
|                 axpby_ssp_pplus(source, 0., source, 1., source, 0, 0); |  | ||||||
|                 axpby_ssp_pminus(source, 0., source, 1., source, Ls_-1, Ls_-1); |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // source conversion for 5D sources |         // source conversion for 5D sources | ||||||
| @@ -129,26 +175,22 @@ void TGaugeProp<FImpl>::execute(void) | |||||||
|         { |         { | ||||||
|             if (Ls_ != env().getObjectLs(par().source)) |             if (Ls_ != env().getObjectLs(par().source)) | ||||||
|             { |             { | ||||||
|                 HADRON_ERROR("Ls mismatch between quark action and source"); |                 HADRON_ERROR(Size, "Ls mismatch between quark action and source"); | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 PropToFerm(source, fullSrc, s, c); |                 PropToFerm<FImpl>(source, fullSrc, s, c); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         sol = zero; |         sol = zero; | ||||||
|         solver(sol, source); |         solver(sol, source); | ||||||
|         FermToProp(prop, sol, s, c); |         FermToProp<FImpl>(prop, sol, s, c); | ||||||
|         // create 4D propagators from 5D one if necessary |         // create 4D propagators from 5D one if necessary | ||||||
|         if (Ls_ > 1) |         if (Ls_ > 1) | ||||||
|         { |         { | ||||||
|             PropagatorField &p4d = |             PropagatorField &p4d = envGet(PropagatorField, getName()); | ||||||
|             *env().template getObject<PropagatorField>(getName()); |             make_4D(sol, tmp, Ls_); | ||||||
|              |             FermToProp<FImpl>(p4d, tmp, s, c); | ||||||
|             axpby_ssp_pminus(sol, 0., sol, 1., sol, 0, 0); |  | ||||||
|             axpby_ssp_pplus(sol, 1., sol, 1., sol, 0, Ls_-1); |  | ||||||
|             ExtractSlice(tmp, sol, 0, 0); |  | ||||||
|             FermToProp(p4d, tmp, s, c); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										75
									
								
								extras/Hadrons/Modules/MGauge/FundtoHirep.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								extras/Hadrons/Modules/MGauge/FundtoHirep.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,75 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MGauge/FundtoHirep.cc | ||||||
|  |  | ||||||
|  | Copyright (C) 2015 | ||||||
|  | Copyright (C) 2016 | ||||||
|  |  | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Modules/MGauge/FundtoHirep.hpp> | ||||||
|  |  | ||||||
|  | using namespace Grid; | ||||||
|  | using namespace Hadrons; | ||||||
|  | using namespace MGauge; | ||||||
|  |  | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <class Rep> | ||||||
|  | TFundtoHirep<Rep>::TFundtoHirep(const std::string name) | ||||||
|  | : Module<FundtoHirepPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <class Rep> | ||||||
|  | std::vector<std::string> TFundtoHirep<Rep>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in; | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class Rep> | ||||||
|  | std::vector<std::string> TFundtoHirep<Rep>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename Rep> | ||||||
|  | void TFundtoHirep<Rep>::setup(void) | ||||||
|  | { | ||||||
|  |     envCreateLat(typename Rep::LatticeField, getName()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <class Rep> | ||||||
|  | void TFundtoHirep<Rep>::execute(void) | ||||||
|  | { | ||||||
|  |     auto &U      = *env().template getObject<LatticeGaugeField>(par().gaugeconf); | ||||||
|  |     LOG(Message) << "Transforming Representation" << std::endl; | ||||||
|  |  | ||||||
|  |     Rep TargetRepresentation(U._grid); | ||||||
|  |     TargetRepresentation.update_representation(U); | ||||||
|  |  | ||||||
|  |     auto &URep = envGet(typename Rep::LatticeField, getName()); | ||||||
|  |     URep = TargetRepresentation.U; | ||||||
|  | } | ||||||
							
								
								
									
										77
									
								
								extras/Hadrons/Modules/MGauge/FundtoHirep.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								extras/Hadrons/Modules/MGauge/FundtoHirep.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MGauge/FundtoHirep.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015 | ||||||
|  | Copyright (C) 2016 | ||||||
|  |  | ||||||
|  | Author: David Preti <david.preti@to.infn.it> | ||||||
|  | 	Guido Cossu <guido.cossu@ed.ac.uk> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_MGauge_FundtoHirep_hpp_ | ||||||
|  | #define Hadrons_MGauge_FundtoHirep_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                         Load a NERSC configuration                         * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MGauge) | ||||||
|  |  | ||||||
|  | class FundtoHirepPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(FundtoHirepPar, | ||||||
|  |                                     std::string, gaugeconf); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <class Rep> | ||||||
|  | class TFundtoHirep: public Module<FundtoHirepPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TFundtoHirep(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TFundtoHirep(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  |     // setup | ||||||
|  |     void setup(void); | ||||||
|  |     // execution | ||||||
|  |     void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | //MODULE_REGISTER_NS(FundtoAdjoint,   TFundtoHirep<AdjointRepresentation>, MGauge); | ||||||
|  | //MODULE_REGISTER_NS(FundtoTwoIndexSym, TFundtoHirep<TwoIndexSymmetricRepresentation>, MGauge); | ||||||
|  | //MODULE_REGISTER_NS(FundtoTwoIndexAsym, TFundtoHirep<TwoIndexAntiSymmetricRepresentation>, MGauge); | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_MGauge_FundtoHirep_hpp_ | ||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MGauge/Random.cc | Source file: extras/Hadrons/Modules/MGauge/Random.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -44,7 +43,9 @@ TRandom::TRandom(const std::string name) | |||||||
| // dependencies/products /////////////////////////////////////////////////////// | // dependencies/products /////////////////////////////////////////////////////// | ||||||
| std::vector<std::string> TRandom::getInput(void) | std::vector<std::string> TRandom::getInput(void) | ||||||
| { | { | ||||||
|     return std::vector<std::string>(); |     std::vector<std::string> in; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
| } | } | ||||||
|  |  | ||||||
| std::vector<std::string> TRandom::getOutput(void) | std::vector<std::string> TRandom::getOutput(void) | ||||||
| @@ -57,13 +58,14 @@ std::vector<std::string> TRandom::getOutput(void) | |||||||
| // setup /////////////////////////////////////////////////////////////////////// | // setup /////////////////////////////////////////////////////////////////////// | ||||||
| void TRandom::setup(void) | void TRandom::setup(void) | ||||||
| { | { | ||||||
|     env().registerLattice<LatticeGaugeField>(getName()); |     envCreateLat(LatticeGaugeField, getName()); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| void TRandom::execute(void) | void TRandom::execute(void) | ||||||
| { | { | ||||||
|     LOG(Message) << "Generating random gauge configuration" << std::endl; |     LOG(Message) << "Generating random gauge configuration" << std::endl; | ||||||
|     LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName()); |      | ||||||
|  |     auto &U = envGet(LatticeGaugeField, getName()); | ||||||
|     SU3::HotConfiguration(*env().get4dRng(), U); |     SU3::HotConfiguration(*env().get4dRng(), U); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MGauge/Random.hpp | Source file: extras/Hadrons/Modules/MGauge/Random.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -51,6 +50,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|   | |||||||
| @@ -4,9 +4,9 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MGauge/StochEm.cc | Source file: extras/Hadrons/Modules/MGauge/StochEm.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -57,32 +57,28 @@ std::vector<std::string> TStochEm::getOutput(void) | |||||||
| // setup /////////////////////////////////////////////////////////////////////// | // setup /////////////////////////////////////////////////////////////////////// | ||||||
| void TStochEm::setup(void) | void TStochEm::setup(void) | ||||||
| { | { | ||||||
|     if (!env().hasRegisteredObject("_" + getName() + "_weight")) |     if (!env().hasCreatedObject("_" + getName() + "_weight")) | ||||||
|     { |     { | ||||||
|         env().registerLattice<EmComp>("_" + getName() + "_weight"); |         envCacheLat(EmComp, "_" + getName() + "_weight"); | ||||||
|     } |     } | ||||||
|     env().registerLattice<EmField>(getName()); |     envCreateLat(EmField, getName()); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| void TStochEm::execute(void) | void TStochEm::execute(void) | ||||||
| { | { | ||||||
|  |     LOG(Message) << "Generating stochatic EM potential..." << std::endl; | ||||||
|  |  | ||||||
|     PhotonR photon(par().gauge, par().zmScheme); |     PhotonR photon(par().gauge, par().zmScheme); | ||||||
|     EmField &a = *env().createLattice<EmField>(getName()); |     auto    &a = envGet(EmField, getName()); | ||||||
|     EmComp  *w; |     auto    &w = envGet(EmComp, "_" + getName() + "_weight"); | ||||||
|      |      | ||||||
|     if (!env().hasCreatedObject("_" + getName() + "_weight")) |     if (!env().hasCreatedObject("_" + getName() + "_weight")) | ||||||
|     { |     { | ||||||
|         LOG(Message) << "Caching stochatic EM potential weight (gauge: " |         LOG(Message) << "Caching stochatic EM potential weight (gauge: " | ||||||
|                      << par().gauge << ", zero-mode scheme: " |                      << par().gauge << ", zero-mode scheme: " | ||||||
|                      << par().zmScheme << ")..." << std::endl; |                      << par().zmScheme << ")..." << std::endl; | ||||||
|         w = env().createLattice<EmComp>("_" + getName() + "_weight"); |         photon.StochasticWeight(w); | ||||||
|         photon.StochasticWeight(*w); |  | ||||||
|     } |     } | ||||||
|     else |     photon.StochasticField(a, *env().get4dRng(), w); | ||||||
|     { |  | ||||||
|         w = env().getObject<EmComp>("_" + getName() + "_weight"); |  | ||||||
|     } |  | ||||||
|     LOG(Message) << "Generating stochatic EM potential..." << std::endl; |  | ||||||
|     photon.StochasticField(a, *env().get4dRng(), *w); |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,9 +4,9 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MGauge/StochEm.hpp | Source file: extras/Hadrons/Modules/MGauge/StochEm.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -60,6 +60,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MGauge/Unit.cc | Source file: extras/Hadrons/Modules/MGauge/Unit.cc | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -57,13 +56,14 @@ std::vector<std::string> TUnit::getOutput(void) | |||||||
| // setup /////////////////////////////////////////////////////////////////////// | // setup /////////////////////////////////////////////////////////////////////// | ||||||
| void TUnit::setup(void) | void TUnit::setup(void) | ||||||
| { | { | ||||||
|     env().registerLattice<LatticeGaugeField>(getName()); |     envCreateLat(LatticeGaugeField, getName()); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| void TUnit::execute(void) | void TUnit::execute(void) | ||||||
| { | { | ||||||
|     LOG(Message) << "Creating unit gauge configuration" << std::endl; |     LOG(Message) << "Creating unit gauge configuration" << std::endl; | ||||||
|     LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName()); |      | ||||||
|  |     auto &U = envGet(LatticeGaugeField, getName()); | ||||||
|     SU3::ColdConfiguration(*env().get4dRng(), U); |     SU3::ColdConfiguration(*env().get4dRng(), U); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MGauge/Unit.hpp | Source file: extras/Hadrons/Modules/MGauge/Unit.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -51,6 +50,7 @@ public: | |||||||
|     // dependencies/products |     // dependencies/products | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|   | |||||||
							
								
								
									
										140
									
								
								extras/Hadrons/Modules/MIO/LoadBinary.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								extras/Hadrons/Modules/MIO/LoadBinary.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,140 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MIO/LoadBinary.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  | #ifndef Hadrons_MIO_LoadBinary_hpp_ | ||||||
|  | #define Hadrons_MIO_LoadBinary_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                       Load a binary configurations                         * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MIO) | ||||||
|  |  | ||||||
|  | class LoadBinaryPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(LoadBinaryPar, | ||||||
|  |                                     std::string, file, | ||||||
|  |                                     std::string, format); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename Impl> | ||||||
|  | class TLoadBinary: public Module<LoadBinaryPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     typedef typename Impl::Field                  Field; | ||||||
|  |     typedef typename Impl::Simd                   Simd; | ||||||
|  |     typedef typename Field::vector_object         vobj; | ||||||
|  |     typedef typename vobj::scalar_object          sobj; | ||||||
|  |     typedef typename sobj::DoublePrecision        sobj_double; | ||||||
|  |     typedef BinarySimpleMunger<sobj_double, sobj> Munger; | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TLoadBinary(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TLoadBinary(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(LoadBinary, TLoadBinary<GIMPL>, MIO); | ||||||
|  | MODULE_REGISTER_NS(LoadBinaryScalarSU2, TLoadBinary<ScalarNxNAdjImplR<2>>, MIO); | ||||||
|  | MODULE_REGISTER_NS(LoadBinaryScalarSU3, TLoadBinary<ScalarNxNAdjImplR<3>>, MIO); | ||||||
|  | MODULE_REGISTER_NS(LoadBinaryScalarSU4, TLoadBinary<ScalarNxNAdjImplR<4>>, MIO); | ||||||
|  | MODULE_REGISTER_NS(LoadBinaryScalarSU5, TLoadBinary<ScalarNxNAdjImplR<5>>, MIO); | ||||||
|  | MODULE_REGISTER_NS(LoadBinaryScalarSU6, TLoadBinary<ScalarNxNAdjImplR<6>>, MIO); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                         TLoadBinary implementation                         * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename Impl> | ||||||
|  | TLoadBinary<Impl>::TLoadBinary(const std::string name) | ||||||
|  | : Module<LoadBinaryPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename Impl> | ||||||
|  | std::vector<std::string> TLoadBinary<Impl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename Impl> | ||||||
|  | std::vector<std::string> TLoadBinary<Impl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename Impl> | ||||||
|  | void TLoadBinary<Impl>::setup(void) | ||||||
|  | { | ||||||
|  |     envCreateLat(Field, getName()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename Impl> | ||||||
|  | void TLoadBinary<Impl>::execute(void) | ||||||
|  | { | ||||||
|  |     Munger      munge; | ||||||
|  |     uint32_t    nersc_csum, scidac_csuma, scidac_csumb; | ||||||
|  |     auto        &U = envGet(Field, getName()); | ||||||
|  |     std::string filename = par().file + "." | ||||||
|  |                            + std::to_string(vm().getTrajectory()); | ||||||
|  |  | ||||||
|  |     LOG(Message) << "Loading " << par().format  | ||||||
|  |                  << " binary configuration from file '" << filename | ||||||
|  |                  << "'" << std::endl; | ||||||
|  |     BinaryIO::readLatticeObject<vobj, sobj_double>(U, filename, munge, 0,  | ||||||
|  |                                                    par().format, nersc_csum, | ||||||
|  |                                                    scidac_csuma, scidac_csumb); | ||||||
|  |     LOG(Message) << "Checksums:" << std::endl; | ||||||
|  |     LOG(Message) << "  NERSC    " << nersc_csum << std::endl; | ||||||
|  |     LOG(Message) << "  SciDAC A " << scidac_csuma << std::endl; | ||||||
|  |     LOG(Message) << "  SciDAC B " << scidac_csumb << std::endl; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_MIO_LoadBinary_hpp_ | ||||||
| @@ -2,10 +2,9 @@ | |||||||
| 
 | 
 | ||||||
| Grid physics library, www.github.com/paboyle/Grid  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
| 
 | 
 | ||||||
| Source file: extras/Hadrons/Modules/MGauge/Load.cc | Source file: extras/Hadrons/Modules/MIO/LoadNersc.cc | ||||||
| 
 | 
 | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
| 
 | 
 | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
| 
 | 
 | ||||||
| @@ -26,30 +25,29 @@ with this program; if not, write to the Free Software Foundation, Inc., | |||||||
| See the full license in the file "LICENSE" in the top level distribution directory | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
| *************************************************************************************/ | *************************************************************************************/ | ||||||
| /*  END LEGAL */ | /*  END LEGAL */ | ||||||
| 
 | #include <Grid/Hadrons/Modules/MIO/LoadNersc.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MGauge/Load.hpp> |  | ||||||
| 
 | 
 | ||||||
| using namespace Grid; | using namespace Grid; | ||||||
| using namespace Hadrons; | using namespace Hadrons; | ||||||
| using namespace MGauge; | using namespace MIO; | ||||||
| 
 | 
 | ||||||
| /******************************************************************************
 | /******************************************************************************
 | ||||||
| *                           TLoad implementation                               * | *                       TLoadNersc implementation                             * | ||||||
| ******************************************************************************/ | ******************************************************************************/ | ||||||
| // constructor /////////////////////////////////////////////////////////////////
 | // constructor /////////////////////////////////////////////////////////////////
 | ||||||
| TLoad::TLoad(const std::string name) | TLoadNersc::TLoadNersc(const std::string name) | ||||||
| : Module<LoadPar>(name) | : Module<LoadNerscPar>(name) | ||||||
| {} | {} | ||||||
| 
 | 
 | ||||||
| // dependencies/products ///////////////////////////////////////////////////////
 | // dependencies/products ///////////////////////////////////////////////////////
 | ||||||
| std::vector<std::string> TLoad::getInput(void) | std::vector<std::string> TLoadNersc::getInput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> in; |     std::vector<std::string> in; | ||||||
|      |      | ||||||
|     return in; |     return in; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<std::string> TLoad::getOutput(void) | std::vector<std::string> TLoadNersc::getOutput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> out = {getName()}; |     std::vector<std::string> out = {getName()}; | ||||||
|      |      | ||||||
| @@ -57,21 +55,21 @@ std::vector<std::string> TLoad::getOutput(void) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // setup ///////////////////////////////////////////////////////////////////////
 | // setup ///////////////////////////////////////////////////////////////////////
 | ||||||
| void TLoad::setup(void) | void TLoadNersc::setup(void) | ||||||
| { | { | ||||||
|     env().registerLattice<LatticeGaugeField>(getName()); |     envCreateLat(LatticeGaugeField, getName()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // execution ///////////////////////////////////////////////////////////////////
 | // execution ///////////////////////////////////////////////////////////////////
 | ||||||
| void TLoad::execute(void) | void TLoadNersc::execute(void) | ||||||
| { | { | ||||||
|     FieldMetaData header; |     FieldMetaData header; | ||||||
|     std::string   fileName = par().file + "." |     std::string   fileName = par().file + "." | ||||||
|                            + std::to_string(env().getTrajectory()); |                              + std::to_string(vm().getTrajectory()); | ||||||
|      |  | ||||||
|     LOG(Message) << "Loading NERSC configuration from file '" << fileName |     LOG(Message) << "Loading NERSC configuration from file '" << fileName | ||||||
|                  << "'" << std::endl; |                  << "'" << std::endl; | ||||||
|     LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName()); | 
 | ||||||
|  |     auto &U = envGet(LatticeGaugeField, getName()); | ||||||
|     NerscIO::readConfiguration(U, header, fileName); |     NerscIO::readConfiguration(U, header, fileName); | ||||||
|     LOG(Message) << "NERSC header:" << std::endl; |     LOG(Message) << "NERSC header:" << std::endl; | ||||||
|     dump_meta_data(header, LOG(Message)); |     dump_meta_data(header, LOG(Message)); | ||||||
| @@ -2,10 +2,9 @@ | |||||||
| 
 | 
 | ||||||
| Grid physics library, www.github.com/paboyle/Grid  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
| 
 | 
 | ||||||
| Source file: extras/Hadrons/Modules/MGauge/Load.hpp | Source file: extras/Hadrons/Modules/MIO/LoadNersc.hpp | ||||||
| 
 | 
 | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
| 
 | 
 | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
| 
 | 
 | ||||||
| @@ -26,9 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc., | |||||||
| See the full license in the file "LICENSE" in the top level distribution directory | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
| *************************************************************************************/ | *************************************************************************************/ | ||||||
| /*  END LEGAL */ | /*  END LEGAL */ | ||||||
| 
 | #ifndef Hadrons_MIO_LoadNersc_hpp_ | ||||||
| #ifndef Hadrons_MGauge_Load_hpp_ | #define Hadrons_MIO_LoadNersc_hpp_ | ||||||
| #define Hadrons_MGauge_Load_hpp_ |  | ||||||
| 
 | 
 | ||||||
| #include <Grid/Hadrons/Global.hpp> | #include <Grid/Hadrons/Global.hpp> | ||||||
| #include <Grid/Hadrons/Module.hpp> | #include <Grid/Hadrons/Module.hpp> | ||||||
| @@ -39,22 +37,22 @@ BEGIN_HADRONS_NAMESPACE | |||||||
| /******************************************************************************
 | /******************************************************************************
 | ||||||
|  *                       Load a NERSC configuration                           * |  *                       Load a NERSC configuration                           * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| BEGIN_MODULE_NAMESPACE(MGauge) | BEGIN_MODULE_NAMESPACE(MIO) | ||||||
| 
 | 
 | ||||||
| class LoadPar: Serializable | class LoadNerscPar: Serializable | ||||||
| { | { | ||||||
| public: | public: | ||||||
|     GRID_SERIALIZABLE_CLASS_MEMBERS(LoadPar, |     GRID_SERIALIZABLE_CLASS_MEMBERS(LoadNerscPar, | ||||||
|                                     std::string, file); |                                     std::string, file); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class TLoad: public Module<LoadPar> | class TLoadNersc: public Module<LoadNerscPar> | ||||||
| { | { | ||||||
| public: | public: | ||||||
|     // constructor
 |     // constructor
 | ||||||
|     TLoad(const std::string name); |     TLoadNersc(const std::string name); | ||||||
|     // destructor
 |     // destructor
 | ||||||
|     virtual ~TLoad(void) = default; |     virtual ~TLoadNersc(void) = default; | ||||||
|     // dependency relation
 |     // dependency relation
 | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
| @@ -64,10 +62,10 @@ public: | |||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| MODULE_REGISTER_NS(Load, TLoad, MGauge); | MODULE_REGISTER_NS(LoadNersc, TLoadNersc, MIO); | ||||||
| 
 | 
 | ||||||
| END_MODULE_NAMESPACE | END_MODULE_NAMESPACE | ||||||
| 
 | 
 | ||||||
| END_HADRONS_NAMESPACE | END_HADRONS_NAMESPACE | ||||||
| 
 | 
 | ||||||
| #endif // Hadrons_MGauge_Load_hpp_
 | #endif // Hadrons_MIO_LoadNersc_hpp_
 | ||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MLoop/NoiseLoop.hpp | Source file: extras/Hadrons/Modules/MLoop/NoiseLoop.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2016 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -74,6 +75,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -112,16 +114,16 @@ std::vector<std::string> TNoiseLoop<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TNoiseLoop<FImpl>::setup(void) | void TNoiseLoop<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     env().template registerLattice<PropagatorField>(getName()); |     envCreateLat(PropagatorField, getName()); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TNoiseLoop<FImpl>::execute(void) | void TNoiseLoop<FImpl>::execute(void) | ||||||
| { | { | ||||||
|     PropagatorField &loop = *env().template createLattice<PropagatorField>(getName()); |     auto &loop = envGet(PropagatorField, getName()); | ||||||
|     PropagatorField &q    = *env().template getObject<PropagatorField>(par().q); |     auto &q    = envGet(PropagatorField, par().q); | ||||||
|     PropagatorField &eta  = *env().template getObject<PropagatorField>(par().eta); |     auto &eta  = envGet(PropagatorField, par().eta); | ||||||
|     loop = q*adj(eta); |     loop = q*adj(eta); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,3 +1,31 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalar/ChargedProp.cc | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: James Harrison <jch1g10@soton.ac.uk> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
| #include <Grid/Hadrons/Modules/MScalar/ChargedProp.hpp> | #include <Grid/Hadrons/Modules/MScalar/ChargedProp.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MScalar/Scalar.hpp> | #include <Grid/Hadrons/Modules/MScalar/Scalar.hpp> | ||||||
|  |  | ||||||
| @@ -37,89 +65,43 @@ void TChargedProp::setup(void) | |||||||
|     { |     { | ||||||
|         phaseName_.push_back("_shiftphase_" + std::to_string(mu)); |         phaseName_.push_back("_shiftphase_" + std::to_string(mu)); | ||||||
|     } |     } | ||||||
|     GFSrcName_ = "_" + getName() + "_DinvSrc"; |     GFSrcName_ = getName() + "_DinvSrc"; | ||||||
|     if (!env().hasRegisteredObject(freeMomPropName_)) |     fftName_   = getName() + "_fft"; | ||||||
|     { |  | ||||||
|         env().registerLattice<ScalarField>(freeMomPropName_); |     freeMomPropDone_ = env().hasCreatedObject(freeMomPropName_); | ||||||
|     } |     GFSrcDone_       = env().hasCreatedObject(GFSrcName_); | ||||||
|     if (!env().hasRegisteredObject(phaseName_[0])) |     phasesDone_      = env().hasCreatedObject(phaseName_[0]); | ||||||
|     { |     envCacheLat(ScalarField, freeMomPropName_); | ||||||
|     for (unsigned int mu = 0; mu < env().getNd(); ++mu) |     for (unsigned int mu = 0; mu < env().getNd(); ++mu) | ||||||
|     { |     { | ||||||
|             env().registerLattice<ScalarField>(phaseName_[mu]); |         envCacheLat(ScalarField, phaseName_[mu]); | ||||||
|     } |     } | ||||||
|     } |     envCacheLat(ScalarField, GFSrcName_); | ||||||
|     if (!env().hasRegisteredObject(GFSrcName_)) |     envCreateLat(ScalarField, getName()); | ||||||
|     { |     envTmpLat(ScalarField, "buf"); | ||||||
|         env().registerLattice<ScalarField>(GFSrcName_); |     envTmpLat(ScalarField, "result"); | ||||||
|     } |     envTmpLat(ScalarField, "Amu"); | ||||||
|     env().registerLattice<ScalarField>(getName()); |     envCache(FFT, fftName_, 1, env().getGrid()); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| void TChargedProp::execute(void) | void TChargedProp::execute(void) | ||||||
| { | { | ||||||
|     // CACHING ANALYTIC EXPRESSIONS |     // CACHING ANALYTIC EXPRESSIONS | ||||||
|     ScalarField &source = *env().getObject<ScalarField>(par().source); |     makeCaches(); | ||||||
|     Complex     ci(0.0,1.0); |  | ||||||
|     FFT         fft(env().getGrid()); |  | ||||||
|      |  | ||||||
|     // cache free scalar propagator |  | ||||||
|     if (!env().hasCreatedObject(freeMomPropName_)) |  | ||||||
|     { |  | ||||||
|         LOG(Message) << "Caching momentum space free scalar propagator" |  | ||||||
|                      << " (mass= " << par().mass << ")..." << std::endl; |  | ||||||
|         freeMomProp_ = env().createLattice<ScalarField>(freeMomPropName_); |  | ||||||
|         SIMPL::MomentumSpacePropagator(*freeMomProp_, par().mass); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         freeMomProp_ = env().getObject<ScalarField>(freeMomPropName_); |  | ||||||
|     } |  | ||||||
|     // cache G*F*src |  | ||||||
|     if (!env().hasCreatedObject(GFSrcName_)) |  | ||||||
|          |  | ||||||
|     { |  | ||||||
|         GFSrc_ = env().createLattice<ScalarField>(GFSrcName_); |  | ||||||
|         fft.FFT_all_dim(*GFSrc_, source, FFT::forward); |  | ||||||
|         *GFSrc_ = (*freeMomProp_)*(*GFSrc_); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         GFSrc_ = env().getObject<ScalarField>(GFSrcName_); |  | ||||||
|     } |  | ||||||
|     // cache phases |  | ||||||
|     if (!env().hasCreatedObject(phaseName_[0])) |  | ||||||
|     { |  | ||||||
|         std::vector<int> &l = env().getGrid()->_fdimensions; |  | ||||||
|          |  | ||||||
|         LOG(Message) << "Caching shift phases..." << std::endl; |  | ||||||
|         for (unsigned int mu = 0; mu < env().getNd(); ++mu) |  | ||||||
|         { |  | ||||||
|             Real    twoPiL = M_PI*2./l[mu]; |  | ||||||
|              |  | ||||||
|             phase_.push_back(env().createLattice<ScalarField>(phaseName_[mu])); |  | ||||||
|             LatticeCoordinate(*(phase_[mu]), mu); |  | ||||||
|             *(phase_[mu]) = exp(ci*twoPiL*(*(phase_[mu]))); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         for (unsigned int mu = 0; mu < env().getNd(); ++mu) |  | ||||||
|         { |  | ||||||
|             phase_.push_back(env().getObject<ScalarField>(phaseName_[mu])); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // PROPAGATOR CALCULATION |     // PROPAGATOR CALCULATION | ||||||
|     LOG(Message) << "Computing charged scalar propagator" |     LOG(Message) << "Computing charged scalar propagator" | ||||||
|                  << " (mass= " << par().mass |                  << " (mass= " << par().mass | ||||||
|                  << ", charge= " << par().charge << ")..." << std::endl; |                  << ", charge= " << par().charge << ")..." << std::endl; | ||||||
|      |      | ||||||
|     ScalarField &prop   = *env().createLattice<ScalarField>(getName()); |     auto   &prop  = envGet(ScalarField, getName()); | ||||||
|     ScalarField buf(env().getGrid()); |     auto   &GFSrc = envGet(ScalarField, GFSrcName_); | ||||||
|     ScalarField &GFSrc = *GFSrc_, &G = *freeMomProp_; |     auto   &G     = envGet(ScalarField, freeMomPropName_); | ||||||
|  |     auto   &fft   = envGet(FFT, fftName_); | ||||||
|     double q      = par().charge; |     double q      = par().charge; | ||||||
|  |     envGetTmp(ScalarField, result);  | ||||||
|  |     envGetTmp(ScalarField, buf);  | ||||||
|  |  | ||||||
|     // G*F*Src |     // G*F*Src | ||||||
|     prop = GFSrc; |     prop = GFSrc; | ||||||
| @@ -146,12 +128,12 @@ void TChargedProp::execute(void) | |||||||
|     if (!par().output.empty()) |     if (!par().output.empty()) | ||||||
|     { |     { | ||||||
|         std::string           filename = par().output + "." + |         std::string           filename = par().output + "." + | ||||||
|                                          std::to_string(env().getTrajectory()); |                                          std::to_string(vm().getTrajectory()); | ||||||
|          |          | ||||||
|         LOG(Message) << "Saving zero-momentum projection to '" |         LOG(Message) << "Saving zero-momentum projection to '" | ||||||
|                      << filename << "'..." << std::endl; |                      << filename << "'..." << std::endl; | ||||||
|          |          | ||||||
|         CorrWriter            writer(filename); |         ResultWriter          writer(RESULT_FILE_NAME(par().output)); | ||||||
|         std::vector<TComplex> vecBuf; |         std::vector<TComplex> vecBuf; | ||||||
|         std::vector<Complex>  result; |         std::vector<Complex>  result; | ||||||
|          |          | ||||||
| @@ -166,15 +148,55 @@ void TChargedProp::execute(void) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| void TChargedProp::momD1(ScalarField &s, FFT &fft) | void TChargedProp::makeCaches(void) | ||||||
| { | { | ||||||
|     EmField     &A = *env().getObject<EmField>(par().emField); |     auto &freeMomProp = envGet(ScalarField, freeMomPropName_); | ||||||
|     ScalarField buf(env().getGrid()), result(env().getGrid()), |     auto &GFSrc       = envGet(ScalarField, GFSrcName_); | ||||||
|                 Amu(env().getGrid()); |     auto &fft         = envGet(FFT, fftName_); | ||||||
|  |  | ||||||
|  |     if (!freeMomPropDone_) | ||||||
|  |     { | ||||||
|  |         LOG(Message) << "Caching momentum space free scalar propagator" | ||||||
|  |                      << " (mass= " << par().mass << ")..." << std::endl; | ||||||
|  |         SIMPL::MomentumSpacePropagator(freeMomProp, par().mass); | ||||||
|  |     } | ||||||
|  |     if (!GFSrcDone_) | ||||||
|  |     {    | ||||||
|  |         FFT  fft(env().getGrid()); | ||||||
|  |         auto &source = envGet(ScalarField, par().source); | ||||||
|  |  | ||||||
|  |         LOG(Message) << "Caching G*F*src..." << std::endl; | ||||||
|  |         fft.FFT_all_dim(GFSrc, source, FFT::forward); | ||||||
|  |         GFSrc = freeMomProp*GFSrc; | ||||||
|  |     } | ||||||
|  |     if (!phasesDone_) | ||||||
|  |     { | ||||||
|  |         std::vector<int> &l = env().getGrid()->_fdimensions; | ||||||
|         Complex          ci(0.0,1.0); |         Complex          ci(0.0,1.0); | ||||||
|          |          | ||||||
|     result = zero; |         LOG(Message) << "Caching shift phases..." << std::endl; | ||||||
|  |         for (unsigned int mu = 0; mu < env().getNd(); ++mu) | ||||||
|  |         { | ||||||
|  |             Real twoPiL = M_PI*2./l[mu]; | ||||||
|  |             auto &phmu  = envGet(ScalarField, phaseName_[mu]); | ||||||
|              |              | ||||||
|  |             LatticeCoordinate(phmu, mu); | ||||||
|  |             phmu = exp(ci*twoPiL*phmu); | ||||||
|  |             phase_.push_back(&phmu); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void TChargedProp::momD1(ScalarField &s, FFT &fft) | ||||||
|  | { | ||||||
|  |     auto        &A = envGet(EmField, par().emField); | ||||||
|  |     Complex     ci(0.0,1.0); | ||||||
|  |  | ||||||
|  |     envGetTmp(ScalarField, buf); | ||||||
|  |     envGetTmp(ScalarField, result); | ||||||
|  |     envGetTmp(ScalarField, Amu); | ||||||
|  |  | ||||||
|  |     result = zero; | ||||||
|     for (unsigned int mu = 0; mu < env().getNd(); ++mu) |     for (unsigned int mu = 0; mu < env().getNd(); ++mu) | ||||||
|     { |     { | ||||||
|         Amu = peekLorentz(A, mu); |         Amu = peekLorentz(A, mu); | ||||||
| @@ -198,12 +220,13 @@ void TChargedProp::momD1(ScalarField &s, FFT &fft) | |||||||
|  |  | ||||||
| void TChargedProp::momD2(ScalarField &s, FFT &fft) | void TChargedProp::momD2(ScalarField &s, FFT &fft) | ||||||
| { | { | ||||||
|     EmField     &A = *env().getObject<EmField>(par().emField); |     auto &A = envGet(EmField, par().emField); | ||||||
|     ScalarField buf(env().getGrid()), result(env().getGrid()), |  | ||||||
|                 Amu(env().getGrid()); |     envGetTmp(ScalarField, buf); | ||||||
|  |     envGetTmp(ScalarField, result); | ||||||
|  |     envGetTmp(ScalarField, Amu); | ||||||
|  |  | ||||||
|     result = zero; |     result = zero; | ||||||
|      |  | ||||||
|     for (unsigned int mu = 0; mu < env().getNd(); ++mu) |     for (unsigned int mu = 0; mu < env().getNd(); ++mu) | ||||||
|     { |     { | ||||||
|         Amu = peekLorentz(A, mu); |         Amu = peekLorentz(A, mu); | ||||||
|   | |||||||
| @@ -1,3 +1,30 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalar/ChargedProp.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
| #ifndef Hadrons_MScalar_ChargedProp_hpp_ | #ifndef Hadrons_MScalar_ChargedProp_hpp_ | ||||||
| #define Hadrons_MScalar_ChargedProp_hpp_ | #define Hadrons_MScalar_ChargedProp_hpp_ | ||||||
|  |  | ||||||
| @@ -37,19 +64,20 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
| private: | private: | ||||||
|  |     void makeCaches(void); | ||||||
|     void momD1(ScalarField &s, FFT &fft); |     void momD1(ScalarField &s, FFT &fft); | ||||||
|     void momD2(ScalarField &s, FFT &fft); |     void momD2(ScalarField &s, FFT &fft); | ||||||
| private: | private: | ||||||
|     std::string                freeMomPropName_, GFSrcName_; |     bool                       freeMomPropDone_, GFSrcDone_, phasesDone_; | ||||||
|  |     std::string                freeMomPropName_, GFSrcName_, fftName_; | ||||||
|     std::vector<std::string>   phaseName_; |     std::vector<std::string>   phaseName_; | ||||||
|     ScalarField                *freeMomProp_, *GFSrc_; |  | ||||||
|     std::vector<ScalarField *> phase_; |     std::vector<ScalarField *> phase_; | ||||||
|     EmField                    *A; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| MODULE_REGISTER_NS(ChargedProp, TChargedProp, MScalar); | MODULE_REGISTER_NS(ChargedProp, TChargedProp, MScalar); | ||||||
|   | |||||||
| @@ -1,3 +1,30 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalar/FreeProp.cc | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
| #include <Grid/Hadrons/Modules/MScalar/FreeProp.hpp> | #include <Grid/Hadrons/Modules/MScalar/FreeProp.hpp> | ||||||
| #include <Grid/Hadrons/Modules/MScalar/Scalar.hpp> | #include <Grid/Hadrons/Modules/MScalar/Scalar.hpp> | ||||||
|  |  | ||||||
| @@ -33,38 +60,31 @@ void TFreeProp::setup(void) | |||||||
| { | { | ||||||
|     freeMomPropName_ = FREEMOMPROP(par().mass); |     freeMomPropName_ = FREEMOMPROP(par().mass); | ||||||
|      |      | ||||||
|     if (!env().hasRegisteredObject(freeMomPropName_)) |     freePropDone_ = env().hasCreatedObject(freeMomPropName_); | ||||||
|     { |     envCacheLat(ScalarField, freeMomPropName_); | ||||||
|         env().registerLattice<ScalarField>(freeMomPropName_); |     envCreateLat(ScalarField, getName()); | ||||||
|     } |  | ||||||
|     env().registerLattice<ScalarField>(getName()); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| void TFreeProp::execute(void) | void TFreeProp::execute(void) | ||||||
| { | { | ||||||
|     ScalarField &prop   = *env().createLattice<ScalarField>(getName()); |     auto &freeMomProp = envGet(ScalarField, freeMomPropName_); | ||||||
|     ScalarField &source = *env().getObject<ScalarField>(par().source); |     auto &prop        = envGet(ScalarField, getName()); | ||||||
|     ScalarField *freeMomProp; |     auto &source      = envGet(ScalarField, par().source); | ||||||
|  |  | ||||||
|     if (!env().hasCreatedObject(freeMomPropName_)) |     if (!freePropDone_) | ||||||
|     { |     { | ||||||
|         LOG(Message) << "Caching momentum space free scalar propagator" |         LOG(Message) << "Caching momentum space free scalar propagator" | ||||||
|                      << " (mass= " << par().mass << ")..." << std::endl; |                      << " (mass= " << par().mass << ")..." << std::endl; | ||||||
|         freeMomProp = env().createLattice<ScalarField>(freeMomPropName_); |         SIMPL::MomentumSpacePropagator(freeMomProp, par().mass); | ||||||
|         SIMPL::MomentumSpacePropagator(*freeMomProp, par().mass); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         freeMomProp = env().getObject<ScalarField>(freeMomPropName_); |  | ||||||
|     } |     } | ||||||
|     LOG(Message) << "Computing free scalar propagator..." << std::endl; |     LOG(Message) << "Computing free scalar propagator..." << std::endl; | ||||||
|     SIMPL::FreePropagator(source, prop, *freeMomProp); |     SIMPL::FreePropagator(source, prop, freeMomProp); | ||||||
|      |      | ||||||
|     if (!par().output.empty()) |     if (!par().output.empty()) | ||||||
|     { |     { | ||||||
|         TextWriter            writer(par().output + "." + |         TextWriter            writer(par().output + "." + | ||||||
|                                      std::to_string(env().getTrajectory())); |                                      std::to_string(vm().getTrajectory())); | ||||||
|         std::vector<TComplex> buf; |         std::vector<TComplex> buf; | ||||||
|         std::vector<Complex>  result; |         std::vector<Complex>  result; | ||||||
|          |          | ||||||
|   | |||||||
| @@ -1,3 +1,30 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalar/FreeProp.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
| #ifndef Hadrons_MScalar_FreeProp_hpp_ | #ifndef Hadrons_MScalar_FreeProp_hpp_ | ||||||
| #define Hadrons_MScalar_FreeProp_hpp_ | #define Hadrons_MScalar_FreeProp_hpp_ | ||||||
|  |  | ||||||
| @@ -33,12 +60,14 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
| private: | private: | ||||||
|     std::string freeMomPropName_; |     std::string freeMomPropName_; | ||||||
|  |     bool        freePropDone_; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| MODULE_REGISTER_NS(FreeProp, TFreeProp, MScalar); | MODULE_REGISTER_NS(FreeProp, TFreeProp, MScalar); | ||||||
|   | |||||||
| @@ -1,3 +1,30 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalar/Scalar.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
| #ifndef Hadrons_Scalar_hpp_ | #ifndef Hadrons_Scalar_hpp_ | ||||||
| #define Hadrons_Scalar_hpp_ | #define Hadrons_Scalar_hpp_ | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										166
									
								
								extras/Hadrons/Modules/MScalarSUN/Div.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										166
									
								
								extras/Hadrons/Modules/MScalarSUN/Div.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,166 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalarSUN/Div.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  | #ifndef Hadrons_MScalarSUN_Div_hpp_ | ||||||
|  | #define Hadrons_MScalarSUN_Div_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                         Div                                 * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MScalarSUN) | ||||||
|  |  | ||||||
|  | class DivPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_ENUM(DiffType, undef, forward, 1, backward, 2, central, 3); | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(DivPar, | ||||||
|  |                                     std::vector<std::string>, op, | ||||||
|  |                                     DiffType,                 type, | ||||||
|  |                                     std::string,              output); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | class TDiv: public Module<DivPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     typedef typename SImpl::Field        Field; | ||||||
|  |     typedef typename SImpl::ComplexField ComplexField; | ||||||
|  |     class Result: Serializable | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         GRID_SERIALIZABLE_CLASS_MEMBERS(Result, | ||||||
|  |                                         DivPar::DiffType, type, | ||||||
|  |                                         Complex,          value); | ||||||
|  |     }; | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TDiv(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TDiv(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(DivSU2, TDiv<ScalarNxNAdjImplR<2>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(DivSU3, TDiv<ScalarNxNAdjImplR<3>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(DivSU4, TDiv<ScalarNxNAdjImplR<4>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(DivSU5, TDiv<ScalarNxNAdjImplR<5>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(DivSU6, TDiv<ScalarNxNAdjImplR<6>>, MScalarSUN); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                 TDiv implementation                             * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | TDiv<SImpl>::TDiv(const std::string name) | ||||||
|  | : Module<DivPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TDiv<SImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     return par().op; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TDiv<SImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |  | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TDiv<SImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     if (par().op.size() != env().getNd()) | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Size, "the number of components differs from number of dimensions"); | ||||||
|  |     } | ||||||
|  |     envCreateLat(ComplexField, getName()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TDiv<SImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     const auto nd = env().getNd(); | ||||||
|  |  | ||||||
|  |     LOG(Message) << "Computing the " << par().type << " divergence of ["; | ||||||
|  |     for (unsigned int mu = 0; mu < nd; ++mu) | ||||||
|  |     { | ||||||
|  |         std::cout << par().op[mu] << ((mu == nd - 1) ? "]" : ", "); | ||||||
|  |     } | ||||||
|  |     std::cout << std::endl; | ||||||
|  |  | ||||||
|  |     auto &div = envGet(ComplexField, getName()); | ||||||
|  |     div = zero; | ||||||
|  |     for (unsigned int mu = 0; mu < nd; ++mu) | ||||||
|  |     { | ||||||
|  |         auto &op = envGet(ComplexField, par().op[mu]); | ||||||
|  |         switch(par().type) | ||||||
|  |         { | ||||||
|  |             case DivPar::DiffType::backward: | ||||||
|  |                 div += op - Cshift(op, mu, -1); | ||||||
|  |                 break; | ||||||
|  |             case DivPar::DiffType::forward: | ||||||
|  |                 div += Cshift(op, mu, 1) - op; | ||||||
|  |                 break; | ||||||
|  |             case DivPar::DiffType::central: | ||||||
|  |                 div += 0.5*(Cshift(op, mu, 1) - Cshift(op, mu, -1)); | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     if (!par().output.empty()) | ||||||
|  |     { | ||||||
|  |         Result       r; | ||||||
|  |         ResultWriter writer(RESULT_FILE_NAME(par().output)); | ||||||
|  |  | ||||||
|  |         r.type  = par().type; | ||||||
|  |         r.value = TensorRemove(sum(div)); | ||||||
|  |         write(writer, "div", r); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_MScalarSUN_Div_hpp_ | ||||||
							
								
								
									
										146
									
								
								extras/Hadrons/Modules/MScalarSUN/TrMag.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										146
									
								
								extras/Hadrons/Modules/MScalarSUN/TrMag.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,146 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalarSUN/TrMag.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  | #ifndef Hadrons_MScalarSUN_TrMag_hpp_ | ||||||
|  | #define Hadrons_MScalarSUN_TrMag_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                       Module to compute tr(mag^n)                          * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MScalarSUN) | ||||||
|  |  | ||||||
|  | class TrMagPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(TrMagPar, | ||||||
|  |                                     std::string,  field, | ||||||
|  |                                     unsigned int, maxPow, | ||||||
|  |                                     std::string,  output); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | class TTrMag: public Module<TrMagPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     typedef typename SImpl::Field        Field; | ||||||
|  |     typedef typename SImpl::ComplexField ComplexField; | ||||||
|  |     class Result: Serializable | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         GRID_SERIALIZABLE_CLASS_MEMBERS(Result, | ||||||
|  |                                         std::string, op, | ||||||
|  |                                         Real,        value); | ||||||
|  |     }; | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TTrMag(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TTrMag(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(TrMagSU2, TTrMag<ScalarNxNAdjImplR<2>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrMagSU3, TTrMag<ScalarNxNAdjImplR<3>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrMagSU4, TTrMag<ScalarNxNAdjImplR<4>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrMagSU5, TTrMag<ScalarNxNAdjImplR<5>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrMagSU6, TTrMag<ScalarNxNAdjImplR<6>>, MScalarSUN); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                         TTrMag implementation                              * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | TTrMag<SImpl>::TTrMag(const std::string name) | ||||||
|  | : Module<TrMagPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TTrMag<SImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().field}; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TTrMag<SImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {}; | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TTrMag<SImpl>::setup(void) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TTrMag<SImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     LOG(Message) << "Computing tr(mag^n) for n even up to " << par().maxPow | ||||||
|  |                  << "..." << std::endl; | ||||||
|  |  | ||||||
|  |     std::vector<Result> result; | ||||||
|  |     ResultWriter        writer(RESULT_FILE_NAME(par().output)); | ||||||
|  |     auto                &phi = envGet(Field, par().field); | ||||||
|  |  | ||||||
|  |     auto m2 = sum(phi), mn = m2; | ||||||
|  |  | ||||||
|  |     m2 = -m2*m2; | ||||||
|  |     mn = 1.; | ||||||
|  |     for (unsigned int n = 2; n <= par().maxPow; n += 2) | ||||||
|  |     { | ||||||
|  |         Result r; | ||||||
|  |  | ||||||
|  |         mn = mn*m2; | ||||||
|  |         r.op    = "tr(mag^" + std::to_string(n) + ")"; | ||||||
|  |         r.value = TensorRemove(trace(mn)).real(); | ||||||
|  |         result.push_back(r); | ||||||
|  |     } | ||||||
|  |     write(writer, "trmag", result); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_MScalarSUN_TrMag_hpp_ | ||||||
							
								
								
									
										182
									
								
								extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										182
									
								
								extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,182 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  | #ifndef Hadrons_MScalarSUN_TrPhi_hpp_ | ||||||
|  | #define Hadrons_MScalarSUN_TrPhi_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                         Module to compute tr(phi^n)                        * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MScalarSUN) | ||||||
|  |  | ||||||
|  | class TrPhiPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(TrPhiPar, | ||||||
|  |                                     std::string,  field, | ||||||
|  |                                     unsigned int, maxPow, | ||||||
|  |                                     std::string,  output); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | class TTrPhi: public Module<TrPhiPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     typedef typename SImpl::Field        Field; | ||||||
|  |     typedef typename SImpl::ComplexField ComplexField; | ||||||
|  |     class Result: Serializable | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         GRID_SERIALIZABLE_CLASS_MEMBERS(Result, | ||||||
|  |                                         std::string, op, | ||||||
|  |                                         Real,        value); | ||||||
|  |     }; | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TTrPhi(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TTrPhi(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | private: | ||||||
|  |     // output name generator | ||||||
|  |     std::string outName(const unsigned int n); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(TrPhiSU2, TTrPhi<ScalarNxNAdjImplR<2>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrPhiSU3, TTrPhi<ScalarNxNAdjImplR<3>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrPhiSU4, TTrPhi<ScalarNxNAdjImplR<4>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrPhiSU5, TTrPhi<ScalarNxNAdjImplR<5>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TrPhiSU6, TTrPhi<ScalarNxNAdjImplR<6>>, MScalarSUN); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                          TTrPhi implementation                             * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | TTrPhi<SImpl>::TTrPhi(const std::string name) | ||||||
|  | : Module<TrPhiPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TTrPhi<SImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().field}; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TTrPhi<SImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out; | ||||||
|  |  | ||||||
|  |     for (unsigned int n = 2; n <= par().maxPow; n += 2) | ||||||
|  |     { | ||||||
|  |         out.push_back(outName(n)); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TTrPhi<SImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     if (par().maxPow < 2) | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Size, "'maxPow' should be at least equal to 2"); | ||||||
|  |     } | ||||||
|  |     envTmpLat(Field, "phi2"); | ||||||
|  |     envTmpLat(Field, "buf"); | ||||||
|  |     for (unsigned int n = 2; n <= par().maxPow; n += 2) | ||||||
|  |     { | ||||||
|  |         envCreateLat(ComplexField, outName(n)); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TTrPhi<SImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     LOG(Message) << "Computing tr(phi^n) for n even up to " << par().maxPow | ||||||
|  |                  << "..." << std::endl;  | ||||||
|  |  | ||||||
|  |     std::vector<Result> result; | ||||||
|  |     auto                &phi = envGet(Field, par().field); | ||||||
|  |  | ||||||
|  |     envGetTmp(Field, phi2); | ||||||
|  |     envGetTmp(Field, buf); | ||||||
|  |     buf  = 1.; | ||||||
|  |     phi2 = -phi*phi;  | ||||||
|  |     for (unsigned int n = 2; n <= par().maxPow; n += 2) | ||||||
|  |     { | ||||||
|  |         auto &phin = envGet(ComplexField, outName(n)); | ||||||
|  |  | ||||||
|  |         buf  = buf*phi2; | ||||||
|  |         phin = trace(buf); | ||||||
|  |         if (!par().output.empty()) | ||||||
|  |         { | ||||||
|  |             Result r; | ||||||
|  |  | ||||||
|  |             r.op    = "tr(phi^" + std::to_string(n) + ")"; | ||||||
|  |             r.value = TensorRemove(sum(phin)).real(); | ||||||
|  |             result.push_back(r); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     if (result.size() > 0) | ||||||
|  |     { | ||||||
|  |         ResultWriter writer(RESULT_FILE_NAME(par().output)); | ||||||
|  |  | ||||||
|  |         write(writer, "trphi", result); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // output name generator /////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | std::string TTrPhi<SImpl>::outName(const unsigned int n) | ||||||
|  | { | ||||||
|  |     return getName() + "_" + std::to_string(n); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_MScalarSUN_TrPhi_hpp_ | ||||||
							
								
								
									
										184
									
								
								extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,184 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  | #ifndef Hadrons_MScalarSUN_TwoPoint_hpp_ | ||||||
|  | #define Hadrons_MScalarSUN_TwoPoint_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                 2-pt functions for a given set of operators                * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MScalarSUN) | ||||||
|  |  | ||||||
|  | class TwoPointPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(TwoPointPar, | ||||||
|  |                                     std::vector<std::string>, op, | ||||||
|  |                                     std::string,              output); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | class TTwoPoint: public Module<TwoPointPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     typedef typename SImpl::Field        Field; | ||||||
|  |     typedef typename SImpl::ComplexField ComplexField; | ||||||
|  |     class Result: Serializable | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         GRID_SERIALIZABLE_CLASS_MEMBERS(Result, | ||||||
|  |                                         std::string, sink, | ||||||
|  |                                         std::string, source, | ||||||
|  |                                         std::vector<Complex>, data); | ||||||
|  |     }; | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TTwoPoint(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TTwoPoint(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | private: | ||||||
|  |     // make 2-pt function | ||||||
|  |     template <class SinkSite, class SourceSite> | ||||||
|  |     std::vector<Complex> makeTwoPoint(const std::vector<SinkSite>   &sink, | ||||||
|  |                                       const std::vector<SourceSite> &source); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(TwoPointSU2, TTwoPoint<ScalarNxNAdjImplR<2>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TwoPointSU3, TTwoPoint<ScalarNxNAdjImplR<3>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TwoPointSU4, TTwoPoint<ScalarNxNAdjImplR<4>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TwoPointSU5, TTwoPoint<ScalarNxNAdjImplR<5>>, MScalarSUN); | ||||||
|  | MODULE_REGISTER_NS(TwoPointSU6, TTwoPoint<ScalarNxNAdjImplR<6>>, MScalarSUN); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                 TTwoPoint implementation                             * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | TTwoPoint<SImpl>::TTwoPoint(const std::string name) | ||||||
|  | : Module<TwoPointPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TTwoPoint<SImpl>::getInput(void) | ||||||
|  | {    | ||||||
|  |     return par().op; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename SImpl> | ||||||
|  | std::vector<std::string> TTwoPoint<SImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {}; | ||||||
|  |  | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TTwoPoint<SImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     const unsigned int nt = env().getDim().back(); | ||||||
|  |     envTmp(std::vector<std::vector<TComplex>>, "slicedOp", 1, par().op.size(),  | ||||||
|  |            std::vector<TComplex>(nt)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename SImpl> | ||||||
|  | void TTwoPoint<SImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     LOG(Message) << "Computing 2-point functions for operators:" << std::endl; | ||||||
|  |     for (auto &o: par().op) | ||||||
|  |     { | ||||||
|  |         LOG(Message) << "  '" << o << "'" << std::endl; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     ResultWriter        writer(RESULT_FILE_NAME(par().output)); | ||||||
|  |     const unsigned int  nd = env().getDim().size(); | ||||||
|  |     std::vector<Result> result; | ||||||
|  |      | ||||||
|  |     envGetTmp(std::vector<std::vector<TComplex>>, slicedOp); | ||||||
|  |     for (unsigned int i = 0; i < par().op.size(); ++i) | ||||||
|  |     { | ||||||
|  |         auto &op = envGet(ComplexField, par().op[i]); | ||||||
|  |  | ||||||
|  |         sliceSum(op, slicedOp[i], nd - 1); | ||||||
|  |     } | ||||||
|  |     for (unsigned int i = 0; i < par().op.size(); ++i) | ||||||
|  |     for (unsigned int j = 0; j < par().op.size(); ++j) | ||||||
|  |     { | ||||||
|  |         Result r; | ||||||
|  |  | ||||||
|  |         r.sink   = par().op[i]; | ||||||
|  |         r.source = par().op[j]; | ||||||
|  |         r.data   = makeTwoPoint(slicedOp[i], slicedOp[j]); | ||||||
|  |         result.push_back(r); | ||||||
|  |     } | ||||||
|  |     write(writer, "twopt", result); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // make 2-pt function ////////////////////////////////////////////////////////// | ||||||
|  | template <class SImpl> | ||||||
|  | template <class SinkSite, class SourceSite> | ||||||
|  | std::vector<Complex> TTwoPoint<SImpl>::makeTwoPoint( | ||||||
|  |                                   const std::vector<SinkSite>   &sink, | ||||||
|  |                                   const std::vector<SourceSite> &source) | ||||||
|  | { | ||||||
|  |     assert(sink.size() == source.size()); | ||||||
|  |      | ||||||
|  |     unsigned int         nt = sink.size(); | ||||||
|  |     std::vector<Complex> res(nt, 0.); | ||||||
|  |      | ||||||
|  |     for (unsigned int dt = 0; dt < nt; ++dt) | ||||||
|  |     { | ||||||
|  |         for (unsigned int t  = 0; t < nt; ++t) | ||||||
|  |         { | ||||||
|  |             res[dt] += TensorRemove(trace(sink[(t+dt)%nt]*source[t])); | ||||||
|  |         } | ||||||
|  |         res[dt] *= 1./static_cast<double>(nt); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     return res; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_MScalarSUN_TwoPoint_hpp_ | ||||||
| @@ -1,3 +1,32 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MSink/Point.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
| #ifndef Hadrons_MSink_Point_hpp_ | #ifndef Hadrons_MSink_Point_hpp_ | ||||||
| #define Hadrons_MSink_Point_hpp_ | #define Hadrons_MSink_Point_hpp_ | ||||||
|  |  | ||||||
| @@ -33,10 +62,14 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
|  | private: | ||||||
|  |     bool        hasPhase_{false};  | ||||||
|  |     std::string momphName_; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| MODULE_REGISTER_NS(Point,       TPoint<FIMPL>,        MSink); | MODULE_REGISTER_NS(Point,       TPoint<FIMPL>,        MSink); | ||||||
| @@ -49,6 +82,7 @@ MODULE_REGISTER_NS(ScalarPoint, TPoint<ScalarImplCR>, MSink); | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| TPoint<FImpl>::TPoint(const std::string name) | TPoint<FImpl>::TPoint(const std::string name) | ||||||
| : Module<PointPar>(name) | : Module<PointPar>(name) | ||||||
|  | , momphName_ (name + "_momph") | ||||||
| {} | {} | ||||||
|  |  | ||||||
| // dependencies/products /////////////////////////////////////////////////////// | // dependencies/products /////////////////////////////////////////////////////// | ||||||
| @@ -72,22 +106,27 @@ std::vector<std::string> TPoint<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TPoint<FImpl>::setup(void) | void TPoint<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     unsigned int size; |     envTmpLat(LatticeComplex, "coor"); | ||||||
|      |     envCacheLat(LatticeComplex, momphName_); | ||||||
|     size = env().template lattice4dSize<LatticeComplex>(); |     envCreate(SinkFn, getName(), 1, nullptr); | ||||||
|     env().registerObject(getName(), size); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TPoint<FImpl>::execute(void) | void TPoint<FImpl>::execute(void) | ||||||
| {    | {    | ||||||
|     std::vector<Real> p = strToVec<Real>(par().mom); |  | ||||||
|     LatticeComplex    ph(env().getGrid()), coor(env().getGrid()); |  | ||||||
|     Complex           i(0.0,1.0); |  | ||||||
|      |  | ||||||
|     LOG(Message) << "Setting up point sink function for momentum [" |     LOG(Message) << "Setting up point sink function for momentum [" | ||||||
|                  << par().mom << "]" << std::endl; |                  << par().mom << "]" << std::endl; | ||||||
|  |  | ||||||
|  |     auto &ph = envGet(LatticeComplex, momphName_); | ||||||
|  |      | ||||||
|  |     if (!hasPhase_) | ||||||
|  |     { | ||||||
|  |         Complex           i(0.0,1.0); | ||||||
|  |         std::vector<Real> p; | ||||||
|  |  | ||||||
|  |         envGetTmp(LatticeComplex, coor); | ||||||
|  |         p  = strToVec<Real>(par().mom); | ||||||
|         ph = zero; |         ph = zero; | ||||||
|         for(unsigned int mu = 0; mu < env().getNd(); mu++) |         for(unsigned int mu = 0; mu < env().getNd(); mu++) | ||||||
|         { |         { | ||||||
| @@ -95,7 +134,9 @@ void TPoint<FImpl>::execute(void) | |||||||
|             ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; |             ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; | ||||||
|         } |         } | ||||||
|         ph = exp((Real)(2*M_PI)*i*ph); |         ph = exp((Real)(2*M_PI)*i*ph); | ||||||
|     auto sink = [ph](const PropagatorField &field) |         hasPhase_ = true; | ||||||
|  |     } | ||||||
|  |     auto sink = [&ph](const PropagatorField &field) | ||||||
|     { |     { | ||||||
|         SlicedPropagator res; |         SlicedPropagator res; | ||||||
|         PropagatorField  tmp = ph*field; |         PropagatorField  tmp = ph*field; | ||||||
| @@ -104,7 +145,7 @@ void TPoint<FImpl>::execute(void) | |||||||
|          |          | ||||||
|         return res; |         return res; | ||||||
|     }; |     }; | ||||||
|     env().setObject(getName(), new SinkFn(sink)); |     envGet(SinkFn, getName()) = sink; | ||||||
| } | } | ||||||
|  |  | ||||||
| END_MODULE_NAMESPACE | END_MODULE_NAMESPACE | ||||||
|   | |||||||
							
								
								
									
										127
									
								
								extras/Hadrons/Modules/MSink/Smear.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								extras/Hadrons/Modules/MSink/Smear.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,127 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MSink/Smear.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_MSink_Smear_hpp_ | ||||||
|  | #define Hadrons_MSink_Smear_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                                 Smear                                      * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MSink) | ||||||
|  |  | ||||||
|  | class SmearPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(SmearPar, | ||||||
|  |                                     std::string, q, | ||||||
|  |                                     std::string, sink); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | class TSmear: public Module<SmearPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     FERM_TYPE_ALIASES(FImpl,); | ||||||
|  |     SINK_TYPE_ALIASES(); | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TSmear(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TSmear(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(Smear, TSmear<FIMPL>, MSink); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                          TSmear implementation                             * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | TSmear<FImpl>::TSmear(const std::string name) | ||||||
|  | : Module<SmearPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TSmear<FImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().q, par().sink}; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TSmear<FImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TSmear<FImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     envCreate(SlicedPropagator, getName(), 1, env().getDim(Tp)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TSmear<FImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     LOG(Message) << "Sink smearing propagator '" << par().q | ||||||
|  |                  << "' using sink function '" << par().sink << "'." | ||||||
|  |                  << std::endl; | ||||||
|  |  | ||||||
|  |     auto &sink = envGet(SinkFn, par().sink); | ||||||
|  |     auto &q    = envGet(PropagatorField, par().q); | ||||||
|  |     auto &out  = envGet(SlicedPropagator, getName()); | ||||||
|  |      | ||||||
|  |     out = sink(q); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_MSink_Smear_hpp_ | ||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | Source file: extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -61,7 +60,9 @@ public: | |||||||
|     virtual ~TRBPrecCG(void) = default; |     virtual ~TRBPrecCG(void) = default; | ||||||
|     // dependencies/products |     // dependencies/products | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getReference(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -83,11 +84,19 @@ TRBPrecCG<FImpl>::TRBPrecCG(const std::string name) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| std::vector<std::string> TRBPrecCG<FImpl>::getInput(void) | std::vector<std::string> TRBPrecCG<FImpl>::getInput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> in = {par().action}; |     std::vector<std::string> in = {}; | ||||||
|      |      | ||||||
|     return in; |     return in; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TRBPrecCG<FImpl>::getReference(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> ref = {par().action}; | ||||||
|  |      | ||||||
|  |     return ref; | ||||||
|  | } | ||||||
|  |  | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void) | std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void) | ||||||
| { | { | ||||||
| @@ -100,17 +109,12 @@ std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TRBPrecCG<FImpl>::setup(void) | void TRBPrecCG<FImpl>::setup(void) | ||||||
| { | { | ||||||
|  |     LOG(Message) << "setting up Schur red-black preconditioned CG for" | ||||||
|  |                  << " action '" << par().action << "' with residual " | ||||||
|  |                  << par().residual << std::endl; | ||||||
|  |  | ||||||
|     auto Ls     = env().getObjectLs(par().action); |     auto Ls     = env().getObjectLs(par().action); | ||||||
|      |     auto &mat   = envGet(FMat, par().action); | ||||||
|     env().registerObject(getName(), 0, Ls); |  | ||||||
|     env().addOwnership(getName(), par().action); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// |  | ||||||
| template <typename FImpl> |  | ||||||
| void TRBPrecCG<FImpl>::execute(void) |  | ||||||
| { |  | ||||||
|     auto &mat   = *(env().template getObject<FMat>(par().action)); |  | ||||||
|     auto solver = [&mat, this](FermionField &sol, const FermionField &source) |     auto solver = [&mat, this](FermionField &sol, const FermionField &source) | ||||||
|     { |     { | ||||||
|         ConjugateGradient<FermionField>           cg(par().residual, 10000); |         ConjugateGradient<FermionField>           cg(par().residual, 10000); | ||||||
| @@ -118,13 +122,14 @@ void TRBPrecCG<FImpl>::execute(void) | |||||||
|          |          | ||||||
|         schurSolver(mat, source, sol); |         schurSolver(mat, source, sol); | ||||||
|     }; |     }; | ||||||
|      |     envCreate(SolverFn, getName(), Ls, solver); | ||||||
|     LOG(Message) << "setting up Schur red-black preconditioned CG for" |  | ||||||
|                  << " action '" << par().action << "' with residual " |  | ||||||
|                  << par().residual << std::endl; |  | ||||||
|     env().setObject(getName(), new SolverFn(solver)); |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TRBPrecCG<FImpl>::execute(void) | ||||||
|  | {} | ||||||
|  |  | ||||||
| END_MODULE_NAMESPACE | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
| END_HADRONS_NAMESPACE | END_HADRONS_NAMESPACE | ||||||
|   | |||||||
| @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MSource/Point.hpp | Source file: extras/Hadrons/Modules/MSource/Point.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -72,6 +72,7 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
| @@ -111,19 +112,20 @@ std::vector<std::string> TPoint<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TPoint<FImpl>::setup(void) | void TPoint<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     env().template registerLattice<PropagatorField>(getName()); |     envCreateLat(PropagatorField, getName()); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TPoint<FImpl>::execute(void) | void TPoint<FImpl>::execute(void) | ||||||
| { | { | ||||||
|     std::vector<int> position = strToVec<int>(par().position); |  | ||||||
|     typename SitePropagator::scalar_object id; |  | ||||||
|      |  | ||||||
|     LOG(Message) << "Creating point source at position [" << par().position |     LOG(Message) << "Creating point source at position [" << par().position | ||||||
|                 << "]" << std::endl; |                 << "]" << std::endl; | ||||||
|     PropagatorField &src = *env().template createLattice<PropagatorField>(getName()); |  | ||||||
|  |     std::vector<int> position = strToVec<int>(par().position); | ||||||
|  |     auto             &src     = envGet(PropagatorField, getName()); | ||||||
|  |     SitePropagator   id; | ||||||
|  |      | ||||||
|     id  = 1.; |     id  = 1.; | ||||||
|     src = zero; |     src = zero; | ||||||
|     pokeSite(id, src, position); |     pokeSite(id, src, position); | ||||||
|   | |||||||
							
								
								
									
										160
									
								
								extras/Hadrons/Modules/MSource/SeqConserved.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								extras/Hadrons/Modules/MSource/SeqConserved.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,160 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MSource/SeqConserved.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_MSource_SeqConserved_hpp_ | ||||||
|  | #define Hadrons_MSource_SeqConserved_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |   | ||||||
|  |  Sequential source | ||||||
|  |  ----------------------------- | ||||||
|  |  * src_x = q_x * theta(x_3 - tA) * theta(tB - x_3) * J_mu * exp(i x.mom) | ||||||
|  |   | ||||||
|  |  * options: | ||||||
|  |  - q: input propagator (string) | ||||||
|  |  - action: fermion action used for propagator q (string) | ||||||
|  |  - tA: begin timeslice (integer) | ||||||
|  |  - tB: end timesilce (integer) | ||||||
|  |  - curr_type: type of conserved current to insert (Current) | ||||||
|  |  - mu: Lorentz index of current to insert (integer) | ||||||
|  |  - mom: momentum insertion, space-separated float sequence (e.g ".1 .2 1. 0.") | ||||||
|  |   | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                              SeqConserved                                  * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MSource) | ||||||
|  |  | ||||||
|  | class SeqConservedPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(SeqConservedPar, | ||||||
|  |                                     std::string,  q, | ||||||
|  |                                     std::string,  action, | ||||||
|  |                                     unsigned int, tA, | ||||||
|  |                                     unsigned int, tB, | ||||||
|  |                                     Current,      curr_type, | ||||||
|  |                                     unsigned int, mu, | ||||||
|  |                                     std::string,  mom); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | class TSeqConserved: public Module<SeqConservedPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     FERM_TYPE_ALIASES(FImpl,); | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TSeqConserved(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TSeqConserved(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(SeqConserved, TSeqConserved<FIMPL>, MSource); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                      TSeqConserved implementation                          * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | TSeqConserved<FImpl>::TSeqConserved(const std::string name) | ||||||
|  | : Module<SeqConservedPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TSeqConserved<FImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().q, par().action}; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TSeqConserved<FImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TSeqConserved<FImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     auto Ls_ = env().getObjectLs(par().action); | ||||||
|  |     envCreateLat(PropagatorField, getName(), Ls_); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TSeqConserved<FImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     if (par().tA == par().tB) | ||||||
|  |     { | ||||||
|  |         LOG(Message) << "Generating sequential source with conserved " | ||||||
|  |                      << par().curr_type << " current insertion (mu = "  | ||||||
|  |                      << par().mu << ") at " << "t = " << par().tA << std::endl; | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         LOG(Message) << "Generating sequential source with conserved " | ||||||
|  |                      << par().curr_type << " current insertion (mu = "  | ||||||
|  |                      << par().mu << ") for " << par().tA << " <= t <= "  | ||||||
|  |                      << par().tB << std::endl; | ||||||
|  |     } | ||||||
|  |     auto &src = envGet(PropagatorField, getName()); | ||||||
|  |     auto &q   = envGet(PropagatorField, par().q); | ||||||
|  |     auto &mat = envGet(FMat, par().action); | ||||||
|  |  | ||||||
|  |     std::vector<Real> mom = strToVec<Real>(par().mom); | ||||||
|  |     mat.SeqConservedCurrent(q, src, par().curr_type, par().mu,  | ||||||
|  |                             mom, par().tA, par().tB); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_SeqConserved_hpp_ | ||||||
| @@ -4,11 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MSource/SeqGamma.hpp | Source file: extras/Hadrons/Modules/MSource/SeqGamma.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
| Copyright (C) 2017 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -81,10 +80,14 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
|  | private: | ||||||
|  |     bool        hasPhase_{false}; | ||||||
|  |     std::string momphName_, tName_; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| MODULE_REGISTER_NS(SeqGamma, TSeqGamma<FIMPL>, MSource); | MODULE_REGISTER_NS(SeqGamma, TSeqGamma<FIMPL>, MSource); | ||||||
| @@ -96,6 +99,8 @@ MODULE_REGISTER_NS(SeqGamma, TSeqGamma<FIMPL>, MSource); | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| TSeqGamma<FImpl>::TSeqGamma(const std::string name) | TSeqGamma<FImpl>::TSeqGamma(const std::string name) | ||||||
| : Module<SeqGammaPar>(name) | : Module<SeqGammaPar>(name) | ||||||
|  | , momphName_ (name + "_momph") | ||||||
|  | , tName_ (name + "_t") | ||||||
| {} | {} | ||||||
|  |  | ||||||
| // dependencies/products /////////////////////////////////////////////////////// | // dependencies/products /////////////////////////////////////////////////////// | ||||||
| @@ -119,7 +124,10 @@ std::vector<std::string> TSeqGamma<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TSeqGamma<FImpl>::setup(void) | void TSeqGamma<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     env().template registerLattice<PropagatorField>(getName()); |     envCreateLat(PropagatorField, getName()); | ||||||
|  |     envCacheLat(Lattice<iScalar<vInteger>>, tName_); | ||||||
|  |     envCacheLat(LatticeComplex, momphName_); | ||||||
|  |     envTmpLat(LatticeComplex, "coor"); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| @@ -137,23 +145,29 @@ void TSeqGamma<FImpl>::execute(void) | |||||||
|                      << " sequential source for " |                      << " sequential source for " | ||||||
|                      << par().tA << " <= t <= " << par().tB << std::endl; |                      << par().tA << " <= t <= " << par().tB << std::endl; | ||||||
|     } |     } | ||||||
|     PropagatorField &src = *env().template createLattice<PropagatorField>(getName()); |     auto  &src = envGet(PropagatorField, getName()); | ||||||
|     PropagatorField &q   = *env().template getObject<PropagatorField>(par().q); |     auto  &q   = envGet(PropagatorField, par().q); | ||||||
|     Lattice<iScalar<vInteger>> t(env().getGrid()); |     auto  &ph  = envGet(LatticeComplex, momphName_); | ||||||
|     LatticeComplex             ph(env().getGrid()), coor(env().getGrid()); |     auto  &t   = envGet(Lattice<iScalar<vInteger>>, tName_); | ||||||
|     Gamma g(par().gamma); |     Gamma g(par().gamma); | ||||||
|     std::vector<Real>          p; |  | ||||||
|     Complex                    i(0.0,1.0); |  | ||||||
|      |      | ||||||
|  |     if (!hasPhase_) | ||||||
|  |     { | ||||||
|  |         Complex           i(0.0,1.0); | ||||||
|  |         std::vector<Real> p; | ||||||
|  |  | ||||||
|  |         envGetTmp(LatticeComplex, coor); | ||||||
|         p  = strToVec<Real>(par().mom); |         p  = strToVec<Real>(par().mom); | ||||||
|         ph = zero; |         ph = zero; | ||||||
|         for(unsigned int mu = 0; mu < env().getNd(); mu++) |         for(unsigned int mu = 0; mu < env().getNd(); mu++) | ||||||
|         { |         { | ||||||
|             LatticeCoordinate(coor, mu); |             LatticeCoordinate(coor, mu); | ||||||
|         ph = ph + p[mu]*coor*((1./(env().getGrid()->_fdimensions[mu]))); |             ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; | ||||||
|         } |         } | ||||||
|         ph = exp((Real)(2*M_PI)*i*ph); |         ph = exp((Real)(2*M_PI)*i*ph); | ||||||
|         LatticeCoordinate(t, Tp); |         LatticeCoordinate(t, Tp); | ||||||
|  |         hasPhase_ = true; | ||||||
|  |     } | ||||||
|     src = where((t >= par().tA) and (t <= par().tB), ph*(g*q), 0.*q); |     src = where((t >= par().tA) and (t <= par().tB), ph*(g*q), 0.*q); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MSource/Wall.hpp | Source file: extras/Hadrons/Modules/MSource/Wall.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2017 | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
| Author: Andrew Lawson <andrew.lawson1991@gmail.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
| This program is free software; you can redistribute it and/or modify | This program is free software; you can redistribute it and/or modify | ||||||
| it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | ||||||
| @@ -73,10 +74,14 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
|  | private: | ||||||
|  |     bool        hasPhase_{false}; | ||||||
|  |     std::string momphName_, tName_; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| MODULE_REGISTER_NS(Wall, TWall<FIMPL>, MSource); | MODULE_REGISTER_NS(Wall, TWall<FIMPL>, MSource); | ||||||
| @@ -88,13 +93,15 @@ MODULE_REGISTER_NS(Wall, TWall<FIMPL>, MSource); | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| TWall<FImpl>::TWall(const std::string name) | TWall<FImpl>::TWall(const std::string name) | ||||||
| : Module<WallPar>(name) | : Module<WallPar>(name) | ||||||
|  | , momphName_ (name + "_momph") | ||||||
|  | , tName_ (name + "_t") | ||||||
| {} | {} | ||||||
|  |  | ||||||
| // dependencies/products /////////////////////////////////////////////////////// | // dependencies/products /////////////////////////////////////////////////////// | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| std::vector<std::string> TWall<FImpl>::getInput(void) | std::vector<std::string> TWall<FImpl>::getInput(void) | ||||||
| { | { | ||||||
|     std::vector<std::string> in; |     std::vector<std::string> in = {}; | ||||||
|      |      | ||||||
|     return in; |     return in; | ||||||
| } | } | ||||||
| @@ -111,7 +118,7 @@ std::vector<std::string> TWall<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TWall<FImpl>::setup(void) | void TWall<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     env().template registerLattice<PropagatorField>(getName()); |     envCreateLat(PropagatorField, getName()); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| @@ -121,21 +128,28 @@ void TWall<FImpl>::execute(void) | |||||||
|     LOG(Message) << "Generating wall source at t = " << par().tW  |     LOG(Message) << "Generating wall source at t = " << par().tW  | ||||||
|                  << " with momentum " << par().mom << std::endl; |                  << " with momentum " << par().mom << std::endl; | ||||||
|      |      | ||||||
|     PropagatorField &src = *env().template createLattice<PropagatorField>(getName()); |     auto  &src = envGet(PropagatorField, getName()); | ||||||
|     Lattice<iScalar<vInteger>> t(env().getGrid()); |     auto  &ph  = envGet(LatticeComplex, momphName_); | ||||||
|     LatticeComplex             ph(env().getGrid()), coor(env().getGrid()); |     auto  &t   = envGet(Lattice<iScalar<vInteger>>, tName_); | ||||||
|     std::vector<Real>          p; |  | ||||||
|     Complex                    i(0.0,1.0); |  | ||||||
|      |      | ||||||
|  |     if (!hasPhase_) | ||||||
|  |     { | ||||||
|  |         Complex           i(0.0,1.0); | ||||||
|  |         std::vector<Real> p; | ||||||
|  |  | ||||||
|  |         envGetTmp(LatticeComplex, coor); | ||||||
|         p  = strToVec<Real>(par().mom); |         p  = strToVec<Real>(par().mom); | ||||||
|         ph = zero; |         ph = zero; | ||||||
|     for(unsigned int mu = 0; mu < Nd; mu++) |         for(unsigned int mu = 0; mu < env().getNd(); mu++) | ||||||
|         { |         { | ||||||
|             LatticeCoordinate(coor, mu); |             LatticeCoordinate(coor, mu); | ||||||
|         ph = ph + p[mu]*coor*((1./(env().getGrid()->_fdimensions[mu]))); |             ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; | ||||||
|         } |         } | ||||||
|         ph = exp((Real)(2*M_PI)*i*ph); |         ph = exp((Real)(2*M_PI)*i*ph); | ||||||
|         LatticeCoordinate(t, Tp); |         LatticeCoordinate(t, Tp); | ||||||
|  |         hasPhase_ = true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     src = 1.; |     src = 1.; | ||||||
|     src = where((t == par().tW), src*ph, 0.*src); |     src = where((t == par().tW), src*ph, 0.*src); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid | |||||||
|  |  | ||||||
| Source file: extras/Hadrons/Modules/MSource/Z2.hpp | Source file: extras/Hadrons/Modules/MSource/Z2.hpp | ||||||
|  |  | ||||||
| Copyright (C) 2015 | Copyright (C) 2015-2018 | ||||||
| Copyright (C) 2016 |  | ||||||
|  |  | ||||||
| Author: Antonin Portelli <antonin.portelli@me.com> | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
| @@ -76,10 +75,14 @@ public: | |||||||
|     // dependency relation |     // dependency relation | ||||||
|     virtual std::vector<std::string> getInput(void); |     virtual std::vector<std::string> getInput(void); | ||||||
|     virtual std::vector<std::string> getOutput(void); |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|     // setup |     // setup | ||||||
|     virtual void setup(void); |     virtual void setup(void); | ||||||
|     // execution |     // execution | ||||||
|     virtual void execute(void); |     virtual void execute(void); | ||||||
|  | private: | ||||||
|  |     bool        hasT_{false}; | ||||||
|  |     std::string tName_; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| MODULE_REGISTER_NS(Z2,       TZ2<FIMPL>,        MSource); | MODULE_REGISTER_NS(Z2,       TZ2<FIMPL>,        MSource); | ||||||
| @@ -92,6 +95,7 @@ MODULE_REGISTER_NS(ScalarZ2, TZ2<ScalarImplCR>, MSource); | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| TZ2<FImpl>::TZ2(const std::string name) | TZ2<FImpl>::TZ2(const std::string name) | ||||||
| : Module<Z2Par>(name) | : Module<Z2Par>(name) | ||||||
|  | , tName_ (name + "_t") | ||||||
| {} | {} | ||||||
|  |  | ||||||
| // dependencies/products /////////////////////////////////////////////////////// | // dependencies/products /////////////////////////////////////////////////////// | ||||||
| @@ -115,17 +119,15 @@ std::vector<std::string> TZ2<FImpl>::getOutput(void) | |||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TZ2<FImpl>::setup(void) | void TZ2<FImpl>::setup(void) | ||||||
| { | { | ||||||
|     env().template registerLattice<PropagatorField>(getName()); |     envCreateLat(PropagatorField, getName()); | ||||||
|  |     envCacheLat(Lattice<iScalar<vInteger>>, tName_); | ||||||
|  |     envTmpLat(LatticeComplex, "eta"); | ||||||
| } | } | ||||||
|  |  | ||||||
| // execution /////////////////////////////////////////////////////////////////// | // execution /////////////////////////////////////////////////////////////////// | ||||||
| template <typename FImpl> | template <typename FImpl> | ||||||
| void TZ2<FImpl>::execute(void) | void TZ2<FImpl>::execute(void) | ||||||
| { | { | ||||||
|     Lattice<iScalar<vInteger>> t(env().getGrid()); |  | ||||||
|     LatticeComplex             eta(env().getGrid()); |  | ||||||
|     Complex                    shift(1., 1.); |  | ||||||
|      |  | ||||||
|     if (par().tA == par().tB) |     if (par().tA == par().tB) | ||||||
|     { |     { | ||||||
|         LOG(Message) << "Generating Z_2 wall source at t= " << par().tA |         LOG(Message) << "Generating Z_2 wall source at t= " << par().tA | ||||||
| @@ -136,8 +138,17 @@ void TZ2<FImpl>::execute(void) | |||||||
|         LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " |         LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " | ||||||
|                      << par().tB << std::endl; |                      << par().tB << std::endl; | ||||||
|     } |     } | ||||||
|     PropagatorField &src = *env().template createLattice<PropagatorField>(getName()); |      | ||||||
|  |     auto    &src = envGet(PropagatorField, getName()); | ||||||
|  |     auto    &t   = envGet(Lattice<iScalar<vInteger>>, tName_); | ||||||
|  |     Complex shift(1., 1.); | ||||||
|  |  | ||||||
|  |     if (!hasT_) | ||||||
|  |     { | ||||||
|         LatticeCoordinate(t, Tp); |         LatticeCoordinate(t, Tp); | ||||||
|  |         hasT_ = true; | ||||||
|  |     } | ||||||
|  |     envGetTmp(LatticeComplex, eta); | ||||||
|     bernoulli(*env().get4dRng(), eta); |     bernoulli(*env().get4dRng(), eta); | ||||||
|     eta = (2.*eta - shift)*(1./::sqrt(2.)); |     eta = (2.*eta - shift)*(1./::sqrt(2.)); | ||||||
|     eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta); |     eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta); | ||||||
|   | |||||||
							
								
								
									
										186
									
								
								extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										186
									
								
								extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,186 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_MUtilities_TestSeqConserved_hpp_ | ||||||
|  | #define Hadrons_MUtilities_TestSeqConserved_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |   Ward Identity contractions using sequential propagators. | ||||||
|  |  ----------------------------- | ||||||
|  |   | ||||||
|  |  * options: | ||||||
|  |  - q:      point source propagator, 5D if available (string) | ||||||
|  |  - qSeq:   result of sequential insertion of conserved current using q (string) | ||||||
|  |  - action: action used for computation of q (string) | ||||||
|  |  - origin: string giving point source origin of q (string) | ||||||
|  |  - t_J:    time at which sequential current is inserted (int) | ||||||
|  |  - mu:     Lorentz index of current inserted (int) | ||||||
|  |  - curr:   current type, e.g. vector/axial (Current) | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                            TestSeqConserved                                * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MUtilities) | ||||||
|  |  | ||||||
|  | class TestSeqConservedPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(TestSeqConservedPar, | ||||||
|  |                                     std::string,  q, | ||||||
|  |                                     std::string,  qSeq, | ||||||
|  |                                     std::string,  action, | ||||||
|  |                                     std::string,  origin, | ||||||
|  |                                     unsigned int, t_J, | ||||||
|  |                                     unsigned int, mu, | ||||||
|  |                                     Current,      curr); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | class TTestSeqConserved: public Module<TestSeqConservedPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     FERM_TYPE_ALIASES(FImpl,); | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TTestSeqConserved(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TTestSeqConserved(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(TestSeqConserved, TTestSeqConserved<FIMPL>, MUtilities); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                     TTestSeqConserved implementation                       * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | TTestSeqConserved<FImpl>::TTestSeqConserved(const std::string name) | ||||||
|  | : Module<TestSeqConservedPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TTestSeqConserved<FImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().q, par().qSeq, par().action}; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TTestSeqConserved<FImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TTestSeqConserved<FImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     auto Ls = env().getObjectLs(par().q); | ||||||
|  |     if (Ls != env().getObjectLs(par().action)) | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Size, "Ls mismatch between quark action and propagator"); | ||||||
|  |     } | ||||||
|  |     envTmpLat(PropagatorField, "tmp"); | ||||||
|  |     envTmpLat(LatticeComplex, "c"); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TTestSeqConserved<FImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     // Check sequential insertion of current gives same result as conserved  | ||||||
|  |     // current sink upon contraction. Assume q uses a point source. | ||||||
|  |  | ||||||
|  |     auto                  &q    = envGet(PropagatorField, par().q); | ||||||
|  |     auto                  &qSeq = envGet(PropagatorField, par().qSeq); | ||||||
|  |     auto                  &act  = envGet(FMat, par().action); | ||||||
|  |     Gamma                 g5(Gamma::Algebra::Gamma5); | ||||||
|  |     Gamma::Algebra        gA = (par().curr == Current::Axial) ? | ||||||
|  |                                   Gamma::Algebra::Gamma5 : | ||||||
|  |                                   Gamma::Algebra::Identity; | ||||||
|  |     Gamma                 g(gA); | ||||||
|  |     SitePropagator        qSite; | ||||||
|  |     Complex               test_S, test_V, check_S, check_V; | ||||||
|  |     std::vector<TComplex> check_buf; | ||||||
|  |     std::vector<int>      siteCoord; | ||||||
|  |  | ||||||
|  |     envGetTmp(PropagatorField, tmp); | ||||||
|  |     envGetTmp(LatticeComplex, c); | ||||||
|  |     siteCoord = strToVec<int>(par().origin); | ||||||
|  |     peekSite(qSite, qSeq, siteCoord); | ||||||
|  |     test_S = trace(qSite*g); | ||||||
|  |     test_V = trace(qSite*g*Gamma::gmu[par().mu]); | ||||||
|  |     act.ContractConservedCurrent(q, q, tmp, par().curr, par().mu); | ||||||
|  |     c = trace(tmp*g); | ||||||
|  |     sliceSum(c, check_buf, Tp); | ||||||
|  |     check_S = TensorRemove(check_buf[par().t_J]); | ||||||
|  |  | ||||||
|  |     c = trace(tmp*g*Gamma::gmu[par().mu]); | ||||||
|  |     sliceSum(c, check_buf, Tp); | ||||||
|  |     check_V = TensorRemove(check_buf[par().t_J]); | ||||||
|  |  | ||||||
|  |     LOG(Message) << "Test S  = " << abs(test_S)   << std::endl; | ||||||
|  |     LOG(Message) << "Test V  = " << abs(test_V) << std::endl; | ||||||
|  |     LOG(Message) << "Check S = " << abs(check_S) << std::endl; | ||||||
|  |     LOG(Message) << "Check V = " << abs(check_V) << std::endl; | ||||||
|  |  | ||||||
|  |     // Check difference = 0 | ||||||
|  |     check_S -= test_S; | ||||||
|  |     check_V -= test_V; | ||||||
|  |  | ||||||
|  |     LOG(Message) << "Consistency check for sequential conserved "  | ||||||
|  |                  << par().curr << " current insertion: " << std::endl;  | ||||||
|  |     LOG(Message) << "Diff S  = " << abs(check_S) << std::endl; | ||||||
|  |     LOG(Message) << "Diff V  = " << abs(check_V) << std::endl; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_TestSeqConserved_hpp_ | ||||||
							
								
								
									
										150
									
								
								extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										150
									
								
								extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,150 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  | Author: Lanny91 <andrew.lawson@gmail.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_MUtilities_TestSeqGamma_hpp_ | ||||||
|  | #define Hadrons_MUtilities_TestSeqGamma_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Module.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                              TestSeqGamma                                  * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | BEGIN_MODULE_NAMESPACE(MUtilities) | ||||||
|  |  | ||||||
|  | class TestSeqGammaPar: Serializable | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     GRID_SERIALIZABLE_CLASS_MEMBERS(TestSeqGammaPar, | ||||||
|  |                                     std::string,    q, | ||||||
|  |                                     std::string,    qSeq, | ||||||
|  |                                     std::string,    origin, | ||||||
|  |                                     Gamma::Algebra, gamma, | ||||||
|  |                                     unsigned int,   t_g); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | class TTestSeqGamma: public Module<TestSeqGammaPar> | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     FERM_TYPE_ALIASES(FImpl,); | ||||||
|  | public: | ||||||
|  |     // constructor | ||||||
|  |     TTestSeqGamma(const std::string name); | ||||||
|  |     // destructor | ||||||
|  |     virtual ~TTestSeqGamma(void) = default; | ||||||
|  |     // dependency relation | ||||||
|  |     virtual std::vector<std::string> getInput(void); | ||||||
|  |     virtual std::vector<std::string> getOutput(void); | ||||||
|  | protected: | ||||||
|  |     // setup | ||||||
|  |     virtual void setup(void); | ||||||
|  |     // execution | ||||||
|  |     virtual void execute(void); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | MODULE_REGISTER_NS(TestSeqGamma, TTestSeqGamma<FIMPL>, MUtilities); | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                      TTestSeqGamma implementation                          * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // constructor ///////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | TTestSeqGamma<FImpl>::TTestSeqGamma(const std::string name) | ||||||
|  | : Module<TestSeqGammaPar>(name) | ||||||
|  | {} | ||||||
|  |  | ||||||
|  | // dependencies/products /////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TTestSeqGamma<FImpl>::getInput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> in = {par().q, par().qSeq}; | ||||||
|  |      | ||||||
|  |     return in; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename FImpl> | ||||||
|  | std::vector<std::string> TTestSeqGamma<FImpl>::getOutput(void) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> out = {getName()}; | ||||||
|  |      | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // setup /////////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TTestSeqGamma<FImpl>::setup(void) | ||||||
|  | { | ||||||
|  |     envTmpLat(LatticeComplex, "c"); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // execution /////////////////////////////////////////////////////////////////// | ||||||
|  | template <typename FImpl> | ||||||
|  | void TTestSeqGamma<FImpl>::execute(void) | ||||||
|  | { | ||||||
|  |     auto                  &q    = envGet(PropagatorField, par().q); | ||||||
|  |     auto                  &qSeq = envGet(PropagatorField, par().qSeq); | ||||||
|  |     Gamma                 g5(Gamma::Algebra::Gamma5); | ||||||
|  |     Gamma                 g(par().gamma); | ||||||
|  |     SitePropagator        qSite; | ||||||
|  |     Complex               test, check; | ||||||
|  |     std::vector<TComplex> check_buf; | ||||||
|  |     std::vector<int>      siteCoord; | ||||||
|  |  | ||||||
|  |     // Check sequential insertion of gamma matrix gives same result as  | ||||||
|  |     // insertion of gamma at sink upon contraction. Assume q uses a point  | ||||||
|  |     // source. | ||||||
|  |      | ||||||
|  |     envGetTmp(LatticeComplex, c); | ||||||
|  |     siteCoord = strToVec<int>(par().origin); | ||||||
|  |     peekSite(qSite, qSeq, siteCoord); | ||||||
|  |     test = trace(g*qSite); | ||||||
|  |  | ||||||
|  |     c = trace(adj(g)*g5*adj(q)*g5*g*q); | ||||||
|  |     sliceSum(c, check_buf, Tp); | ||||||
|  |     check = TensorRemove(check_buf[par().t_g]); | ||||||
|  |  | ||||||
|  |     LOG(Message) << "Seq Result = " << abs(test)  << std::endl; | ||||||
|  |     LOG(Message) << "Reference  = " << abs(check) << std::endl; | ||||||
|  |  | ||||||
|  |     // Check difference = 0 | ||||||
|  |     check -= test; | ||||||
|  |  | ||||||
|  |     LOG(Message) << "Consistency check for sequential " << par().gamma   | ||||||
|  |                  << " insertion = " << abs(check) << std::endl; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_MODULE_NAMESPACE | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_TestSeqGamma_hpp_ | ||||||
							
								
								
									
										622
									
								
								extras/Hadrons/VirtualMachine.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										622
									
								
								extras/Hadrons/VirtualMachine.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,622 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/VirtualMachine.cc | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/VirtualMachine.hpp> | ||||||
|  | #include <Grid/Hadrons/GeneticScheduler.hpp> | ||||||
|  | #include <Grid/Hadrons/ModuleFactory.hpp> | ||||||
|  |  | ||||||
|  | using namespace Grid; | ||||||
|  | using namespace QCD; | ||||||
|  | using namespace Hadrons; | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                      VirtualMachine implementation                         * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // trajectory counter ////////////////////////////////////////////////////////// | ||||||
|  | void VirtualMachine::setTrajectory(const unsigned int traj) | ||||||
|  | { | ||||||
|  |     traj_ = traj; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | unsigned int VirtualMachine::getTrajectory(void) const | ||||||
|  | { | ||||||
|  |     return traj_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // module management /////////////////////////////////////////////////////////// | ||||||
|  | void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) | ||||||
|  | { | ||||||
|  |     std::string name = pt->getName(); | ||||||
|  |      | ||||||
|  |     if (!hasModule(name)) | ||||||
|  |     { | ||||||
|  |         std::vector<unsigned int> inputAddress; | ||||||
|  |         unsigned int              address; | ||||||
|  |         ModuleInfo                m; | ||||||
|  |          | ||||||
|  |         // module registration ------------------------------------------------- | ||||||
|  |         m.data = std::move(pt); | ||||||
|  |         m.type = typeIdPt(*m.data.get()); | ||||||
|  |         m.name = name; | ||||||
|  |         // input dependencies | ||||||
|  |         for (auto &in: m.data->getInput()) | ||||||
|  |         { | ||||||
|  |             if (!env().hasObject(in)) | ||||||
|  |             { | ||||||
|  |                 // if object does not exist, add it with no creator module | ||||||
|  |                 env().addObject(in , -1); | ||||||
|  |             } | ||||||
|  |             m.input.push_back(env().getObjectAddress(in)); | ||||||
|  |         } | ||||||
|  |         // reference dependencies | ||||||
|  |         for (auto &ref: m.data->getReference()) | ||||||
|  |         { | ||||||
|  |             if (!env().hasObject(ref)) | ||||||
|  |             { | ||||||
|  |                 // if object does not exist, add it with no creator module | ||||||
|  |                 env().addObject(ref , -1); | ||||||
|  |             } | ||||||
|  |             m.input.push_back(env().getObjectAddress(ref)); | ||||||
|  |         } | ||||||
|  |         auto inCopy = m.input; | ||||||
|  |         // if module has inputs with references, they need to be added as | ||||||
|  |         // an input | ||||||
|  |         for (auto &in: inCopy) | ||||||
|  |         { | ||||||
|  |             int inm = env().getObjectModule(in); | ||||||
|  |  | ||||||
|  |             if (inm > 0) | ||||||
|  |             { | ||||||
|  |                 if (getModule(inm)->getReference().size() > 0) | ||||||
|  |                 { | ||||||
|  |                     for (auto &rin: getModule(inm)->getReference()) | ||||||
|  |                     { | ||||||
|  |                         m.input.push_back(env().getObjectAddress(rin)); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         module_.push_back(std::move(m)); | ||||||
|  |         address              = static_cast<unsigned int>(module_.size() - 1); | ||||||
|  |         moduleAddress_[name] = address; | ||||||
|  |         // connecting outputs to potential inputs ------------------------------ | ||||||
|  |         for (auto &out: getModule(address)->getOutput()) | ||||||
|  |         { | ||||||
|  |             if (!env().hasObject(out)) | ||||||
|  |             { | ||||||
|  |                 // output does not exists, add it | ||||||
|  |                 env().addObject(out, address); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 if (env().getObjectModule(env().getObjectAddress(out)) < 0) | ||||||
|  |                 { | ||||||
|  |                     // output exists but without creator, correct it | ||||||
|  |                     env().setObjectModule(env().getObjectAddress(out), address); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     // output already fully registered, error | ||||||
|  |                     HADRON_ERROR(Definition, "object '" + out | ||||||
|  |                                  + "' is already produced by module '" | ||||||
|  |                                  + module_[env().getObjectModule(out)].name | ||||||
|  |                                  + "' (while pushing module '" + name + "')"); | ||||||
|  |                 } | ||||||
|  |                 if (getModule(address)->getReference().size() > 0) | ||||||
|  |                 { | ||||||
|  |                     // module has references, dependency should be propagated | ||||||
|  |                     // to children modules; find module with `out` as an input | ||||||
|  |                     // and add references to their input | ||||||
|  |                     auto pred = [this, out](const ModuleInfo &n) | ||||||
|  |                     { | ||||||
|  |                         auto &in = n.input; | ||||||
|  |                         auto it  = std::find(in.begin(), in.end(),  | ||||||
|  |                                              env().getObjectAddress(out)); | ||||||
|  |                          | ||||||
|  |                         return (it != in.end()); | ||||||
|  |                     }; | ||||||
|  |                     auto it = std::find_if(module_.begin(), module_.end(), pred); | ||||||
|  |                     while (it != module_.end()) | ||||||
|  |                     { | ||||||
|  |                         for (auto &ref: getModule(address)->getReference()) | ||||||
|  |                         { | ||||||
|  |                             it->input.push_back(env().getObjectAddress(ref)); | ||||||
|  |                         } | ||||||
|  |                         it = std::find_if(++it, module_.end(), pred); | ||||||
|  |                     }    | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         graphOutdated_         = true; | ||||||
|  |         memoryProfileOutdated_ = true; | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Definition, "module '" + name + "' already exists"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | unsigned int VirtualMachine::getNModule(void) const | ||||||
|  | { | ||||||
|  |     return module_.size(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::createModule(const std::string name, const std::string type, | ||||||
|  |                                   XmlReader &reader) | ||||||
|  | { | ||||||
|  |     auto &factory = ModuleFactory::getInstance(); | ||||||
|  |     auto pt       = factory.create(type, name); | ||||||
|  |      | ||||||
|  |     pt->parseParameters(reader, "options"); | ||||||
|  |     pushModule(pt); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ModuleBase * VirtualMachine::getModule(const unsigned int address) const | ||||||
|  | { | ||||||
|  |     if (hasModule(address)) | ||||||
|  |     { | ||||||
|  |         return module_[address].data.get(); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Definition, "no module with address " + std::to_string(address)); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ModuleBase * VirtualMachine::getModule(const std::string name) const | ||||||
|  | { | ||||||
|  |     return getModule(getModuleAddress(name)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | unsigned int VirtualMachine::getModuleAddress(const std::string name) const | ||||||
|  | { | ||||||
|  |     if (hasModule(name)) | ||||||
|  |     { | ||||||
|  |         return moduleAddress_.at(name); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Definition, "no module with name '" + name + "'"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string VirtualMachine::getModuleName(const unsigned int address) const | ||||||
|  | { | ||||||
|  |     if (hasModule(address)) | ||||||
|  |     { | ||||||
|  |         return module_[address].name; | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Definition, "no module with address " + std::to_string(address)); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string VirtualMachine::getModuleType(const unsigned int address) const | ||||||
|  | { | ||||||
|  |     if (hasModule(address)) | ||||||
|  |     { | ||||||
|  |         return typeName(module_[address].type); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Definition, "no module with address " + std::to_string(address)); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string VirtualMachine::getModuleType(const std::string name) const | ||||||
|  | { | ||||||
|  |     return getModuleType(getModuleAddress(name)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string VirtualMachine::getModuleNamespace(const unsigned int address) const | ||||||
|  | { | ||||||
|  |     std::string type = getModuleType(address), ns; | ||||||
|  |      | ||||||
|  |     auto pos2 = type.rfind("::"); | ||||||
|  |     auto pos1 = type.rfind("::", pos2 - 2); | ||||||
|  |      | ||||||
|  |     return type.substr(pos1 + 2, pos2 - pos1 - 2); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string VirtualMachine::getModuleNamespace(const std::string name) const | ||||||
|  | { | ||||||
|  |     return getModuleNamespace(getModuleAddress(name)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool VirtualMachine::hasModule(const unsigned int address) const | ||||||
|  | { | ||||||
|  |     return (address < module_.size()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool VirtualMachine::hasModule(const std::string name) const | ||||||
|  | { | ||||||
|  |     return (moduleAddress_.find(name) != moduleAddress_.end()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // print VM content //////////////////////////////////////////////////////////// | ||||||
|  | void VirtualMachine::printContent(void) const | ||||||
|  | { | ||||||
|  |     LOG(Debug) << "Modules: " << std::endl; | ||||||
|  |     for (unsigned int i = 0; i < module_.size(); ++i) | ||||||
|  |     { | ||||||
|  |         LOG(Debug) << std::setw(4) << i << ": " | ||||||
|  |                    << getModuleName(i) << std::endl; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // module graph //////////////////////////////////////////////////////////////// | ||||||
|  | Graph<unsigned int> VirtualMachine::getModuleGraph(void) | ||||||
|  | { | ||||||
|  |     if (graphOutdated_) | ||||||
|  |     { | ||||||
|  |         makeModuleGraph(); | ||||||
|  |         graphOutdated_ = false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return graph_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::makeModuleGraph(void) | ||||||
|  | { | ||||||
|  |     Graph<unsigned int> graph; | ||||||
|  |      | ||||||
|  |     // create vertices | ||||||
|  |     for (unsigned int m = 0; m < module_.size(); ++m) | ||||||
|  |     { | ||||||
|  |         graph.addVertex(m); | ||||||
|  |     } | ||||||
|  |     // create edges | ||||||
|  |     for (unsigned int m = 0; m < module_.size(); ++m) | ||||||
|  |     { | ||||||
|  |         for (auto &in: module_[m].input) | ||||||
|  |         { | ||||||
|  |             graph.addEdge(env().getObjectModule(in), m); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     graph_ = graph; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // memory profile ////////////////////////////////////////////////////////////// | ||||||
|  | const VirtualMachine::MemoryProfile & VirtualMachine::getMemoryProfile(void) | ||||||
|  | { | ||||||
|  |     if (memoryProfileOutdated_) | ||||||
|  |     { | ||||||
|  |         makeMemoryProfile(); | ||||||
|  |         memoryProfileOutdated_ = false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return profile_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::makeMemoryProfile(void) | ||||||
|  | { | ||||||
|  |     bool protect = env().objectsProtected(); | ||||||
|  |     bool hmsg    = HadronsLogMessage.isActive(); | ||||||
|  |     bool gmsg    = GridLogMessage.isActive(); | ||||||
|  |     bool err     = HadronsLogError.isActive(); | ||||||
|  |     auto program = getModuleGraph().topoSort(); | ||||||
|  |  | ||||||
|  |     resetProfile(); | ||||||
|  |     profile_.module.resize(getNModule()); | ||||||
|  |     env().protectObjects(false); | ||||||
|  |     GridLogMessage.Active(false); | ||||||
|  |     HadronsLogMessage.Active(false); | ||||||
|  |     HadronsLogError.Active(false); | ||||||
|  |     for (auto it = program.rbegin(); it != program.rend(); ++it)  | ||||||
|  |     { | ||||||
|  |         auto a = *it; | ||||||
|  |  | ||||||
|  |         if (profile_.module[a].empty()) | ||||||
|  |         { | ||||||
|  |             LOG(Debug) << "Profiling memory for module '" << module_[a].name | ||||||
|  |                        << "' (" << a << ")..." << std::endl; | ||||||
|  |             memoryProfile(a); | ||||||
|  |             env().freeAll(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     env().protectObjects(protect); | ||||||
|  |     GridLogMessage.Active(gmsg); | ||||||
|  |     HadronsLogMessage.Active(hmsg); | ||||||
|  |     HadronsLogError.Active(err); | ||||||
|  |     LOG(Debug) << "Memory profile:" << std::endl; | ||||||
|  |     LOG(Debug) << "----------------" << std::endl; | ||||||
|  |     for (unsigned int a = 0; a < profile_.module.size(); ++a) | ||||||
|  |     { | ||||||
|  |         LOG(Debug) << getModuleName(a) << " (" << a << ")" << std::endl; | ||||||
|  |         for (auto &o: profile_.module[a]) | ||||||
|  |         { | ||||||
|  |             LOG(Debug) << "|__ " << env().getObjectName(o.first) << " (" | ||||||
|  |                        << sizeString(o.second) << ")" << std::endl; | ||||||
|  |         } | ||||||
|  |         LOG(Debug) << std::endl; | ||||||
|  |     } | ||||||
|  |     LOG(Debug) << "----------------" << std::endl; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::resetProfile(void) | ||||||
|  | { | ||||||
|  |     profile_.module.clear(); | ||||||
|  |     profile_.object.clear(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::resizeProfile(void) | ||||||
|  | { | ||||||
|  |     if (env().getMaxAddress() > profile_.object.size()) | ||||||
|  |     { | ||||||
|  |         MemoryPrint empty; | ||||||
|  |  | ||||||
|  |         empty.size   = 0; | ||||||
|  |         empty.module = -1; | ||||||
|  |         profile_.object.resize(env().getMaxAddress(), empty); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::updateProfile(const unsigned int address) | ||||||
|  | { | ||||||
|  |     resizeProfile(); | ||||||
|  |     for (unsigned int a = 0; a < env().getMaxAddress(); ++a) | ||||||
|  |     { | ||||||
|  |         if (env().hasCreatedObject(a) and (profile_.object[a].module == -1)) | ||||||
|  |         { | ||||||
|  |             profile_.object[a].size     = env().getObjectSize(a); | ||||||
|  |             profile_.object[a].storage  = env().getObjectStorage(a); | ||||||
|  |             profile_.object[a].module   = address; | ||||||
|  |             profile_.module[address][a] = profile_.object[a].size; | ||||||
|  |             if (env().getObjectModule(a) < 0) | ||||||
|  |             { | ||||||
|  |                 env().setObjectModule(a, address); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::cleanEnvironment(void) | ||||||
|  | { | ||||||
|  |     resizeProfile(); | ||||||
|  |     for (unsigned int a = 0; a < env().getMaxAddress(); ++a) | ||||||
|  |     { | ||||||
|  |         if (env().hasCreatedObject(a) and (profile_.object[a].module == -1)) | ||||||
|  |         { | ||||||
|  |             env().freeObject(a); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::memoryProfile(const unsigned int address) | ||||||
|  | { | ||||||
|  |     auto m = getModule(address); | ||||||
|  |  | ||||||
|  |     LOG(Debug) << "Setting up module '" << m->getName()  | ||||||
|  |                << "' (" << address << ")..." << std::endl; | ||||||
|  |     try | ||||||
|  |     { | ||||||
|  |         m->setup(); | ||||||
|  |         updateProfile(address); | ||||||
|  |     } | ||||||
|  |     catch (Exceptions::Definition &) | ||||||
|  |     { | ||||||
|  |         cleanEnvironment(); | ||||||
|  |         for (auto &in: m->getInput()) | ||||||
|  |         { | ||||||
|  |             memoryProfile(env().getObjectModule(in)); | ||||||
|  |         } | ||||||
|  |         for (auto &ref: m->getReference()) | ||||||
|  |         { | ||||||
|  |             memoryProfile(env().getObjectModule(ref)); | ||||||
|  |         } | ||||||
|  |         m->setup(); | ||||||
|  |         updateProfile(address); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::memoryProfile(const std::string name) | ||||||
|  | { | ||||||
|  |     memoryProfile(getModuleAddress(name)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // garbage collector /////////////////////////////////////////////////////////// | ||||||
|  | VirtualMachine::GarbageSchedule  | ||||||
|  | VirtualMachine::makeGarbageSchedule(const Program &p) const | ||||||
|  | { | ||||||
|  |     GarbageSchedule freeProg; | ||||||
|  |      | ||||||
|  |     freeProg.resize(p.size()); | ||||||
|  |     for (unsigned int a = 0; a < env().getMaxAddress(); ++a) | ||||||
|  |     { | ||||||
|  |         if (env().getObjectStorage(a) == Environment::Storage::temporary) | ||||||
|  |         { | ||||||
|  |             auto it = std::find(p.begin(), p.end(), env().getObjectModule(a)); | ||||||
|  |  | ||||||
|  |             if (it != p.end()) | ||||||
|  |             { | ||||||
|  |                 freeProg[std::distance(p.begin(), it)].insert(a); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         else if (env().getObjectStorage(a) == Environment::Storage::object) | ||||||
|  |         { | ||||||
|  |             auto pred = [a, this](const unsigned int b) | ||||||
|  |             { | ||||||
|  |                 auto &in = module_[b].input; | ||||||
|  |                 auto it  = std::find(in.begin(), in.end(), a); | ||||||
|  |                  | ||||||
|  |                 return (it != in.end()) or (b == env().getObjectModule(a)); | ||||||
|  |             }; | ||||||
|  |             auto it = std::find_if(p.rbegin(), p.rend(), pred); | ||||||
|  |             if (it != p.rend()) | ||||||
|  |             { | ||||||
|  |                 freeProg[std::distance(it, p.rend()) - 1].insert(a); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return freeProg; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // high-water memory function ////////////////////////////////////////////////// | ||||||
|  | VirtualMachine::Size VirtualMachine::memoryNeeded(const Program &p) | ||||||
|  | { | ||||||
|  |     const MemoryProfile &profile = getMemoryProfile(); | ||||||
|  |     GarbageSchedule     freep    = makeGarbageSchedule(p); | ||||||
|  |     Size                current = 0, max = 0; | ||||||
|  |  | ||||||
|  |     for (unsigned int i = 0; i < p.size(); ++i) | ||||||
|  |     { | ||||||
|  |         for (auto &o: profile.module[p[i]]) | ||||||
|  |         { | ||||||
|  |             current += o.second; | ||||||
|  |         } | ||||||
|  |         max = std::max(current, max); | ||||||
|  |         for (auto &o: freep[i]) | ||||||
|  |         { | ||||||
|  |             current -= profile.object[o].size; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return max; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // genetic scheduler /////////////////////////////////////////////////////////// | ||||||
|  | VirtualMachine::Program VirtualMachine::schedule(const GeneticPar &par) | ||||||
|  | { | ||||||
|  |     typedef GeneticScheduler<Size, unsigned int> Scheduler; | ||||||
|  |  | ||||||
|  |     auto graph = getModuleGraph(); | ||||||
|  |  | ||||||
|  |     //constrained topological sort using a genetic algorithm | ||||||
|  |     LOG(Message) << "Scheduling computation..." << std::endl; | ||||||
|  |     LOG(Message) << "               #module= " << graph.size() << std::endl; | ||||||
|  |     LOG(Message) << "       population size= " << par.popSize << std::endl; | ||||||
|  |     LOG(Message) << "       max. generation= " << par.maxGen << std::endl; | ||||||
|  |     LOG(Message) << "  max. cst. generation= " << par.maxCstGen << std::endl; | ||||||
|  |     LOG(Message) << "         mutation rate= " << par.mutationRate << std::endl; | ||||||
|  |      | ||||||
|  |     unsigned int          k = 0, gen, prevPeak, nCstPeak = 0; | ||||||
|  |     std::random_device    rd; | ||||||
|  |     Scheduler::Parameters gpar; | ||||||
|  |      | ||||||
|  |     gpar.popSize      = par.popSize; | ||||||
|  |     gpar.mutationRate = par.mutationRate; | ||||||
|  |     gpar.seed         = rd(); | ||||||
|  |     CartesianCommunicator::BroadcastWorld(0, &(gpar.seed), sizeof(gpar.seed)); | ||||||
|  |     Scheduler::ObjFunc memPeak = [this](const Program &p)->Size | ||||||
|  |     { | ||||||
|  |         return memoryNeeded(p); | ||||||
|  |     }; | ||||||
|  |     Scheduler scheduler(graph, memPeak, gpar); | ||||||
|  |     gen = 0; | ||||||
|  |     do | ||||||
|  |     { | ||||||
|  |         LOG(Debug) << "Generation " << gen << ":" << std::endl; | ||||||
|  |         scheduler.nextGeneration(); | ||||||
|  |         if (gen != 0) | ||||||
|  |         { | ||||||
|  |             if (prevPeak == scheduler.getMinValue()) | ||||||
|  |             { | ||||||
|  |                 nCstPeak++; | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 nCstPeak = 0; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         prevPeak = scheduler.getMinValue(); | ||||||
|  |         if (gen % 10 == 0) | ||||||
|  |         { | ||||||
|  |             LOG(Iterative) << "Generation " << gen << ": " | ||||||
|  |                            << sizeString(scheduler.getMinValue()) << std::endl; | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         gen++; | ||||||
|  |     } while ((gen < par.maxGen) and (nCstPeak < par.maxCstGen)); | ||||||
|  |      | ||||||
|  |     return scheduler.getMinSchedule(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // general execution /////////////////////////////////////////////////////////// | ||||||
|  | #define BIG_SEP "===============" | ||||||
|  | #define SEP     "---------------" | ||||||
|  | #define MEM_MSG(size) sizeString(size) | ||||||
|  |  | ||||||
|  | void VirtualMachine::executeProgram(const Program &p) const | ||||||
|  | { | ||||||
|  |     Size            memPeak = 0, sizeBefore, sizeAfter; | ||||||
|  |     GarbageSchedule freeProg; | ||||||
|  |      | ||||||
|  |     // build garbage collection schedule | ||||||
|  |     LOG(Debug) << "Building garbage collection schedule..." << std::endl; | ||||||
|  |     freeProg = makeGarbageSchedule(p); | ||||||
|  |  | ||||||
|  |     // program execution | ||||||
|  |     LOG(Debug) << "Executing program..." << std::endl; | ||||||
|  |     for (unsigned int i = 0; i < p.size(); ++i) | ||||||
|  |     { | ||||||
|  |         // execute module | ||||||
|  |         LOG(Message) << SEP << " Measurement step " << i + 1 << "/" | ||||||
|  |                      << p.size() << " (module '" << module_[p[i]].name | ||||||
|  |                      << "') " << SEP << std::endl; | ||||||
|  |         (*module_[p[i]].data)(); | ||||||
|  |         sizeBefore = env().getTotalSize(); | ||||||
|  |         // print used memory after execution | ||||||
|  |         LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) | ||||||
|  |                      << std::endl; | ||||||
|  |         if (sizeBefore > memPeak) | ||||||
|  |         { | ||||||
|  |             memPeak = sizeBefore; | ||||||
|  |         } | ||||||
|  |         // garbage collection for step i | ||||||
|  |         LOG(Message) << "Garbage collection..." << std::endl; | ||||||
|  |         for (auto &j: freeProg[i]) | ||||||
|  |         { | ||||||
|  |             env().freeObject(j); | ||||||
|  |         } | ||||||
|  |         // print used memory after garbage collection if necessary | ||||||
|  |         sizeAfter = env().getTotalSize(); | ||||||
|  |         if (sizeBefore != sizeAfter) | ||||||
|  |         { | ||||||
|  |             LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) | ||||||
|  |                             << std::endl; | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             LOG(Message) << "Nothing to free" << std::endl; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void VirtualMachine::executeProgram(const std::vector<std::string> &p) const | ||||||
|  | { | ||||||
|  |     Program pAddress; | ||||||
|  |      | ||||||
|  |     for (auto &n: p) | ||||||
|  |     { | ||||||
|  |         pAddress.push_back(getModuleAddress(n)); | ||||||
|  |     } | ||||||
|  |     executeProgram(pAddress); | ||||||
|  | } | ||||||
							
								
								
									
										207
									
								
								extras/Hadrons/VirtualMachine.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										207
									
								
								extras/Hadrons/VirtualMachine.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,207 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  | Source file: extras/Hadrons/VirtualMachine.hpp | ||||||
|  |  | ||||||
|  | Copyright (C) 2015-2018 | ||||||
|  |  | ||||||
|  | Author: Antonin Portelli <antonin.portelli@me.com> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef Hadrons_VirtualMachine_hpp_ | ||||||
|  | #define Hadrons_VirtualMachine_hpp_ | ||||||
|  |  | ||||||
|  | #include <Grid/Hadrons/Global.hpp> | ||||||
|  | #include <Grid/Hadrons/Graph.hpp> | ||||||
|  | #include <Grid/Hadrons/Environment.hpp> | ||||||
|  |  | ||||||
|  | BEGIN_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #define DEFINE_VM_ALIAS \ | ||||||
|  | inline VirtualMachine & vm(void) const\ | ||||||
|  | {\ | ||||||
|  |     return VirtualMachine::getInstance();\ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                   Virtual machine for module execution                     * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // forward declaration of Module | ||||||
|  | class ModuleBase; | ||||||
|  |  | ||||||
|  | class VirtualMachine | ||||||
|  | { | ||||||
|  |     SINGLETON_DEFCTOR(VirtualMachine); | ||||||
|  | public: | ||||||
|  |     typedef SITE_SIZE_TYPE                      Size; | ||||||
|  |     typedef std::unique_ptr<ModuleBase>         ModPt; | ||||||
|  |     typedef std::vector<std::set<unsigned int>> GarbageSchedule; | ||||||
|  |     typedef std::vector<unsigned int>           Program; | ||||||
|  |     struct MemoryPrint | ||||||
|  |     { | ||||||
|  |         Size                 size; | ||||||
|  |         Environment::Storage storage; | ||||||
|  |         int                  module; | ||||||
|  |     }; | ||||||
|  |     struct MemoryProfile | ||||||
|  |     { | ||||||
|  |         std::vector<std::map<unsigned int, Size>> module; | ||||||
|  |         std::vector<MemoryPrint>                  object; | ||||||
|  |     }; | ||||||
|  |     class GeneticPar: Serializable | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         GeneticPar(void): | ||||||
|  |             popSize{20}, maxGen{1000}, maxCstGen{100}, mutationRate{.1} {}; | ||||||
|  |     public: | ||||||
|  |         GRID_SERIALIZABLE_CLASS_MEMBERS(GeneticPar, | ||||||
|  |                                         unsigned int, popSize, | ||||||
|  |                                         unsigned int, maxGen, | ||||||
|  |                                         unsigned int, maxCstGen, | ||||||
|  |                                         double      , mutationRate); | ||||||
|  |     }; | ||||||
|  | private: | ||||||
|  |     struct ModuleInfo | ||||||
|  |     { | ||||||
|  |         const std::type_info      *type{nullptr}; | ||||||
|  |         std::string               name; | ||||||
|  |         ModPt                     data{nullptr}; | ||||||
|  |         std::vector<unsigned int> input; | ||||||
|  |         size_t                    maxAllocated; | ||||||
|  |     }; | ||||||
|  | public: | ||||||
|  |     // trajectory counter | ||||||
|  |     void                setTrajectory(const unsigned int traj); | ||||||
|  |     unsigned int        getTrajectory(void) const; | ||||||
|  |     // module management | ||||||
|  |     void                pushModule(ModPt &pt); | ||||||
|  |     template <typename M> | ||||||
|  |     void                createModule(const std::string name); | ||||||
|  |     template <typename M> | ||||||
|  |     void                createModule(const std::string name, | ||||||
|  |                                          const typename M::Par &par); | ||||||
|  |     void                createModule(const std::string name, | ||||||
|  |                                          const std::string type, | ||||||
|  |                                          XmlReader &reader); | ||||||
|  |     unsigned int        getNModule(void) const; | ||||||
|  |     ModuleBase *        getModule(const unsigned int address) const; | ||||||
|  |     ModuleBase *        getModule(const std::string name) const; | ||||||
|  |     template <typename M> | ||||||
|  |     M *                 getModule(const unsigned int address) const; | ||||||
|  |     template <typename M> | ||||||
|  |     M *                 getModule(const std::string name) const; | ||||||
|  |     unsigned int        getModuleAddress(const std::string name) const; | ||||||
|  |     std::string         getModuleName(const unsigned int address) const; | ||||||
|  |     std::string         getModuleType(const unsigned int address) const; | ||||||
|  |     std::string         getModuleType(const std::string name) const; | ||||||
|  |     std::string         getModuleNamespace(const unsigned int address) const; | ||||||
|  |     std::string         getModuleNamespace(const std::string name) const; | ||||||
|  |     bool                hasModule(const unsigned int address) const; | ||||||
|  |     bool                hasModule(const std::string name) const; | ||||||
|  |     // print VM content | ||||||
|  |     void                printContent(void) const; | ||||||
|  |     // module graph (could be a const reference if topoSort was const) | ||||||
|  |     Graph<unsigned int> getModuleGraph(void); | ||||||
|  |     // memory profile | ||||||
|  |     const MemoryProfile &getMemoryProfile(void); | ||||||
|  |     // garbage collector | ||||||
|  |     GarbageSchedule     makeGarbageSchedule(const Program &p) const; | ||||||
|  |     // high-water memory function | ||||||
|  |     Size                memoryNeeded(const Program &p); | ||||||
|  |     // genetic scheduler | ||||||
|  |     Program             schedule(const GeneticPar &par); | ||||||
|  |     // general execution | ||||||
|  |     void                executeProgram(const Program &p) const; | ||||||
|  |     void                executeProgram(const std::vector<std::string> &p) const; | ||||||
|  | private: | ||||||
|  |     // environment shortcut | ||||||
|  |     DEFINE_ENV_ALIAS; | ||||||
|  |     // module graph | ||||||
|  |     void makeModuleGraph(void); | ||||||
|  |     // memory profile | ||||||
|  |     void makeMemoryProfile(void); | ||||||
|  |     void resetProfile(void); | ||||||
|  |     void resizeProfile(void); | ||||||
|  |     void updateProfile(const unsigned int address); | ||||||
|  |     void cleanEnvironment(void); | ||||||
|  |     void memoryProfile(const std::string name); | ||||||
|  |     void memoryProfile(const unsigned int address); | ||||||
|  | private: | ||||||
|  |     // general | ||||||
|  |     unsigned int                        traj_; | ||||||
|  |     // module and related maps | ||||||
|  |     std::vector<ModuleInfo>             module_; | ||||||
|  |     std::map<std::string, unsigned int> moduleAddress_; | ||||||
|  |     std::string                         currentModule_{""}; | ||||||
|  |     // module graph | ||||||
|  |     bool                                graphOutdated_{true}; | ||||||
|  |     Graph<unsigned int>                 graph_; | ||||||
|  |     // memory profile | ||||||
|  |     bool                                memoryProfileOutdated_{true}; | ||||||
|  |     MemoryProfile                       profile_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | /****************************************************************************** | ||||||
|  |  *                   VirtualMachine template implementation                   * | ||||||
|  |  ******************************************************************************/ | ||||||
|  | // module management /////////////////////////////////////////////////////////// | ||||||
|  | template <typename M> | ||||||
|  | void VirtualMachine::createModule(const std::string name) | ||||||
|  | { | ||||||
|  |     ModPt pt(new M(name)); | ||||||
|  |      | ||||||
|  |     pushModule(pt); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename M> | ||||||
|  | void VirtualMachine::createModule(const std::string name, | ||||||
|  |                                const typename M::Par &par) | ||||||
|  | { | ||||||
|  |     ModPt pt(new M(name)); | ||||||
|  |      | ||||||
|  |     static_cast<M *>(pt.get())->setPar(par); | ||||||
|  |     pushModule(pt); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename M> | ||||||
|  | M * VirtualMachine::getModule(const unsigned int address) const | ||||||
|  | { | ||||||
|  |     if (auto *pt = dynamic_cast<M *>(getModule(address))) | ||||||
|  |     { | ||||||
|  |         return pt; | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         HADRON_ERROR(Definition, "module '" + module_[address].name | ||||||
|  |                      + "' does not have type " + typeid(M).name() | ||||||
|  |                      + "(has type: " + getModuleType(address) + ")"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <typename M> | ||||||
|  | M * VirtualMachine::getModule(const std::string name) const | ||||||
|  | { | ||||||
|  |     return getModule<M>(getModuleAddress(name)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | END_HADRONS_NAMESPACE | ||||||
|  |  | ||||||
|  | #endif // Hadrons_VirtualMachine_hpp_ | ||||||
| @@ -1,38 +1,53 @@ | |||||||
| modules_cc =\ | modules_cc =\ | ||||||
|   Modules/MContraction/WeakHamiltonianEye.cc \ |  | ||||||
|   Modules/MContraction/WeakHamiltonianNonEye.cc \ |  | ||||||
|   Modules/MContraction/WeakNeutral4ptDisc.cc \ |  | ||||||
|   Modules/MGauge/Load.cc \ |  | ||||||
|   Modules/MGauge/Random.cc \ |  | ||||||
|   Modules/MGauge/StochEm.cc \ |  | ||||||
|   Modules/MGauge/Unit.cc \ |  | ||||||
|   Modules/MScalar/ChargedProp.cc \ |   Modules/MScalar/ChargedProp.cc \ | ||||||
|   Modules/MScalar/FreeProp.cc |   Modules/MScalar/FreeProp.cc \ | ||||||
|  |   Modules/MContraction/WeakHamiltonianEye.cc \ | ||||||
|  |   Modules/MContraction/WeakNeutral4ptDisc.cc \ | ||||||
|  |   Modules/MContraction/WeakHamiltonianNonEye.cc \ | ||||||
|  |   Modules/MGauge/Unit.cc \ | ||||||
|  |   Modules/MGauge/StochEm.cc \ | ||||||
|  |   Modules/MGauge/Random.cc \ | ||||||
|  |   Modules/MGauge/FundtoHirep.cc \ | ||||||
|  |   Modules/MScalar/FreeProp.cc \ | ||||||
|  |   Modules/MScalar/ChargedProp.cc \ | ||||||
|  |   Modules/MIO/LoadNersc.cc | ||||||
|  |  | ||||||
| modules_hpp =\ | modules_hpp =\ | ||||||
|   Modules/MAction/DWF.hpp \ |  | ||||||
|   Modules/MAction/Wilson.hpp \ |  | ||||||
|   Modules/MContraction/Baryon.hpp \ |   Modules/MContraction/Baryon.hpp \ | ||||||
|   Modules/MContraction/DiscLoop.hpp \ |  | ||||||
|   Modules/MContraction/Gamma3pt.hpp \ |  | ||||||
|   Modules/MContraction/Meson.hpp \ |   Modules/MContraction/Meson.hpp \ | ||||||
|   Modules/MContraction/WeakHamiltonian.hpp \ |   Modules/MContraction/WeakHamiltonian.hpp \ | ||||||
|   Modules/MContraction/WeakHamiltonianEye.hpp \ |  | ||||||
|   Modules/MContraction/WeakHamiltonianNonEye.hpp \ |   Modules/MContraction/WeakHamiltonianNonEye.hpp \ | ||||||
|  |   Modules/MContraction/DiscLoop.hpp \ | ||||||
|   Modules/MContraction/WeakNeutral4ptDisc.hpp \ |   Modules/MContraction/WeakNeutral4ptDisc.hpp \ | ||||||
|  |   Modules/MContraction/Gamma3pt.hpp \ | ||||||
|  |   Modules/MContraction/WardIdentity.hpp \ | ||||||
|  |   Modules/MContraction/WeakHamiltonianEye.hpp \ | ||||||
|   Modules/MFermion/GaugeProp.hpp \ |   Modules/MFermion/GaugeProp.hpp \ | ||||||
|   Modules/MGauge/Load.hpp \ |   Modules/MSource/SeqGamma.hpp \ | ||||||
|   Modules/MGauge/Random.hpp \ |   Modules/MSource/Point.hpp \ | ||||||
|   Modules/MGauge/StochEm.hpp \ |   Modules/MSource/Wall.hpp \ | ||||||
|   Modules/MGauge/Unit.hpp \ |   Modules/MSource/Z2.hpp \ | ||||||
|   Modules/MLoop/NoiseLoop.hpp \ |   Modules/MSource/SeqConserved.hpp \ | ||||||
|   Modules/MScalar/ChargedProp.hpp \ |   Modules/MSink/Smear.hpp \ | ||||||
|   Modules/MScalar/FreeProp.hpp \ |  | ||||||
|   Modules/MScalar/Scalar.hpp \ |  | ||||||
|   Modules/MSink/Point.hpp \ |   Modules/MSink/Point.hpp \ | ||||||
|   Modules/MSolver/RBPrecCG.hpp \ |   Modules/MSolver/RBPrecCG.hpp \ | ||||||
|   Modules/MSource/Point.hpp \ |   Modules/MGauge/Unit.hpp \ | ||||||
|   Modules/MSource/SeqGamma.hpp \ |   Modules/MGauge/Random.hpp \ | ||||||
|   Modules/MSource/Wall.hpp \ |   Modules/MGauge/StochEm.hpp \ | ||||||
|   Modules/MSource/Z2.hpp |   Modules/MGauge/FundtoHirep.hpp \ | ||||||
|  |   Modules/MUtilities/TestSeqGamma.hpp \ | ||||||
|  |   Modules/MUtilities/TestSeqConserved.hpp \ | ||||||
|  |   Modules/MLoop/NoiseLoop.hpp \ | ||||||
|  |   Modules/MScalar/FreeProp.hpp \ | ||||||
|  |   Modules/MScalar/Scalar.hpp \ | ||||||
|  |   Modules/MScalar/ChargedProp.hpp \ | ||||||
|  |   Modules/MAction/DWF.hpp \ | ||||||
|  |   Modules/MAction/Wilson.hpp \ | ||||||
|  |   Modules/MAction/WilsonClover.hpp \ | ||||||
|  |   Modules/MScalarSUN/Div.hpp \ | ||||||
|  |   Modules/MScalarSUN/TrMag.hpp \ | ||||||
|  |   Modules/MScalarSUN/TwoPoint.hpp \ | ||||||
|  |   Modules/MScalarSUN/TrPhi.hpp \ | ||||||
|  |   Modules/MIO/LoadNersc.hpp \ | ||||||
|  |   Modules/MIO/LoadBinary.hpp | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,28 +1,18 @@ | |||||||
| extra_sources= | extra_sources= | ||||||
| extra_headers= | extra_headers= | ||||||
| if BUILD_COMMS_MPI |  | ||||||
|   extra_sources+=communicator/Communicator_mpi.cc |  | ||||||
|   extra_sources+=communicator/Communicator_base.cc |  | ||||||
| endif |  | ||||||
|  |  | ||||||
| if BUILD_COMMS_MPI3 | if BUILD_COMMS_MPI3 | ||||||
|   extra_sources+=communicator/Communicator_mpi3.cc |   extra_sources+=communicator/Communicator_mpi3.cc | ||||||
|   extra_sources+=communicator/Communicator_base.cc |   extra_sources+=communicator/Communicator_base.cc | ||||||
| endif |   extra_sources+=communicator/SharedMemoryMPI.cc | ||||||
|  |   extra_sources+=communicator/SharedMemory.cc | ||||||
| if BUILD_COMMS_MPIT |  | ||||||
|   extra_sources+=communicator/Communicator_mpit.cc |  | ||||||
|   extra_sources+=communicator/Communicator_base.cc |  | ||||||
| endif |  | ||||||
|  |  | ||||||
| if BUILD_COMMS_SHMEM |  | ||||||
|   extra_sources+=communicator/Communicator_shmem.cc |  | ||||||
|   extra_sources+=communicator/Communicator_base.cc |  | ||||||
| endif | endif | ||||||
|  |  | ||||||
| if BUILD_COMMS_NONE | if BUILD_COMMS_NONE | ||||||
|   extra_sources+=communicator/Communicator_none.cc |   extra_sources+=communicator/Communicator_none.cc | ||||||
|   extra_sources+=communicator/Communicator_base.cc |   extra_sources+=communicator/Communicator_base.cc | ||||||
|  |   extra_sources+=communicator/SharedMemoryNone.cc | ||||||
|  |   extra_sources+=communicator/SharedMemory.cc | ||||||
| endif | endif | ||||||
|  |  | ||||||
| if BUILD_HDF5 | if BUILD_HDF5 | ||||||
|   | |||||||
| @@ -37,37 +37,27 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk> | |||||||
| #include <Grid/algorithms/approx/Chebyshev.h> | #include <Grid/algorithms/approx/Chebyshev.h> | ||||||
| #include <Grid/algorithms/approx/Remez.h> | #include <Grid/algorithms/approx/Remez.h> | ||||||
| #include <Grid/algorithms/approx/MultiShiftFunction.h> | #include <Grid/algorithms/approx/MultiShiftFunction.h> | ||||||
|  | #include <Grid/algorithms/approx/Forecast.h> | ||||||
|  |  | ||||||
|  | #include <Grid/algorithms/iterative/Deflation.h> | ||||||
| #include <Grid/algorithms/iterative/ConjugateGradient.h> | #include <Grid/algorithms/iterative/ConjugateGradient.h> | ||||||
| #include <Grid/algorithms/iterative/ConjugateResidual.h> | #include <Grid/algorithms/iterative/ConjugateResidual.h> | ||||||
| #include <Grid/algorithms/iterative/NormalEquations.h> | #include <Grid/algorithms/iterative/NormalEquations.h> | ||||||
| #include <Grid/algorithms/iterative/SchurRedBlack.h> | #include <Grid/algorithms/iterative/SchurRedBlack.h> | ||||||
| #include <Grid/algorithms/iterative/ConjugateGradientMultiShift.h> | #include <Grid/algorithms/iterative/ConjugateGradientMultiShift.h> | ||||||
| #include <Grid/algorithms/iterative/ConjugateGradientMixedPrec.h> | #include <Grid/algorithms/iterative/ConjugateGradientMixedPrec.h> | ||||||
|  | #include <Grid/algorithms/iterative/BlockConjugateGradient.h> | ||||||
| // Lanczos support | #include <Grid/algorithms/iterative/ConjugateGradientReliableUpdate.h> | ||||||
| //#include <Grid/algorithms/iterative/MatrixUtils.h> |  | ||||||
| #include <Grid/algorithms/iterative/ImplicitlyRestartedLanczos.h> | #include <Grid/algorithms/iterative/ImplicitlyRestartedLanczos.h> | ||||||
|  | #include <Grid/algorithms/iterative/ImplicitlyRestartedLanczosCJ.h> | ||||||
|  | #include <Grid/algorithms/iterative/ImplicitlyRestartedBlockLanczos.h> | ||||||
| #include <Grid/algorithms/CoarsenedMatrix.h> | #include <Grid/algorithms/CoarsenedMatrix.h> | ||||||
| #include <Grid/algorithms/FFT.h> | #include <Grid/algorithms/FFT.h> | ||||||
|  |  | ||||||
| // Eigen/lanczos |  | ||||||
| // EigCg | // EigCg | ||||||
| // MCR |  | ||||||
| // Pcg | // Pcg | ||||||
| // Multishift CG |  | ||||||
| // Hdcg | // Hdcg | ||||||
| // GCR | // GCR | ||||||
| // etc.. | // etc.. | ||||||
|  |  | ||||||
| // integrator/Leapfrog |  | ||||||
| // integrator/Omelyan |  | ||||||
| // integrator/ForceGradient |  | ||||||
|  |  | ||||||
| // montecarlo/hmc |  | ||||||
| // montecarlo/rhmc |  | ||||||
| // montecarlo/metropolis |  | ||||||
| // etc... |  | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -103,29 +103,32 @@ namespace Grid { | |||||||
|     GridBase *CoarseGrid; |     GridBase *CoarseGrid; | ||||||
|     GridBase *FineGrid; |     GridBase *FineGrid; | ||||||
|     std::vector<Lattice<Fobj> > subspace; |     std::vector<Lattice<Fobj> > subspace; | ||||||
|  |     int checkerboard; | ||||||
|  |  | ||||||
|     Aggregation(GridBase *_CoarseGrid,GridBase *_FineGrid) :  |   Aggregation(GridBase *_CoarseGrid,GridBase *_FineGrid,int _checkerboard) :  | ||||||
|     CoarseGrid(_CoarseGrid), |     CoarseGrid(_CoarseGrid), | ||||||
|       FineGrid(_FineGrid), |       FineGrid(_FineGrid), | ||||||
|       subspace(nbasis,_FineGrid) |       subspace(nbasis,_FineGrid), | ||||||
|  |       checkerboard(_checkerboard) | ||||||
| 	{ | 	{ | ||||||
| 	}; | 	}; | ||||||
|    |    | ||||||
|     void Orthogonalise(void){ |     void Orthogonalise(void){ | ||||||
|       CoarseScalar InnerProd(CoarseGrid);  |       CoarseScalar InnerProd(CoarseGrid);  | ||||||
|  |       std::cout << GridLogMessage <<" Gramm-Schmidt pass 1"<<std::endl; | ||||||
|       blockOrthogonalise(InnerProd,subspace); |       blockOrthogonalise(InnerProd,subspace); | ||||||
|  |       std::cout << GridLogMessage <<" Gramm-Schmidt pass 2"<<std::endl; | ||||||
|  |       blockOrthogonalise(InnerProd,subspace); | ||||||
|  |       //      std::cout << GridLogMessage <<" Gramm-Schmidt checking orthogonality"<<std::endl; | ||||||
|  |       //      CheckOrthogonal(); | ||||||
|     }  |     }  | ||||||
|     void CheckOrthogonal(void){ |     void CheckOrthogonal(void){ | ||||||
|       CoarseVector iProj(CoarseGrid);  |       CoarseVector iProj(CoarseGrid);  | ||||||
|       CoarseVector eProj(CoarseGrid);  |       CoarseVector eProj(CoarseGrid);  | ||||||
|       Lattice<CComplex> pokey(CoarseGrid); |  | ||||||
|  |  | ||||||
|        |  | ||||||
|       for(int i=0;i<nbasis;i++){ |       for(int i=0;i<nbasis;i++){ | ||||||
| 	blockProject(iProj,subspace[i],subspace); | 	blockProject(iProj,subspace[i],subspace); | ||||||
|  |  | ||||||
| 	eProj=zero;  | 	eProj=zero;  | ||||||
| 	for(int ss=0;ss<CoarseGrid->oSites();ss++){ | 	parallel_for(int ss=0;ss<CoarseGrid->oSites();ss++){ | ||||||
| 	  eProj._odata[ss](i)=CComplex(1.0); | 	  eProj._odata[ss](i)=CComplex(1.0); | ||||||
| 	} | 	} | ||||||
| 	eProj=eProj - iProj; | 	eProj=eProj - iProj; | ||||||
| @@ -137,6 +140,7 @@ namespace Grid { | |||||||
|       blockProject(CoarseVec,FineVec,subspace); |       blockProject(CoarseVec,FineVec,subspace); | ||||||
|     } |     } | ||||||
|     void PromoteFromSubspace(const CoarseVector &CoarseVec,FineField &FineVec){ |     void PromoteFromSubspace(const CoarseVector &CoarseVec,FineField &FineVec){ | ||||||
|  |       FineVec.checkerboard = subspace[0].checkerboard; | ||||||
|       blockPromote(CoarseVec,FineVec,subspace); |       blockPromote(CoarseVec,FineVec,subspace); | ||||||
|     } |     } | ||||||
|     void CreateSubspaceRandom(GridParallelRNG &RNG){ |     void CreateSubspaceRandom(GridParallelRNG &RNG){ | ||||||
| @@ -147,6 +151,7 @@ namespace Grid { | |||||||
|       Orthogonalise(); |       Orthogonalise(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /* | ||||||
|     virtual void CreateSubspaceLanczos(GridParallelRNG  &RNG,LinearOperatorBase<FineField> &hermop,int nn=nbasis)  |     virtual void CreateSubspaceLanczos(GridParallelRNG  &RNG,LinearOperatorBase<FineField> &hermop,int nn=nbasis)  | ||||||
|     { |     { | ||||||
|       // Run a Lanczos with sloppy convergence |       // Run a Lanczos with sloppy convergence | ||||||
| @@ -195,7 +200,7 @@ namespace Grid { | |||||||
| 	  std::cout << GridLogMessage <<"subspace["<<b<<"] = "<<norm2(subspace[b])<<std::endl; | 	  std::cout << GridLogMessage <<"subspace["<<b<<"] = "<<norm2(subspace[b])<<std::endl; | ||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|  |     */ | ||||||
|     virtual void CreateSubspace(GridParallelRNG  &RNG,LinearOperatorBase<FineField> &hermop,int nn=nbasis) { |     virtual void CreateSubspace(GridParallelRNG  &RNG,LinearOperatorBase<FineField> &hermop,int nn=nbasis) { | ||||||
|  |  | ||||||
|       RealD scale; |       RealD scale; | ||||||
|   | |||||||
| @@ -230,6 +230,7 @@ namespace Grid { | |||||||
|       // Barrel shift and collect global pencil |       // Barrel shift and collect global pencil | ||||||
|       std::vector<int> lcoor(Nd), gcoor(Nd); |       std::vector<int> lcoor(Nd), gcoor(Nd); | ||||||
|       result = source; |       result = source; | ||||||
|  |       int pc = processor_coor[dim]; | ||||||
|       for(int p=0;p<processors[dim];p++) { |       for(int p=0;p<processors[dim];p++) { | ||||||
|         PARALLEL_REGION |         PARALLEL_REGION | ||||||
|         { |         { | ||||||
| @@ -240,7 +241,8 @@ namespace Grid { | |||||||
|           for(int idx=0;idx<sgrid->lSites();idx++) { |           for(int idx=0;idx<sgrid->lSites();idx++) { | ||||||
|             sgrid->LocalIndexToLocalCoor(idx,cbuf); |             sgrid->LocalIndexToLocalCoor(idx,cbuf); | ||||||
|             peekLocalSite(s,result,cbuf); |             peekLocalSite(s,result,cbuf); | ||||||
|             cbuf[dim]+=p*L; | 	    cbuf[dim]+=((pc+p) % processors[dim])*L; | ||||||
|  | 	    //            cbuf[dim]+=p*L; | ||||||
|             pokeLocalSite(s,pgbuf,cbuf); |             pokeLocalSite(s,pgbuf,cbuf); | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
| @@ -278,7 +280,6 @@ namespace Grid { | |||||||
|       flops+= flops_call*NN; |       flops+= flops_call*NN; | ||||||
|        |        | ||||||
|       // writing out result |       // writing out result | ||||||
|       int pc = processor_coor[dim]; |  | ||||||
|       PARALLEL_REGION |       PARALLEL_REGION | ||||||
|       { |       { | ||||||
|         std::vector<int> clbuf(Nd), cgbuf(Nd); |         std::vector<int> clbuf(Nd), cgbuf(Nd); | ||||||
|   | |||||||
| @@ -162,15 +162,10 @@ namespace Grid { | |||||||
| 	_Mat.M(in,out); | 	_Mat.M(in,out); | ||||||
|       } |       } | ||||||
|       void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ |       void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ | ||||||
| 	ComplexD dot; |  | ||||||
|  |  | ||||||
| 	_Mat.M(in,out); | 	_Mat.M(in,out); | ||||||
| 	 | 	 | ||||||
| 	dot= innerProduct(in,out); | 	ComplexD dot= innerProduct(in,out); n1=real(dot); | ||||||
| 	n1=real(dot); | 	n2=norm2(out); | ||||||
|  |  | ||||||
| 	dot = innerProduct(out,out); |  | ||||||
| 	n2=real(dot); |  | ||||||
|       } |       } | ||||||
|       void HermOp(const Field &in, Field &out){ |       void HermOp(const Field &in, Field &out){ | ||||||
| 	_Mat.M(in,out); | 	_Mat.M(in,out); | ||||||
| @@ -189,13 +184,15 @@ namespace Grid { | |||||||
|       virtual  RealD MpcDag   (const Field &in, Field &out) =0; |       virtual  RealD MpcDag   (const Field &in, Field &out) =0; | ||||||
|       virtual void MpcDagMpc(const Field &in, Field &out,RealD &ni,RealD &no) { |       virtual void MpcDagMpc(const Field &in, Field &out,RealD &ni,RealD &no) { | ||||||
|       Field tmp(in._grid); |       Field tmp(in._grid); | ||||||
|  |       tmp.checkerboard = in.checkerboard; | ||||||
| 	ni=Mpc(in,tmp); | 	ni=Mpc(in,tmp); | ||||||
| 	no=MpcDag(tmp,out); | 	no=MpcDag(tmp,out); | ||||||
|       } |       } | ||||||
|       void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ |       virtual void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ | ||||||
|  |       out.checkerboard = in.checkerboard; | ||||||
| 	MpcDagMpc(in,out,n1,n2); | 	MpcDagMpc(in,out,n1,n2); | ||||||
|       } |       } | ||||||
|       void HermOp(const Field &in, Field &out){ |       virtual void HermOp(const Field &in, Field &out){ | ||||||
| 	RealD n1,n2; | 	RealD n1,n2; | ||||||
| 	HermOpAndNorm(in,out,n1,n2); | 	HermOpAndNorm(in,out,n1,n2); | ||||||
|       } |       } | ||||||
| @@ -212,7 +209,6 @@ namespace Grid { | |||||||
|       void OpDir  (const Field &in, Field &out,int dir,int disp) { |       void OpDir  (const Field &in, Field &out,int dir,int disp) { | ||||||
| 	assert(0); | 	assert(0); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|     }; |     }; | ||||||
|     template<class Matrix,class Field> |     template<class Matrix,class Field> | ||||||
|       class SchurDiagMooeeOperator :  public SchurOperatorBase<Field> { |       class SchurDiagMooeeOperator :  public SchurOperatorBase<Field> { | ||||||
| @@ -222,12 +218,14 @@ namespace Grid { | |||||||
|       SchurDiagMooeeOperator (Matrix &Mat): _Mat(Mat){}; |       SchurDiagMooeeOperator (Matrix &Mat): _Mat(Mat){}; | ||||||
|       virtual  RealD Mpc      (const Field &in, Field &out) { |       virtual  RealD Mpc      (const Field &in, Field &out) { | ||||||
|       Field tmp(in._grid); |       Field tmp(in._grid); | ||||||
|  |       tmp.checkerboard = !in.checkerboard; | ||||||
| 	//std::cout <<"grid pointers: in._grid="<< in._grid << " out._grid=" << out._grid << "  _Mat.Grid=" << _Mat.Grid() << " _Mat.RedBlackGrid=" << _Mat.RedBlackGrid() << std::endl; | 	//std::cout <<"grid pointers: in._grid="<< in._grid << " out._grid=" << out._grid << "  _Mat.Grid=" << _Mat.Grid() << " _Mat.RedBlackGrid=" << _Mat.RedBlackGrid() << std::endl; | ||||||
|  |  | ||||||
| 	_Mat.Meooe(in,tmp); | 	_Mat.Meooe(in,tmp); | ||||||
| 	_Mat.MooeeInv(tmp,out); | 	_Mat.MooeeInv(tmp,out); | ||||||
| 	_Mat.Meooe(out,tmp); | 	_Mat.Meooe(out,tmp); | ||||||
|  |  | ||||||
|  |       //std::cout << "cb in " << in.checkerboard << "  cb out " << out.checkerboard << std::endl; | ||||||
| 	_Mat.Mooee(in,out); | 	_Mat.Mooee(in,out); | ||||||
| 	return axpy_norm(out,-1.0,tmp,out); | 	return axpy_norm(out,-1.0,tmp,out); | ||||||
|       } |       } | ||||||
| @@ -270,7 +268,6 @@ namespace Grid { | |||||||
| 	return axpy_norm(out,-1.0,tmp,in); | 	return axpy_norm(out,-1.0,tmp,in); | ||||||
|       } |       } | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     template<class Matrix,class Field> |     template<class Matrix,class Field> | ||||||
|       class SchurDiagTwoOperator :  public SchurOperatorBase<Field> { |       class SchurDiagTwoOperator :  public SchurOperatorBase<Field> { | ||||||
|     protected: |     protected: | ||||||
| @@ -299,6 +296,151 @@ namespace Grid { | |||||||
| 	return axpy_norm(out,-1.0,tmp,in); | 	return axpy_norm(out,-1.0,tmp,in); | ||||||
|       } |       } | ||||||
|     }; |     }; | ||||||
|  |     /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|  |     // Left  handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) psi = eta  -->  ( 1 - Moo^-1 Moe Mee^-1 Meo ) psi = Moo^-1 eta | ||||||
|  |     // Right handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) Moo^-1 Moo psi = eta  -->  ( 1 - Moe Mee^-1 Meo ) Moo^-1 phi=eta ; psi = Moo^-1 phi | ||||||
|  |     /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|  |     template<class Matrix,class Field> using SchurDiagOneRH = SchurDiagTwoOperator<Matrix,Field> ; | ||||||
|  |     template<class Matrix,class Field> using SchurDiagOneLH = SchurDiagOneOperator<Matrix,Field> ; | ||||||
|  |     /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|  |     //  Staggered use | ||||||
|  |     /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|  |     template<class Matrix,class Field> | ||||||
|  |       class SchurStaggeredOperator :  public SchurOperatorBase<Field> { | ||||||
|  |     protected: | ||||||
|  |       Matrix &_Mat; | ||||||
|  |       Field tmp; | ||||||
|  |       RealD mass; | ||||||
|  |       double tMpc; | ||||||
|  |       double tIP; | ||||||
|  |       double tMeo; | ||||||
|  |       double taxpby_norm; | ||||||
|  |       uint64_t ncall; | ||||||
|  |     public: | ||||||
|  |       void Report(void) | ||||||
|  |       { | ||||||
|  | 	std::cout << GridLogMessage << " HermOpAndNorm.Mpc "<< tMpc/ncall<<" usec "<<std::endl; | ||||||
|  | 	std::cout << GridLogMessage << " HermOpAndNorm.IP  "<< tIP /ncall<<" usec "<<std::endl; | ||||||
|  | 	std::cout << GridLogMessage << " Mpc.MeoMoe        "<< tMeo/ncall<<" usec "<<std::endl; | ||||||
|  | 	std::cout << GridLogMessage << " Mpc.axpby_norm    "<< taxpby_norm/ncall<<" usec "<<std::endl; | ||||||
|  |       } | ||||||
|  |       SchurStaggeredOperator (Matrix &Mat): _Mat(Mat), tmp(_Mat.RedBlackGrid())  | ||||||
|  |       {  | ||||||
|  | 	assert( _Mat.isTrivialEE() ); | ||||||
|  | 	mass = _Mat.Mass(); | ||||||
|  | 	tMpc=0; | ||||||
|  | 	tIP =0; | ||||||
|  |         tMeo=0; | ||||||
|  |         taxpby_norm=0; | ||||||
|  | 	ncall=0; | ||||||
|  |       } | ||||||
|  |       virtual void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ | ||||||
|  | 	ncall++; | ||||||
|  | 	tMpc-=usecond(); | ||||||
|  | 	n2 = Mpc(in,out); | ||||||
|  | 	tMpc+=usecond(); | ||||||
|  | 	tIP-=usecond(); | ||||||
|  | 	ComplexD dot= innerProduct(in,out); | ||||||
|  | 	tIP+=usecond(); | ||||||
|  | 	n1 = real(dot); | ||||||
|  |       } | ||||||
|  |       virtual void HermOp(const Field &in, Field &out){ | ||||||
|  | 	ncall++; | ||||||
|  | 	tMpc-=usecond(); | ||||||
|  | 	_Mat.Meooe(in,out); | ||||||
|  | 	_Mat.Meooe(out,tmp); | ||||||
|  | 	tMpc+=usecond(); | ||||||
|  | 	taxpby_norm-=usecond(); | ||||||
|  | 	axpby(out,-1.0,mass*mass,tmp,in); | ||||||
|  | 	taxpby_norm+=usecond(); | ||||||
|  |       } | ||||||
|  |       virtual  RealD Mpc      (const Field &in, Field &out) { | ||||||
|  | 	tMeo-=usecond(); | ||||||
|  | 	_Mat.Meooe(in,out); | ||||||
|  | 	_Mat.Meooe(out,tmp); | ||||||
|  | 	tMeo+=usecond(); | ||||||
|  | 	taxpby_norm-=usecond(); | ||||||
|  | 	RealD nn=axpby_norm(out,-1.0,mass*mass,tmp,in); | ||||||
|  | 	taxpby_norm+=usecond(); | ||||||
|  | 	return nn; | ||||||
|  |       } | ||||||
|  |       virtual  RealD MpcDag   (const Field &in, Field &out){ | ||||||
|  | 	return Mpc(in,out); | ||||||
|  |       } | ||||||
|  |       virtual void MpcDagMpc(const Field &in, Field &out,RealD &ni,RealD &no) { | ||||||
|  | 	assert(0);// Never need with staggered | ||||||
|  |       } | ||||||
|  |     }; | ||||||
|  |     template<class Matrix,class Field> using SchurStagOperator = SchurStaggeredOperator<Matrix,Field>; | ||||||
|  |  | ||||||
|  | #if 0 | ||||||
|  |   // This is specific to (Z)mobius fermions | ||||||
|  |   template<class Matrix, class Field> | ||||||
|  |     class KappaSimilarityTransform { | ||||||
|  |   public: | ||||||
|  | //    INHERIT_IMPL_TYPES(Matrix); | ||||||
|  |     typedef typename Matrix::Coeff_t                     Coeff_t; | ||||||
|  |     std::vector<Coeff_t> kappa, kappaDag, kappaInv, kappaInvDag; | ||||||
|  |  | ||||||
|  |     KappaSimilarityTransform (Matrix &zmob) { | ||||||
|  |       for (int i=0;i<(int)zmob.bs.size();i++) { | ||||||
|  | 	Coeff_t k = 1.0 / ( 2.0 * (zmob.bs[i] *(4 - zmob.M5) + 1.0) ); | ||||||
|  | 	kappa.push_back( k ); | ||||||
|  | 	kappaDag.push_back( conj(k) ); | ||||||
|  | 	kappaInv.push_back( 1.0 / k ); | ||||||
|  | 	kappaInvDag.push_back( 1.0 / conj(k) ); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   template<typename vobj> | ||||||
|  |     void sscale(const Lattice<vobj>& in, Lattice<vobj>& out, Coeff_t* s) { | ||||||
|  |     GridBase *grid=out._grid; | ||||||
|  |     out.checkerboard = in.checkerboard; | ||||||
|  |     assert(grid->_simd_layout[0] == 1); // should be fine for ZMobius for now | ||||||
|  |     int Ls = grid->_rdimensions[0]; | ||||||
|  |     parallel_for(int ss=0;ss<grid->oSites();ss++){ | ||||||
|  |       vobj tmp = s[ss % Ls]*in._odata[ss]; | ||||||
|  |       vstream(out._odata[ss],tmp); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   RealD sscale_norm(const Field& in, Field& out, Coeff_t* s) { | ||||||
|  |     sscale(in,out,s); | ||||||
|  |     return norm2(out); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   virtual RealD M       (const Field& in, Field& out) { return sscale_norm(in,out,&kappa[0]);   } | ||||||
|  |   virtual RealD MDag    (const Field& in, Field& out) { return sscale_norm(in,out,&kappaDag[0]);} | ||||||
|  |   virtual RealD MInv    (const Field& in, Field& out) { return sscale_norm(in,out,&kappaInv[0]);} | ||||||
|  |   virtual RealD MInvDag (const Field& in, Field& out) { return sscale_norm(in,out,&kappaInvDag[0]);} | ||||||
|  |  | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   template<class Matrix,class Field> | ||||||
|  |     class SchurDiagTwoKappaOperator :  public SchurOperatorBase<Field> { | ||||||
|  |   public: | ||||||
|  |     KappaSimilarityTransform<Matrix, Field> _S; | ||||||
|  |     SchurDiagTwoOperator<Matrix, Field> _Mat; | ||||||
|  |  | ||||||
|  |     SchurDiagTwoKappaOperator (Matrix &Mat): _S(Mat), _Mat(Mat) {}; | ||||||
|  |  | ||||||
|  |     virtual  RealD Mpc      (const Field &in, Field &out) { | ||||||
|  |       Field tmp(in._grid); | ||||||
|  |  | ||||||
|  |       _S.MInv(in,out); | ||||||
|  |       _Mat.Mpc(out,tmp); | ||||||
|  |       return _S.M(tmp,out); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |     virtual  RealD MpcDag   (const Field &in, Field &out){ | ||||||
|  |       Field tmp(in._grid); | ||||||
|  |  | ||||||
|  |       _S.MDag(in,out); | ||||||
|  |       _Mat.MpcDag(out,tmp); | ||||||
|  |       return _S.MInvDag(tmp,out); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
|     ///////////////////////////////////////////////////////////// |     ///////////////////////////////////////////////////////////// | ||||||
| @@ -314,6 +456,14 @@ namespace Grid { | |||||||
|       virtual void operator() (const Field &in, Field &out) = 0; |       virtual void operator() (const Field &in, Field &out) = 0; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     template<class Field> class IdentityLinearFunction : public LinearFunction<Field> { | ||||||
|  |     public: | ||||||
|  |       void operator() (const Field &in, Field &out){ | ||||||
|  | 	out = in; | ||||||
|  |       }; | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |  | ||||||
|     ///////////////////////////////////////////////////////////// |     ///////////////////////////////////////////////////////////// | ||||||
|     // Base classes for Multishift solvers for operators |     // Base classes for Multishift solvers for operators | ||||||
|     ///////////////////////////////////////////////////////////// |     ///////////////////////////////////////////////////////////// | ||||||
| @@ -336,6 +486,64 @@ namespace Grid { | |||||||
|      }; |      }; | ||||||
|     */ |     */ | ||||||
|  |  | ||||||
|  |   //////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|  |   // Hermitian operator Linear function and operator function | ||||||
|  |   //////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|  |     template<class Field> | ||||||
|  |       class HermOpOperatorFunction : public OperatorFunction<Field> { | ||||||
|  |       void operator() (LinearOperatorBase<Field> &Linop, const Field &in, Field &out) { | ||||||
|  | 	Linop.HermOp(in,out); | ||||||
|  |       }; | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     template<typename Field> | ||||||
|  |       class PlainHermOp : public LinearFunction<Field> { | ||||||
|  |     public: | ||||||
|  |       LinearOperatorBase<Field> &_Linop; | ||||||
|  |        | ||||||
|  |       PlainHermOp(LinearOperatorBase<Field>& linop) : _Linop(linop)  | ||||||
|  |       {} | ||||||
|  |        | ||||||
|  |       void operator()(const Field& in, Field& out) { | ||||||
|  | 	_Linop.HermOp(in,out); | ||||||
|  |       } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     template<typename Field> | ||||||
|  |     class FunctionHermOp : public LinearFunction<Field> { | ||||||
|  |     public: | ||||||
|  |       OperatorFunction<Field>   & _poly; | ||||||
|  |       LinearOperatorBase<Field> &_Linop; | ||||||
|  |        | ||||||
|  |       FunctionHermOp(OperatorFunction<Field> & poly,LinearOperatorBase<Field>& linop)  | ||||||
|  | 	: _poly(poly), _Linop(linop) {}; | ||||||
|  |        | ||||||
|  |       void operator()(const Field& in, Field& out) { | ||||||
|  | 	_poly(_Linop,in,out); | ||||||
|  |       } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |   template<class Field> | ||||||
|  |   class Polynomial : public OperatorFunction<Field> { | ||||||
|  |   private: | ||||||
|  |     std::vector<RealD> Coeffs; | ||||||
|  |   public: | ||||||
|  |     Polynomial(std::vector<RealD> &_Coeffs) : Coeffs(_Coeffs) { }; | ||||||
|  |  | ||||||
|  |     // Implement the required interface | ||||||
|  |     void operator() (LinearOperatorBase<Field> &Linop, const Field &in, Field &out) { | ||||||
|  |  | ||||||
|  |       Field AtoN(in._grid); | ||||||
|  |       Field Mtmp(in._grid); | ||||||
|  |       AtoN = in; | ||||||
|  |       out = AtoN*Coeffs[0]; | ||||||
|  |       for(int n=1;n<Coeffs.size();n++){ | ||||||
|  | 	Mtmp = AtoN; | ||||||
|  | 	Linop.HermOp(Mtmp,AtoN); | ||||||
|  | 	out=out+AtoN*Coeffs[n]; | ||||||
|  |       } | ||||||
|  |     }; | ||||||
|  |   }; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ | |||||||
|  |  | ||||||
| Author: Peter Boyle <paboyle@ph.ed.ac.uk> | Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||||
| Author: paboyle <paboyle@ph.ed.ac.uk> | Author: paboyle <paboyle@ph.ed.ac.uk> | ||||||
|  | Author: Christoph Lehner <clehner@bnl.gov> | ||||||
|  |  | ||||||
|     This program is free software; you can redistribute it and/or modify |     This program is free software; you can redistribute it and/or modify | ||||||
|     it under the terms of the GNU General Public License as published by |     it under the terms of the GNU General Public License as published by | ||||||
| @@ -33,40 +34,11 @@ Author: paboyle <paboyle@ph.ed.ac.uk> | |||||||
|  |  | ||||||
| namespace Grid { | namespace Grid { | ||||||
|  |  | ||||||
|   //////////////////////////////////////////////////////////////////////////////////////////// | struct ChebyParams : Serializable { | ||||||
|   // Simple general polynomial with user supplied coefficients |   GRID_SERIALIZABLE_CLASS_MEMBERS(ChebyParams, | ||||||
|   //////////////////////////////////////////////////////////////////////////////////////////// | 				  RealD, alpha,   | ||||||
|   template<class Field> | 				  RealD, beta,    | ||||||
|   class HermOpOperatorFunction : public OperatorFunction<Field> { | 				  int, Npoly); | ||||||
|     void operator() (LinearOperatorBase<Field> &Linop, const Field &in, Field &out) { |  | ||||||
|       Linop.HermOp(in,out); |  | ||||||
|     }; |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   template<class Field> |  | ||||||
|   class Polynomial : public OperatorFunction<Field> { |  | ||||||
|   private: |  | ||||||
|     std::vector<RealD> Coeffs; |  | ||||||
|   public: |  | ||||||
|     Polynomial(std::vector<RealD> &_Coeffs) : Coeffs(_Coeffs) { }; |  | ||||||
|  |  | ||||||
|     // Implement the required interface |  | ||||||
|     void operator() (LinearOperatorBase<Field> &Linop, const Field &in, Field &out) { |  | ||||||
|  |  | ||||||
|       Field AtoN(in._grid); |  | ||||||
|       Field Mtmp(in._grid); |  | ||||||
|       AtoN = in; |  | ||||||
|       out = AtoN*Coeffs[0]; |  | ||||||
| //            std::cout <<"Poly in " <<norm2(in)<<" size "<< Coeffs.size()<<std::endl; |  | ||||||
| //            std::cout <<"Coeffs[0]= "<<Coeffs[0]<< " 0 " <<norm2(out)<<std::endl; |  | ||||||
|       for(int n=1;n<Coeffs.size();n++){ |  | ||||||
| 	Mtmp = AtoN; |  | ||||||
| 	Linop.HermOp(Mtmp,AtoN); |  | ||||||
| 	out=out+AtoN*Coeffs[n]; |  | ||||||
| //            std::cout <<"Coeffs "<<n<<"= "<< Coeffs[n]<< " 0 " <<std::endl; |  | ||||||
| //		std::cout << n<<" " <<norm2(out)<<std::endl; |  | ||||||
|       } |  | ||||||
|     }; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   //////////////////////////////////////////////////////////////////////////////////////////// |   //////////////////////////////////////////////////////////////////////////////////////////// | ||||||
| @@ -82,8 +54,16 @@ namespace Grid { | |||||||
|  |  | ||||||
|   public: |   public: | ||||||
|     void csv(std::ostream &out){ |     void csv(std::ostream &out){ | ||||||
|  |  | ||||||
|  | #if 0 | ||||||
|  |       RealD delta = (hi-lo)*1.0e-9; | ||||||
|  |       for (RealD x=lo; x<hi; x+=delta) { | ||||||
|  | 	delta*=1.1; | ||||||
|  | #else | ||||||
| 	RealD diff = hi-lo; | 	RealD diff = hi-lo; | ||||||
|       for (RealD x=lo-0.2*diff; x<hi+0.2*diff; x+=(hi-lo)/1000) { |       //for (RealD x=lo-0.2*diff; x<hi+0.2*diff; x+=(hi-lo)/1000) { | ||||||
|  |       for (RealD x=lo-0.2*diff; x<hi+0.2*diff; x+=diff/1000.0) { // ypj [note] divide by float | ||||||
|  | #endif | ||||||
| 	RealD f = approx(x); | 	RealD f = approx(x); | ||||||
| 	out<< x<<" "<<f<<std::endl; | 	out<< x<<" "<<f<<std::endl; | ||||||
|       } |       } | ||||||
| @@ -99,6 +79,7 @@ namespace Grid { | |||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     Chebyshev(){}; |     Chebyshev(){}; | ||||||
|  |     Chebyshev(ChebyParams p){ Init(p.alpha,p.beta,p.Npoly);}; | ||||||
|     Chebyshev(RealD _lo,RealD _hi,int _order, RealD (* func)(RealD) ) {Init(_lo,_hi,_order,func);}; |     Chebyshev(RealD _lo,RealD _hi,int _order, RealD (* func)(RealD) ) {Init(_lo,_hi,_order,func);}; | ||||||
|     Chebyshev(RealD _lo,RealD _hi,int _order) {Init(_lo,_hi,_order);}; |     Chebyshev(RealD _lo,RealD _hi,int _order) {Init(_lo,_hi,_order);}; | ||||||
|  |  | ||||||
| @@ -114,7 +95,7 @@ namespace Grid { | |||||||
|        |        | ||||||
|       if(order < 2) exit(-1); |       if(order < 2) exit(-1); | ||||||
|       Coeffs.resize(order); |       Coeffs.resize(order); | ||||||
|       Coeffs.assign(0.,order); |       Coeffs.assign(order,0.);   | ||||||
|       Coeffs[order-1] = 1.; |       Coeffs[order-1] = 1.; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -193,6 +174,47 @@ namespace Grid { | |||||||
|       return sum; |       return sum; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     RealD approxD(RealD x) | ||||||
|  |     { | ||||||
|  |       RealD Un; | ||||||
|  |       RealD Unm; | ||||||
|  |       RealD Unp; | ||||||
|  |        | ||||||
|  |       RealD y=( x-0.5*(hi+lo))/(0.5*(hi-lo)); | ||||||
|  |        | ||||||
|  |       RealD U0=1; | ||||||
|  |       RealD U1=2*y; | ||||||
|  |        | ||||||
|  |       RealD sum; | ||||||
|  |       sum = Coeffs[1]*U0; | ||||||
|  |       sum+= Coeffs[2]*U1*2.0; | ||||||
|  |        | ||||||
|  |       Un =U1; | ||||||
|  |       Unm=U0; | ||||||
|  |       for(int i=2;i<order-1;i++){ | ||||||
|  | 	Unp=2*y*Un-Unm; | ||||||
|  | 	Unm=Un; | ||||||
|  | 	Un =Unp; | ||||||
|  | 	sum+= Un*Coeffs[i+1]*(i+1.0); | ||||||
|  |       } | ||||||
|  |       return sum/(0.5*(hi-lo)); | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     RealD approxInv(RealD z, RealD x0, int maxiter, RealD resid) { | ||||||
|  |       RealD x = x0; | ||||||
|  |       RealD eps; | ||||||
|  |        | ||||||
|  |       int i; | ||||||
|  |       for (i=0;i<maxiter;i++) { | ||||||
|  | 	eps = approx(x) - z; | ||||||
|  | 	if (fabs(eps / z) < resid) | ||||||
|  | 	  return x; | ||||||
|  | 	x = x - eps / approxD(x); | ||||||
|  |       } | ||||||
|  |        | ||||||
|  |       return std::numeric_limits<double>::quiet_NaN(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|     // Implement the required interface |     // Implement the required interface | ||||||
|     void operator() (LinearOperatorBase<Field> &Linop, const Field &in, Field &out) { |     void operator() (LinearOperatorBase<Field> &Linop, const Field &in, Field &out) { | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										152
									
								
								lib/algorithms/approx/Forecast.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								lib/algorithms/approx/Forecast.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,152 @@ | |||||||
|  | /************************************************************************************* | ||||||
|  |  | ||||||
|  | Grid physics library, www.github.com/paboyle/Grid | ||||||
|  |  | ||||||
|  | Source file: ./lib/algorithms/approx/Forecast.h | ||||||
|  |  | ||||||
|  | Copyright (C) 2015 | ||||||
|  |  | ||||||
|  | Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||||
|  | Author: paboyle <paboyle@ph.ed.ac.uk> | ||||||
|  | Author: David Murphy <dmurphy@phys.columbia.edu> | ||||||
|  |  | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the GNU General Public License as published by | ||||||
|  | the Free Software Foundation; either version 2 of the License, or | ||||||
|  | (at your option) any later version. | ||||||
|  |  | ||||||
|  | This program is distributed in the hope that it will be useful, | ||||||
|  | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | GNU General Public License for more details. | ||||||
|  |  | ||||||
|  | You should have received a copy of the GNU General Public License along | ||||||
|  | with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  | See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  | *************************************************************************************/ | ||||||
|  | /*  END LEGAL */ | ||||||
|  |  | ||||||
|  | #ifndef INCLUDED_FORECAST_H | ||||||
|  | #define INCLUDED_FORECAST_H | ||||||
|  |  | ||||||
|  | namespace Grid { | ||||||
|  |  | ||||||
|  |   // Abstract base class. | ||||||
|  |   // Takes a matrix (Mat), a source (phi), and a vector of Fields (chi) | ||||||
|  |   // and returns a forecasted solution to the system D*psi = phi (psi). | ||||||
|  |   template<class Matrix, class Field> | ||||||
|  |   class Forecast | ||||||
|  |   { | ||||||
|  |     public: | ||||||
|  |       virtual Field operator()(Matrix &Mat, const Field& phi, const std::vector<Field>& chi) = 0; | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   // Implementation of Brower et al.'s chronological inverter (arXiv:hep-lat/9509012), | ||||||
|  |   // used to forecast solutions across poles of the EOFA heatbath. | ||||||
|  |   // | ||||||
|  |   // Modified from CPS (cps_pp/src/util/dirac_op/d_op_base/comsrc/minresext.C) | ||||||
|  |   template<class Matrix, class Field> | ||||||
|  |   class ChronoForecast : public Forecast<Matrix,Field> | ||||||
|  |   { | ||||||
|  |     public: | ||||||
|  |       Field operator()(Matrix &Mat, const Field& phi, const std::vector<Field>& prev_solns) | ||||||
|  |       { | ||||||
|  |         int degree = prev_solns.size(); | ||||||
|  |         Field chi(phi); // forecasted solution | ||||||
|  |  | ||||||
|  |         // Trivial cases | ||||||
|  |         if(degree == 0){ chi = zero; return chi; } | ||||||
|  |         else if(degree == 1){ return prev_solns[0]; } | ||||||
|  |  | ||||||
|  |         RealD dot; | ||||||
|  |         ComplexD xp; | ||||||
|  |         Field r(phi); // residual | ||||||
|  |         Field Mv(phi); | ||||||
|  |         std::vector<Field> v(prev_solns); // orthonormalized previous solutions | ||||||
|  |         std::vector<Field> MdagMv(degree,phi); | ||||||
|  |  | ||||||
|  |         // Array to hold the matrix elements | ||||||
|  |         std::vector<std::vector<ComplexD>> G(degree, std::vector<ComplexD>(degree)); | ||||||
|  |  | ||||||
|  |         // Solution and source vectors | ||||||
|  |         std::vector<ComplexD> a(degree); | ||||||
|  |         std::vector<ComplexD> b(degree); | ||||||
|  |  | ||||||
|  |         // Orthonormalize the vector basis | ||||||
|  |         for(int i=0; i<degree; i++){ | ||||||
|  |           v[i] *= 1.0/std::sqrt(norm2(v[i])); | ||||||
|  |           for(int j=i+1; j<degree; j++){ v[j] -= innerProduct(v[i],v[j]) * v[i]; } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Perform sparse matrix multiplication and construct rhs | ||||||
|  |         for(int i=0; i<degree; i++){ | ||||||
|  |           b[i] = innerProduct(v[i],phi); | ||||||
|  |           Mat.M(v[i],Mv); | ||||||
|  |           Mat.Mdag(Mv,MdagMv[i]); | ||||||
|  |           G[i][i] = innerProduct(v[i],MdagMv[i]); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Construct the matrix | ||||||
|  |         for(int j=0; j<degree; j++){ | ||||||
|  |         for(int k=j+1; k<degree; k++){ | ||||||
|  |           G[j][k] = innerProduct(v[j],MdagMv[k]); | ||||||
|  |           G[k][j] = std::conj(G[j][k]); | ||||||
|  |         }} | ||||||
|  |  | ||||||
|  |         // Gauss-Jordan elimination with partial pivoting | ||||||
|  |         for(int i=0; i<degree; i++){ | ||||||
|  |  | ||||||
|  |           // Perform partial pivoting | ||||||
|  |           int k = i; | ||||||
|  |           for(int j=i+1; j<degree; j++){ if(std::abs(G[j][j]) > std::abs(G[k][k])){ k = j; } } | ||||||
|  |           if(k != i){ | ||||||
|  |             xp = b[k]; | ||||||
|  |             b[k] = b[i]; | ||||||
|  |             b[i] = xp; | ||||||
|  |             for(int j=0; j<degree; j++){ | ||||||
|  |               xp = G[k][j]; | ||||||
|  |               G[k][j] = G[i][j]; | ||||||
|  |               G[i][j] = xp; | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |  | ||||||
|  |           // Convert matrix to upper triangular form | ||||||
|  |           for(int j=i+1; j<degree; j++){ | ||||||
|  |             xp = G[j][i]/G[i][i]; | ||||||
|  |             b[j] -= xp * b[i]; | ||||||
|  |             for(int k=0; k<degree; k++){ G[j][k] -= xp*G[i][k]; } | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Use Gaussian elimination to solve equations and calculate initial guess | ||||||
|  |         chi = zero; | ||||||
|  |         r = phi; | ||||||
|  |         for(int i=degree-1; i>=0; i--){ | ||||||
|  |           a[i] = 0.0; | ||||||
|  |           for(int j=i+1; j<degree; j++){ a[i] += G[i][j] * a[j]; } | ||||||
|  |           a[i] = (b[i]-a[i])/G[i][i]; | ||||||
|  |           chi += a[i]*v[i]; | ||||||
|  |           r -= a[i]*MdagMv[i]; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         RealD true_r(0.0); | ||||||
|  |         ComplexD tmp; | ||||||
|  |         for(int i=0; i<degree; i++){ | ||||||
|  |           tmp = -b[i]; | ||||||
|  |           for(int j=0; j<degree; j++){ tmp += G[i][j]*a[j]; } | ||||||
|  |           tmp = std::conj(tmp)*tmp; | ||||||
|  |           true_r += std::sqrt(tmp.real()); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         RealD error = std::sqrt(norm2(r)/norm2(phi)); | ||||||
|  |         std::cout << GridLogMessage << "ChronoForecast: |res|/|src| = " << error << std::endl; | ||||||
|  |  | ||||||
|  |         return chi; | ||||||
|  |       }; | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										137
									
								
								lib/algorithms/densematrix/DenseMatrix.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								lib/algorithms/densematrix/DenseMatrix.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,137 @@ | |||||||
|  |     /************************************************************************************* | ||||||
|  |  | ||||||
|  |     Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  |     Source file: ./lib/algorithms/iterative/DenseMatrix.h | ||||||
|  |  | ||||||
|  |     Copyright (C) 2015 | ||||||
|  |  | ||||||
|  | Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||||
|  | Author: paboyle <paboyle@ph.ed.ac.uk> | ||||||
|  |  | ||||||
|  |     This program is free software; you can redistribute it and/or modify | ||||||
|  |     it under the terms of the GNU General Public License as published by | ||||||
|  |     the Free Software Foundation; either version 2 of the License, or | ||||||
|  |     (at your option) any later version. | ||||||
|  |  | ||||||
|  |     This program is distributed in the hope that it will be useful, | ||||||
|  |     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  |     GNU General Public License for more details. | ||||||
|  |  | ||||||
|  |     You should have received a copy of the GNU General Public License along | ||||||
|  |     with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  |     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  |     See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  |     *************************************************************************************/ | ||||||
|  |     /*  END LEGAL */ | ||||||
|  | #ifndef GRID_DENSE_MATRIX_H | ||||||
|  | #define GRID_DENSE_MATRIX_H | ||||||
|  |  | ||||||
|  | namespace Grid { | ||||||
|  |     ///////////////////////////////////////////////////////////// | ||||||
|  |     // Matrix untils | ||||||
|  |     ///////////////////////////////////////////////////////////// | ||||||
|  |  | ||||||
|  | template<class T> using DenseVector = std::vector<T>; | ||||||
|  | template<class T> using DenseMatrix = DenseVector<DenseVector<T> >; | ||||||
|  |  | ||||||
|  | template<class T> void Size(DenseVector<T> & vec, int &N)  | ||||||
|  | {  | ||||||
|  |   N= vec.size(); | ||||||
|  | } | ||||||
|  | template<class T> void Size(DenseMatrix<T> & mat, int &N,int &M)  | ||||||
|  | {  | ||||||
|  |   N= mat.size(); | ||||||
|  |   M= mat[0].size(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template<class T> void SizeSquare(DenseMatrix<T> & mat, int &N)  | ||||||
|  | {  | ||||||
|  |   int M; Size(mat,N,M); | ||||||
|  |   assert(N==M); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template<class T> void Resize(DenseVector<T > & mat, int N) {  | ||||||
|  |   mat.resize(N); | ||||||
|  | } | ||||||
|  | template<class T> void Resize(DenseMatrix<T > & mat, int N, int M) {  | ||||||
|  |   mat.resize(N); | ||||||
|  |   for(int i=0;i<N;i++){ | ||||||
|  |     mat[i].resize(M); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | template<class T> void Fill(DenseMatrix<T> & mat, T&val) {  | ||||||
|  |   int N,M; | ||||||
|  |   Size(mat,N,M); | ||||||
|  |   for(int i=0;i<N;i++){ | ||||||
|  |   for(int j=0;j<M;j++){ | ||||||
|  |     mat[i][j] = val; | ||||||
|  |   }} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** Transpose of a matrix **/ | ||||||
|  | template<class T> DenseMatrix<T> Transpose(DenseMatrix<T> & mat){ | ||||||
|  |   int N,M; | ||||||
|  |   Size(mat,N,M); | ||||||
|  |   DenseMatrix<T> C; Resize(C,M,N); | ||||||
|  |   for(int i=0;i<M;i++){ | ||||||
|  |   for(int j=0;j<N;j++){ | ||||||
|  |     C[i][j] = mat[j][i]; | ||||||
|  |   }}  | ||||||
|  |   return C; | ||||||
|  | } | ||||||
|  | /** Set DenseMatrix to unit matrix **/ | ||||||
|  | template<class T> void Unity(DenseMatrix<T> &A){ | ||||||
|  |   int N;  SizeSquare(A,N); | ||||||
|  |   for(int i=0;i<N;i++){ | ||||||
|  |     for(int j=0;j<N;j++){ | ||||||
|  |       if ( i==j ) A[i][j] = 1; | ||||||
|  |       else        A[i][j] = 0; | ||||||
|  |     }  | ||||||
|  |   }  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** Add C * I to matrix **/ | ||||||
|  | template<class T> | ||||||
|  | void PlusUnit(DenseMatrix<T> & A,T c){ | ||||||
|  |   int dim;  SizeSquare(A,dim); | ||||||
|  |   for(int i=0;i<dim;i++){A[i][i] = A[i][i] + c;}  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** return the Hermitian conjugate of matrix **/ | ||||||
|  | template<class T> | ||||||
|  | DenseMatrix<T> HermitianConj(DenseMatrix<T> &mat){ | ||||||
|  |  | ||||||
|  |   int dim; SizeSquare(mat,dim); | ||||||
|  |  | ||||||
|  |   DenseMatrix<T> C; Resize(C,dim,dim); | ||||||
|  |  | ||||||
|  |   for(int i=0;i<dim;i++){ | ||||||
|  |     for(int j=0;j<dim;j++){ | ||||||
|  |       C[i][j] = conj(mat[j][i]); | ||||||
|  |     }  | ||||||
|  |   }  | ||||||
|  |   return C; | ||||||
|  | } | ||||||
|  | /**Get a square submatrix**/ | ||||||
|  | template <class T> | ||||||
|  | DenseMatrix<T> GetSubMtx(DenseMatrix<T> &A,int row_st, int row_end, int col_st, int col_end) | ||||||
|  | { | ||||||
|  |   DenseMatrix<T> H; Resize(H,row_end - row_st,col_end-col_st); | ||||||
|  |  | ||||||
|  |   for(int i = row_st; i<row_end; i++){ | ||||||
|  |   for(int j = col_st; j<col_end; j++){ | ||||||
|  |     H[i-row_st][j-col_st]=A[i][j]; | ||||||
|  |   }} | ||||||
|  |   return H; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #include "Householder.h" | ||||||
|  | #include "Francis.h" | ||||||
|  |  | ||||||
|  | #endif | ||||||
|  |  | ||||||
							
								
								
									
										525
									
								
								lib/algorithms/densematrix/Francis.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										525
									
								
								lib/algorithms/densematrix/Francis.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,525 @@ | |||||||
|  |     /************************************************************************************* | ||||||
|  |  | ||||||
|  |     Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  |     Source file: ./lib/algorithms/iterative/Francis.h | ||||||
|  |  | ||||||
|  |     Copyright (C) 2015 | ||||||
|  |  | ||||||
|  | Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||||
|  |  | ||||||
|  |     This program is free software; you can redistribute it and/or modify | ||||||
|  |     it under the terms of the GNU General Public License as published by | ||||||
|  |     the Free Software Foundation; either version 2 of the License, or | ||||||
|  |     (at your option) any later version. | ||||||
|  |  | ||||||
|  |     This program is distributed in the hope that it will be useful, | ||||||
|  |     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  |     GNU General Public License for more details. | ||||||
|  |  | ||||||
|  |     You should have received a copy of the GNU General Public License along | ||||||
|  |     with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  |     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  |     See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  |     *************************************************************************************/ | ||||||
|  |     /*  END LEGAL */ | ||||||
|  | #ifndef FRANCIS_H | ||||||
|  | #define FRANCIS_H | ||||||
|  |  | ||||||
|  | #include <cstdlib> | ||||||
|  | #include <string> | ||||||
|  | #include <cmath> | ||||||
|  | #include <iostream> | ||||||
|  | #include <sstream> | ||||||
|  | #include <stdexcept> | ||||||
|  | #include <fstream> | ||||||
|  | #include <complex> | ||||||
|  | #include <algorithm> | ||||||
|  |  | ||||||
|  | //#include <timer.h> | ||||||
|  | //#include <lapacke.h> | ||||||
|  | //#include <Eigen/Dense> | ||||||
|  |  | ||||||
|  | namespace Grid { | ||||||
|  |  | ||||||
|  | template <class T> int SymmEigensystem(DenseMatrix<T > &Ain, DenseVector<T> &evals, DenseMatrix<T> &evecs, RealD small); | ||||||
|  | template <class T> int     Eigensystem(DenseMatrix<T > &Ain, DenseVector<T> &evals, DenseMatrix<T> &evecs, RealD small); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Find the eigenvalues of an upper hessenberg matrix using the Francis QR algorithm. | ||||||
|  | H = | ||||||
|  |       x  x  x  x  x  x  x  x  x | ||||||
|  |       x  x  x  x  x  x  x  x  x | ||||||
|  |       0  x  x  x  x  x  x  x  x | ||||||
|  |       0  0  x  x  x  x  x  x  x | ||||||
|  |       0  0  0  x  x  x  x  x  x | ||||||
|  |       0  0  0  0  x  x  x  x  x | ||||||
|  |       0  0  0  0  0  x  x  x  x | ||||||
|  |       0  0  0  0  0  0  x  x  x | ||||||
|  |       0  0  0  0  0  0  0  x  x | ||||||
|  | Factorization is P T P^H where T is upper triangular (mod cc blocks) and P is orthagonal/unitary. | ||||||
|  | **/ | ||||||
|  | template <class T> | ||||||
|  | int QReigensystem(DenseMatrix<T> &Hin, DenseVector<T> &evals, DenseMatrix<T> &evecs, RealD small) | ||||||
|  | { | ||||||
|  |   DenseMatrix<T> H = Hin;  | ||||||
|  |  | ||||||
|  |   int N ; SizeSquare(H,N); | ||||||
|  |   int M = N; | ||||||
|  |  | ||||||
|  |   Fill(evals,0); | ||||||
|  |   Fill(evecs,0); | ||||||
|  |  | ||||||
|  |   T s,t,x=0,y=0,z=0; | ||||||
|  |   T u,d; | ||||||
|  |   T apd,amd,bc; | ||||||
|  |   DenseVector<T> p(N,0); | ||||||
|  |   T nrm = Norm(H);    ///DenseMatrix Norm | ||||||
|  |   int n, m; | ||||||
|  |   int e = 0; | ||||||
|  |   int it = 0; | ||||||
|  |   int tot_it = 0; | ||||||
|  |   int l = 0; | ||||||
|  |   int r = 0; | ||||||
|  |   DenseMatrix<T> P; Resize(P,N,N); Unity(P); | ||||||
|  |   DenseVector<int> trows(N,0); | ||||||
|  |  | ||||||
|  |   /// Check if the matrix is really hessenberg, if not abort | ||||||
|  |   RealD sth = 0; | ||||||
|  |   for(int j=0;j<N;j++){ | ||||||
|  |     for(int i=j+2;i<N;i++){ | ||||||
|  |       sth = abs(H[i][j]); | ||||||
|  |       if(sth > small){ | ||||||
|  | 	std::cout << "Non hessenberg H = " << sth << " > " << small << std::endl; | ||||||
|  | 	exit(1); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   do{ | ||||||
|  |     std::cout << "Francis QR Step N = " << N << std::endl; | ||||||
|  |     /** Check for convergence | ||||||
|  |       x  x  x  x  x | ||||||
|  |       0  x  x  x  x | ||||||
|  |       0  0  x  x  x | ||||||
|  |       0  0  x  x  x | ||||||
|  |       0  0  0  0  x | ||||||
|  |       for this matrix l = 4 | ||||||
|  |      **/ | ||||||
|  |     do{ | ||||||
|  |       l = Chop_subdiag(H,nrm,e,small); | ||||||
|  |       r = 0;    ///May have converged on more than one eval | ||||||
|  |       ///Single eval | ||||||
|  |       if(l == N-1){ | ||||||
|  |         evals[e] = H[l][l]; | ||||||
|  |         N--; e++; r++; it = 0; | ||||||
|  |       } | ||||||
|  |       ///RealD eval | ||||||
|  |       if(l == N-2){ | ||||||
|  |         trows[l+1] = 1;    ///Needed for UTSolve | ||||||
|  |         apd = H[l][l] + H[l+1][l+1]; | ||||||
|  |         amd = H[l][l] - H[l+1][l+1]; | ||||||
|  |         bc =  (T)4.0*H[l+1][l]*H[l][l+1]; | ||||||
|  |         evals[e]   = (T)0.5*( apd + sqrt(amd*amd + bc) ); | ||||||
|  |         evals[e+1] = (T)0.5*( apd - sqrt(amd*amd + bc) ); | ||||||
|  |         N-=2; e+=2; r++; it = 0; | ||||||
|  |       } | ||||||
|  |     } while(r>0); | ||||||
|  |  | ||||||
|  |     if(N ==0) break; | ||||||
|  |  | ||||||
|  |     DenseVector<T > ck; Resize(ck,3); | ||||||
|  |     DenseVector<T> v;   Resize(v,3); | ||||||
|  |  | ||||||
|  |     for(int m = N-3; m >= l; m--){ | ||||||
|  |       ///Starting vector essentially random shift. | ||||||
|  |       if(it%10 == 0 && N >= 3 && it > 0){ | ||||||
|  |         s = (T)1.618033989*( abs( H[N-1][N-2] ) + abs( H[N-2][N-3] ) ); | ||||||
|  |         t = (T)0.618033989*( abs( H[N-1][N-2] ) + abs( H[N-2][N-3] ) ); | ||||||
|  |         x = H[m][m]*H[m][m] + H[m][m+1]*H[m+1][m] - s*H[m][m] + t; | ||||||
|  |         y = H[m+1][m]*(H[m][m] + H[m+1][m+1] - s); | ||||||
|  |         z = H[m+1][m]*H[m+2][m+1]; | ||||||
|  |       } | ||||||
|  |       ///Starting vector implicit Q theorem | ||||||
|  |       else{ | ||||||
|  |         s = (H[N-2][N-2] + H[N-1][N-1]); | ||||||
|  |         t = (H[N-2][N-2]*H[N-1][N-1] - H[N-2][N-1]*H[N-1][N-2]); | ||||||
|  |         x = H[m][m]*H[m][m] + H[m][m+1]*H[m+1][m] - s*H[m][m] + t; | ||||||
|  |         y = H[m+1][m]*(H[m][m] + H[m+1][m+1] - s); | ||||||
|  |         z = H[m+1][m]*H[m+2][m+1]; | ||||||
|  |       } | ||||||
|  |       ck[0] = x; ck[1] = y; ck[2] = z; | ||||||
|  |  | ||||||
|  |       if(m == l) break; | ||||||
|  |  | ||||||
|  |       /** Some stupid thing from numerical recipies, seems to work**/ | ||||||
|  |       // PAB.. for heaven's sake quote page, purpose, evidence it works. | ||||||
|  |       //       what sort of comment is that!?!?!? | ||||||
|  |       u=abs(H[m][m-1])*(abs(y)+abs(z)); | ||||||
|  |       d=abs(x)*(abs(H[m-1][m-1])+abs(H[m][m])+abs(H[m+1][m+1])); | ||||||
|  |       if ((T)abs(u+d) == (T)abs(d) ){ | ||||||
|  | 	l = m; break; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       //if (u < small){l = m; break;} | ||||||
|  |     } | ||||||
|  |     if(it > 100000){ | ||||||
|  |      std::cout << "QReigensystem: bugger it got stuck after 100000 iterations" << std::endl; | ||||||
|  |      std::cout << "got " << e << " evals " << l << " " << N << std::endl; | ||||||
|  |       exit(1); | ||||||
|  |     } | ||||||
|  |     normalize(ck);    ///Normalization cancels in PHP anyway | ||||||
|  |     T beta; | ||||||
|  |     Householder_vector<T >(ck, 0, 2, v, beta); | ||||||
|  |     Householder_mult<T >(H,v,beta,0,l,l+2,0); | ||||||
|  |     Householder_mult<T >(H,v,beta,0,l,l+2,1); | ||||||
|  |     ///Accumulate eigenvector | ||||||
|  |     Householder_mult<T >(P,v,beta,0,l,l+2,1); | ||||||
|  |     int sw = 0;      ///Are we on the last row? | ||||||
|  |     for(int k=l;k<N-2;k++){ | ||||||
|  |       x = H[k+1][k]; | ||||||
|  |       y = H[k+2][k]; | ||||||
|  |       z = (T)0.0; | ||||||
|  |       if(k+3 <= N-1){ | ||||||
|  | 	z = H[k+3][k]; | ||||||
|  |       } else{ | ||||||
|  | 	sw = 1;  | ||||||
|  | 	v[2] = (T)0.0; | ||||||
|  |       } | ||||||
|  |       ck[0] = x; ck[1] = y; ck[2] = z; | ||||||
|  |       normalize(ck); | ||||||
|  |       Householder_vector<T >(ck, 0, 2-sw, v, beta); | ||||||
|  |       Householder_mult<T >(H,v, beta,0,k+1,k+3-sw,0); | ||||||
|  |       Householder_mult<T >(H,v, beta,0,k+1,k+3-sw,1); | ||||||
|  |       ///Accumulate eigenvector | ||||||
|  |       Householder_mult<T >(P,v, beta,0,k+1,k+3-sw,1); | ||||||
|  |     } | ||||||
|  |     it++; | ||||||
|  |     tot_it++; | ||||||
|  |   }while(N > 1); | ||||||
|  |   N = evals.size(); | ||||||
|  |   ///Annoying - UT solves in reverse order; | ||||||
|  |   DenseVector<T> tmp; Resize(tmp,N); | ||||||
|  |   for(int i=0;i<N;i++){ | ||||||
|  |     tmp[i] = evals[N-i-1]; | ||||||
|  |   }  | ||||||
|  |   evals = tmp; | ||||||
|  |   UTeigenvectors(H, trows, evals, evecs); | ||||||
|  |   for(int i=0;i<evals.size();i++){evecs[i] = P*evecs[i]; normalize(evecs[i]);} | ||||||
|  |   return tot_it; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int my_Wilkinson(DenseMatrix<T> &Hin, DenseVector<T> &evals, DenseMatrix<T> &evecs, RealD small) | ||||||
|  | { | ||||||
|  |   /** | ||||||
|  |   Find the eigenvalues of an upper Hessenberg matrix using the Wilkinson QR algorithm. | ||||||
|  |   H = | ||||||
|  |   x  x  0  0  0  0 | ||||||
|  |   x  x  x  0  0  0 | ||||||
|  |   0  x  x  x  0  0 | ||||||
|  |   0  0  x  x  x  0 | ||||||
|  |   0  0  0  x  x  x | ||||||
|  |   0  0  0  0  x  x | ||||||
|  |   Factorization is P T P^H where T is upper triangular (mod cc blocks) and P is orthagonal/unitary.  **/ | ||||||
|  |   return my_Wilkinson(Hin, evals, evecs, small, small); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int my_Wilkinson(DenseMatrix<T> &Hin, DenseVector<T> &evals, DenseMatrix<T> &evecs, RealD small, RealD tol) | ||||||
|  | { | ||||||
|  |   int N; SizeSquare(Hin,N); | ||||||
|  |   int M = N; | ||||||
|  |  | ||||||
|  |   ///I don't want to modify the input but matricies must be passed by reference | ||||||
|  |   //Scale a matrix by its "norm" | ||||||
|  |   //RealD Hnorm = abs( Hin.LargestDiag() ); H =  H*(1.0/Hnorm); | ||||||
|  |   DenseMatrix<T> H;  H = Hin; | ||||||
|  |    | ||||||
|  |   RealD Hnorm = abs(Norm(Hin)); | ||||||
|  |   H = H * (1.0 / Hnorm); | ||||||
|  |  | ||||||
|  |   // TODO use openmp and memset | ||||||
|  |   Fill(evals,0); | ||||||
|  |   Fill(evecs,0); | ||||||
|  |  | ||||||
|  |   T s, t, x = 0, y = 0, z = 0; | ||||||
|  |   T u, d; | ||||||
|  |   T apd, amd, bc; | ||||||
|  |   DenseVector<T> p; Resize(p,N); Fill(p,0); | ||||||
|  |  | ||||||
|  |   T nrm = Norm(H);    ///DenseMatrix Norm | ||||||
|  |   int n, m; | ||||||
|  |   int e = 0; | ||||||
|  |   int it = 0; | ||||||
|  |   int tot_it = 0; | ||||||
|  |   int l = 0; | ||||||
|  |   int r = 0; | ||||||
|  |   DenseMatrix<T> P; Resize(P,N,N); | ||||||
|  |   Unity(P); | ||||||
|  |   DenseVector<int> trows(N, 0); | ||||||
|  |   /// Check if the matrix is really symm tridiag | ||||||
|  |   RealD sth = 0; | ||||||
|  |   for(int j = 0; j < N; ++j) | ||||||
|  |   { | ||||||
|  |     for(int i = j + 2; i < N; ++i) | ||||||
|  |     { | ||||||
|  |       if(abs(H[i][j]) > tol || abs(H[j][i]) > tol) | ||||||
|  |       { | ||||||
|  | 	std::cout << "Non Tridiagonal H(" << i << ","<< j << ") = |" << Real( real( H[j][i] ) ) << "| > " << tol << std::endl; | ||||||
|  | 	std::cout << "Warning tridiagonalize and call again" << std::endl; | ||||||
|  |         // exit(1); // see what is going on | ||||||
|  |         //return; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   do{ | ||||||
|  |     do{ | ||||||
|  |       //Jasper | ||||||
|  |       //Check if the subdiagonal term is small enough (<small) | ||||||
|  |       //if true then it is converged. | ||||||
|  |       //check start from H.dim - e - 1 | ||||||
|  |       //How to deal with more than 2 are converged? | ||||||
|  |       //What if Chop_symm_subdiag return something int the middle? | ||||||
|  |       //-------------- | ||||||
|  |       l = Chop_symm_subdiag(H,nrm, e, small); | ||||||
|  |       r = 0;    ///May have converged on more than one eval | ||||||
|  |       //Jasper | ||||||
|  |       //In this case | ||||||
|  |       // x  x  0  0  0  0 | ||||||
|  |       // x  x  x  0  0  0 | ||||||
|  |       // 0  x  x  x  0  0 | ||||||
|  |       // 0  0  x  x  x  0 | ||||||
|  |       // 0  0  0  x  x  0 | ||||||
|  |       // 0  0  0  0  0  x  <- l | ||||||
|  |       //-------------- | ||||||
|  |       ///Single eval | ||||||
|  |       if(l == N - 1) | ||||||
|  |       { | ||||||
|  |         evals[e] = H[l][l]; | ||||||
|  |         N--; | ||||||
|  |         e++; | ||||||
|  |         r++; | ||||||
|  |         it = 0; | ||||||
|  |       } | ||||||
|  |       //Jasper | ||||||
|  |       // x  x  0  0  0  0 | ||||||
|  |       // x  x  x  0  0  0 | ||||||
|  |       // 0  x  x  x  0  0 | ||||||
|  |       // 0  0  x  x  0  0 | ||||||
|  |       // 0  0  0  0  x  x  <- l | ||||||
|  |       // 0  0  0  0  x  x | ||||||
|  |       //-------------- | ||||||
|  |       ///RealD eval | ||||||
|  |       if(l == N - 2) | ||||||
|  |       { | ||||||
|  |         trows[l + 1] = 1;    ///Needed for UTSolve | ||||||
|  |         apd = H[l][l] + H[l + 1][ l + 1]; | ||||||
|  |         amd = H[l][l] - H[l + 1][l + 1]; | ||||||
|  |         bc =  (T) 4.0 * H[l + 1][l] * H[l][l + 1]; | ||||||
|  |         evals[e] = (T) 0.5 * (apd + sqrt(amd * amd + bc)); | ||||||
|  |         evals[e + 1] = (T) 0.5 * (apd - sqrt(amd * amd + bc)); | ||||||
|  |         N -= 2; | ||||||
|  |         e += 2; | ||||||
|  |         r++; | ||||||
|  |         it = 0; | ||||||
|  |       } | ||||||
|  |     }while(r > 0); | ||||||
|  |     //Jasper | ||||||
|  |     //Already converged | ||||||
|  |     //-------------- | ||||||
|  |     if(N == 0) break; | ||||||
|  |  | ||||||
|  |     DenseVector<T> ck,v; Resize(ck,2); Resize(v,2); | ||||||
|  |  | ||||||
|  |     for(int m = N - 3; m >= l; m--) | ||||||
|  |     { | ||||||
|  |       ///Starting vector essentially random shift. | ||||||
|  |       if(it%10 == 0 && N >= 3 && it > 0) | ||||||
|  |       { | ||||||
|  |         t = abs(H[N - 1][N - 2]) + abs(H[N - 2][N - 3]); | ||||||
|  |         x = H[m][m] - t; | ||||||
|  |         z = H[m + 1][m]; | ||||||
|  |       } else { | ||||||
|  |       ///Starting vector implicit Q theorem | ||||||
|  |         d = (H[N - 2][N - 2] - H[N - 1][N - 1]) * (T) 0.5; | ||||||
|  |         t =  H[N - 1][N - 1] - H[N - 1][N - 2] * H[N - 1][N - 2]  | ||||||
|  | 	  / (d + sign(d) * sqrt(d * d + H[N - 1][N - 2] * H[N - 1][N - 2])); | ||||||
|  |         x = H[m][m] - t; | ||||||
|  |         z = H[m + 1][m]; | ||||||
|  |       } | ||||||
|  |       //Jasper | ||||||
|  |       //why it is here???? | ||||||
|  |       //----------------------- | ||||||
|  |       if(m == l) | ||||||
|  |         break; | ||||||
|  |  | ||||||
|  |       u = abs(H[m][m - 1]) * (abs(y) + abs(z)); | ||||||
|  |       d = abs(x) * (abs(H[m - 1][m - 1]) + abs(H[m][m]) + abs(H[m + 1][m + 1])); | ||||||
|  |       if ((T)abs(u + d) == (T)abs(d)) | ||||||
|  |       { | ||||||
|  |         l = m; | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     //Jasper | ||||||
|  |     if(it > 1000000) | ||||||
|  |     { | ||||||
|  |       std::cout << "Wilkinson: bugger it got stuck after 100000 iterations" << std::endl; | ||||||
|  |       std::cout << "got " << e << " evals " << l << " " << N << std::endl; | ||||||
|  |       exit(1); | ||||||
|  |     } | ||||||
|  |     // | ||||||
|  |     T s, c; | ||||||
|  |     Givens_calc<T>(x, z, c, s); | ||||||
|  |     Givens_mult<T>(H, l, l + 1, c, -s, 0); | ||||||
|  |     Givens_mult<T>(H, l, l + 1, c,  s, 1); | ||||||
|  |     Givens_mult<T>(P, l, l + 1, c,  s, 1); | ||||||
|  |     // | ||||||
|  |     for(int k = l; k < N - 2; ++k) | ||||||
|  |     { | ||||||
|  |       x = H.A[k + 1][k]; | ||||||
|  |       z = H.A[k + 2][k]; | ||||||
|  |       Givens_calc<T>(x, z, c, s); | ||||||
|  |       Givens_mult<T>(H, k + 1, k + 2, c, -s, 0); | ||||||
|  |       Givens_mult<T>(H, k + 1, k + 2, c,  s, 1); | ||||||
|  |       Givens_mult<T>(P, k + 1, k + 2, c,  s, 1); | ||||||
|  |     } | ||||||
|  |     it++; | ||||||
|  |     tot_it++; | ||||||
|  |   }while(N > 1); | ||||||
|  |  | ||||||
|  |   N = evals.size(); | ||||||
|  |   ///Annoying - UT solves in reverse order; | ||||||
|  |   DenseVector<T> tmp(N); | ||||||
|  |   for(int i = 0; i < N; ++i) | ||||||
|  |     tmp[i] = evals[N-i-1]; | ||||||
|  |   evals = tmp; | ||||||
|  |   // | ||||||
|  |   UTeigenvectors(H, trows, evals, evecs); | ||||||
|  |   //UTSymmEigenvectors(H, trows, evals, evecs); | ||||||
|  |   for(int i = 0; i < evals.size(); ++i) | ||||||
|  |   { | ||||||
|  |     evecs[i] = P * evecs[i]; | ||||||
|  |     normalize(evecs[i]); | ||||||
|  |     evals[i] = evals[i] * Hnorm; | ||||||
|  |   } | ||||||
|  |   // // FIXME this is to test | ||||||
|  |   // Hin.write("evecs3", evecs); | ||||||
|  |   // Hin.write("evals3", evals); | ||||||
|  |   // // check rsd | ||||||
|  |   // for(int i = 0; i < M; i++) { | ||||||
|  |   //   vector<T> Aevec = Hin * evecs[i]; | ||||||
|  |   //   RealD norm2(0.); | ||||||
|  |   //   for(int j = 0; j < M; j++) { | ||||||
|  |   //     norm2 += (Aevec[j] - evals[i] * evecs[i][j]) * (Aevec[j] - evals[i] * evecs[i][j]); | ||||||
|  |   //   } | ||||||
|  |   // } | ||||||
|  |   return tot_it; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Hess(DenseMatrix<T > &A, DenseMatrix<T> &Q, int start){ | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |   turn a matrix A = | ||||||
|  |   x  x  x  x  x | ||||||
|  |   x  x  x  x  x | ||||||
|  |   x  x  x  x  x | ||||||
|  |   x  x  x  x  x | ||||||
|  |   x  x  x  x  x | ||||||
|  |   into | ||||||
|  |   x  x  x  x  x | ||||||
|  |   x  x  x  x  x | ||||||
|  |   0  x  x  x  x | ||||||
|  |   0  0  x  x  x | ||||||
|  |   0  0  0  x  x | ||||||
|  |   with householder rotations | ||||||
|  |   Slow. | ||||||
|  |   */ | ||||||
|  |   int N ; SizeSquare(A,N); | ||||||
|  |   DenseVector<T > p; Resize(p,N); Fill(p,0); | ||||||
|  |  | ||||||
|  |   for(int k=start;k<N-2;k++){ | ||||||
|  |     //cerr << "hess" << k << std::endl; | ||||||
|  |     DenseVector<T > ck,v; Resize(ck,N-k-1); Resize(v,N-k-1); | ||||||
|  |     for(int i=k+1;i<N;i++){ck[i-k-1] = A(i,k);}  ///kth column | ||||||
|  |     normalize(ck);    ///Normalization cancels in PHP anyway | ||||||
|  |     T beta; | ||||||
|  |     Householder_vector<T >(ck, 0, ck.size()-1, v, beta);  ///Householder vector | ||||||
|  |     Householder_mult<T>(A,v,beta,start,k+1,N-1,0);  ///A -> PA | ||||||
|  |     Householder_mult<T >(A,v,beta,start,k+1,N-1,1);  ///PA -> PAP^H | ||||||
|  |     ///Accumulate eigenvector | ||||||
|  |     Householder_mult<T >(Q,v,beta,start,k+1,N-1,1);  ///Q -> QP^H | ||||||
|  |   } | ||||||
|  |   /*for(int l=0;l<N-2;l++){ | ||||||
|  |     for(int k=l+2;k<N;k++){ | ||||||
|  |     A(0,k,l); | ||||||
|  |     } | ||||||
|  |     }*/ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Tri(DenseMatrix<T > &A, DenseMatrix<T> &Q, int start){ | ||||||
|  | ///Tridiagonalize a matrix | ||||||
|  |   int N; SizeSquare(A,N); | ||||||
|  |   Hess(A,Q,start); | ||||||
|  |   /*for(int l=0;l<N-2;l++){ | ||||||
|  |     for(int k=l+2;k<N;k++){ | ||||||
|  |     A(0,l,k); | ||||||
|  |     } | ||||||
|  |     }*/ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void ForceTridiagonal(DenseMatrix<T> &A){ | ||||||
|  | ///Tridiagonalize a matrix | ||||||
|  |   int N ; SizeSquare(A,N); | ||||||
|  |   for(int l=0;l<N-2;l++){ | ||||||
|  |     for(int k=l+2;k<N;k++){ | ||||||
|  |       A[l][k]=0; | ||||||
|  |       A[k][l]=0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int my_SymmEigensystem(DenseMatrix<T > &Ain, DenseVector<T> &evals, DenseVector<DenseVector<T> > &evecs, RealD small){ | ||||||
|  |   ///Solve a symmetric eigensystem, not necessarily in tridiagonal form | ||||||
|  |   int N; SizeSquare(Ain,N); | ||||||
|  |   DenseMatrix<T > A; A = Ain; | ||||||
|  |   DenseMatrix<T > Q; Resize(Q,N,N); Unity(Q); | ||||||
|  |   Tri(A,Q,0); | ||||||
|  |   int it = my_Wilkinson<T>(A, evals, evecs, small); | ||||||
|  |   for(int k=0;k<N;k++){evecs[k] = Q*evecs[k];} | ||||||
|  |   return it; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int Wilkinson(DenseMatrix<T> &Ain, DenseVector<T> &evals, DenseVector<DenseVector<T> > &evecs, RealD small){ | ||||||
|  |   return my_Wilkinson(Ain, evals, evecs, small); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int SymmEigensystem(DenseMatrix<T> &Ain, DenseVector<T> &evals, DenseVector<DenseVector<T> > &evecs, RealD small){ | ||||||
|  |   return my_SymmEigensystem(Ain, evals, evecs, small); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int Eigensystem(DenseMatrix<T > &Ain, DenseVector<T> &evals, DenseVector<DenseVector<T> > &evecs, RealD small){ | ||||||
|  | ///Solve a general eigensystem, not necessarily in tridiagonal form | ||||||
|  |   int N = Ain.dim; | ||||||
|  |   DenseMatrix<T > A(N); A = Ain; | ||||||
|  |   DenseMatrix<T > Q(N);Q.Unity(); | ||||||
|  |   Hess(A,Q,0); | ||||||
|  |   int it = QReigensystem<T>(A, evals, evecs, small); | ||||||
|  |   for(int k=0;k<N;k++){evecs[k] = Q*evecs[k];} | ||||||
|  |   return it; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | } | ||||||
|  | #endif | ||||||
							
								
								
									
										242
									
								
								lib/algorithms/densematrix/Householder.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										242
									
								
								lib/algorithms/densematrix/Householder.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,242 @@ | |||||||
|  |     /************************************************************************************* | ||||||
|  |  | ||||||
|  |     Grid physics library, www.github.com/paboyle/Grid  | ||||||
|  |  | ||||||
|  |     Source file: ./lib/algorithms/iterative/Householder.h | ||||||
|  |  | ||||||
|  |     Copyright (C) 2015 | ||||||
|  |  | ||||||
|  | Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||||
|  |  | ||||||
|  |     This program is free software; you can redistribute it and/or modify | ||||||
|  |     it under the terms of the GNU General Public License as published by | ||||||
|  |     the Free Software Foundation; either version 2 of the License, or | ||||||
|  |     (at your option) any later version. | ||||||
|  |  | ||||||
|  |     This program is distributed in the hope that it will be useful, | ||||||
|  |     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  |     GNU General Public License for more details. | ||||||
|  |  | ||||||
|  |     You should have received a copy of the GNU General Public License along | ||||||
|  |     with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  |     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  | ||||||
|  |     See the full license in the file "LICENSE" in the top level distribution directory | ||||||
|  |     *************************************************************************************/ | ||||||
|  |     /*  END LEGAL */ | ||||||
|  | #ifndef HOUSEHOLDER_H | ||||||
|  | #define HOUSEHOLDER_H | ||||||
|  |  | ||||||
|  | #define TIMER(A) std::cout << GridLogMessage << __FUNC__ << " file "<< __FILE__ <<" line " << __LINE__ << std::endl; | ||||||
|  | #define ENTER()  std::cout << GridLogMessage << "ENTRY "<<__FUNC__ << " file "<< __FILE__ <<" line " << __LINE__ << std::endl; | ||||||
|  | #define LEAVE()  std::cout << GridLogMessage << "EXIT  "<<__FUNC__ << " file "<< __FILE__ <<" line " << __LINE__ << std::endl; | ||||||
|  |  | ||||||
|  | #include <cstdlib> | ||||||
|  | #include <string> | ||||||
|  | #include <cmath> | ||||||
|  | #include <iostream> | ||||||
|  | #include <sstream> | ||||||
|  | #include <stdexcept> | ||||||
|  | #include <fstream> | ||||||
|  | #include <complex> | ||||||
|  | #include <algorithm> | ||||||
|  |  | ||||||
|  | namespace Grid { | ||||||
|  | /** Comparison function for finding the max element in a vector **/ | ||||||
|  | template <class T> bool cf(T i, T j) {  | ||||||
|  |   return abs(i) < abs(j);  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /**  | ||||||
|  | 	Calculate a real Givens angle  | ||||||
|  |  **/ | ||||||
|  | template <class T> inline void Givens_calc(T y, T z, T &c, T &s){ | ||||||
|  |  | ||||||
|  |   RealD mz = (RealD)abs(z); | ||||||
|  |    | ||||||
|  |   if(mz==0.0){ | ||||||
|  |     c = 1; s = 0; | ||||||
|  |   } | ||||||
|  |   if(mz >= (RealD)abs(y)){ | ||||||
|  |     T t = -y/z; | ||||||
|  |     s = (T)1.0 / sqrt ((T)1.0 + t * t); | ||||||
|  |     c = s * t; | ||||||
|  |   } else { | ||||||
|  |     T t = -z/y; | ||||||
|  |     c = (T)1.0 / sqrt ((T)1.0 + t * t); | ||||||
|  |     s = c * t; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> inline void Givens_mult(DenseMatrix<T> &A,  int i, int k, T c, T s, int dir) | ||||||
|  | { | ||||||
|  |   int q ; SizeSquare(A,q); | ||||||
|  |  | ||||||
|  |   if(dir == 0){ | ||||||
|  |     for(int j=0;j<q;j++){ | ||||||
|  |       T nu = A[i][j]; | ||||||
|  |       T w  = A[k][j]; | ||||||
|  |       A[i][j] = (c*nu + s*w); | ||||||
|  |       A[k][j] = (-s*nu + c*w); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if(dir == 1){ | ||||||
|  |     for(int j=0;j<q;j++){ | ||||||
|  |       T nu = A[j][i]; | ||||||
|  |       T w  = A[j][k]; | ||||||
|  |       A[j][i] = (c*nu - s*w); | ||||||
|  |       A[j][k] = (s*nu + c*w); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | 	from input = x; | ||||||
|  | 	Compute the complex Householder vector, v, such that | ||||||
|  | 	P = (I - b v transpose(v) ) | ||||||
|  | 	b = 2/v.v | ||||||
|  |  | ||||||
|  | 	P | x |    | x | k = 0 | ||||||
|  | 	| x |    | 0 |  | ||||||
|  | 	| x | =  | 0 | | ||||||
|  | 	| x |    | 0 | j = 3 | ||||||
|  | 	| x |	   | x | | ||||||
|  |  | ||||||
|  | 	These are the "Unreduced" Householder vectors. | ||||||
|  |  | ||||||
|  |  **/ | ||||||
|  | template <class T> inline void Householder_vector(DenseVector<T> input, int k, int j, DenseVector<T> &v, T &beta) | ||||||
|  | { | ||||||
|  |   int N ; Size(input,N); | ||||||
|  |   T m = *max_element(input.begin() + k, input.begin() + j + 1, cf<T> ); | ||||||
|  |  | ||||||
|  |   if(abs(m) > 0.0){ | ||||||
|  |     T alpha = 0; | ||||||
|  |  | ||||||
|  |     for(int i=k; i<j+1; i++){ | ||||||
|  |       v[i] = input[i]/m; | ||||||
|  |       alpha = alpha + v[i]*conj(v[i]); | ||||||
|  |     } | ||||||
|  |     alpha = sqrt(alpha); | ||||||
|  |     beta = (T)1.0/(alpha*(alpha + abs(v[k]) )); | ||||||
|  |  | ||||||
|  |     if(abs(v[k]) > 0.0)  v[k] = v[k] + (v[k]/abs(v[k]))*alpha; | ||||||
|  |     else                 v[k] = -alpha; | ||||||
|  |   } else{ | ||||||
|  |     for(int i=k; i<j+1; i++){ | ||||||
|  |       v[i] = 0.0; | ||||||
|  |     }  | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | 	from input = x; | ||||||
|  | 	Compute the complex Householder vector, v, such that | ||||||
|  | 	P = (I - b v transpose(v) ) | ||||||
|  | 	b = 2/v.v | ||||||
|  |  | ||||||
|  | 	Px = alpha*e_dir | ||||||
|  |  | ||||||
|  | 	These are the "Unreduced" Householder vectors. | ||||||
|  |  | ||||||
|  |  **/ | ||||||
|  |  | ||||||
|  | template <class T> inline void Householder_vector(DenseVector<T> input, int k, int j, int dir, DenseVector<T> &v, T &beta) | ||||||
|  | { | ||||||
|  |   int N = input.size(); | ||||||
|  |   T m = *max_element(input.begin() + k, input.begin() + j + 1, cf); | ||||||
|  |    | ||||||
|  |   if(abs(m) > 0.0){ | ||||||
|  |     T alpha = 0; | ||||||
|  |  | ||||||
|  |     for(int i=k; i<j+1; i++){ | ||||||
|  |       v[i] = input[i]/m; | ||||||
|  |       alpha = alpha + v[i]*conj(v[i]); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     alpha = sqrt(alpha); | ||||||
|  |     beta = 1.0/(alpha*(alpha + abs(v[dir]) )); | ||||||
|  | 	 | ||||||
|  |     if(abs(v[dir]) > 0.0) v[dir] = v[dir] + (v[dir]/abs(v[dir]))*alpha; | ||||||
|  |     else                  v[dir] = -alpha; | ||||||
|  |   }else{ | ||||||
|  |     for(int i=k; i<j+1; i++){ | ||||||
|  |       v[i] = 0.0; | ||||||
|  |     }  | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | 	Compute the product PA if trans = 0 | ||||||
|  | 	AP if trans = 1 | ||||||
|  | 	P = (I - b v transpose(v) ) | ||||||
|  | 	b = 2/v.v | ||||||
|  | 	start at element l of matrix A | ||||||
|  | 	v is of length j - k + 1 of v are nonzero | ||||||
|  |  **/ | ||||||
|  |  | ||||||
|  | template <class T> inline void Householder_mult(DenseMatrix<T> &A , DenseVector<T> v, T beta, int l, int k, int j, int trans) | ||||||
|  | { | ||||||
|  |   int N ; SizeSquare(A,N); | ||||||
|  |  | ||||||
|  |   if(abs(beta) > 0.0){ | ||||||
|  |     for(int p=l; p<N; p++){ | ||||||
|  |       T s = 0; | ||||||
|  |       if(trans==0){ | ||||||
|  | 	for(int i=k;i<j+1;i++) s += conj(v[i-k])*A[i][p]; | ||||||
|  | 	s *= beta; | ||||||
|  | 	for(int i=k;i<j+1;i++){ A[i][p] = A[i][p]-s*conj(v[i-k]);} | ||||||
|  |       } else { | ||||||
|  | 	for(int i=k;i<j+1;i++){ s += conj(v[i-k])*A[p][i];} | ||||||
|  | 	s *= beta; | ||||||
|  | 	for(int i=k;i<j+1;i++){ A[p][i]=A[p][i]-s*conj(v[i-k]);} | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | 	Compute the product PA if trans = 0 | ||||||
|  | 	AP if trans = 1 | ||||||
|  | 	P = (I - b v transpose(v) ) | ||||||
|  | 	b = 2/v.v | ||||||
|  | 	start at element l of matrix A | ||||||
|  | 	v is of length j - k + 1 of v are nonzero | ||||||
|  | 	A is tridiagonal | ||||||
|  |  **/ | ||||||
|  | template <class T> inline void Householder_mult_tri(DenseMatrix<T> &A , DenseVector<T> v, T beta, int l, int M, int k, int j, int trans) | ||||||
|  | { | ||||||
|  |   if(abs(beta) > 0.0){ | ||||||
|  |  | ||||||
|  |     int N ; SizeSquare(A,N); | ||||||
|  |  | ||||||
|  |     DenseMatrix<T> tmp; Resize(tmp,N,N); Fill(tmp,0);  | ||||||
|  |  | ||||||
|  |     T s; | ||||||
|  |     for(int p=l; p<M; p++){ | ||||||
|  |       s = 0; | ||||||
|  |       if(trans==0){ | ||||||
|  | 	for(int i=k;i<j+1;i++) s = s + conj(v[i-k])*A[i][p]; | ||||||
|  |       }else{ | ||||||
|  | 	for(int i=k;i<j+1;i++) s = s + v[i-k]*A[p][i]; | ||||||
|  |       } | ||||||
|  |       s = beta*s; | ||||||
|  |       if(trans==0){ | ||||||
|  | 	for(int i=k;i<j+1;i++) tmp[i][p] = tmp(i,p) - s*v[i-k]; | ||||||
|  |       }else{ | ||||||
|  | 	for(int i=k;i<j+1;i++) tmp[p][i] = tmp[p][i] - s*conj(v[i-k]); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     for(int p=l; p<M; p++){ | ||||||
|  |       if(trans==0){ | ||||||
|  | 	for(int i=k;i<j+1;i++) A[i][p] = A[i][p] + tmp[i][p]; | ||||||
|  |       }else{ | ||||||
|  | 	for(int i=k;i<j+1;i++) A[p][i] = A[p][i] + tmp[p][i]; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | } | ||||||
|  | #endif | ||||||
| @@ -87,15 +87,22 @@ void ThinQRfact (Eigen::MatrixXcd &m_rr, | |||||||
|   //////////////////////////////////////////////////////////////////////////////////////////////////// |   //////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|   sliceInnerProductMatrix(m_rr,R,R,Orthog); |   sliceInnerProductMatrix(m_rr,R,R,Orthog); | ||||||
|  |  | ||||||
|   //////////////////////////////////////////////////////////////////////////////////////////////////// |   // Force manifest hermitian to avoid rounding related | ||||||
|   // Cholesky from Eigen |   m_rr = 0.5*(m_rr+m_rr.adjoint()); | ||||||
|   // There exists a ldlt that is documented as more stable |  | ||||||
|   //////////////////////////////////////////////////////////////////////////////////////////////////// |  | ||||||
|   Eigen::MatrixXcd L    = m_rr.llt().matrixL();  |  | ||||||
|  |  | ||||||
|  | #if 0 | ||||||
|  |   std::cout << " Calling Cholesky  ldlt on m_rr "  << m_rr <<std::endl; | ||||||
|  |   Eigen::MatrixXcd L_ldlt = m_rr.ldlt().matrixL();  | ||||||
|  |   std::cout << " Called Cholesky  ldlt on m_rr "  << L_ldlt <<std::endl; | ||||||
|  |   auto  D_ldlt = m_rr.ldlt().vectorD();  | ||||||
|  |   std::cout << " Called Cholesky  ldlt on m_rr "  << D_ldlt <<std::endl; | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  |   //  std::cout << " Calling Cholesky  llt on m_rr "  <<std::endl; | ||||||
|  |   Eigen::MatrixXcd L    = m_rr.llt().matrixL();  | ||||||
|  |   //  std::cout << " Called Cholesky  llt on m_rr "  << L <<std::endl; | ||||||
|   C    = L.adjoint(); |   C    = L.adjoint(); | ||||||
|   Cinv = C.inverse(); |   Cinv = C.inverse(); | ||||||
|  |  | ||||||
|   //////////////////////////////////////////////////////////////////////////////////////////////////// |   //////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|   // Q = R C^{-1} |   // Q = R C^{-1} | ||||||
|   // |   // | ||||||
| @@ -103,7 +110,6 @@ void ThinQRfact (Eigen::MatrixXcd &m_rr, | |||||||
|   // |   // | ||||||
|   // NB maddMatrix conventions are Right multiplication X[j] a[j,i] already |   // NB maddMatrix conventions are Right multiplication X[j] a[j,i] already | ||||||
|   //////////////////////////////////////////////////////////////////////////////////////////////////// |   //////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|   // FIXME:: make a sliceMulMatrix to avoid zero vector |  | ||||||
|   sliceMulMatrix(Q,Cinv,R,Orthog); |   sliceMulMatrix(Q,Cinv,R,Orthog); | ||||||
| } | } | ||||||
| //////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||
|   | |||||||
| @@ -52,8 +52,9 @@ class ConjugateGradient : public OperatorFunction<Field> { | |||||||
|         MaxIterations(maxit), |         MaxIterations(maxit), | ||||||
|         ErrorOnNoConverge(err_on_no_conv){}; |         ErrorOnNoConverge(err_on_no_conv){}; | ||||||
|  |  | ||||||
|   void operator()(LinearOperatorBase<Field> &Linop, const Field &src, |   void operator()(LinearOperatorBase<Field> &Linop, const Field &src, Field &psi) { | ||||||
|                   Field &psi) { |  | ||||||
|  |  | ||||||
|     psi.checkerboard = src.checkerboard; |     psi.checkerboard = src.checkerboard; | ||||||
|     conformable(psi, src); |     conformable(psi, src); | ||||||
|  |  | ||||||
| @@ -70,7 +71,6 @@ class ConjugateGradient : public OperatorFunction<Field> { | |||||||
|      |      | ||||||
|     Linop.HermOpAndNorm(psi, mmp, d, b); |     Linop.HermOpAndNorm(psi, mmp, d, b); | ||||||
|  |  | ||||||
|  |  | ||||||
|     r = src - mmp; |     r = src - mmp; | ||||||
|     p = r; |     p = r; | ||||||
|  |  | ||||||
| @@ -78,12 +78,12 @@ class ConjugateGradient : public OperatorFunction<Field> { | |||||||
|     cp = a; |     cp = a; | ||||||
|     ssq = norm2(src); |     ssq = norm2(src); | ||||||
|  |  | ||||||
|     std::cout << GridLogIterative << std::setprecision(4) << "ConjugateGradient: guess " << guess << std::endl; |     std::cout << GridLogIterative << std::setprecision(8) << "ConjugateGradient: guess " << guess << std::endl; | ||||||
|     std::cout << GridLogIterative << std::setprecision(4) << "ConjugateGradient:   src " << ssq << std::endl; |     std::cout << GridLogIterative << std::setprecision(8) << "ConjugateGradient:   src " << ssq << std::endl; | ||||||
|     std::cout << GridLogIterative << std::setprecision(4) << "ConjugateGradient:    mp " << d << std::endl; |     std::cout << GridLogIterative << std::setprecision(8) << "ConjugateGradient:    mp " << d << std::endl; | ||||||
|     std::cout << GridLogIterative << std::setprecision(4) << "ConjugateGradient:   mmp " << b << std::endl; |     std::cout << GridLogIterative << std::setprecision(8) << "ConjugateGradient:   mmp " << b << std::endl; | ||||||
|     std::cout << GridLogIterative << std::setprecision(4) << "ConjugateGradient:  cp,r " << cp << std::endl; |     std::cout << GridLogIterative << std::setprecision(8) << "ConjugateGradient:  cp,r " << cp << std::endl; | ||||||
|     std::cout << GridLogIterative << std::setprecision(4) << "ConjugateGradient:     p " << a << std::endl; |     std::cout << GridLogIterative << std::setprecision(8) << "ConjugateGradient:     p " << a << std::endl; | ||||||
|  |  | ||||||
|     RealD rsq = Tolerance * Tolerance * ssq; |     RealD rsq = Tolerance * Tolerance * ssq; | ||||||
|  |  | ||||||
| @@ -92,42 +92,48 @@ class ConjugateGradient : public OperatorFunction<Field> { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     std::cout << GridLogIterative << std::setprecision(4) |     std::cout << GridLogIterative << std::setprecision(8) | ||||||
|               << "ConjugateGradient: k=0 residual " << cp << " target " << rsq << std::endl; |               << "ConjugateGradient: k=0 residual " << cp << " target " << rsq << std::endl; | ||||||
|  |  | ||||||
|     GridStopWatch LinalgTimer; |     GridStopWatch LinalgTimer; | ||||||
|  |     GridStopWatch InnerTimer; | ||||||
|  |     GridStopWatch AxpyNormTimer; | ||||||
|  |     GridStopWatch LinearCombTimer; | ||||||
|     GridStopWatch MatrixTimer; |     GridStopWatch MatrixTimer; | ||||||
|     GridStopWatch SolverTimer; |     GridStopWatch SolverTimer; | ||||||
|  |  | ||||||
|     SolverTimer.Start(); |     SolverTimer.Start(); | ||||||
|     int k; |     int k; | ||||||
|     for (k = 1; k <= MaxIterations; k++) { |     for (k = 1; k <= MaxIterations*1000; k++) { | ||||||
|       c = cp; |       c = cp; | ||||||
|  |  | ||||||
|       MatrixTimer.Start(); |       MatrixTimer.Start(); | ||||||
|       Linop.HermOpAndNorm(p, mmp, d, qq); |       Linop.HermOp(p, mmp); | ||||||
|       MatrixTimer.Stop(); |       MatrixTimer.Stop(); | ||||||
|  |  | ||||||
|       LinalgTimer.Start(); |       LinalgTimer.Start(); | ||||||
|       //  RealD    qqck = norm2(mmp); |  | ||||||
|       //  ComplexD dck  = innerProduct(p,mmp); |  | ||||||
|  |  | ||||||
|  |       InnerTimer.Start(); | ||||||
|  |       ComplexD dc  = innerProduct(p,mmp); | ||||||
|  |       InnerTimer.Stop(); | ||||||
|  |       d = dc.real(); | ||||||
|       a = c / d; |       a = c / d; | ||||||
|       b_pred = a * (a * qq - d) / c; |  | ||||||
|  |  | ||||||
|  |       AxpyNormTimer.Start(); | ||||||
|       cp = axpy_norm(r, -a, mmp, r); |       cp = axpy_norm(r, -a, mmp, r); | ||||||
|  |       AxpyNormTimer.Stop(); | ||||||
|       b = cp / c; |       b = cp / c; | ||||||
|  |  | ||||||
|       // Fuse these loops ; should be really easy |       LinearCombTimer.Start(); | ||||||
|       psi = a * p + psi; |       parallel_for(int ss=0;ss<src._grid->oSites();ss++){ | ||||||
|       p = p * b + r; | 	vstream(psi[ss], a      *  p[ss] + psi[ss]); | ||||||
|  | 	vstream(p  [ss], b      *  p[ss] + r[ss]); | ||||||
|  |       } | ||||||
|  |       LinearCombTimer.Stop(); | ||||||
|       LinalgTimer.Stop(); |       LinalgTimer.Stop(); | ||||||
|  |  | ||||||
|       std::cout << GridLogIterative << "ConjugateGradient: Iteration " << k |       std::cout << GridLogIterative << "ConjugateGradient: Iteration " << k | ||||||
|                 << " residual " << cp << " target " << rsq << std::endl; |                 << " residual " << cp << " target " << rsq << std::endl; | ||||||
|       std::cout << GridLogDebug << "a = "<< a << " b_pred = "<< b_pred << "  b = "<< b << std::endl; |  | ||||||
|       std::cout << GridLogDebug << "qq = "<< qq << " d = "<< d << "  c = "<< c << std::endl; |  | ||||||
|  |  | ||||||
|       // Stopping condition |       // Stopping condition | ||||||
|       if (cp <= rsq) { |       if (cp <= rsq) { | ||||||
| @@ -148,6 +154,9 @@ class ConjugateGradient : public OperatorFunction<Field> { | |||||||
| 	std::cout << GridLogMessage << "\tElapsed    " << SolverTimer.Elapsed() <<std::endl; | 	std::cout << GridLogMessage << "\tElapsed    " << SolverTimer.Elapsed() <<std::endl; | ||||||
| 	std::cout << GridLogMessage << "\tMatrix     " << MatrixTimer.Elapsed() <<std::endl; | 	std::cout << GridLogMessage << "\tMatrix     " << MatrixTimer.Elapsed() <<std::endl; | ||||||
| 	std::cout << GridLogMessage << "\tLinalg     " << LinalgTimer.Elapsed() <<std::endl; | 	std::cout << GridLogMessage << "\tLinalg     " << LinalgTimer.Elapsed() <<std::endl; | ||||||
|  | 	std::cout << GridLogMessage << "\tInner      " << InnerTimer.Elapsed() <<std::endl; | ||||||
|  | 	std::cout << GridLogMessage << "\tAxpyNorm   " << AxpyNormTimer.Elapsed() <<std::endl; | ||||||
|  | 	std::cout << GridLogMessage << "\tLinearComb " << LinearCombTimer.Elapsed() <<std::endl; | ||||||
|  |  | ||||||
|         if (ErrorOnNoConverge) assert(true_residual / Tolerance < 10000.0); |         if (ErrorOnNoConverge) assert(true_residual / Tolerance < 10000.0); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -60,6 +60,7 @@ namespace Grid { | |||||||
|     } |     } | ||||||
|    |    | ||||||
|     void operator() (const FieldD &src_d_in, FieldD &sol_d){ |     void operator() (const FieldD &src_d_in, FieldD &sol_d){ | ||||||
|  |  | ||||||
|       TotalInnerIterations = 0; |       TotalInnerIterations = 0; | ||||||
| 	 | 	 | ||||||
|       GridStopWatch TotalTimer; |       GridStopWatch TotalTimer; | ||||||
|   | |||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user