10-10-2014
My point is, count isn't wrong as much as completely meaningless. The order your threads run in isn't absolute. Thread #5 could run before thread #1, succeed, and return a count of 1! If you want the threads to know what order they are, you'll have to tell them.
Increment outside the parallel section and feed that value into the function as a parameter. If the function succeeds, have it set a flag variable to the correct 'count' value. Other threads can check that flag variable before their loop, and quit early if nonzero.
Last edited by Corona688; 10-10-2014 at 12:46 PM..
8 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hello,
I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies
2. UNIX for Dummies Questions & Answers
Hello everyone,
I've got a question regarding the gzip command.
I regulary use gzip to pack huge ammounts of files.
Is it ok to start 'gzip *' several times in the same directory to parallelize the packing process or can this result in problems, e.g. broken or unpacked files?
My tests... (7 Replies)
Discussion started by: Basch
7 Replies
3. Shell Programming and Scripting
hello
im new here so i want to say hi everybody :)
i have to write a script and im newbie :/ i hope that in this forum are many ppl who knows subject :)
i have hundrets folders. in each folder is a file name trace.txt. each trace.txt has a lot of tracert's results separates with "-----" it... (6 Replies)
Discussion started by: michael8484
6 Replies
4. HP-UX
Hi folks,
I am trying to run more than 8 threads in OpenMP team on my HP-UX 11i v3 system (without root access), but NO success.
Compiler: aCC A.06.26
I tried to setup: OMP_NUM_THREADS, omp_set_num_threads(), max_thread_proc=1000, nkthread=8416, set_dynamic=0
Machine has 2 processors... (1 Reply)
Discussion started by: ATveretinov
1 Replies
5. Programming
Hello to all,
Here is my situation. Some time in the mid-80's I stumbled across a small white programming book - can't remember the name but it was unique in that it started right out giving instructions on creating building blocks in code as a foundation for a complete system. The book was... (2 Replies)
Discussion started by: jozefn
2 Replies
6. Programming
Dear Linux users,
I'm a noob at openmp, gcc and c programming. I can run my own openmp code in terminal with no problem, eg. gcc -fopenmp program.c -o program.
But now I'm trying to compile and run another person's code, it contains a makefile and multiple .c and .h files. I don't know how to... (2 Replies)
Discussion started by: pigeon151
2 Replies
7. Programming
I am using a large code-base that compiled successfully before using make with a makefile and cmake. However, now that I'm trying to use openmp with it, I'm now getting the errors
undefined reference to `omp_get_thread_num'
undefined reference to `omp_get_num_threads'I don't think this... (0 Replies)
Discussion started by: larry burns
0 Replies
8. Programming
hi,
I have two basic questions, I will be really grateful if I receive any
comment from you,
I have an MPI code where I am trying to implement OpenMP directives.
The machine where I run the code has 16 cores. I run the code with
export OMP_NUM_THREADS=2
mpirun -np 4 ./exec
If I... (0 Replies)
Discussion started by: armando_2011
0 Replies
LEARN ABOUT NETBSD
pthread_barrier_wait
PTHREAD_BARRIER(3) BSD Library Functions Manual PTHREAD_BARRIER(3)
NAME
pthread_barrier -- barrier interface
LIBRARY
POSIX Threads Library (libpthread, -lpthread)
SYNOPSIS
#include <pthread.h>
int
pthread_barrier_init(pthread_barrier_t * restrict barrier, const pthread_barrierattr_t * restrict attr, unsigned int count);
int
pthread_barrier_destroy(pthread_barrier_t *barrier);
int
pthread_barrier_wait(pthread_barrier_t *barrier);
DESCRIPTION
The pthread_barrier_init() function creates a new barrier with attributes attr and count. The count parameter indicates the number of
threads which will participate in the barrier. The pthread_barrierattr_init(3) function may be used to specify the attributes supplied in
attr. If attr is NULL, the default attributes are used. Barriers are most commonly used in the decomposition of parallel loops.
The pthread_barrier_destroy() function causes the resources allocated to barrier to be released. No threads should be blocked on barrier.
The pthread_barrier_wait() function causes the current thread to wait on the barrier specified. Once as many threads as specified by the
count parameter to the corresponding pthread_barrier_init() call have called pthread_barrier_wait(), all threads will wake up, return from
their respective pthread_barrier_wait() calls and continue execution.
RETURN VALUES
If successful, pthread_barrier_init() will return zero and put the new barrier id into barrier, otherwise an error number will be returned to
indicate the error.
If successful, pthread_barrier_destroy() will return zero. Otherwise an error value will be returned.
If successful, pthread_barrier_wait() will return zero for all waiting threads except for one. One thread will receive status
PTHREAD_BARRIER_SERIAL_THREAD, which is intended to indicate that this thread may be used to update shared data. It is the responsibility of
this thread to insure the visibility and atomicity of any updates to shared data with respect to the other threads participating in the bar-
rier. In the case of failure, an error value will be returned.
ERRORS
The pthread_barrier_init() function may fail if:
[EINVAL] The value specified by count is zero or attr is invalid.
The pthread_barrier_destroy() function may fail if:
[EBUSY] The barrier still has active threads associated with it.
[EINVAL] The value specified by barrier is invalid.
The pthread_barrier_wait() function may fail if:
[EINVAL] The value specified by barrier is invalid.
SEE ALSO
pthread_barrierattr(3), pthread_cond(3), pthread_mutex(3)
STANDARDS
These functions conform to IEEE Std 1003.1-2001 (``POSIX.1'').
BSD
July 8, 2010 BSD