Sponsored Content
Full Discussion: Program in parallel
Top Forums Programming Program in parallel Post 302623833 by bestb on Saturday 14th of April 2012 08:02:33 PM
Old 04-14-2012
Quote:
Originally Posted by Corona688
The simplest way would be to run four copies of the program, each checking a different range of numbers.
ok I changed to this... what you think?

Code:
#include <cmath> 
#include <iostream> 

#define N 10000 

using namespace std; i

int main() 
{
	int i,j, 
		square; 
	bool orFirst[N+1], 
		 orSquare[N+1]; 
	#pragma omp parallel for 
	for (i=1;i<=N;i++) 
	{
		square=sqrt(i); 
		#pragma omp sections
		{
			#pragma omp section 
			{
				orFirst[i]=true; 
				for (j=2;j<=square;j++) 
					if (i%j==0) 
					{
						orFirst[i]=false; 
						break; 
					}
			}
			#pragma omp section 
			{
				if (square*square==i) 
					orSquare[i]=true; 
				else 
					orSquare[i]=false; 
			}
		}
	}
	orFirst[1]=false; 
	cout<<"First No in range 1-10000: ";
	for (i=1;i<=N;i++) 
		if (orFirst[i]==true) 
			cout<<i<<" "; 
	cout<<"\n\nSquare No in the range of 1-10000: ";
	for (i=1;i<=N;i++) 
		if (orSquare[i]==true) 
			cout<<i<<" "; 
	cin.get(); 
	return 0; 
}

 

10 More Discussions You Might Find Interesting

1. Programming

running a parallel program

hi , i need to run a parallel program . for example; program1 { array=" the second program should called here : program 2" the execution should continue } the 2nd program should recieve an array of information as argument and it should... (4 Replies)
Discussion started by: bankpro
4 Replies

2. Shell Programming and Scripting

parallel processing

Hi I want to run two shell script files parallely. These two scripts are interacting with the database. can any body help on this Pls Regards Audippa naidu.M (3 Replies)
Discussion started by: audippa
3 Replies

3. UNIX for Dummies Questions & Answers

Parallel processing using AWK program

Hi All, could any expert tell me about writing a parallel processing program using AWK program is possible or not? Any example would be much appreciated... With Regards / Mysore Ganapati :confused: (5 Replies)
Discussion started by: ganapati
5 Replies

4. Programming

A program to trace execution of another program

Hi, I wanted to know if i can write a program using switches and signals, etc to trace execution of other unix program which calls c program internally. If yes how? If not with signals and switches then are there any other methods apart from debugging with gdb/dbx. (3 Replies)
Discussion started by: jiten_hegde
3 Replies

5. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

6. Shell Programming and Scripting

FTP in parallel.

Hi, Can anyone let me know how I can run FTP scripts in parallel. I have a script for each file to perform an FTP from mainframe to Unix. I have many files that I need to transfer and each of them is thru a script. I want to run all the scripts in parallel to reduce the time taken for FTP.... (2 Replies)
Discussion started by: bornon2303
2 Replies

7. Programming

Python program faster than C++ program.

I wrote a simple program that generates a random word 10,000,000 times. I wrote it in python, then in C++ and compared the two completion times. The python script was faster! Is that normal? Why would the python script be faster? I was under the impression that C++ was faster. What are some of... (2 Replies)
Discussion started by: cbreiny
2 Replies

8. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

9. Programming

Parallel Processing Detection and Program Return Value Detection

Hey, for the purpose of a research project I need to know if a specific type of parallel processing is being utilized by any user-run programs. Is there a way to detect whether a program either returns a value to another program at the end of execution, or just utilizes any form of parallel... (4 Replies)
Discussion started by: azar.zorn
4 Replies

10. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies
__gnu_parallel::_Lexicographic< _T1, _T2, _Compare >(3)      Library Functions Manual	   __gnu_parallel::_Lexicographic< _T1, _T2, _Compare >(3)

NAME
__gnu_parallel::_Lexicographic< _T1, _T2, _Compare > - SYNOPSIS
Inherits std::binary_function< std::pair< _T1, _T2 >, std::pair< _T1, _T2 >, bool >. Public Types typedef std::pair< _T1, _T2 > first_argument_type typedef bool result_type typedef std::pair< _T1, _T2 > second_argument_type Public Member Functions _Lexicographic (_Compare &__comp) bool operator() (const std::pair< _T1, _T2 > &__p1, const std::pair< _T1, _T2 > &__p2) const Detailed Description template<typename _T1, typename _T2, typename _Compare>class __gnu_parallel::_Lexicographic< _T1, _T2, _Compare > Compare __a pair of types lexicographically, ascending. Definition at line 53 of file multiseq_selection.h. Member Typedef Documentation typedef std::pair< _T1, _T2 > std::binary_function< std::pair< _T1, _T2 > , std::pair< _T1, _T2 > , bool >::first_argument_type [inherited] first_argument_type is the type of the first argument Definition at line 117 of file stl_function.h. typedef bool std::binary_function< std::pair< _T1, _T2 > , std::pair< _T1, _T2 > , bool >::result_type [inherited] result_type is the return type Definition at line 123 of file stl_function.h. typedef std::pair< _T1, _T2 > std::binary_function< std::pair< _T1, _T2 > , std::pair< _T1, _T2 > , bool >::second_argument_type [inherited] second_argument_type is the type of the second argument Definition at line 120 of file stl_function.h. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Jun 10 2014 __gnu_parallel::_Lexicographic< _T1, _T2, _Compare >(3)
All times are GMT -4. The time now is 07:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy