Coder Social home page Coder Social logo

Comments (7)

westwind2013 avatar westwind2013 commented on August 19, 2024

A further checking indicates other similar bugs relating to the use of malloc.

from susy.

daschaich avatar daschaich commented on August 19, 2024

Thanks very much for the report! I may not have a chance to address it until I get back from a conference on 15 January.

In the meantime, I'm curious what compiler you're using, as obviously this isn't an issue we have encountered with any of those we use (mainly various versions of gcc, with either mpich2 and mvapich MPI implementations).

In a standards-compliant compiler I would expect the two possibilities you write in each case to be handled identically. The style currently in the code (dereferencing the pointer rather than repeating the type) is typically advocated in order to improve the maintainability of the code. See here for one example, which also suggests moving the sizeof to the front. That may be worth testing, especially considering the apparent integer arithmetic issue suggested by your other report. This should look something like
Twist_Fermion **src = malloc(sizeof **src * Norder);
and so on.

from susy.

westwind2013 avatar westwind2013 commented on August 19, 2024

Thank you for your reply. Moving the sizeof to the front is good. But I am worried that the coding style as below

Twist_Fermion **src = malloc(sizeof **src * Norder);

still has a bug in it. As src is a pointer to data type "Twist_Fermion *". When we do the malloc(), we hope to malloc a memory space of size "sizeof (*src) * Norder" instead of "sizeof (**src) * Norder" --- the former indicates Norder elements of data type "Twist_Fermion *" while the latter indicates Norder elements of data type "Twist_Fermion".

Btw, I am actually working on a project that aims to provide an automated testing tool for MPI programs. I use this program as a target to do some analysis and happen to find these bugs. I don't know well enough the program actually.

from susy.

daschaich avatar daschaich commented on August 19, 2024

Norder elements of data type "Twist_Fermion *" is exactly what we want for the RHMC algorithm, which involves Norder source vectors, each of which is malloc'd with sites_on_node elements a few lines further down. In the end src is an array of Norder pointers to arrays of sites_on_node Twist_Fermions, with the individual structs accessed via src[N][i] for the components of source vector N associated with lattice site i.

Anyway, it sounds like moving the sizeof to the front resolves the problem you encountered, so I quickly did that in commit e2d120b and will close this issue as well. Feel free to reopen if problems remain.

from susy.

westwind2013 avatar westwind2013 commented on August 19, 2024

If we want to add "Twist_Fermion *", should we use

Twist_Fermion **src = malloc(sizeof *src * Norder);

instead of

Twist_Fermion **src = malloc(sizeof **src * Norder);

?

from susy.

daschaich avatar daschaich commented on August 19, 2024

Okay, I'm finding the dereferencing hard to parse, so I scrapped it for the sake of readability. Commit 53adcdc essentially implements your original suggestion. Valgrind seems happy, at least in serial.

from susy.

westwind2013 avatar westwind2013 commented on August 19, 2024

That's great. To be honest, I don't know much about physics, and thus just look the program from the perspective of the programmer.

Thank you for your work:)

from susy.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.