Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TParallel Not a Class?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Nov 25, 2014 12:18 PM Last Post By: Andrew McIsaac
Andrew McIsaac

Posts: 93
Registered: 3/12/13
TParallel Not a Class?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 25, 2014 12:48 AM
Good morning,
Using C++ XE7 Enterprise, Target : VCL
This should be easy, followed simple examples, but can not make it work.

It does not Recognize the TParallel - is not a class or namespace name ? for me :(

Two buttons to count number of primes, 1 is regular for loop, other is TParallel For Loop, as per the given examples, I omitted the stopwatch timers.
Within .h file ( Form1)

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button_For;
TButton *Button_PPL_For;
void __fastcall Button_ForClick(TObject *Sender);
void __fastcall Button_PPL_ForClick(TObject *Sender);
private: // User declarations
void __fastcall MyIteratorEvent(TObject* Sender,int AIndex);
public: // User declarations
int Tot;
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Form1 .cpp :

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;

bool IsPrime(int N)
{
bool aPrime=true;
for (int Test=2; Test < N-1; Test++) {
if(N % Test == 0){
aPrime = false;
break;
}
}
return aPrime;
}

void __fastcall TForm1::MyIteratorEvent(TObject* Sender,int AIndex)
{
if(IsPrime(AIndex))
{
TInterlocked::Increment(Tot);
};
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button_ForClick(TObject *Sender)
{
int Max=50000;
Tot=0;
for (int I=1; I<=Max; I++) {
if(IsPrime(I)){
Tot++;
}
}
Button_For->Caption=Tot;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button_PPL_ForClick(TObject *Sender)
{
int Max= 50000;
Tot=0;
TParallel::For(NULL,1,Max,MyIteratorEvent);
Button_PPL_For->Caption=Tot;
}

Also verified no Updates Available for my install of XE7.

I don't understand how I am getting a not a Class error.

Thanks in advance,
Andrew

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TParallel Not a Class?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 25, 2014 12:12 PM   in response to: Andrew McIsaac in response to: Andrew McIsaac
Andrew wrote:

Using C++ XE7 Enterprise, Target : VCL
This should be easy, followed simple examples, but can not make it
work.
It does not Recognize the TParallel - is not a class or namespace name
? for me :(

Add this header file include to your code:

#include <System.Threading.hpp>


--
Remy Lebeau (TeamB)
Andrew McIsaac

Posts: 93
Registered: 3/12/13
Re: TParallel Not a Class?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 25, 2014 12:15 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks

Nice when its something simple.
No need to figure a Messed up Windows Setting ... :)

Thank you
Andrew.

Edited by: Andrew McIsaac on Nov 25, 2014 12:16 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02