| Algorithm 5. Pseudo-code of the Swap Phase for Parallel PAM |
| 1. repeat |
| 2. for p := 1 → P do in parallel |
| 3. for each data point Xi ϵ p do /* All PEs do in parallel*/ |
| 4. for j := 1 → K do |
| 5. Find Euclidean distance b/w Xi and Mj |
| 6. Tag Xi with j for which this distance is minimum |
| 7. endfor |
| 8. endfor |
| 9. endfor |
| 10. Concatenate clustering results from all PEs /* All PEs do this*/ |
| 11. for p := 1 → P do in parallel |
| 12. for j := 1 → K do /* All PEs do in parallel*/ |
| 13. for each data point Xa ϵ p & cluster j do |
| 14. for each data point Xi ϵ cluster j do |
| 15. Find sum of Euclidean distances b/w Xa and Xi |
| 16. endfor |
| 17. Find minimum sum for each cluster |
| 18. endfor |
| 19. endfor |
| 20. endfor |
| 21. for j := 1 → K do /* Only master PE will do this */ |
| 22. for p := 1 → P do |
| 23. Update Xa as jth Medoid for which the sum is minimum from all PEs |
| 24. endfor |
| 25. endfor |
| 26. until no update in any of ‘K’ Medoids |