Thu May 23 21:11:42 2024
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2015-04-01

HANGOUT

2024-05-23 | 2024-04-23 | 2024-03-23 | 2024-02-23 | 2024-01-23 | 2023-12-23 | 2023-11-23 | 2023-10-23 | 2023-09-23 | 2023-08-23 | 2023-07-23 | 2023-06-23 | 2023-05-23 | 2023-04-23 | 2023-03-23 | 2023-02-23 | 2023-01-23 | 2022-12-23 | 2022-11-23 | 2022-10-23 | 2022-09-23 | 2022-08-23 | 2022-07-23 | 2022-06-23 | 2022-05-23 | 2022-04-23 | 2022-03-23 | 2022-02-23 | 2022-01-23 | 2021-12-23 | 2021-11-23 | 2021-10-23 | 2021-09-23 | 2021-08-23 | 2021-07-23 | 2021-06-23 | 2021-05-23 | 2021-04-23 | 2021-03-23 | 2021-02-23 | 2021-01-23 | 2020-12-23 | 2020-11-23 | 2020-10-23 | 2020-09-23 | 2020-08-23 | 2020-07-23 | 2020-06-23 | 2020-05-23 | 2020-04-23 | 2020-03-23 | 2020-02-23 | 2020-01-23 | 2019-12-23 | 2019-11-23 | 2019-10-23 | 2019-09-23 | 2019-08-23 | 2019-07-23 | 2019-06-23 | 2019-05-23 | 2019-04-23 | 2019-03-23 | 2019-02-23 | 2019-01-23 | 2018-12-23 | 2018-11-23 | 2018-10-23 | 2018-09-23 | 2018-08-23 | 2018-07-23 | 2018-06-23 | 2018-05-23 | 2018-04-23 | 2018-03-23 | 2018-02-23 | 2018-01-23 | 2017-12-23 | 2017-11-23 | 2017-10-23 | 2017-09-23 | 2017-08-23 | 2017-07-23 | 2017-06-23 | 2017-05-23 | 2017-04-23 | 2017-03-23 | 2017-02-23 | 2017-01-23 | 2016-12-23 | 2016-11-23 | 2016-10-23 | 2016-09-23 | 2016-08-23 | 2016-07-23 | 2016-06-23 | 2016-05-23 | 2016-04-23 | 2016-03-23 | 2016-02-23 | 2016-01-23 | 2015-12-23 | 2015-11-23 | 2015-10-23 | 2015-09-23 | 2015-08-23 | 2015-07-23 | 2015-06-23 | 2015-05-23 | 2015-04-23 | 2015-03-23 | 2015-02-23 | 2015-01-23 | 2014-12-23 | 2014-11-23 | 2014-10-23 | 2014-09-23 | 2014-08-23 | 2014-07-23 | 2014-06-23 | 2014-05-23 | 2014-04-23 | 2014-03-23 | 2014-02-23 | 2014-01-23 | 2013-12-23 | 2013-11-23 | 2013-10-23 | 2013-09-23 | 2013-08-23 | 2013-07-23 | 2013-06-23 | 2013-05-23 | 2013-04-23 | 2013-03-23 | 2013-02-23 | 2013-01-23 | 2012-12-23 | 2012-11-23 | 2012-10-23 | 2012-09-23 | 2012-08-23 | 2012-07-23 | 2012-06-23 | 2012-05-23 | 2012-04-23 | 2012-03-23 | 2012-02-23 | 2012-01-23 | 2011-12-23 | 2011-11-23 | 2011-10-23 | 2011-09-23 | 2011-08-23 | 2011-07-23 | 2011-06-23 | 2011-05-23 | 2011-04-23 | 2011-03-23 | 2011-02-23 | 2011-01-23 | 2010-12-23 | 2010-11-23 | 2010-10-23 | 2010-09-23 | 2010-08-23 | 2010-07-23 | 2010-06-23 | 2010-05-23 | 2010-04-23 | 2010-03-23 | 2010-02-23 | 2010-01-23 | 2009-12-23 | 2009-11-23 | 2009-10-23 | 2009-09-23 | 2009-08-23 | 2009-07-23 | 2009-06-23 | 2009-05-23 | 2009-04-23 | 2009-03-23 | 2009-02-23 | 2009-01-23 | 2008-12-23 | 2008-11-23 | 2008-10-23 | 2008-09-23 | 2008-08-23 | 2008-07-23 | 2008-06-23 | 2008-05-23 | 2008-04-23 | 2008-03-23 | 2008-02-23 | 2008-01-23 | 2007-12-23 | 2007-11-23 | 2007-10-23 | 2007-09-23 | 2007-08-23 | 2007-07-23 | 2007-06-23 | 2007-05-23 | 2007-04-23 | 2007-03-23 | 2007-02-23 | 2007-01-23 | 2006-12-23 | 2006-11-23 | 2006-10-23 | 2006-09-23 | 2006-08-23 | 2006-07-23 | 2006-06-23 | 2006-05-23 | 2006-04-23 | 2006-03-23 | 2006-02-23 | 2006-01-23 | 2005-12-23 | 2005-11-23 | 2005-10-23 | 2005-09-23 | 2005-08-23 | 2005-07-23 | 2005-06-23 | 2005-05-23 | 2005-04-23 | 2005-03-23 | 2005-02-23 | 2005-01-23 | 2004-12-23 | 2004-11-23 | 2004-10-23 | 2004-09-23 | 2004-08-23 | 2004-07-23 | 2004-06-23 | 2004-05-23 | 2004-04-23 | 2004-03-23 | 2004-02-23 | 2004-01-23 | 2003-12-23 | 2003-11-23 | 2003-10-23 | 2003-09-23 | 2003-08-23 | 2003-07-23 | 2003-06-23 | 2003-05-23 | 2003-04-23 | 2003-03-23 | 2003-02-23 | 2003-01-23 | 2002-12-23 | 2002-11-23 | 2002-10-23 | 2002-09-23 | 2002-08-23 | 2002-07-23 | 2002-06-23 | 2002-05-23 | 2002-04-23 | 2002-03-23 | 2002-02-23 | 2002-01-23 | 2001-12-23 | 2001-11-23 | 2001-10-23 | 2001-09-23 | 2001-08-23 | 2001-07-23 | 2001-06-23 | 2001-05-23 | 2001-04-23 | 2001-03-23 | 2001-02-23 | 2001-01-23 | 2000-12-23 | 2000-11-23 | 2000-10-23 | 2000-09-23 | 2000-08-23 | 2000-07-23 | 2000-06-23 | 2000-05-23 | 2000-04-23 | 2000-03-23 | 2000-02-23 | 2000-01-23 | 1999-12-23

Key: Value:

Key: Value:

MESSAGE
DATE 2015-04-01
FROM Ruben Safir
SUBJECT Subject: [NYLXS - HANGOUT] omp pthread madness

[This mail was also posted to comp.unix.programmer.]

I'm doing this test program with OMP threads and I'm getting a very odd
result which I have no idea where this is happening.

i set up a shared workspace for the threads called wordspace[MAX_SPACE]
and what should happen is that it gets filled with coordinate points. PI
can be estimated by a formula based on how many at random as they are
picked, end up within a circle.

When I construct it without threads, it does a decent job of predicting
about 3.14 etc.

With OMP, it is giving numbers in the 6 zone. I don't see anything that
would make my random selection change, nor do I see anything else, so I'm
at a loss, and admittedly can use some mentoring here, not only to
understand my mistake, but to understand the theory so I don't repeat it.


pi_lib.h

#ifndef MONTI_PI
#define MONTI_PI

#define MEMORY_SPACE 10000

struct point{
double x;
double y;
};

struct point * random_point(void);
double calc_pi(void);
int count_inside(void);


#endif


pid_lib.c

/* Question 4.18 from the operating systems HW from Text
* OS Ed 9
* Class Operating SYstems at LIU
* Prog M Ghriger
*
* Ruben Safir - Student
* ********************************************************/
#include
#include
#include "pi_lib.h"
#include
#include

struct point workspace[MEMORY_SPACE];
long seed = 0;
long inside_the_circle = 0;
struct timespec ts;
struct point sample;

struct point * random_point(void)
{
int i;
double x,y;

if(seed == 0){
clock_gettime(CLOCK_REALTIME, &ts);
seed = ts.tv_nsec;
srand(seed);
}
for (i = 0; i < MEMORY_SPACE; i++){
//fprintf( stderr, "Error %d\n", __LINE__);
//x = ((double)rand()) % (double)1000000 ;
x = rand() % 1000000 ;
x = x / (double)1000000;

// printf ("x==> %F", x);
//y = ((double)rand())% (double)1000000 ;
y = rand()% 10000000 ;
y = y / (double)10000000;
// printf(" y==> %F\n", y);
workspace[i].x = x;
workspace[i].y = y;
}

return &workspace[0];
}

int count_inside(void)
{
int i = 0;
double d;
for(i = 0; i < MEMORY_SPACE; i++){
d = sqrt(pow(workspace[i].x, 2.0) + pow(workspace[i].y,
2.0));
// printf ("distance => %f\n", d);
if (d <= 1.0)
inside_the_circle++;
}
return inside_the_circle;
}

double calc_pi(){
return 4.0 * (( double)inside_the_circle/ (double)MEMORY_SPACE) ;
}



monty_pi_omp.c

#include
#include
#include "pi_lib.h"
#include
#include

void * wrapper(void*);
double pi;

int main(int argc, char * argv[]){
double pi;
#pragma omp parallel
{
random_point();
count_inside();
}

pi = calc_pi();
printf("Pi is estimated at ==> %f\n\n", pi);

return 1;
}


and just for comparison

this is monty_pi.c

#include
#include
#include "pi_lib.h"
#include

void * wrapper(void*);

int main(int argc, char * argv[]){
double pi;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_t tid;
void * arg = NULL;
pthread_create(&tid, &attr, wrapper, arg);
pthread_join(tid, NULL);

pi = calc_pi();
printf("Pi is estimated at ==> %f\n\n", pi);

return 1;
}

void * wrapper(void * arg){
random_point();
count_inside();
pthread_exit(arg);
}

and this was the makefile

XX:=gcc
CXXFLAGS:=-Wall -g -pg
LDFLAGS:= -pg -pthread -fopenmp

monty_pi_omp : monty_pi_omp.o pi_lib.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o monty_pi_omp.exe monty_pi_omp.o
pi_lib.o

monty_pi : monty_pi.o pi_lib.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o monty_pi.exe monty_pi.o pi_lib.o

monty_pi_omp.o : monty_pi_omp.c pi_lib.h
$(CXX) $(CXXFLAGS) $(LDFLAGS) -c monty_pi_omp.c

monty_pi.o : monty_pi.c pi_lib.h
$(CXX) $(CXXFLAGS) $(LDFLAGS) -c monty_pi.c

pi_lib.o : pi_lib.h pi_lib.c
$(CXX) $(CXXFLAGS) $(LDFLAGS) -c pi_lib.c

include make.deps
make.deps: *.c; ${CXX} ${CXXFLAGS} -M *.c >$-at-

  1. 2015-04-01 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] omp pthread madness
  2. 2015-04-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: omp pthread madness
  3. 2015-04-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Re: omp pthread madness
  4. 2015-04-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: [New discussion] which technologies/skills are good to have
  5. 2015-04-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: omp pthread madness
  6. 2015-04-02 mrbrklyn-at-panix.com Subject: [NYLXS - HANGOUT] [LinuxJournalservices-at-linuxjournalservices.com: Free Geek
  7. 2015-04-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Fw: Perl Developer / Linux SysAdmin Opportunities in South Florida
  8. 2015-04-07 Elfen Magix <elfen_magix-at-yahoo.com> Subject: [NYLXS - HANGOUT] Low Cost or Free Raspberry Pi's?
  9. 2015-04-07 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Let My People Go
  10. 2015-04-08 Rick Moen <rick-at-linuxmafia.com> Subject: [NYLXS - HANGOUT] (forw) Re: DistroWatch.com: Put the fun back into computing. Use
  11. 2015-04-08 adrba-at-nyct.net Re: [NYLXS - HANGOUT] Let My People Go
  12. 2015-04-08 adrba-at-nyct.net Re: [NYLXS - HANGOUT] JOUNAL MEETING AT 10AM TOMORROW
  13. 2015-04-08 Steven Ovadia <steve.ovadia-at-gmail.com> Subject: [NYLXS - HANGOUT] Explore Privacy Issues at the LACUNY Institute!
  14. 2015-04-09 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Re: Kernel thread scheduling
  15. 2015-04-09 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Re: Kernel thread scheduling
  16. 2015-04-10 Elfen Magix <elfen_magix-at-yahoo.com> Subject: [NYLXS - HANGOUT] Bulk Raspberry Pi Deal A Failure.
  17. 2015-04-12 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Kernel Hacking Workshop - Focusing on the CFS Scheduler
  18. 2015-04-13 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Schedule Meetings
  19. 2015-04-13 Robert Menes <viewtiful.icchan-at-gmail.com> Re: [NYLXS - HANGOUT] Schedule Meetings
  20. 2015-04-13 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Kernel Hacking Resources
  21. 2015-04-14 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Invitation: Vintage Computer Festival
  22. 2015-04-14 einker <eminker-at-gmail.com> Re: [NYLXS - HANGOUT] Fwd: Invitation: Vintage Computer Festival
  23. 2015-04-15 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Monday: Join 121 HackerNestologists at "HackerNest NYC April
  24. 2015-04-15 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [ruben-at-mrbrklyn.com: Re: Heap Management Problem]
  25. 2015-04-15 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: [HackerNestNYC] Security Info for Monday's HackerNest NYC
  26. 2015-04-15 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Re: [LIU Comp Sci] BASh Shell Scripting
  27. 2015-04-16 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] Schedule Meetings
  28. 2015-04-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] linsched
  29. 2015-04-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Re: virtualbox
  30. 2015-04-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Re: Kernel thread scheduling
  31. 2015-04-17 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Kernel Scheduling Project
  32. 2015-04-17 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Graduate School goes in circles
  33. 2015-04-17 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Come Sunday Morning
  34. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Re: The more I learn the less I know
  35. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] interesting jobs
  36. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] marco typeof and 0
  37. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Summers Here
  38. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Re: [LIU Comp Sci] Fwd: [NYLXS - HANGOUT] Summers Here
  39. 2015-04-19 Ruben <mrbrklyn-at-panix.com> Re: [LIU Comp Sci] Fwd: [NYLXS - HANGOUT] Summers Here
  40. 2015-04-19 Elfen Magix <elfen_magix-at-yahoo.com> Re: [NYLXS - HANGOUT] Summers Here
  41. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Syria and Sarin Gas
  42. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] extract video
  43. 2015-04-19 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] Syria and Sarin Gas
  44. 2015-04-20 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] sytemd crimes
  45. 2015-04-20 Ruben <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] OS Homework
  46. 2015-04-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Skinner Box
  47. 2015-04-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Business children and Privacy
  48. 2015-04-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] nukes in NYC
  49. 2015-04-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] nukes in NYC
  50. 2015-04-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Nukes over NYC
  51. 2015-04-24 adrba-at-nyct.net Re: [NYLXS - HANGOUT] Summers Here LET'S
  52. 2015-04-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Fwd: Kernel Scheduling and wait queues
  53. 2015-04-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] While the weather is heating up ...
  54. 2015-04-27 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] While the weather is heating up ...
  55. 2015-04-27 mrbrklyn-at-panix.com Subject: [NYLXS - HANGOUT] [info-at-fsf.org: DMCA exemption commenting process broken beyond
  56. 2015-04-28 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Re: Arduino article for next Linux Journal
  57. 2015-04-28 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] final project - Linux Scheduler
  58. 2015-04-29 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] trolling newsgroupds
  59. 2015-04-30 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] usenet and systemd
  60. 2015-04-30 Elfen Magix <elfen_magix-at-yahoo.com> Subject: [NYLXS - HANGOUT] NYC ROBO Conference

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!