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

  • SEARCH
  • Home
  • 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 3458276
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:57:46+00:00 2026-05-18T09:57:46+00:00

I’m writing to a file as follows. The order does not necessarily matter (though

  • 0

I’m writing to a file as follows. The order does not necessarily matter (though it would be nice if I could get it ordered by K, as would be inherently in serial code)

            CALL MPI_BARRIER(MPI_COMM_WORLD, IERR)
            OPEN(EIGENVALUES_UP_IO, FILE=EIGENVALUES_UP_PATH, ACCESS='APPEND')
            WRITE(EIGENVALUES_UP_IO, *) K * 0.0001_DP * PI, (EIGENVALUES(J), J = 1, ATOM_COUNT)
            CLOSE(EIGENVALUES_UP_IO)

I’m aware this is likely to be the worst option.

I’ve taken a look at MPI_FILE_WRITE_AT etc. but I’m not sure they (directly) take data in the form that I have?

The file must be in the same format as this, which comes out as a line per K, with ATOM_COUNT + 1 columns. The values are REAL(8)

I’ve hunted over and over, and can’t find any simple references on achieving this. Any help? 🙂

Similar code in C (assuming it’s basically the same as FORTRAN) is just as useful

Thanks!

  • 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-18T09:57:47+00:00Added an answer on May 18, 2026 at 9:57 am

    So determining the right IO strategy depends on a lot of factors. If you are just sending back a handful of eigenvalues, and you’re stuck writing out ASCII, you might be best off just sending all the data back to process 0 to write. This is not normally a winning strategy, as it obviously doesn’t scale; but if the amount of data is very small, it could well be better than the contention involved in trying to write out to a shared file (which is, again, harder with ASCII).

    Some code is below which will schlep the amount of data back to proc 0, assuming everyone has the same amount of data.

    Another approach would just be to have everyone write out their own ks and eigenvalues, and then as a postprocessing step once the program is finished, cat them all together. That avoids the MPI step, and (with the right filesystem) can scale up quite a ways, and is easy; whether that’s better is fairly easily testable, and will depend on the amount of data, number of processors, and underlying file system.

       program testio
        use mpi
        implicit none
    
        integer, parameter :: atom_count = 5
        integer, parameter :: kpertask   = 2
        integer, parameter :: fileunit   = 7
        integer, parameter :: io_master  = 0
        double precision, parameter :: pi = 3.14159
    
        integer :: totalk
        integer :: ierr
        integer :: rank, nprocs
    
        integer :: handle
        integer(kind=MPI_OFFSET_KIND) :: offset
        integer :: filetype
    
        integer :: j,k
        double precision, dimension(atom_count, kpertask) :: eigenvalues
        double precision, dimension(kpertask) :: ks
    
        double precision, allocatable, dimension(:,:):: alleigenvals
        double precision, allocatable, dimension(:)  :: allks
    
        call MPI_INIT(ierr)
        call MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr)
        call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
    
        totalk   = nprocs*kpertask
    
        !! setup test data
    
        do k=1,kpertask
            ks(k) = (rank*kpertask+k)*1.d-4*PI
            do j=1,atom_count
                eigenvalues(j,k) = rank*100+j
            enddo
        enddo
    
        !! Everyone sends proc 0 their data
    
        if (rank == 0) then
            allocate(allks(totalk))
            allocate(alleigenvals(atom_count, totalk))
        endif
    
        call MPI_GATHER(ks, kpertask, MPI_DOUBLE_PRECISION,    &
                        allks, kpertask, MPI_DOUBLE_PRECISION, &
                        io_master, MPI_COMM_WORLD, ierr)
    
        call MPI_GATHER(eigenvalues, kpertask*atom_count, MPI_DOUBLE_PRECISION,  &
                        alleigenvals, kpertask*atom_count, MPI_DOUBLE_PRECISION, &
                        io_master, MPI_COMM_WORLD, ierr)
    
        if (rank == 0) then 
            open(unit=fileunit, file='output.txt')
            do k=1,totalk
                WRITE(fileunit, *) allks(k), (alleigenvals(j,k), j = 1, atom_count)
            enddo
            close(unit=fileunit)
    
            deallocate(allks)
            deallocate(alleigenvals)
        endif
        call MPI_FINALIZE(ierr)
    end program testio
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.