-
Notifications
You must be signed in to change notification settings - Fork 245
Description
I defined PFC pfc(AES_SECURITY);
in the main function, And refer to the openMP library and threadmp.cpp to calculate pk = pfc.mult(g, s);
with multiple threads:
//omp_set_num_threads(1); // pass
omp_set_num_threads(2); // error
#pragma omp parallel for
for (int i = 0; i < 100; i++)
{
G1 pk;
pk = pfc.mult(g, s); // public key
cout << pk.g << endl;
}
but an error will be reported during execution, and the content of each error report is different. The following is the content of a certain error report:
MIRACL error from routine nres_modadd
called from nres_modmult
called from ecurve_add
called from nres_modmult
called from ecurve_add
called from your program
Overflow - Number too big
I also tried other multithreading libraries, mutexes, and web frameworks (crow) to try parallel computing, but I still can't solve the problem of pfc parameter passing.
How should I use pfc functions such as pfc.hash_to_aes_key()
, pfc.pairing()
, pfc.hash_and_map()
, etc. in multithreading? Thanks a lot!
I am using Visual Studio 2022 on Windows 11 to compile and execute the code through Debug-win32. The complete code of the main.cpp and mirdef.h files is as follows:
// main.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include<omp.h>
#define _CRT_SECURE_NO_WARNINGS
//security define
#define AES_SECURITY 128
#define MR_PAIRING_SSP
#include "pairing_1.h"
#include "ssp_pair.h"
#include "miracl.h"
#include "mirdef.h"
using namespace std;
int main()
{
PFC pfc(AES_SECURITY);
G1 g,pk;
Big s;
time_t seed;
time(&seed);
irand((long)seed);
pfc.random(g);
pfc.precomp_for_mult(g); // precompute on fixed g
pfc.random(s); // mk=s
//omp_set_num_threads(1); // pass
omp_set_num_threads(2); // error
#pragma omp parallel for
for (int i = 0; i < 100; i++)
{
G1 pk;
pk = pfc.mult(g, s); // public key
cout << pk.g << endl;
}
}
// mirdef.h
#define MIRACL 32
#define MR_LITTLE_ENDIAN /* This may need to be changed */
#define mr_utype int
/* the underlying type is usually int *
* but see mrmuldv.any */
#define mr_unsign32 unsigned int
/* 32 bit unsigned type */
#define MR_IBITS 32 /* bits in int */
#define MR_LBITS 32 /* bits in long */
#define MR_FLASH 52
/* delete this definition if integer *
* only version of MIRACL required */
/* Number of bits per double mantissa */
#define mr_dltype __int64 /* ... or long long for Unix/Linux */
#define mr_unsign64 unsigned __int64
#define MAXBASE ((mr_small)1<<(MIRACL-1))
#define MR_OPENMP_MT