Test frotran code by MPI packaging and unpacking

Source: Internet
Author: User

Transfer an integer array and a double-precision array from 0th processes to 1st processes, which are implemented by packaging and unpacking.

 

 Program pack <br/> include 'mpif. h' <br/> integer maxbuf, Len <br/> parameter (maxbuf = 200, Len = 10) <br/> integer myid, P, mycomm, ierr, status (mpi_status_size, 2), <br/> & Ia (LEN), count1, count2, I, POS <br/> real * 8 A (LEN) <br/> character Buf (maxbuf) </P> <p> call mpi_init (ierr) <br/> call mpi_comm_dup (mpi_comm_world, mycomm, ierr) <br/> call mpi_comm_rank (mycomm, myid, ierr) <br/> call mpi_comm_size (mycomm, P, ierr) <br/> Print *, 'process', myid, 'of', P, 'is running' </P> <p> If (myid. eq.0) Then <br/> do 10 I = 1, Len <br/> Ia (I) = I <br/> A (I) = dble (I) <br/> 10 continue <br/> endif </P> <p> call mpi_pack_size (Len, mpi_integer, mycomm, count1, ierr) <br/> call mpi_pack_size (Len, mpi_double_precision, mycomm, <br/> & count2, ierr) <br/> Print *, 'the pack size of 10 integer and real8 are: ', <br/> & count1, count2 <br/> Pos = 1 <br/> If (myid. eq.0.and. p. gt.1) Then <br/> call mpi_pack (IA, Len, mpi_integer, Buf, maxbuf, POs, <br/> & mycomm, ierr) <br/> call mpi_pack (, len, mpi_double_precision, Buf, maxbuf, <br/> & Pos, mycomm, ierr) <br/> call mpi_send (BUF, pos-1, mpi_packed, 1, 1, mycomm, ierr) <br/> elseif (myid. eq.1) Then <br/> call mpi_recv (BUF, maxbuf, mpi_packed, 0, 1, mycomm, <br/> & status, ierr) <br/> call mpi_unpack (BUF, maxbuf, POs, IA, Len, mpi_integer, <br/> & mycomm, ierr) <br/> call mpi_unpack (BUF, maxbuf, POs, A, Len, mpi_double_precision, <br/> & mycomm, ierr) <br/> Print *, 'the specified ED values are: ', A (1), a (2), a (3) <br/> endif <br/> call mpi_comm_free (mycomm, ierr) <br/> call mpi_finalize (ierr) <br/> stop <br/> end </P> <p>

 

Result:

 [Root @ c0109 zlt] # mpiexec-N 2. /A <br/> process 0 of 2 is running <br/> the pack size of 10 integer and real8 are: 40 80 <br/> process 1 of 2 is running <br/> the pack size of 10 integer and real8 are: 40 80 <br/> the specified ED values are: 1.00000000000000 2.00000000000000 3.00000000000000 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.