{"id":3079,"date":"2024-04-03T20:05:57","date_gmt":"2024-04-03T15:05:57","guid":{"rendered":"https:\/\/afzalbadshah.com\/?p=3079"},"modified":"2024-05-08T22:21:14","modified_gmt":"2024-05-08T17:21:14","slug":"mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors","status":"publish","type":"post","link":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/","title":{"rendered":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We&#8217;ll create a master-worker model where the master process distributes tasks to worker processes, each responsible for computing the square of a subset of the array elements. <a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/mpi-with-python\/\" target=\"_blank\" rel=\"noopener\" title=\"\">The detailed tutorial of MPI with a python can be visited here.<\/a> <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from mpi4py import MPI\n\ncomm = MPI.COMM_WORLD  # Initialize MPI communicator\nrank = comm.Get_rank()  # Get the rank of the current process (0 for master, 1+ for workers)\nsize = comm.Get_size()  # Get the total number of processes\n\n# Define a simple task for each process (replace with your actual workload)\ndef calculate_square(number):\n    return number * number\n\nif rank == 0:  # Master process\n    data = &#91;2, 4]  # Sample data (modify with your data)\n    for i in range(1, size):  # Send data to worker processes (skip rank 0 - master)\n        comm.send(data&#91;i - 1], dest=i)\n\n    # Receive results from workers\n    results = &#91;]\n    for i in range(1, size):\n        result = comm.recv(source=i)\n        results.append(result)\n\n    print(\"Master received results:\", results)\nelse:  # Worker processes (rank 1+)\n    data = comm.recv(source=0)  # Receive data from master\n    result = calculate_square(data)\n    comm.send(result, dest=0)  # Send result back to master\n\nMPI.Finalize()  # Finalize MPI environment\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Parallel Computing with MPI4py || Calculating the Square\" width=\"640\" height=\"480\" src=\"https:\/\/www.youtube.com\/embed\/TaH3mvzLZNY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Code Explanation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s go through each line of the provided code and understand its functionality:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from mpi4py import MPI<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This line imports the necessary MPI functionality from the mpi4py library.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>comm = MPI.COMM_WORLD  # Initialize MPI communicator<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, we initialize the MPI communicator <code>comm<\/code>, which will be used for communication between different processes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rank = comm.Get_rank()  # Get the rank of the current process (0 for master, 1+ for workers)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This line retrieves the rank of the current process within the communicator. The rank identifies each process uniquely, with rank 0 typically representing the master process.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>size = comm.Get_size()  # Get the total number of processes<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This line obtains the total number of processes within the communicator.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def calculate_square(number):\n    return number * number<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This function <code>calculate_square()<\/code> takes a number as input and returns its square. This is the task that each worker process will perform. I&#8217;ve two core system, therefore taking two values. You should know the number of processors to pass the same values (In Windows you can find the numbers of cores by &#8220;wmic cpu get NumberOfCores&#8221;).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if rank == 0:  # Master process\n    data = &#91;2, 4]  # Sample data (modify with your data)\n    for i in range(1, size):  # Send data to worker processes (skip rank 0 - master)\n        comm.send(data&#91;i - 1], dest=i)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the master process (rank 0), we define the sample data <code>[2, 4]<\/code>. Then, we iterate over all worker processes (ranks 1 to <code>size-1<\/code>) and send each element of the data array to the corresponding worker process.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    results = &#91;]\n    for i in range(1, size):\n        result = comm.recv(source=i)\n        results.append(result)\n\n    print(\"Master received results:\", results)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After sending data to the worker processes, the master process waits to receive results from each worker process. It iterates over all worker processes, receives their results, and appends them to a list called <code>results<\/code>. Finally, it prints the received results.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>else:  # Worker processes (rank 1+)\n    data = comm.recv(source=0)  # Receive data from master\n    result = calculate_square(data)\n    comm.send(result, dest=0)  # Send result back to master<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In worker processes (ranks 1+), each process receives data from the master process, computes the square using the <code>calculate_square()<\/code> function, and sends the result back to the master process.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MPI.Finalize()  # Finalize MPI environment<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This line finalizes the MPI environment, releasing all resources associated with it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we&#8217;ve learned how to use the mpi4py library to distribute computation tasks across multiple processes in Python. Specifically, we&#8217;ve implemented a master-worker model to calculate the squares of array elements concurrently using multiple processors. This approach can significantly speed up computation for large datasets and computationally intensive tasks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Material<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/drive.google.com\/drive\/folders\/1vKaZIsBGLhzew2DKmmYfMCSrPAo4jXe-?usp=sharing\" target=\"_blank\" rel=\"noopener\" title=\"\">Download the programs (code), covering the MPI4Py.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We&#8217;ll create a master-worker model where the master process distributes tasks to worker processes, each responsible for computing the square of a subset of the array elements. The detailed tutorial of MPI&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3084,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[506],"tags":[564,540,543,502],"class_list":["post-3079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mpi-with-python","tag-jupyter","tag-mpi","tag-mpi4py","tag-python"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We&#039;ll create a master-worker model where the\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Afzal Badshah, PhD\"\/>\n\t<meta name=\"google-site-verification\" content=\"B8FNGv4w1toMpU3HUnD_SN9H9YMtp1ObsLuEDuirArI\" \/>\n\t<meta name=\"p:domain_verify\" content=\"87b5ca26c36438b20581a102dc290a47\" \/>\n\t<meta name=\"yandex-verification\" content=\"0eb3e2a9157fd34d\" \/>\n\t<meta name=\"keywords\" content=\"jupyter,mpi,mpi4py,python,mpi with python\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_GB\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Afzal Badshah, PhD - Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD\" \/>\n\t\t<meta property=\"og:description\" content=\"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We&#039;ll create a master-worker model where the\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2024-04-03T15:05:57+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2024-05-08T17:21:14+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/web.facebook.com\/abmanduri\/\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@DrAFZALBADSHAH\" \/>\n\t\t<meta name=\"twitter:title\" content=\"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We&#039;ll create a master-worker model where the\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@DrAFZALBADSHAH\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp\" \/>\n\t\t<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t\t<meta name=\"twitter:data1\" content=\"Afzal Badshah, PhD\" \/>\n\t\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#blogposting\",\"name\":\"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD\",\"headline\":\"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors\",\"author\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/afzalbadshah.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/MPI-Python-jpg.webp?fit=1280%2C720&ssl=1\",\"width\":1280,\"height\":720},\"datePublished\":\"2024-04-03T20:05:57+05:00\",\"dateModified\":\"2024-05-08T22:21:14+05:00\",\"inLanguage\":\"en-GB\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#webpage\"},\"articleSection\":\"MPI with Python, jupyter, MPI, mpi4py, python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/afzalbadshah.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"name\":\"Courses\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"position\":2,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/mpi-with-python\\\/#listItem\",\"name\":\"MPI with Python\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/mpi-with-python\\\/#listItem\",\"position\":3,\"name\":\"MPI with Python\",\"item\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/mpi-with-python\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#listItem\",\"name\":\"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"name\":\"Courses\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#listItem\",\"position\":4,\"name\":\"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/mpi-with-python\\\/#listItem\",\"name\":\"MPI with Python\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\",\"name\":\"Afzal Badshah, PhD\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#personImage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/wp-content\\\/litespeed\\\/avatar\\\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787755418\",\"width\":96,\"height\":96,\"caption\":\"Afzal Badshah, PhD\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/\",\"name\":\"Afzal Badshah, PhD\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#authorImage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/wp-content\\\/litespeed\\\/avatar\\\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787755418\",\"width\":96,\"height\":96,\"caption\":\"Afzal Badshah, PhD\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#webpage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/\",\"name\":\"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD\",\"description\":\"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We'll create a master-worker model where the\",\"inLanguage\":\"en-GB\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/afzalbadshah.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/MPI-Python-jpg.webp?fit=1280%2C720&ssl=1\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#mainImage\",\"width\":1280,\"height\":720},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/04\\\/03\\\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\\\/#mainImage\"},\"datePublished\":\"2024-04-03T20:05:57+05:00\",\"dateModified\":\"2024-05-08T22:21:14+05:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#website\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/\",\"name\":\"Afzal Badshah, PhD\",\"alternateName\":\"Afzal Badshah\",\"description\":\"Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence\",\"inLanguage\":\"en-GB\",\"publisher\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD","description":"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We'll create a master-worker model where the","canonical_url":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/","robots":"max-image-preview:large","keywords":"jupyter,mpi,mpi4py,python,mpi with python","webmasterTools":{"google-site-verification":"B8FNGv4w1toMpU3HUnD_SN9H9YMtp1ObsLuEDuirArI","p:domain_verify":"87b5ca26c36438b20581a102dc290a47","yandex-verification":"0eb3e2a9157fd34d","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#blogposting","name":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD","headline":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors","author":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"publisher":{"@id":"https:\/\/afzalbadshah.com\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp?fit=1280%2C720&ssl=1","width":1280,"height":720},"datePublished":"2024-04-03T20:05:57+05:00","dateModified":"2024-05-08T22:21:14+05:00","inLanguage":"en-GB","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#webpage"},"isPartOf":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#webpage"},"articleSection":"MPI with Python, jupyter, MPI, mpi4py, python"},{"@type":"BreadcrumbList","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com#listItem","position":1,"name":"Home","item":"https:\/\/afzalbadshah.com","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","name":"Courses"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","position":2,"name":"Courses","item":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/mpi-with-python\/#listItem","name":"MPI with Python"},"previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/mpi-with-python\/#listItem","position":3,"name":"MPI with Python","item":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/mpi-with-python\/","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#listItem","name":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors"},"previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","name":"Courses"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#listItem","position":4,"name":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors","previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/mpi-with-python\/#listItem","name":"MPI with Python"}}]},{"@type":"Person","@id":"https:\/\/afzalbadshah.com\/#person","name":"Afzal Badshah, PhD","image":{"@type":"ImageObject","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#personImage","url":"https:\/\/afzalbadshah.com\/wp-content\/litespeed\/avatar\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787755418","width":96,"height":96,"caption":"Afzal Badshah, PhD"}},{"@type":"Person","@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author","url":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/","name":"Afzal Badshah, PhD","image":{"@type":"ImageObject","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#authorImage","url":"https:\/\/afzalbadshah.com\/wp-content\/litespeed\/avatar\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787755418","width":96,"height":96,"caption":"Afzal Badshah, PhD"}},{"@type":"WebPage","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#webpage","url":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/","name":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD","description":"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We'll create a master-worker model where the","inLanguage":"en-GB","isPartOf":{"@id":"https:\/\/afzalbadshah.com\/#website"},"breadcrumb":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#breadcrumblist"},"author":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"creator":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp?fit=1280%2C720&ssl=1","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#mainImage","width":1280,"height":720},"primaryImageOfPage":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/#mainImage"},"datePublished":"2024-04-03T20:05:57+05:00","dateModified":"2024-05-08T22:21:14+05:00"},{"@type":"WebSite","@id":"https:\/\/afzalbadshah.com\/#website","url":"https:\/\/afzalbadshah.com\/","name":"Afzal Badshah, PhD","alternateName":"Afzal Badshah","description":"Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence","inLanguage":"en-GB","publisher":{"@id":"https:\/\/afzalbadshah.com\/#person"}}]},"og:locale":"en_GB","og:site_name":"Afzal Badshah, PhD - Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence","og:type":"article","og:title":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD","og:description":"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We'll create a master-worker model where the","og:url":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/","og:image":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp","og:image:secure_url":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp","og:image:width":1280,"og:image:height":720,"article:published_time":"2024-04-03T15:05:57+00:00","article:modified_time":"2024-05-08T17:21:14+00:00","article:publisher":"https:\/\/web.facebook.com\/abmanduri\/","twitter:card":"summary_large_image","twitter:site":"@DrAFZALBADSHAH","twitter:title":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors - Afzal Badshah, PhD","twitter:description":"In this lab tutorial, we will explore how to utilize multiple processors to compute the squares of elements in an array concurrently using the MPI (Message Passing Interface) library in Python, specifically using the mpi4py module. MPI is a widely-used standard for parallel computing in distributed memory systems. We'll create a master-worker model where the","twitter:creator":"@DrAFZALBADSHAH","twitter:image":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp","twitter:label1":"Written by","twitter:data1":"Afzal Badshah, PhD","twitter:label2":"Est. reading time","twitter:data2":"3 minutes"},"aioseo_meta_data":{"post_id":"3079","title":null,"description":null,"keywords":null,"keyphrases":{"focus":{"keyphrase":"MPI with Python","score":54,"analysis":{"keyphraseInTitle":{"score":9,"maxScore":9,"error":0},"keyphraseInDescription":{"score":3,"maxScore":9,"error":1},"keyphraseLength":{"score":9,"maxScore":9,"error":0,"length":3},"keyphraseInURL":{"score":5,"maxScore":5,"error":0},"keyphraseInIntroduction":{"score":3,"maxScore":9,"error":1},"keyphraseInSubHeadings":{"score":3,"maxScore":9,"error":1},"keyphraseInImageAlt":[],"keywordDensity":{"score":0,"type":"low","maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":true,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2024-04-03 14:54:22","updated":"2025-06-10 22:08:58","focus_keyword":"MPI with Python","additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/\" title=\"Courses\">Courses<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/mpi-with-python\/\" title=\"MPI with Python\">MPI with Python<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tMPI with Python: Calculating Squares of Array Elements Using Multiple Processors\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/afzalbadshah.com"},{"label":"Courses","link":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/"},{"label":"MPI with Python","link":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/mpi-with-python\/"},{"label":"MPI with Python: Calculating Squares of Array Elements Using Multiple Processors","link":"https:\/\/afzalbadshah.com\/index.php\/2024\/04\/03\/mpi-with-python-calculating-squares-of-array-elements-using-multiple-processors\/"}],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/04\/MPI-Python-jpg.webp?fit=1280%2C720&ssl=1","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pf3emP-NF","jetpack-related-posts":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/comments?post=3079"}],"version-history":[{"count":7,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3079\/revisions"}],"predecessor-version":[{"id":3204,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3079\/revisions\/3204"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media\/3084"}],"wp:attachment":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media?parent=3079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/categories?post=3079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/tags?post=3079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}