How to Setup MPI on CentOS 7 – 2 Virtual Machines Part 2

July 13, 2019

hey everyone here's part two of my workshop on virtual machine clustering and setting up MPI now in part one I focus on the virtual machine clustering aspect of the workshop and I talked about how to connect to virtual machines and how to set up an NFS server in clay now in part two I'll focus on setting up MPI now with that being said if you haven't seen part one yet go to the description watch part one and set that up because it is a prerequisite to part two of how to set up MPI on virtual machines now we have Center West – one and sent to West – two connected and the first thing that we do is we need to be able to SSH from one machine to the other machine as Asia's way of remotely jumping from one machine to the other machine for example if is SH route at the IP address I'll jump to this IP address so ten point zero point one point three is the IP address of Machine number two by doing IP addr shown I can see the IP address and it is ten point zero point one point three so I just hit enter and I have to hit yes for this prompt and I have to enter my password now I'm on sent to s machine number two from sense of what's machine number one and that's all SSH does so I'll exit to get out of Center West machine number two and I'll be back on Center West machine number one now when we SSH we usually have to input a password but for MPI to work we don't want the password prompt to come up because when you use FBI you need to have complete access for one machine to the other machine and we can do that via SSH keys so to setup SSH keys and what they actually do is that they provide key access from one machine to the other machine without a password so as long as the key verifies that this he gives you access to this machine then all you need to do is have the key on one machine to access the other machine so the first thing that we do is we have to make the directory and the directory that we'll be creating is in tilde slash SSH you might already have this folder but you should make this the root directory if you do not and you hit enter and it says that cannot create directory because they are exist sometimes it does not exist so now let's just check if we have anything in there so we have a file called known host and what known host is is generated when you SSH to an our machine and it saves these locations and IP addresses and information about where you actually SSH to with the known house but now what we want to do is want to generate a new SSH key a key that gives us access to machine number two to do that I'll be using a direction from github and I'll leave a link in the blog post of course all of this will be in the blog post so don't worry if you missed some commands so I'll copy this command and I'm generating and that's the sage key and I'll place my email within quotes and I hit enter now it's generating the SSH key and for the recipes you can leave it by default you don't need a passphrase and you can hit enter now if we LS within the dot SSH folder we'll see that there are two new files ID RSA an IDR underscore RSA dot pump now next step is to copy or I guess we can copy IDR say dot pub to a file called authorized keys so we're basically copying this file into a new file that hasn't been created yet called authorize underscore keys and we do this because you want the key to be able to access this machine so now what we want to do is we're going to use a command called SCP SCP is for transferring files and copying files from one machine to another machine so the two files that we want to copy our IDR say an idea RSA pub to root at the IP address of our machine number two at : so it is important to leave this colon at the end we hit enter and we have to do our password still because machine number two does not verify authorized keys from these two keys that were saying so if we LS we'll see two new files ID RSA and IDR say dumped on and we want to move well first we have to make the directory tilde slash dot SSH and we hit enter now that directory is created after its created we can move ID RSA and IDR say not pub to the tilde dot s SH and we enter and now we CD to change directory into that folder we LS so we have the keys transferred into machine number two and now we just copy ID our say pub to authorize underscore keys and reenter now we see the new file if we LS again and now if we ssh route at if i'm on the second machine then the IP address of the first machine is 10.0 point one point two in and i hit enter and it says it gives me this prompt but i just say yes then it does not ask me for the password problem because the authorized keys from CentOS machine number one validates and says that if that access this machine has ID our say that pulp and this specific ID our say then give it access so likewise I can SSH at 10.0 point one point three and there's no more password problem now I can exit on both of them so that's the first step because we need to get SSH at access without passwords on both machines now the next step after this is that we need to install a couple of libraries so the first thing that we need to install is that we'll install something called W again now what W get is it is a basically it's a package that allows you to download files from the internet onto the machine so we'll use yum install W get – why on only on machine number one and hit enter and we'll install this package ll what says download certain files from any link and this will take just one second to download and then it downloads now let's check our shared folder so on machine number one it was an NFS / NFS share if we LS received a text file a machine number two it should be in mount NFS and Emma share we LS and we still see the textbook so let's on machine number to get out of this and just see the Delta / it a few times and where your over here now we're gonna move this NFS server and the first thing when you move the location of the shared folder is that you should first use a command called you mount and then you specify the folder that you want to unmount in this case it is slash mount and FS NFS share and then when we do that it unmount that folder and if we go back to that folder we'll see that it's empty because we're moving to shared folder so next up is we're gonna create a new location for the shared folder and when you're using MPI you want the locations of the shared folder to be consistent across all machines so I'm gonna make a directory and I've already created it and it is slash NFS share and it is in the same location as sent to West Machine number one so after you create that directory now we want to change the fstab file that we created in part one and instead of on this line where it says slash mount slide NFS since the new location on our current local machine is just slash NFS share then we just change it to that and we do : WQ to save and quit now if we run the command Mel space – eh it mounts the contents of the eff step older or file I mean and then when we do that if we go to NFS share then we can see that we have moved the NFS folder shared folder correctly so we do this because like I said before MPI wants to have the shared folders in the same relative location on the machines so after you do that on machine number one we can go back to it and W get has already been stalled so what we can do now is we can actually get the package so what the package for MPI is there are many different implementations of MPI and what I'm going to use is n pitch one such implementation so for example there are implementations like Intel's MPI open MP things like that but I'll use an implementation called M pitch so we use W get and you can copy this link but I'll just write it down and type it and I'm going to use version 3.1 point four by the time this video is out the version might change so be sure to check this website to see if there are any latest versions and I hit enter and I download it in the location and so I specifically am in the shared folder and I download that tart GZ partridge easy is just a compressed file format so after you have done that now on both of these machines we want to install some compilers that MPI requires now the first thing is we do yum install yet again and we install yum or I mean GCC which is C's compiler GCC – C++ C++ compiler and kernel – develop we ended up with a – wine at the end we entered and that will install on machine number one and so on machine number two we want to do the same command because all machines must have these packages and you can't just copy and paste them it might take a second to actually download and install these packages but just wait a second and they will install so this is almost until I'll just wait it out it's only a few seconds left and after it is installed well like it's just an installation period they'll take a couple more minutes or seconds and once it is installed then we'll proceed with actually installing MPI MPI a requires just those three packages at least when your unsent OS the names will be different if you use a different operating system so woah actually set the West machine number to finish first but also sent to us fishing number one finish so next up we need to extract and pitch so we do that with a command called tar space – XV app and then the name of the file and we can just use tab to autocomplete and then we hit enter and so this extracts the compressed file to the folder of the same name so we wait until this is done and it is done and we LS and we can see the folder now after doing that we can now since sent to West Machine number two it's also under ship folder we can check that all the contents are correctly inside here now we have to make a directory for where we compile the EM pitch library where the binaries in the Lib folder go to so we make a directory and we'll call it M pitch – and we just leave in the shared folder because you want libraries that are used by all the machines be in the shared folder so we have an empty folder called M pitch – now we're going to change the rectory inside and pitch three point one point four and what we want to do now is if we look there's a bunch of different stuff but the order of how to set and pitch up is that first normally when you have to see all these things if you see the source code of some C related program and library the first thing that you'd normally do is to use dot slash configure because there usually is this configure file and then you can set a prefix to where the contents of the library the binaries the library itself will go to and we'll put it in slash NFS share slash and pitch to and also MPI typically uses a Fortran but you can disable Fortran if you're not developing on Fortran or you're not using an application that requires Fortran so I'll add this extra flag to disable Fortran and I hit enter and it configures all of the settings to be put one you actually make the file into that / NFS share size and bitch too so it won't put anything yet but it's providing some configurations so that when you actually make the library itself it will place the binaries in the Lib folder within the specified prefix folder that we had selected and normally you select a folder within the shared folder so we wait until this is done and this might take a second so I'll just pause the video just to be not waste your time though once it's finished it's a should say configuration completed and now you actually go through the process of making the library happen so the command is very self-explanatory you just we do LS again and we see that there is always this make file and what a make file is is that if we open it up we can see that the make file runs let's just go down a little bit more okay so what you can see is there a bunch of different commands and basically it's for compiling the library itself so we'll just quit out that we don't need to mess around because if you're just setting up and pitch then you don't need to change the configurations unless you know what you're doing so what we do is we type in make to make the file and we get started with actually setting up the library itself so by doing make it goes through the make file contents and we wait until it's completed so I'll skip ahead with this part as well so as long as there are no errors then everything should be fine now the next step that you want to take is you want to run make install make install finishes the installation of the MPI library and this should be relatively quick so I'll just wait a couple seconds until this make install finishes and so because we set our prefix in the configuration to go inside NFS share and pitch to everything should be good and we should have access to it within that folder so it's done and so if we go back a directory and we go back into and pitch to we see all the contents within here several different folders that you did not see before no we changed the rectory to bin and we LS and we see some familiar binaries one binary that seems familiar is MPI run and MPI run is that binary that was in one of the slides in part one now what we want to do is if we go out of this directory and we run MPI run we see that we have access to end by an MPI run but if we go to sent to west machine number two and we run MPI run we can see that we also have access now for you you might not have access to MPI run because what I've done already is I've changed a file called slash bash RC so in this file you want to add these two lines so we export path equals slash NFS share and basically we write the path to our bin and then colon the dollar path and then we also do this for LD library path because what happens is that when you do not write these two lines what bash RC serves to do is that it loads this export to provide access to the bin folder from anywhere on to the machine so I can run MPI run as easily as running LS or CD or any other Linux commands so this provides global utilization of the MPI commands and I'll leave this in the documentation and in the blog post but you just copy these two lines and then you save and then after you save you want to use source tilde slash dot bash our CV and then you hit enter source reloads The Bachelor CD and you do the same thing for Machine number two and you make sure that the two last two lines have NFS Sheeran and pitch two with the bin and then for the LD library path to refer to the lip and you save that and you do source till they bash RZ so I was doing that while I had finished the make and I you did that in between the two steps but just do that adjust here at bash RC make sure you add those two ones now we can access MPI run on both machines from anywhere on the two machines so what's in the next step what we have the library are installed so they're all there is to do is actually run it so we make a directory called projects inside the shared folder you also want and you think that you want to be inside the shared folder we see the two projects and now in projects we create a file called posts so inside hosts what we want to do is we want to write the IP addresses including the most current machine IP address of where we want the process to be run and we use the IP addresses of Center West machine number one and set to what's machine number two and we saved this so after saving this we can start using MPI run so if you do MPI run – F is a flag to select a file that all has all the IP addresses so in this case it's a host file and then – end specifies the amount of cores that we want to use in this case we want to use let's say just four cores and let's run a arbitrary program like for example echo is a linux command that prints whatever is after it so in this case we'll do echo it will do hello world and we'll enter now it says – hello worlds are printed and then we come up with this error where we have to check for firewalls so we hold control and we proceed to exit because the process isn't finishing and the reason for that is that there are several ports that MPI uses and those ports range from several different TCP and UDP ports and this is a networking type of port for packet communication so what we can do is we can temporarily stop the firewall using systemctl stop firewall D and we'll stop the firewall now while we run the program again using the same line the packet should be able to send across the machine so we enter and we see that for hello worlds are printed now a command to check if the process is actually being run is called top so if we type in top on machine number two we can study in all the system processes that are running currently so we see all the commands on the right side in the CPU memory it uses so if we run the command again and hit enter we'll see that nothing change on machine number two because when you're using MPI run on commands designed for serial for running on only one machine then typically you won't see the need for MPI so MPI decides that it does not need to jump the program to the other machine because there won't be any runtime increase so I explained in one of the slides that's MPI looks for the fastest transport and sometimes there is not always the case especially with serial programs programs designed to run on one machine that's MPI thinks that it needs to be run on another machine so for instance doing echo hello world all it does is it returns hello world but when we run out for Korres it basically runs for instances of echo hello world hence the four times it is actually run and what's happening behind the scenes is that it runs four times only on Machine number one it's because it's a typical very small wedding samman and there's no need to actually jump that over to machine number two and that's how MPI works so I'll stop the part two over here and for part three we'll actually go into detail about how to write an MPI command and actually walk through top to see the command actually be running on the second machine so that's it for the setup for MPI on Central West and on to virtual machines when you want to exit the top top is just a task manager you just hit Q and that's it so thanks for watching hopefully you learned how to set up MPI correctly leave questions below and stay tuned for part three

You Might Also Like


  • Reply Somaya Ayman July 13, 2019 at 10:48 am

    Where is part 3 and thanks alot

  • Reply Jing Zhong July 13, 2019 at 10:48 am

    Nice presentation! And I get started! Great!

  • Reply satyam mehrotra July 13, 2019 at 10:48 am

    Pls share part 3

  • Reply satyam mehrotra July 13, 2019 at 10:48 am

    Hey mate i cant find the part 3 …plsshare link

  • Reply Rohit Gautam July 13, 2019 at 10:48 am


  • Reply Afroquest July 13, 2019 at 10:48 am

    Execellent. Apart from the music at the end.:)

  • Reply Andres Arriaga July 13, 2019 at 10:48 am

    Amazing video dude! You saved my life

  • Leave a Reply