Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6872857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:58:59+00:00 2026-05-27T03:58:59+00:00

I would like to easily send an someObject in one MPI_SEND/RECV call in mpi.

  • 0

I would like to easily send an someObject in one MPI_SEND/RECV call in mpi.

   type someObject
     integer :: foo
     real :: bar,baz
     double precision :: a,b,c
     double precision, dimension(someParam) :: x, y
   end type someObject

I started using a MPI_TYPE_STRUCT, but then realized the sizes of the arrays x and y are dependent upon someParam. I initially thought of nesting a MPI_TYPE_CONTIGUOUS in the struct to represent the arrays, but cannot seem to get this to work. If this is even possible?

  ! Setup description of the 1 MPI_INTEGER field
  offsets(0) = 0
  oldtypes(0) = MPI_INTEGER
  blockcounts(0) = 1
  ! Setup description of the 2 MPI_REAL fields
  call MPI_TYPE_EXTENT(MPI_INTEGER, extent, ierr)
  offsets(1) = blockcounts(0) * extent
  oldtypes(1) = MPI_REAL
  blockcounts(1) = 2
  ! Setup descripton of the 3 MPI_DOUBLE_PRECISION fields
  call MPI_TYPE_EXTENT(MPI_DOUBLE_PRECISION, extent, ierr)
  offsets(2) = offsets(1) + blockcounts(1) * extent
  oldtypes(2) = MPI_DOUBLE_PRECISION
  blockcounts(2) = 3
  ! Setup x and y MPI_DOUBLE_PRECISION array fields
  call MPI_TYPE_CONTIGUOUS(someParam, MPI_DOUBLE_PRECISION, sOarraytype, ierr)
  call MPI_TYPE_COMMIT(sOarraytype, ierr)
  call MPI_TYPE_EXTENT(sOarraytype, extent, ierr)
  offsets(3) = offsets(2) + blockcounts(2) * extent
  oldtypes(3) = sOarraytype
  blockcounts(3) = 2 ! x and y

  ! Now Define structured type and commit it
  call MPI_TYPE_STRUCT(4, blockcounts, offsets, oldtypes, sOtype, ierr)
  call MPI_TYPE_COMMIT(sOtype, ierr)

What I would like to do:

...
type(someObject) :: newObject, rcvObject
double precision, dimension(someParam) :: x, y
do i=1,someParam
  x(i) = i
  y(i) = i
end do
newObject = someObject(1,0.0,1.0,2.0,3.0,4.0,x,y)
MPI_SEND(newObject, 1, sOtype, 1, 1, MPI_COMM_WORLD, ierr) ! master
...
! slave would:
MPI_RECV(rcvObject, 1, sOtype, master, MPI_ANY_TAG, MPI_COMM_WORLD, status, ierr)
WRITE(*,*) rcvObject%foo
do i=1,someParam
  WRITE(*,*) rcvObject%x(i), rcvObject%y(i)
end do
...

So far I am just getting segmentation faults, without much indication of what I’m doing wrong or if this is even possible. The documentation never said I couldn’t use a contiguous datatype inside a struct datatype.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:58:59+00:00Added an answer on May 27, 2026 at 3:58 am

    From what it seems you can’t nest those kinds of datatypes and was a completely wrong solution.

    Thanks to: http://static.msi.umn.edu/tutorial/scicomp/general/MPI/mpi_data.html and http://www.osc.edu/supercomputing/training/mpi/Feb_05_2008/mpi_0802_mod_datatypes.pdf for guidance.

    the right way to define the MPI_TYPE_STRUCT is as follows:

    type(someObject) :: newObject, rcvObject
    double precision, dimension(someParam) :: x, y
    data x/someParam * 0/, w/someParam * 0/
    integer sOtype, oldtypes(0:7), blocklengths(0:7), offsets(0:7), iextent, rextent, dpextent
    ! Define MPI datatype for someObject object
    ! set up extents
    call MPI_TYPE_EXTENT(MPI_INTEGER, iextent, ierr)
    call MPI_TYPE_EXTENT(MPI_REAL, rextent, ierr)
    call MPI_TYPE_EXTENT(MPI_DOUBLE_PRECISION, dpextent, ierr)
    ! setup blocklengths /foo,bar,baz,a,b,c,x,y/
    data blocklengths/1,1,1,1,1,1,someParam,someParam/
    ! setup oldtypes
    oldtypes(0) = MPI_INTEGER
    oldtypes(1) = MPI_REAL
    oldtypes(2) = MPI_REAL
    oldtypes(3) = MPI_DOUBLE_PRECISION
    oldtypes(4) = MPI_DOUBLE_PRECISION
    oldtypes(5) = MPI_DOUBLE_PRECISION
    oldtypes(6) = MPI_DOUBLE_PRECISION
    oldtypes(7) = MPI_DOUBLE_PRECISION
    ! setup offsets
    offsets(0) = 0
    offsets(1) = iextent * blocklengths(0)
    offsets(2) = offsets(1) + rextent*blocklengths(1)
    offsets(3) = offsets(2) + rextent*blocklengths(2)
    offsets(4) = offsets(3) + dpextent*blocklengths(3)
    offsets(5) = offsets(4) + dpextent*blocklengths(4)
    offsets(6) = offsets(5) + dpextent*blocklengths(5)
    offsets(7) = offsets(6) + dpextent*blocklengths(6)
    ! Now Define structured type and commit it
    call MPI_TYPE_STRUCT(8, blocklengths, offsets, oldtypes, sOtype, ierr)
    call MPI_TYPE_COMMIT(sOtype, ierr)
    

    That allows me to send and receive the object with the way I originally wanted!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to easily implement a data classification project, so I'm looking for
I'm learning VIM for Rails development and would like to easily navigate methods in
I would like to find an API like Apache Commons that will easily and
I would like to execute code sequentially in an NSOperation. This can be easily
Is there easily embeddable C++ test lib with a friendly license? I would like
I have a webpage which I would like users to be able to send
I am using Ruby on Rails 3.2.2 and I would like to easily /
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like a for loop in jquery so that: For every hover_link: show hidden
Would like someone to take a look at my script and tell me where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.