PPL: error C3861: 'parallel_for': identifier not found - ppl

using win7 x86 and vs2012
I have such code:
#include <ppl.h>
#include "concurrent_vector.h"
.....
int pretendletternum[16];
parallel_for(int(0), pretendletternum[vs[vs.size()-1].index], [=,&wordd](int a1)
{
wchar_t worddd[17]; memcpy(worddd,wordd,sizeof(wchar_t)*wordlenght);
int pretset1 = 0;
int index1 =vs[vs.size()-1].index;
worddd[index1] = (wchar_t)pretendletter[index1][a1];
pretset1|=(1<<index1);
for(int a2 = 0; (questionnum>1)&&(a2<pretendletternum[vs[vs.size()-2].index]);a2++)
{
int index2 = vs[vs.size()-2].index;
worddd[index2] = (wchar_t)pretendletter[index2][a2];
int pretset2 = pretset1;
pretset2|=(1<<index2);
for(int a3 = 0; (questionnum>2)&&(a3<pretendletternum[vs[vs.size()-3].index]);a3++)
{
int index3 = vs[vs.size()-3].index;
worddd[index3] = (wchar_t)pretendletter[index3][a3];
int pretset3 = pretset2;
pretset3|=(1<<index3);
if(!(CheckLetterInWordWithoutSaveUni(worddd,index3,pretset3))) continue;
else if (questionnum==3) { SaveFoundWordParallel(worddd,wordlenght); continue;}
for(int a4 = 0; (questionnum>3)&&(a4<pretendletternum[vs[vs.size()-4].index]);a4++)
{
int index4 = vs[vs.size()-4].index;
worddd[index4] = (wchar_t)pretendletter[index4][a4];
int pretset4 = pretset3;
pretset4|=(1<<index4);
if(!(CheckLetterInWordWithoutSaveUni(worddd,index4,pretset4))) continue;
else if (questionnum==4) { SaveFoundWordParallel(worddd,wordlenght); continue;}
...
});
Get a such error
error C3861: 'parallel_for': identifier not found
but visual studio gives "goto definition" and I have very similar project where it compiles well. And vs can "-" my parallel_for abstract

Try writing it so: concurrency::parallel_for
Or just declare using namespace concurrency beforehand

Related

MQL5 Invalid array access error when trying to access first element of an array

I have a condition which checks if the latest fast moving average value is above or below the slow moving average and if the bid price is above or below the fast ma.
But I am getting this compile error:
The iMA function is returning data.
Here is my code:
int fast_ma_handle;
int slow_ma_handle;
int OnInit()
{
fast_ma_handle = iMA(_Symbol,_Period,8,0,MODE_EMA,PRICE_CLOSE);
slow_ma_handle = iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
double fast_ma_array[], slow_ma_array[];
int copied1 = CopyBuffer(fast_ma_handle,0,0,1,fast_ma_array);
int copied2 = CopyBuffer(slow_ma_handle,0,0,1,slow_ma_array);
double bid_price = SymbolInfoDouble(_Symbol,SYMBOL_BID);
int trend_direction = 0;
if(fast_ma_array[0] > slow_ma_array[0] && bid_price > fast_ma_array)
trend_direction = 1;
else if(fast_ma_array[0] < slow_ma_array[0] && bid_price < fast_ma_array)
trend_direction = -1;
}
Thanks
You have a couple of mistakes in your code. I've corrected it for you.
int fast_ma_handle;
int slow_ma_handle;
int OnInit()
{
fast_ma_handle = iMA(_Symbol,_Period,8,0,MODE_EMA,PRICE_CLOSE);
slow_ma_handle = iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
void OnTick()
{
double fast_ma_array[], slow_ma_array[];
ArraySetAsSeries(fast_ma_array, true);
ArraySetAsSeries(slow_ma_array, true);
int copied1 = CopyBuffer(fast_ma_handle,0,0,100,fast_ma_array);
int copied2 = CopyBuffer(slow_ma_handle,0,0,100,slow_ma_array);
double bid_price = SymbolInfoDouble(_Symbol,SYMBOL_BID);
int trend_direction = 0;
if(fast_ma_array[0] > slow_ma_array[0] && bid_price > fast_ma_array[0])
trend_direction = 1;
else if(fast_ma_array[0] < slow_ma_array[0] && bid_price < fast_ma_array[0])
trend_direction = -1;
}

Replacement for deprecated NXOpenEventStatus?

I need to get the tracking speed of the mouse on OSX 10.13. I found this code on the internet but NXOpenEventStatus is deprecated (as is IOHIDGetAccelerationWithKey), is there an alternative way?
#include <stdio.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/hidsystem/event_status_driver.h>
int main()
{
kern_return_t kr;
double trackpadAcceleration, mouseAcceleration;
NXEventHandle h = 0;
h = NXOpenEventStatus();
if (h == nil)
return -1;
kr = IOHIDGetAccelerationWithKey( h, CFSTR(kIOHIDMouseAccelerationType), &mouseAcceleration);
return 0;
}
Since NXOpenEventStatus and IOHIDGetAccelerationWithKey are both part of the open-source IOKit distribution, you can look at how they're implemented. It turns out we can do what those functions do, using only non-deprecated functions.
To boil it down to the bare minimum, you can get a dictionary of the HID system's properties like this:
#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/IOHIDLib.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
io_service_t service = IORegistryEntryFromPath(kIOMasterPortDefault, kIOServicePlane ":/IOResources/IOHIDSystem");
CFDictionaryRef parameters = IORegistryEntryCreateCFProperty(service, CFSTR(kIOHIDParametersKey), kCFAllocatorDefault, kNilOptions);
NSLog(#"%#", parameters);
IOObjectRelease(service);
}
return 0;
}
Output (for me on macOS 10.13.4):
2018-04-05 17:06:55.560590-0500 accel[11924:131983] {
ActuateDetents = 1;
Clicking = 0;
DragLock = 0;
Dragging = 0;
EjectDelay = 0;
FirstClickThreshold = 1;
ForceSuppressed = 0;
HIDClickSpace = (
5,
5
);
HIDClickTime = 500000000;
HIDDefaultParameters = 1;
HIDF12EjectDelay = 250;
HIDFKeyMode = 1;
HIDInitialKeyRepeat = 250000000;
HIDKeyRepeat = 33333333;
HIDKeyboardModifierMappingPairs = (
);
HIDMouseAcceleration = 98304;
HIDMouseKeysOptionToggles = 0;
HIDPointerAcceleration = 45056;
HIDPointerButtonMode = 2;
HIDScrollAcceleration = 20480;
HIDScrollZoomModifierMask = 262144;
HIDSlowKeysDelay = 0;
HIDStickyKeysDisabled = 0;
HIDStickyKeysOn = 0;
HIDStickyKeysShiftToggles = 0;
HIDTrackpadAcceleration = 57344;
HIDWaitCursorFrameInterval = 16666667;
JitterNoClick = 1;
JitterNoMove = 1;
MouseButtonDivision = 55;
MouseButtonMode = TwoButton;
MouseHorizontalScroll = 1;
MouseMomentumScroll = 1;
MouseOneFingerDoubleTapGesture = 0;
MouseTwoFingerDoubleTapGesture = 0;
MouseTwoFingerHorizSwipeGesture = 0;
MouseVerticalScroll = 1;
"OutsidezoneNoAction When Typing" = 1;
"PalmNoAction Permanent" = 1;
"PalmNoAction When Typing" = 1;
SecondClickThreshold = 1;
"Trackpad Jitter Milliseconds" = 192;
TrackpadCornerSecondaryClick = 0;
TrackpadFiveFingerPinchGesture = 0;
TrackpadFourFingerHorizSwipeGesture = 2;
TrackpadFourFingerPinchGesture = 0;
TrackpadFourFingerVertSwipeGesture = 0;
TrackpadHandResting = 1;
TrackpadHorizScroll = 1;
TrackpadMomentumScroll = 1;
TrackpadPinch = 1;
TrackpadRightClick = 1;
TrackpadRotate = 1;
TrackpadScroll = 1;
TrackpadThreeFingerDrag = 0;
TrackpadThreeFingerHorizSwipeGesture = 2;
TrackpadThreeFingerTapGesture = 0;
TrackpadThreeFingerVertSwipeGesture = 0;
TrackpadThreeFingersRightClick = 0;
TrackpadTwoFingerDoubleTapGesture = 1;
TrackpadTwoFingerFromRightEdgeSwipeGesture = 0;
TwofingerNoAction = 1;
USBMouseStopsTrackpad = 0;
"Use Panther Settings for W" = 0;
UserPreferences = 1;
version = 1;
}
Program ended with exit code: 0
The kIOHIDMouseAccelerationType constant has value HIDMouseAcceleration. I also see HIDPointerAcceleration and HIDTrackpadAcceleration in there. There are kIOHID... constants for those too.
Note also that IOHIDGetAccelerationWithKey divides the registry value by 65536 before returning it. IOHIDSetAccelerationWithKey performs the opposite transformation.

compare images using systemC

I wrote in this forum asking for help to solve this problem that took ame a lot of my time,i write my first program using systemC, I will expain my aim as much as I can , I stored 2 matrix of pixel value of image in two different text files, I write a systemC code that load two matrix and apply somme of absolute difference, if number of different superior of a Threshold the code displays message (motion).
My code composed of two modules, the first module check if there a number stored in a text file, if yes this Module will automates the other module to load the two matrix and compare them, I really need this code for my project graduation any help or suggestion.
#include "systemC.h"
#include "string.h"
#include "stdio.h"
#include"stdlib.h"
#include <time.h>
#include <math.h> /* fabs */
#include <fstream>
#include <iostream>
#include <fstream>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
double elapsed;
int H = 0;
int D = 0;
int a, b;
int in = false;
int L = 0;
char *mode1 = "r";
char *mode2 = "w";
int i, j, k;
int rows1, cols1, rows2, cols2;
bool fileFound = false;
FILE *SwitchContext;
FILE *image1;
FILE *image2;
FILE *image3;
int sum = 0;
clock_t start = clock();
SC_MODULE(synchronization)
{
sc_in<bool>sig ;
SC_CTOR(synchronization)
{
SC_METHOD(synchroprocess)
}
void synchroprocess()
{
cout << "\n Running Automation";
SwitchContext = fopen("F:/SWITCH CONTEXT.txt", mode2);
fscanf(SwitchContext, "%d", &L);
while (L != 0)
{
cout << "waiting...";
}
sig == true;
}
};
SC_MODULE(imageProcess)
{
sc_in<bool>sig;
SC_CTOR(imageProcess)
{
SC_METHOD(MotionDetector)
sensitive(sig);
}
void MotionDetector()
{
image3 = fopen("F:/image3.txt", mode2);
do
{
char *mode1 = "r";
char *mode2 = "w";
image1 = fopen("F:/image1.txt", mode1);
if (!image1)
{
printf("File Not Found!!\n");
fileFound = true;
}
else
fileFound = false;
}
while (fileFound);
do
{
image2 = fopen("F:/image2.txt", mode1);
if (!image2)
{
printf("File Not Found!!\n");
fileFound = true;
}
else
fileFound = false;
}
while (fileFound);
rows1 = rows2 = 384;
cols1 = cols2 = 512;
int **mat1 = (int **)malloc(rows1 * sizeof(int*));
for (i = 0; i < rows1; i++)
mat1[i] = (int *)malloc(cols1 * sizeof(int));
i = 0;
int **mat2 = (int **)malloc(rows2 * sizeof(int*));
for (i = 0; i < rows2; i++)
mat2[i] = (int *)malloc(cols2 * sizeof(int));
i = 0;
while (!feof(image1))
{
for (i = 0; i < rows1; i++)
{
for (j = 0; j < cols1; j++)
fscanf(image1, "%d%", &mat1[i][j]);
}
}
i = 0;
j = 0;
while (!feof(image2))
{
for (i = 0; i < rows2; i++)
{
for (j = 0; j < cols2; j++)
fscanf(image2, "%d%", &mat2[i][j]);
}
}
i = 0;
j = 0;
printf("\n\n");
for (i = 0; i < rows1; i++)
{
for (j = 0; j < cols1; j++) {
a = abs(mat1[i][j] = mat2[i][j]);
b = b + a;
}
}
i = j = 0;
D = b / 196608;
if (D > 0.9)
{
printf("%d,&K");
printf("MOTION...DETECTED");
getchar();
sc_pause;
for (i = 0; i < rows1; i++) {
for (j = 0; j < cols1; j++)
{
fprintf(image3, "%d ", mat2[i][j]);
}
fprintf(image3, "\n");
}
printf("\n Image Saved....");
std::ofstream mon_fichier("F:\toto.txt");
mon_fichier << elapsed << '\n';
}
fclose(image1);
fclose(image2);
fclose(image3);
clock_t end = clock();
elapsed = ((double)end - start) / CLOCKS_PER_SEC;
printf("time is %f", elapsed);
}
};
int sc_main(int argc, char* argv[])
{
imageProcess master("EE2");
master.MotionDetector();
sc_start();
return(0);
}
What you did is basically wrong.
You copy pasted code to SC_MODULE, this code is simple C code
(Do not mix C and C++ files)
This is not how you use clock
What you should do:
You need to check if your algorithm works, for this you do not need SystemC at all
Then you can replace data types with HW one and check if it still works
Then you have to find which data interface is used in HW and how to use this interface
Then you have to tweak your alg. to work with this interface (There you can use SC_MODULE, sc ports etc...)
Also take look at SC_CTHREAD, you will need it.
Without any informations about target platform I can not provide any other help.

Flat buffers : Object serialization must not be nested

FlatBufferBuilder fbb = new FlatBufferBuilder(1024);
String directory = "/Users/samarnath/RmsOne/CreateFlatBuffer/src/com/rms/objects/resources";
File [] policyfiles = ReturnFilesWithPattern(directory, "singlecoverriskpolicy");
for (File file: policyfiles)
{
Long StructureId = 0L;
int insurer = 0;
int insured = 0;
int UnderWriter = 0;
int inception = 0;
int Expiration = 0;
int ExternalID = 0;
Long SubjectId =0L;
int SubjectName = 0;
int SubjectStructureName = 0;
int Share = 0;
Double blanketLimit = 0.0;
Double attachment = 0.0;
int causeofLoss = 0;
int maxDeductible = 0;
int attachmentCurrency = 0;
int offset= 0;
int deductibleCurrencyOffset = 0;
int createOffset =0;
int blanketLimitCurrency = 0;
String folderName = "nfs://dev-spark-share.lab.rmsonecloud.net/mnt/data/UserData/import/outputfiles/Job_5/SmokeTest_2M/eufl_only_client4_2_edm__20151203-134544__24/contract/";
List<String> lines = Files.readAllLines(file.toPath());
List<String> actualLines = lines.subList(1, lines.size());
for (String line:actualLines)
{
String [] riskitems = line.split("~");
SingleCoverRiskPolicy.startSingleCoverRiskPolicy(fbb);
Long Id = Long.parseLong(riskitems[0]);
int policyName = fbb.createString(riskitems[1]);
After the above line i get an error saying Exception in thread "main" java.lang.AssertionError: FlatBuffers: object serialization must not be nested.I get an error in fbb.createString.
The code is simple and i cant figure out whats wrong here
From the documentation: "Everything else (other tables, strings, vectors) MUST be created before the start of the table they are referenced in."
So move int policyName = fbb.createString(riskitems[1]) and any other strings/vectors/tables you reference in SingleCoverRiskPolicy to before startSingleCoverRiskPolicy.

How can I change TermFreVector in Lucene 4.0

Here is the code:
public int docLength(String filename) throws IOException {
int length = 0;
TermFreqVector t = indexReader.getTermFreqVector(0, "contents");
for (int i = 0; i < t.getTermFrequencies().length; i++) {
length += t.getTermFrequencies()[i];
}
return length;
}
public int docLength(int id) throws IOException {
int length = 0;
TermFreqVector t = indexReader.getTermFreqVector(id, "contents");
for (int i = 0; i < t.getTermFrequencies().length; i++) {
length += t.getTermFrequencies()[i];
}
return length;
}
The error is :
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
TermFreqVector cannot be resolved to a type
The method getTermFreqVector(int, String) is undefined for the type IndexReader
at BM25.docLength(BM25.java:96)
at BM25.avgDocLength(BM25.java:130)
Accessing and traversing term vectors changed significantly in 4.0. The Migration Guide is a very helpful resource on that and other changes from 3.6 to 4.0.
In this case, you'll need to access a Terms instance through a call to IndexReader.getTermVector:
int length = 0;
TermEnum terms = indexReader.getTermVector(id, "contents").iterator();
while (terms.next())
length += terms.totalTermFreq(null);
return length;