Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2477 Discussions

error #137: expression must be a modifiable lvalue

Ö__D_
Beginner
3,321 Views

Hello,

I have "expression must be a modifiable lvalue" error in compile time. I've tried to compile both icpc and g++ but nothing changed. I'm trying to learn TBB and try to write findMinFloat "finding mininmum element of float array" with parallel_reduce.  My code block is at the below. I have the error while overloading operator() but I do not have while writing a regular function such as foo(). What can be my problem ? 

class findMinFloat
{
    public:
        float *farr;
        int size;
        float minValue;
        int minIndex;
        void operator()(const blocked_range<int> & range) const
        {
            for(int i = range.begin(); i < range.end(); i++)
            {
                if(farr<minValue)
                {
            //        cout<<farr<<endl;
                    minValue    =    farr; // error #137: expression must be a modifiable lvalue
                    minIndex    =    i;/**/    // error #137: expression must be a modifiable lvalue
                }
            }
        }
        void foo()
        {
            for(int i =0; i < 100; i++)
            {
                if(farr<minValue)
                {
                    minValue    =    farr; //NO ERROR
                    minIndex    =    i;/**/   //NO ERROR
                }
            }
        }
    /*    findMinFloat(float *fp)
        {
            farr    =    fp;
            size =    100;
            minValue = 500;
            minIndex = -1;
        }

/*        findMinFloat(findMinFloat &x, split):
            farr(x.farr), minValue(500), minIndex(-1),size(100)
        {};/**/

};/**/

0 Kudos
2 Replies
Alexey-Kukanov
Employee
3,321 Views

The operator()() of the body class for parallel_reduce should not be const.

0 Kudos
Ö__D_
Beginner
3,321 Views

Alexey Kukanov (Intel) wrote:

The operator()() of the body class for parallel_reduce should not be const.

Thanks for your answer. It solves my problem.

0 Kudos
Reply