Coder Social home page Coder Social logo

llnl / hpc-tutorials Goto Github PK

View Code? Open in Web Editor NEW
213.0 8.0 116.0 1.89 MB

Future home of hpc-tutorials.llnl.gov

Home Page: https://hpc-tutorials.llnl.gov

License: MIT License

Ruby 0.05% HTML 2.03% C 62.63% Fortran 34.07% Shell 0.78% Makefile 0.16% Forth 0.27%
tutorial

hpc-tutorials's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hpc-tutorials's Issues

Suggestion on PThreads (passing argument, example3)

As from the title, in PThreads tutorial, Passing Arguments to Threads, Example 3

Example 3 - Thread Argument Passing (Incorrect)
This example performs argument passing incorrectly. It passes the address of variable t, which is shared memory space and visible to all threads. As the loop iterates, the value of this memory location changes, possibly before the created threads can access it.
int rc;
long t;

for(t=0; t<NUM_THREADS; t++) 
{
   printf("Creating thread %ld\n", t);
   rc = pthread_create(&threads[t], NULL, PrintHello, (void *) &t);
   ...
}

with output

Creating thread 0
Creating thread 1
...
Creating thread 7
Hello from thread 140737488348392
Hello from thread 140737488348392
...
Hello from thread 140737488348392
Hello from thread 140737488348392

It looks like the program prints the address of the variable t, which might be inconsistent with what we want to illustrate --- "the value of this memory location changes". Can we adjust this to something like the following?

void *PrintHello(void *threadid) {
    long * tid;
    tid = (long *)threadid;
    printf("Hello World! It's me, thread #%ld!\n", *tid);
    pthread_exit(NULL);
}

int main() {
    pthread_t threads[NUM_THREADS];
    int rc;
    long t;
    for (t = 0; t < NUM_THREADS; t++)
    {
        printf("In main: creating thread %ld\n", t);
        /* Don't try to access memory location of t! 
         * It constantly changes as the loop goes! 
         * Possibly before the created threads can access it
         */
        rc = pthread_create(&threads[t], NULL, PrintHello, (void *) &t);
        if (rc)
        {
            printf("ERROR; return code from pthread_create() is %d\n", rc);
            exit(-1);
        }
    }

    /* Last thing that main() should do */
    pthread_exit(NULL);
    return 0;
}

So the output goes like

In main: creating thread 0
In main: creating thread 1
Hello World! It's me, thread #1!
In main: creating thread 2
Hello World! It's me, thread #2!
In main: creating thread 3
Hello World! It's me, thread #3!
In main: creating thread 4
Hello World! It's me, thread #4!
Hello World! It's me, thread #5!

which illustrates that the value t had been t++ed before the created thread read the location.

Thanks!

Appendix's routine links don't work on live website

Error:
If you go to these two pages, only the first one will let you follow the links to routine-specific info.
https://github.com/LLNL/HPC-Tutorials/blob/main/mpi/appendix_a.md
https://hpc-tutorials.llnl.gov/mpi/appendix_a/

Cause:
The links are relative to the current directory, but because the live server serves appendix_a.md as a directory in the url, the links end up with a bonus /appendix_a/ in the path, which results in a 404.

Example:
Github links correctly: https://github.com/LLNL/HPC-Tutorials/blob/main/mpi/MPI_appendix/MPI_Bcast.txt
Live site links to this 404: https://hpc-tutorials.llnl.gov/mpi/appendix_a/MPI_appendix/MPI_Bcast.txt
Live site has the page here: https://hpc-tutorials.llnl.gov/mpi/MPI_appendix/MPI_Bcast.txt

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.